6 #include "ompt-internal.h" 7 #include "ompt-specific.h" 13 #define GTID_TO_OMPT_THREAD_ID(id) ((ompt_thread_id_t) (id >=0) ? id + 1: 0) 15 #define LWT_FROM_TEAM(team) (team)->t.ompt_serialized_team_info; 17 #define OMPT_THREAD_ID_BITS 16 29 #define NEXT_ID(id_ptr,tid) \ 30 ((KMP_TEST_THEN_INC64(id_ptr) << OMPT_THREAD_ID_BITS) | (tid)) 32 #define NEXT_ID(id_ptr,tid) (KMP_TEST_THEN_INC64((volatile kmp_int64 *)id_ptr)) 47 __ompt_get_teaminfo(
int depth,
int *size)
49 kmp_info_t *thr = ompt_get_thread();
52 kmp_team *team = thr->th.th_team;
53 if (team == NULL)
return NULL;
55 ompt_lw_taskteam_t *lwt = LWT_FROM_TEAM(team);
59 if (lwt) lwt = lwt->parent;
63 if (!lwt && team) team=team->t.t_parent;
73 return &lwt->ompt_team_info;
76 if (size) *size = team->t.t_nproc;
79 return &team->t.ompt_team_info;
88 __ompt_get_taskinfo(
int depth)
90 ompt_task_info_t *info = NULL;
91 kmp_info_t *thr = ompt_get_thread();
94 kmp_taskdata_t *taskdata = thr->th.th_current_task;
95 ompt_lw_taskteam_t *lwt = LWT_FROM_TEAM(taskdata->td_team);
99 if (lwt) lwt = lwt->parent;
103 if (!lwt && taskdata) {
104 taskdata = taskdata->td_parent;
106 lwt = LWT_FROM_TEAM(taskdata->td_team);
113 info = &lwt->ompt_task_info;
114 }
else if (taskdata) {
115 info = &taskdata->ompt_task_info;
133 __ompt_thread_id_new()
135 static uint64_t ompt_thread_id = 1;
136 return NEXT_ID(&ompt_thread_id, 0);
140 __ompt_thread_begin(ompt_thread_type_t thread_type,
int gtid)
142 ompt_callbacks.ompt_callback(ompt_event_thread_begin)(
143 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
148 __ompt_thread_end(ompt_thread_type_t thread_type,
int gtid)
150 ompt_callbacks.ompt_callback(ompt_event_thread_end)(
151 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
156 __ompt_get_thread_id_internal()
162 int id = __kmp_get_gtid();
165 return GTID_TO_OMPT_THREAD_ID(
id);
173 __ompt_thread_assign_wait_id(
void *variable)
175 int gtid = __kmp_gtid_get_specific();
176 kmp_info_t *ti = ompt_get_thread_gtid(gtid);
178 ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t) variable;
182 __ompt_get_state_internal(ompt_wait_id_t *ompt_wait_id)
184 kmp_info_t *ti = ompt_get_thread();
188 *ompt_wait_id = ti->th.ompt_thread_info.wait_id;
189 return ti->th.ompt_thread_info.state;
191 return ompt_state_undefined;
199 __ompt_get_idle_frame_internal(
void)
201 kmp_info_t *ti = ompt_get_thread();
202 return ti ? ti->th.ompt_thread_info.idle_frame : NULL;
211 __ompt_parallel_id_new(
int gtid)
213 static uint64_t ompt_parallel_id = 1;
214 return gtid >= 0 ? NEXT_ID(&ompt_parallel_id, gtid) : 0;
219 __ompt_get_parallel_function_internal(
int depth)
221 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
222 void *
function = info ? info->microtask : NULL;
228 __ompt_get_parallel_id_internal(
int depth)
230 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
231 ompt_parallel_id_t
id = info ? info->parallel_id : 0;
237 __ompt_get_parallel_team_size_internal(
int depth)
243 (void) __ompt_get_teaminfo(depth, &size);
253 __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
254 int gtid,
void *microtask,
255 ompt_parallel_id_t ompt_pid)
257 lwt->ompt_team_info.parallel_id = ompt_pid;
258 lwt->ompt_team_info.microtask = microtask;
259 lwt->ompt_task_info.task_id = 0;
260 lwt->ompt_task_info.frame.reenter_runtime_frame = 0;
261 lwt->ompt_task_info.frame.exit_runtime_frame = 0;
262 lwt->ompt_task_info.function = NULL;
268 __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr)
270 ompt_lw_taskteam_t *my_parent = thr->th.th_team->t.ompt_serialized_team_info;
271 lwt->parent = my_parent;
272 thr->th.th_team->t.ompt_serialized_team_info = lwt;
277 __ompt_lw_taskteam_unlink(kmp_info_t *thr)
279 ompt_lw_taskteam_t *lwtask = thr->th.th_team->t.ompt_serialized_team_info;
280 if (lwtask) thr->th.th_team->t.ompt_serialized_team_info = lwtask->parent;
290 __ompt_task_id_new(
int gtid)
292 static uint64_t ompt_task_id = 1;
293 return NEXT_ID(&ompt_task_id, gtid);
298 __ompt_get_task_id_internal(
int depth)
300 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
301 ompt_task_id_t task_id = info ? info->task_id : 0;
307 __ompt_get_task_function_internal(
int depth)
309 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
310 void *
function = info ? info->function : NULL;
316 __ompt_get_task_frame_internal(
int depth)
318 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
319 ompt_frame_t *frame = info ? frame = &info->frame : NULL;
329 __ompt_team_assign_id(kmp_team_t *team, ompt_parallel_id_t ompt_pid)
331 team->t.ompt_team_info.parallel_id = ompt_pid;