40 #include "ompt-internal.h"
41 #include "ompt-specific.h"
47 #define GTID_TO_OMPT_THREAD_ID(id) ((ompt_thread_id_t) (id >=0) ? id + 1: 0)
49 #define LWT_FROM_TEAM(team) (team)->t.ompt_serialized_team_info;
51 #define OMPT_THREAD_ID_BITS 16
62 #define NEXT_ID(id_ptr,tid) (KMP_TEST_THEN_INC64((volatile kmp_int64 *)id_ptr))
76 __ompt_get_teaminfo(
int depth,
int *size)
78 kmp_info_t *thr = ompt_get_thread();
81 kmp_team *team = thr->th.th_team;
82 ompt_lw_taskteam_t *lwt = LWT_FROM_TEAM(team);
86 if (lwt) lwt = lwt->parent;
90 if (!lwt && team) team=team->t.t_parent;
100 return &lwt->ompt_team_info;
103 if (size) *size = team->t.t_nproc;
106 return &team->t.ompt_team_info;
115 __ompt_get_taskinfo(
int depth)
117 ompt_task_info_t *info = NULL;
118 kmp_info_t *thr = ompt_get_thread();
121 kmp_taskdata_t *taskdata = thr->th.th_current_task;
122 ompt_lw_taskteam_t *lwt = LWT_FROM_TEAM(taskdata->td_team);
126 if (lwt) lwt = lwt->parent;
130 if (!lwt && taskdata) {
131 taskdata = taskdata->td_parent;
133 lwt = LWT_FROM_TEAM(taskdata->td_team);
140 info = &lwt->ompt_task_info;
141 }
else if (taskdata) {
142 info = &taskdata->ompt_task_info;
160 __ompt_init_internal()
162 if (ompt_status & ompt_status_track) {
164 kmp_info_t *root_thread = ompt_get_thread();
165 __kmp_task_init_ompt(
166 root_thread->th.th_team->t.t_implicit_task_taskdata, 0);
167 __kmp_task_init_ompt(
168 root_thread->th.th_serial_team->t.t_implicit_task_taskdata, 0);
173 int gtid = __kmp_get_gtid();
174 if (KMP_UBER_GTID(gtid)) {
176 root_thread->th.ompt_thread_info.idle_frame = 0;
177 root_thread->th.ompt_thread_info.state = ompt_state_overhead;
178 if ((ompt_status == ompt_status_track_callback) &&
179 ompt_callbacks.ompt_callback(ompt_event_thread_begin)) {
180 __ompt_thread_begin(ompt_thread_initial, gtid);
182 root_thread->th.ompt_thread_info.state = ompt_state_work_serial;
193 __ompt_thread_id_new()
195 static uint64_t ompt_thread_id = 1;
196 return NEXT_ID(&ompt_thread_id, 0);
200 __ompt_thread_begin(ompt_thread_type_t thread_type,
int gtid)
202 ompt_callbacks.ompt_callback(ompt_event_thread_begin)(
203 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
208 __ompt_thread_end(ompt_thread_type_t thread_type,
int gtid)
210 ompt_callbacks.ompt_callback(ompt_event_thread_end)(
211 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
216 __ompt_get_thread_id_internal()
222 int id = __kmp_get_gtid();
225 return GTID_TO_OMPT_THREAD_ID(
id);
233 __ompt_thread_assign_wait_id(
void *variable)
235 int gtid = __kmp_gtid_get_specific();
236 kmp_info_t *ti = ompt_get_thread_gtid(gtid);
238 ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t) variable;
242 __ompt_get_state_internal(ompt_wait_id_t *ompt_wait_id)
244 kmp_info_t *ti = ompt_get_thread();
248 *ompt_wait_id = ti->th.ompt_thread_info.wait_id;
249 return ti->th.ompt_thread_info.state;
251 return ompt_state_undefined;
259 __ompt_get_idle_frame_internal(
void)
261 kmp_info_t *ti = ompt_get_thread();
262 return ti ? ti->th.ompt_thread_info.idle_frame : NULL;
271 __ompt_parallel_id_new(
int gtid)
273 static uint64_t ompt_parallel_id = 1;
274 return gtid >= 0 ? NEXT_ID(&ompt_parallel_id, gtid) : 0;
279 __ompt_get_parallel_function_internal(
int depth)
281 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
282 void *
function = info ? info->microtask : NULL;
288 __ompt_get_parallel_id_internal(
int depth)
290 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
291 ompt_parallel_id_t
id = info ? info->parallel_id : 0;
297 __ompt_get_parallel_team_size_internal(
int depth)
303 (void) __ompt_get_teaminfo(depth, &size);
313 __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
314 int gtid,
void *microtask,
315 ompt_parallel_id_t ompt_pid)
317 lwt->ompt_team_info.parallel_id = ompt_pid;
318 lwt->ompt_team_info.microtask = microtask;
319 lwt->ompt_task_info.task_id = 0;
320 lwt->ompt_task_info.frame.reenter_runtime_frame = 0;
321 lwt->ompt_task_info.frame.exit_runtime_frame = 0;
322 lwt->ompt_task_info.function = NULL;
328 __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr)
330 ompt_lw_taskteam_t *my_parent = thr->th.th_team->t.ompt_serialized_team_info;
331 lwt->parent = my_parent;
332 thr->th.th_team->t.ompt_serialized_team_info = lwt;
337 __ompt_lw_taskteam_unlink(kmp_info_t *thr)
339 ompt_lw_taskteam_t *lwtask = thr->th.th_team->t.ompt_serialized_team_info;
340 if (lwtask) thr->th.th_team->t.ompt_serialized_team_info = lwtask->parent;
350 __ompt_task_id_new(
int gtid)
352 static uint64_t ompt_task_id = 1;
353 return NEXT_ID(&ompt_task_id, gtid);
358 __ompt_get_task_id_internal(
int depth)
360 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
361 ompt_task_id_t task_id = info ? info->task_id : 0;
367 __ompt_get_task_function_internal(
int depth)
369 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
370 void *
function = info ? info->function : NULL;
376 __ompt_get_task_frame_internal(
int depth)
378 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
379 ompt_frame_t *frame = info ? frame = &info->frame : NULL;
389 __ompt_team_assign_id(kmp_team_t *team, ompt_parallel_id_t ompt_pid)
391 team->t.ompt_team_info.parallel_id = ompt_pid;
400 __ompt_get_runtime_version_internal()
402 return &__kmp_version_lib_ver[KMP_VERSION_MAGIC_LEN];