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(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 ompt_lw_taskteam_t *lwt = LWT_FROM_TEAM(team);
57 if (lwt) lwt = lwt->parent;
61 if (!lwt && team) team=team->t.t_parent;
71 return &lwt->ompt_team_info;
74 if (size) *size = team->t.t_nproc;
77 return &team->t.ompt_team_info;
86 __ompt_get_taskinfo(
int depth)
88 ompt_task_info_t *info = NULL;
89 kmp_info_t *thr = ompt_get_thread();
92 kmp_taskdata_t *taskdata = thr->th.th_current_task;
93 ompt_lw_taskteam_t *lwt = LWT_FROM_TEAM(taskdata->td_team);
97 if (lwt) lwt = lwt->parent;
101 if (!lwt && taskdata) {
102 taskdata = taskdata->td_parent;
104 lwt = LWT_FROM_TEAM(taskdata->td_team);
111 info = &lwt->ompt_task_info;
112 }
else if (taskdata) {
113 info = &taskdata->ompt_task_info;
131 __ompt_init_internal()
133 if (ompt_status & ompt_status_track) {
135 kmp_info_t *root_thread = ompt_get_thread();
136 __kmp_task_init_ompt(
137 root_thread->th.th_team->t.t_implicit_task_taskdata, 0);
138 __kmp_task_init_ompt(
139 root_thread->th.th_serial_team->t.t_implicit_task_taskdata, 0);
144 int gtid = __kmp_get_gtid();
145 if (KMP_UBER_GTID(gtid)) {
147 root_thread->th.ompt_thread_info.idle_frame = 0;
148 root_thread->th.ompt_thread_info.state = ompt_state_overhead;
149 if ((ompt_status == ompt_status_track_callback) &&
150 ompt_callbacks.ompt_callback(ompt_event_thread_begin)) {
151 __ompt_thread_begin(ompt_thread_initial, gtid);
153 root_thread->th.ompt_thread_info.state = ompt_state_work_serial;
164 __ompt_thread_id_new()
166 static uint64_t ompt_thread_id = 1;
167 return NEXT_ID(&ompt_thread_id, 0);
171 __ompt_thread_begin(ompt_thread_type_t thread_type,
int gtid)
173 ompt_callbacks.ompt_callback(ompt_event_thread_begin)(
174 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
179 __ompt_thread_end(ompt_thread_type_t thread_type,
int gtid)
181 ompt_callbacks.ompt_callback(ompt_event_thread_end)(
182 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
187 __ompt_get_thread_id_internal()
193 int id = __kmp_get_gtid();
196 return GTID_TO_OMPT_THREAD_ID(
id);
204 __ompt_thread_assign_wait_id(
void *variable)
206 int gtid = __kmp_gtid_get_specific();
207 kmp_info_t *ti = ompt_get_thread_gtid(gtid);
209 ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t) variable;
213 __ompt_get_state_internal(ompt_wait_id_t *ompt_wait_id)
215 kmp_info_t *ti = ompt_get_thread();
219 *ompt_wait_id = ti->th.ompt_thread_info.wait_id;
220 return ti->th.ompt_thread_info.state;
222 return ompt_state_undefined;
230 __ompt_get_idle_frame_internal(
void)
232 kmp_info_t *ti = ompt_get_thread();
233 return ti ? ti->th.ompt_thread_info.idle_frame : NULL;
242 __ompt_parallel_id_new(
int gtid)
244 static uint64_t ompt_parallel_id = 1;
245 return gtid >= 0 ? NEXT_ID(&ompt_parallel_id, gtid) : 0;
250 __ompt_get_parallel_function_internal(
int depth)
252 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
253 void *
function = info ? info->microtask : NULL;
259 __ompt_get_parallel_id_internal(
int depth)
261 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
262 ompt_parallel_id_t
id = info ? info->parallel_id : 0;
268 __ompt_get_parallel_team_size_internal(
int depth)
274 (void) __ompt_get_teaminfo(depth, &size);
284 __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
285 int gtid,
void *microtask,
286 ompt_parallel_id_t ompt_pid)
288 lwt->ompt_team_info.parallel_id = ompt_pid;
289 lwt->ompt_team_info.microtask = microtask;
290 lwt->ompt_task_info.task_id = 0;
291 lwt->ompt_task_info.frame.reenter_runtime_frame = 0;
292 lwt->ompt_task_info.frame.exit_runtime_frame = 0;
293 lwt->ompt_task_info.function = NULL;
299 __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr)
301 ompt_lw_taskteam_t *my_parent = thr->th.th_team->t.ompt_serialized_team_info;
302 lwt->parent = my_parent;
303 thr->th.th_team->t.ompt_serialized_team_info = lwt;
308 __ompt_lw_taskteam_unlink(kmp_info_t *thr)
310 ompt_lw_taskteam_t *lwtask = thr->th.th_team->t.ompt_serialized_team_info;
311 if (lwtask) thr->th.th_team->t.ompt_serialized_team_info = lwtask->parent;
321 __ompt_task_id_new(
int gtid)
323 static uint64_t ompt_task_id = 1;
324 return NEXT_ID(&ompt_task_id, gtid);
329 __ompt_get_task_id_internal(
int depth)
331 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
332 ompt_task_id_t task_id = info ? info->task_id : 0;
338 __ompt_get_task_function_internal(
int depth)
340 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
341 void *
function = info ? info->function : NULL;
347 __ompt_get_task_frame_internal(
int depth)
349 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
350 ompt_frame_t *frame = info ? frame = &info->frame : NULL;
360 __ompt_team_assign_id(kmp_team_t *team, ompt_parallel_id_t ompt_pid)
362 team->t.ompt_team_info.parallel_id = ompt_pid;
371 __ompt_get_runtime_version_internal()
373 return &__kmp_version_lib_ver[KMP_VERSION_MAGIC_LEN];