6 #include "ompt-specific.h" 13 #define THREAD_LOCAL __declspec(thread) 15 #define THREAD_LOCAL __thread 18 #define OMPT_WEAK_ATTRIBUTE KMP_WEAK_ATTRIBUTE 24 #define LWT_FROM_TEAM(team) (team)->t.ompt_serialized_team_info 26 #define OMPT_THREAD_ID_BITS 16 39 ompt_team_info_t *__ompt_get_teaminfo(
int depth,
int *size) {
40 kmp_info_t *thr = ompt_get_thread();
43 kmp_team *team = thr->th.th_team;
47 ompt_lw_taskteam_t *next_lwt = LWT_FROM_TEAM(team), *lwt = NULL;
61 team = team->t.t_parent;
63 next_lwt = LWT_FROM_TEAM(team);
77 return &lwt->ompt_team_info;
81 *size = team->t.t_nproc;
84 return &team->t.ompt_team_info;
91 ompt_task_info_t *__ompt_get_task_info_object(
int depth) {
92 ompt_task_info_t *info = NULL;
93 kmp_info_t *thr = ompt_get_thread();
96 kmp_taskdata_t *taskdata = thr->th.th_current_task;
97 ompt_lw_taskteam_t *lwt = NULL,
98 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
107 if (!lwt && taskdata) {
112 taskdata = taskdata->td_parent;
114 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
122 info = &lwt->ompt_task_info;
123 }
else if (taskdata) {
124 info = &taskdata->ompt_task_info;
131 ompt_task_info_t *__ompt_get_scheduling_taskinfo(
int depth) {
132 ompt_task_info_t *info = NULL;
133 kmp_info_t *thr = ompt_get_thread();
136 kmp_taskdata_t *taskdata = thr->th.th_current_task;
138 ompt_lw_taskteam_t *lwt = NULL,
139 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
148 if (!lwt && taskdata) {
150 if (taskdata->ompt_task_info.scheduling_parent) {
151 taskdata = taskdata->ompt_task_info.scheduling_parent;
152 }
else if (next_lwt) {
157 taskdata = taskdata->td_parent;
159 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
167 info = &lwt->ompt_task_info;
168 }
else if (taskdata) {
169 info = &taskdata->ompt_task_info;
184 ompt_data_t *__ompt_get_thread_data_internal() {
185 if (__kmp_get_gtid() >= 0) {
186 kmp_info_t *thread = ompt_get_thread();
189 return &(thread->th.ompt_thread_info.thread_data);
198 void __ompt_thread_assign_wait_id(
void *variable) {
199 kmp_info_t *ti = ompt_get_thread();
201 ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t)variable;
204 omp_state_t __ompt_get_state_internal(ompt_wait_id_t *ompt_wait_id) {
205 kmp_info_t *ti = ompt_get_thread();
209 *ompt_wait_id = ti->th.ompt_thread_info.wait_id;
210 return ti->th.ompt_thread_info.state;
212 return omp_state_undefined;
219 int __ompt_get_parallel_info_internal(
int ancestor_level,
220 ompt_data_t **parallel_data,
222 ompt_team_info_t *info;
224 info = __ompt_get_teaminfo(ancestor_level, team_size);
226 info = __ompt_get_teaminfo(ancestor_level, NULL);
229 *parallel_data = info ? &(info->parallel_data) : NULL;
238 void __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
int gtid,
239 ompt_data_t *ompt_pid,
void *codeptr) {
242 lwt->ompt_team_info.parallel_data = *ompt_pid;
243 lwt->ompt_team_info.master_return_address = codeptr;
244 lwt->ompt_task_info.task_data.value = 0;
245 lwt->ompt_task_info.frame.enter_frame = NULL;
246 lwt->ompt_task_info.frame.exit_frame = NULL;
247 lwt->ompt_task_info.scheduling_parent = NULL;
248 lwt->ompt_task_info.deps = NULL;
249 lwt->ompt_task_info.ndeps = 0;
254 void __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
256 ompt_lw_taskteam_t *link_lwt = lwt;
257 if (thr->th.th_team->t.t_serialized >
261 (ompt_lw_taskteam_t *)__kmp_allocate(
sizeof(ompt_lw_taskteam_t));
263 link_lwt->heap = on_heap;
266 ompt_team_info_t tmp_team = lwt->ompt_team_info;
267 link_lwt->ompt_team_info = *OMPT_CUR_TEAM_INFO(thr);
268 *OMPT_CUR_TEAM_INFO(thr) = tmp_team;
270 ompt_task_info_t tmp_task = lwt->ompt_task_info;
271 link_lwt->ompt_task_info = *OMPT_CUR_TASK_INFO(thr);
272 *OMPT_CUR_TASK_INFO(thr) = tmp_task;
275 ompt_lw_taskteam_t *my_parent =
276 thr->th.th_team->t.ompt_serialized_team_info;
277 link_lwt->parent = my_parent;
278 thr->th.th_team->t.ompt_serialized_team_info = link_lwt;
282 *OMPT_CUR_TEAM_INFO(thr) = lwt->ompt_team_info;
283 *OMPT_CUR_TASK_INFO(thr) = lwt->ompt_task_info;
287 void __ompt_lw_taskteam_unlink(kmp_info_t *thr) {
288 ompt_lw_taskteam_t *lwtask = thr->th.th_team->t.ompt_serialized_team_info;
290 thr->th.th_team->t.ompt_serialized_team_info = lwtask->parent;
292 ompt_team_info_t tmp_team = lwtask->ompt_team_info;
293 lwtask->ompt_team_info = *OMPT_CUR_TEAM_INFO(thr);
294 *OMPT_CUR_TEAM_INFO(thr) = tmp_team;
296 ompt_task_info_t tmp_task = lwtask->ompt_task_info;
297 lwtask->ompt_task_info = *OMPT_CUR_TASK_INFO(thr);
298 *OMPT_CUR_TASK_INFO(thr) = tmp_task;
312 int __ompt_get_task_info_internal(
int ancestor_level,
int *type,
313 ompt_data_t **task_data,
314 ompt_frame_t **task_frame,
315 ompt_data_t **parallel_data,
317 if (ancestor_level < 0)
321 ompt_task_info_t *info = NULL;
322 ompt_team_info_t *team_info = NULL;
323 kmp_info_t *thr = ompt_get_thread();
326 kmp_taskdata_t *taskdata = thr->th.th_current_task;
327 if (taskdata == NULL)
329 kmp_team *team = thr->th.th_team;
332 ompt_lw_taskteam_t *lwt = NULL,
333 *next_lwt = LWT_FROM_TEAM(taskdata->td_team);
335 while (ancestor_level > 0) {
342 if (!lwt && taskdata) {
344 if (taskdata->ompt_task_info.scheduling_parent) {
345 taskdata = taskdata->ompt_task_info.scheduling_parent;
346 }
else if (next_lwt) {
351 taskdata = taskdata->td_parent;
354 team = team->t.t_parent;
356 next_lwt = LWT_FROM_TEAM(taskdata->td_team);
364 info = &lwt->ompt_task_info;
365 team_info = &lwt->ompt_team_info;
367 *type = ompt_task_implicit;
369 }
else if (taskdata) {
370 info = &taskdata->ompt_task_info;
371 team_info = &team->t.ompt_team_info;
373 if (taskdata->td_parent) {
374 *type = (taskdata->td_flags.tasktype ? ompt_task_explicit
375 : ompt_task_implicit) |
376 TASK_TYPE_DETAILS_FORMAT(taskdata);
378 *type = ompt_task_initial;
383 *task_data = info ? &info->task_data : NULL;
387 *task_frame = info ? &info->frame : NULL;
390 *parallel_data = team_info ? &(team_info->parallel_data) : NULL;
401 void __ompt_team_assign_id(kmp_team_t *team, ompt_data_t ompt_pid) {
402 team->t.ompt_team_info.parallel_data = ompt_pid;
409 static uint64_t __ompt_get_unique_id_internal() {
410 static uint64_t thread = 1;
411 static THREAD_LOCAL uint64_t ID = 0;
413 uint64_t new_thread = KMP_TEST_THEN_INC64((kmp_int64 *)&thread);
414 ID = new_thread << (
sizeof(uint64_t) * 8 - OMPT_THREAD_ID_BITS);