19 #include "ompt-specific.h" 26 #define THREAD_LOCAL __declspec(thread) 28 #define THREAD_LOCAL __thread 31 #define OMPT_WEAK_ATTRIBUTE KMP_WEAK_ATTRIBUTE 37 #define LWT_FROM_TEAM(team) (team)->t.ompt_serialized_team_info 39 #define OMPT_THREAD_ID_BITS 16 52 ompt_team_info_t *__ompt_get_teaminfo(
int depth,
int *size) {
53 kmp_info_t *thr = ompt_get_thread();
56 kmp_team *team = thr->th.th_team;
60 ompt_lw_taskteam_t *next_lwt = LWT_FROM_TEAM(team), *lwt = NULL;
74 team = team->t.t_parent;
76 next_lwt = LWT_FROM_TEAM(team);
90 return &lwt->ompt_team_info;
94 *size = team->t.t_nproc;
97 return &team->t.ompt_team_info;
104 ompt_task_info_t *__ompt_get_task_info_object(
int depth) {
105 ompt_task_info_t *info = NULL;
106 kmp_info_t *thr = ompt_get_thread();
109 kmp_taskdata_t *taskdata = thr->th.th_current_task;
110 ompt_lw_taskteam_t *lwt = NULL,
111 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
120 if (!lwt && taskdata) {
125 taskdata = taskdata->td_parent;
127 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
135 info = &lwt->ompt_task_info;
136 }
else if (taskdata) {
137 info = &taskdata->ompt_task_info;
144 ompt_task_info_t *__ompt_get_scheduling_taskinfo(
int depth) {
145 ompt_task_info_t *info = NULL;
146 kmp_info_t *thr = ompt_get_thread();
149 kmp_taskdata_t *taskdata = thr->th.th_current_task;
151 ompt_lw_taskteam_t *lwt = NULL,
152 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
161 if (!lwt && taskdata) {
163 if (taskdata->ompt_task_info.scheduling_parent) {
164 taskdata = taskdata->ompt_task_info.scheduling_parent;
165 }
else if (next_lwt) {
170 taskdata = taskdata->td_parent;
172 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
180 info = &lwt->ompt_task_info;
181 }
else if (taskdata) {
182 info = &taskdata->ompt_task_info;
197 ompt_data_t *__ompt_get_thread_data_internal() {
198 if (__kmp_get_gtid() >= 0) {
199 kmp_info_t *thread = ompt_get_thread();
202 return &(thread->th.ompt_thread_info.thread_data);
211 void __ompt_thread_assign_wait_id(
void *variable) {
212 kmp_info_t *ti = ompt_get_thread();
214 ti->th.ompt_thread_info.wait_id = (omp_wait_id_t)variable;
217 omp_state_t __ompt_get_state_internal(omp_wait_id_t *omp_wait_id) {
218 kmp_info_t *ti = ompt_get_thread();
222 *omp_wait_id = ti->th.ompt_thread_info.wait_id;
223 return ti->th.ompt_thread_info.state;
225 return omp_state_undefined;
232 int __ompt_get_parallel_info_internal(
int ancestor_level,
233 ompt_data_t **parallel_data,
235 if (__kmp_get_gtid() >= 0) {
236 ompt_team_info_t *info;
238 info = __ompt_get_teaminfo(ancestor_level, team_size);
240 info = __ompt_get_teaminfo(ancestor_level, NULL);
243 *parallel_data = info ? &(info->parallel_data) : NULL;
255 void __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
int gtid,
256 ompt_data_t *ompt_pid,
void *codeptr) {
259 lwt->ompt_team_info.parallel_data = *ompt_pid;
260 lwt->ompt_team_info.master_return_address = codeptr;
261 lwt->ompt_task_info.task_data.value = 0;
262 lwt->ompt_task_info.frame.enter_frame = NULL;
263 lwt->ompt_task_info.frame.exit_frame = NULL;
264 lwt->ompt_task_info.scheduling_parent = NULL;
265 lwt->ompt_task_info.deps = NULL;
266 lwt->ompt_task_info.ndeps = 0;
271 void __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
273 ompt_lw_taskteam_t *link_lwt = lwt;
274 if (thr->th.th_team->t.t_serialized >
278 (ompt_lw_taskteam_t *)__kmp_allocate(
sizeof(ompt_lw_taskteam_t));
280 link_lwt->heap = on_heap;
283 ompt_team_info_t tmp_team = lwt->ompt_team_info;
284 link_lwt->ompt_team_info = *OMPT_CUR_TEAM_INFO(thr);
285 *OMPT_CUR_TEAM_INFO(thr) = tmp_team;
287 ompt_task_info_t tmp_task = lwt->ompt_task_info;
288 link_lwt->ompt_task_info = *OMPT_CUR_TASK_INFO(thr);
289 *OMPT_CUR_TASK_INFO(thr) = tmp_task;
292 ompt_lw_taskteam_t *my_parent =
293 thr->th.th_team->t.ompt_serialized_team_info;
294 link_lwt->parent = my_parent;
295 thr->th.th_team->t.ompt_serialized_team_info = link_lwt;
299 *OMPT_CUR_TEAM_INFO(thr) = lwt->ompt_team_info;
300 *OMPT_CUR_TASK_INFO(thr) = lwt->ompt_task_info;
304 void __ompt_lw_taskteam_unlink(kmp_info_t *thr) {
305 ompt_lw_taskteam_t *lwtask = thr->th.th_team->t.ompt_serialized_team_info;
307 thr->th.th_team->t.ompt_serialized_team_info = lwtask->parent;
309 ompt_team_info_t tmp_team = lwtask->ompt_team_info;
310 lwtask->ompt_team_info = *OMPT_CUR_TEAM_INFO(thr);
311 *OMPT_CUR_TEAM_INFO(thr) = tmp_team;
313 ompt_task_info_t tmp_task = lwtask->ompt_task_info;
314 lwtask->ompt_task_info = *OMPT_CUR_TASK_INFO(thr);
315 *OMPT_CUR_TASK_INFO(thr) = tmp_task;
329 int __ompt_get_task_info_internal(
int ancestor_level,
int *type,
330 ompt_data_t **task_data,
331 omp_frame_t **task_frame,
332 ompt_data_t **parallel_data,
334 if (__kmp_get_gtid() < 0)
337 if (ancestor_level < 0)
341 ompt_task_info_t *info = NULL;
342 ompt_team_info_t *team_info = NULL;
343 kmp_info_t *thr = ompt_get_thread();
344 int level = ancestor_level;
347 kmp_taskdata_t *taskdata = thr->th.th_current_task;
348 if (taskdata == NULL)
350 kmp_team *team = thr->th.th_team, *prev_team = NULL;
353 ompt_lw_taskteam_t *lwt = NULL,
354 *next_lwt = LWT_FROM_TEAM(taskdata->td_team),
357 while (ancestor_level > 0) {
367 if (!lwt && taskdata) {
369 if (taskdata->ompt_task_info.scheduling_parent) {
370 taskdata = taskdata->ompt_task_info.scheduling_parent;
371 }
else if (next_lwt) {
376 taskdata = taskdata->td_parent;
379 team = team->t.t_parent;
381 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
389 info = &lwt->ompt_task_info;
390 team_info = &lwt->ompt_team_info;
392 *type = ompt_task_implicit;
394 }
else if (taskdata) {
395 info = &taskdata->ompt_task_info;
396 team_info = &team->t.ompt_team_info;
398 if (taskdata->td_parent) {
399 *type = (taskdata->td_flags.tasktype ? ompt_task_explicit
400 : ompt_task_implicit) |
401 TASK_TYPE_DETAILS_FORMAT(taskdata);
403 *type = ompt_task_initial;
408 *task_data = info ? &info->task_data : NULL;
412 *task_frame = info ? &info->frame : NULL;
415 *parallel_data = team_info ? &(team_info->parallel_data) : NULL;
419 *thread_num = __kmp_get_tid();
423 *thread_num = prev_team->t.t_master_tid;
435 void __ompt_team_assign_id(kmp_team_t *team, ompt_data_t ompt_pid) {
436 team->t.ompt_team_info.parallel_data = ompt_pid;
443 static uint64_t __ompt_get_unique_id_internal() {
444 static uint64_t thread = 1;
445 static THREAD_LOCAL uint64_t ID = 0;
447 uint64_t new_thread = KMP_TEST_THEN_INC64((kmp_int64 *)&thread);
448 ID = new_thread << (
sizeof(uint64_t) * 8 - OMPT_THREAD_ID_BITS);