18#include "ompt-specific.h"
25#define THREAD_LOCAL __declspec(thread)
27#define THREAD_LOCAL __thread
30#define OMPT_WEAK_ATTRIBUTE KMP_WEAK_ATTRIBUTE_INTERNAL
36#define LWT_FROM_TEAM(team) (team)->t.ompt_serialized_team_info
38#define OMPT_THREAD_ID_BITS 16
51ompt_team_info_t *__ompt_get_teaminfo(
int depth,
int *size) {
52 kmp_info_t *thr = ompt_get_thread();
55 kmp_team *team = thr->th.th_team;
59 ompt_lw_taskteam_t *next_lwt = LWT_FROM_TEAM(team), *lwt = NULL;
73 team = team->t.t_parent;
75 next_lwt = LWT_FROM_TEAM(team);
89 return &lwt->ompt_team_info;
93 *size = team->t.t_nproc;
96 return &team->t.ompt_team_info;
103ompt_task_info_t *__ompt_get_task_info_object(
int depth) {
104 ompt_task_info_t *info = NULL;
105 kmp_info_t *thr = ompt_get_thread();
108 kmp_taskdata_t *taskdata = thr->th.th_current_task;
109 ompt_lw_taskteam_t *lwt = NULL,
110 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
119 if (!lwt && taskdata) {
124 taskdata = taskdata->td_parent;
126 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
134 info = &lwt->ompt_task_info;
135 }
else if (taskdata) {
136 info = &taskdata->ompt_task_info;
143ompt_task_info_t *__ompt_get_scheduling_taskinfo(
int depth) {
144 ompt_task_info_t *info = NULL;
145 kmp_info_t *thr = ompt_get_thread();
148 kmp_taskdata_t *taskdata = thr->th.th_current_task;
150 ompt_lw_taskteam_t *lwt = NULL,
151 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
160 if (!lwt && taskdata) {
162 if (taskdata->ompt_task_info.scheduling_parent) {
163 taskdata = taskdata->ompt_task_info.scheduling_parent;
164 }
else if (next_lwt) {
169 taskdata = taskdata->td_parent;
171 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
179 info = &lwt->ompt_task_info;
180 }
else if (taskdata) {
181 info = &taskdata->ompt_task_info;
195void __ompt_force_initialization() { __kmp_serial_initialize(); }
201ompt_data_t *__ompt_get_thread_data_internal() {
202 if (__kmp_get_gtid() >= 0) {
203 kmp_info_t *thread = ompt_get_thread();
206 return &(thread->th.ompt_thread_info.thread_data);
215void __ompt_thread_assign_wait_id(
void *variable) {
216 kmp_info_t *ti = ompt_get_thread();
219 ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t)(uintptr_t)variable;
222int __ompt_get_state_internal(ompt_wait_id_t *omp_wait_id) {
223 kmp_info_t *ti = ompt_get_thread();
227 *omp_wait_id = ti->th.ompt_thread_info.wait_id;
228 return ti->th.ompt_thread_info.state;
230 return ompt_state_undefined;
237int __ompt_get_parallel_info_internal(
int ancestor_level,
238 ompt_data_t **parallel_data,
240 if (__kmp_get_gtid() >= 0) {
241 ompt_team_info_t *info;
243 info = __ompt_get_teaminfo(ancestor_level, team_size);
245 info = __ompt_get_teaminfo(ancestor_level, NULL);
248 *parallel_data = info ? &(info->parallel_data) : NULL;
260void __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
int gtid,
261 ompt_data_t *ompt_pid,
void *codeptr) {
264 lwt->ompt_team_info.parallel_data = *ompt_pid;
265 lwt->ompt_team_info.master_return_address = codeptr;
266 lwt->ompt_task_info.task_data.value = 0;
267 lwt->ompt_task_info.frame.enter_frame = ompt_data_none;
268 lwt->ompt_task_info.frame.exit_frame = ompt_data_none;
269 lwt->ompt_task_info.frame.enter_frame_flags = OMPT_FRAME_FLAGS_RUNTIME;
270 lwt->ompt_task_info.frame.exit_frame_flags = OMPT_FRAME_FLAGS_RUNTIME;
271 lwt->ompt_task_info.scheduling_parent = NULL;
276void __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
277 int on_heap,
bool always) {
278 ompt_lw_taskteam_t *link_lwt = lwt;
280 thr->th.th_team->t.t_serialized >
284 (ompt_lw_taskteam_t *)__kmp_allocate(
sizeof(ompt_lw_taskteam_t));
286 link_lwt->heap = on_heap;
289 ompt_team_info_t tmp_team = lwt->ompt_team_info;
290 link_lwt->ompt_team_info = *OMPT_CUR_TEAM_INFO(thr);
291 *OMPT_CUR_TEAM_INFO(thr) = tmp_team;
294 ompt_lw_taskteam_t *my_parent =
295 thr->th.th_team->t.ompt_serialized_team_info;
296 link_lwt->parent = my_parent;
297 thr->th.th_team->t.ompt_serialized_team_info = link_lwt;
299 if (ompd_state & OMPD_ENABLE_BP) {
300 ompd_bp_parallel_begin();
304 ompt_task_info_t tmp_task = lwt->ompt_task_info;
305 link_lwt->ompt_task_info = *OMPT_CUR_TASK_INFO(thr);
306 *OMPT_CUR_TASK_INFO(thr) = tmp_task;
310 *OMPT_CUR_TEAM_INFO(thr) = lwt->ompt_team_info;
312 if (ompd_state & OMPD_ENABLE_BP) {
313 ompd_bp_parallel_begin();
316 *OMPT_CUR_TASK_INFO(thr) = lwt->ompt_task_info;
320void __ompt_lw_taskteam_unlink(kmp_info_t *thr) {
321 ompt_lw_taskteam_t *lwtask = thr->th.th_team->t.ompt_serialized_team_info;
323 ompt_task_info_t tmp_task = lwtask->ompt_task_info;
324 lwtask->ompt_task_info = *OMPT_CUR_TASK_INFO(thr);
325 *OMPT_CUR_TASK_INFO(thr) = tmp_task;
327 if (ompd_state & OMPD_ENABLE_BP) {
328 ompd_bp_parallel_end();
331 thr->th.th_team->t.ompt_serialized_team_info = lwtask->parent;
333 ompt_team_info_t tmp_team = lwtask->ompt_team_info;
334 lwtask->ompt_team_info = *OMPT_CUR_TEAM_INFO(thr);
335 *OMPT_CUR_TEAM_INFO(thr) = tmp_team;
349ompt_data_t *__ompt_get_task_data() {
350 kmp_info_t *thr = ompt_get_thread();
351 ompt_data_t *task_data = thr ? OMPT_CUR_TASK_DATA(thr) : NULL;
355ompt_data_t *__ompt_get_target_task_data() {
356 return &__kmp_threads[__kmp_get_gtid()]->th.ompt_thread_info.target_task_data;
359int __ompt_get_task_info_internal(
int ancestor_level,
int *type,
360 ompt_data_t **task_data,
361 ompt_frame_t **task_frame,
362 ompt_data_t **parallel_data,
364 if (__kmp_get_gtid() < 0)
367 if (ancestor_level < 0)
371 ompt_task_info_t *info = NULL;
372 ompt_team_info_t *team_info = NULL;
373 kmp_info_t *thr = ompt_get_thread();
374 int level = ancestor_level;
377 kmp_taskdata_t *taskdata = thr->th.th_current_task;
378 if (taskdata == NULL)
380 kmp_team *team = thr->th.th_team, *prev_team = NULL;
383 ompt_lw_taskteam_t *lwt = NULL,
384 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
386 while (ancestor_level > 0) {
393 if (!lwt && taskdata) {
395 if (taskdata->ompt_task_info.scheduling_parent) {
396 taskdata = taskdata->ompt_task_info.scheduling_parent;
397 }
else if (next_lwt) {
402 taskdata = taskdata->td_parent;
406 team = team->t.t_parent;
408 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
416 info = &lwt->ompt_task_info;
417 team_info = &lwt->ompt_team_info;
419 *type = ompt_task_implicit;
421 }
else if (taskdata) {
422 info = &taskdata->ompt_task_info;
423 team_info = &team->t.ompt_team_info;
425 if (taskdata->td_parent) {
426 *type = TASK_TYPE_DETAILS_FORMAT(taskdata);
428 *type = ompt_task_initial;
433 *task_data = info ? &info->task_data : NULL;
437 *task_frame = info ? &info->frame : NULL;
440 *parallel_data = team_info ? &(team_info->parallel_data) : NULL;
444 *thread_num = __kmp_get_tid();
447 else if (!prev_team) {
455 *thread_num = __kmp_get_tid();
457 *thread_num = prev_team->t.t_master_tid;
465int __ompt_get_task_memory_internal(
void **addr,
size_t *size,
int blocknum) {
470 kmp_info_t *thr = ompt_get_thread();
474 kmp_taskdata_t *taskdata = thr->th.th_current_task;
476 if (taskdata->td_flags.tasktype != TASK_EXPLICIT)
480 *size = taskdata->td_size_alloc;
488void __ompt_team_assign_id(kmp_team_t *team, ompt_data_t ompt_pid) {
489 team->t.ompt_team_info.parallel_data = ompt_pid;
496static uint64_t __ompt_get_unique_id_internal() {
497 static uint64_t thread = 1;
498 static THREAD_LOCAL uint64_t ID = 0;
500 uint64_t new_thread = KMP_TEST_THEN_INC64((kmp_int64 *)&thread);
501 ID = new_thread << (
sizeof(uint64_t) * 8 - OMPT_THREAD_ID_BITS);
506ompt_sync_region_t __ompt_get_barrier_kind(
enum barrier_type bt,
508 if (bt == bs_forkjoin_barrier) {
509 if (thr->th.ompt_thread_info.parallel_flags & ompt_parallel_league)
510 return ompt_sync_region_barrier_teams;
512 return ompt_sync_region_barrier_implicit_parallel;
515 if (bt != bs_plain_barrier || !thr->th.th_ident)
516 return ompt_sync_region_barrier_implementation;
518 kmp_int32 flags = thr->th.th_ident->flags;
521 return ompt_sync_region_barrier_explicit;
524 return ompt_sync_region_barrier_implicit_workshare;
526 return ompt_sync_region_barrier_implementation;