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;
64 team=team->t.t_parent;
66 lwt = LWT_FROM_TEAM(team);
78 return &lwt->ompt_team_info;
81 if (size) *size = team->t.t_nproc;
84 return &team->t.ompt_team_info;
93 __ompt_get_taskinfo(
int depth)
95 ompt_task_info_t *info = NULL;
96 kmp_info_t *thr = ompt_get_thread();
99 kmp_taskdata_t *taskdata = thr->th.th_current_task;
100 ompt_lw_taskteam_t *lwt = LWT_FROM_TEAM(taskdata->td_team);
104 if (lwt) lwt = lwt->parent;
108 if (!lwt && taskdata) {
109 taskdata = taskdata->td_parent;
111 lwt = LWT_FROM_TEAM(taskdata->td_team);
118 info = &lwt->ompt_task_info;
119 }
else if (taskdata) {
120 info = &taskdata->ompt_task_info;
138 __ompt_thread_id_new()
140 static uint64_t ompt_thread_id = 1;
141 return NEXT_ID(&ompt_thread_id, 0);
145 __ompt_thread_begin(ompt_thread_type_t thread_type,
int gtid)
147 ompt_callbacks.ompt_callback(ompt_event_thread_begin)(
148 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
153 __ompt_thread_end(ompt_thread_type_t thread_type,
int gtid)
155 ompt_callbacks.ompt_callback(ompt_event_thread_end)(
156 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
161 __ompt_get_thread_id_internal()
167 int id = __kmp_get_gtid();
170 return GTID_TO_OMPT_THREAD_ID(
id);
178 __ompt_thread_assign_wait_id(
void *variable)
180 int gtid = __kmp_gtid_get_specific();
181 kmp_info_t *ti = ompt_get_thread_gtid(gtid);
183 ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t) variable;
187 __ompt_get_state_internal(ompt_wait_id_t *ompt_wait_id)
189 kmp_info_t *ti = ompt_get_thread();
193 *ompt_wait_id = ti->th.ompt_thread_info.wait_id;
194 return ti->th.ompt_thread_info.state;
196 return ompt_state_undefined;
204 __ompt_get_idle_frame_internal(
void)
206 kmp_info_t *ti = ompt_get_thread();
207 return ti ? ti->th.ompt_thread_info.idle_frame : NULL;
216 __ompt_parallel_id_new(
int gtid)
218 static uint64_t ompt_parallel_id = 1;
219 return gtid >= 0 ? NEXT_ID(&ompt_parallel_id, gtid) : 0;
224 __ompt_get_parallel_function_internal(
int depth)
226 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
227 void *
function = info ? info->microtask : NULL;
233 __ompt_get_parallel_id_internal(
int depth)
235 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
236 ompt_parallel_id_t
id = info ? info->parallel_id : 0;
242 __ompt_get_parallel_team_size_internal(
int depth)
248 (void) __ompt_get_teaminfo(depth, &size);
258 __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
259 int gtid,
void *microtask,
260 ompt_parallel_id_t ompt_pid)
262 lwt->ompt_team_info.parallel_id = ompt_pid;
263 lwt->ompt_team_info.microtask = microtask;
264 lwt->ompt_task_info.task_id = 0;
265 lwt->ompt_task_info.frame.reenter_runtime_frame = NULL;
266 lwt->ompt_task_info.frame.exit_runtime_frame = NULL;
267 lwt->ompt_task_info.function = NULL;
273 __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr)
275 ompt_lw_taskteam_t *my_parent = thr->th.th_team->t.ompt_serialized_team_info;
276 lwt->parent = my_parent;
277 thr->th.th_team->t.ompt_serialized_team_info = lwt;
282 __ompt_lw_taskteam_unlink(kmp_info_t *thr)
284 ompt_lw_taskteam_t *lwtask = thr->th.th_team->t.ompt_serialized_team_info;
285 if (lwtask) thr->th.th_team->t.ompt_serialized_team_info = lwtask->parent;
295 __ompt_task_id_new(
int gtid)
297 static uint64_t ompt_task_id = 1;
298 return NEXT_ID(&ompt_task_id, gtid);
303 __ompt_get_task_id_internal(
int depth)
305 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
306 ompt_task_id_t task_id = info ? info->task_id : 0;
312 __ompt_get_task_function_internal(
int depth)
314 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
315 void *
function = info ? info->function : NULL;
321 __ompt_get_task_frame_internal(
int depth)
323 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
324 ompt_frame_t *frame = info ? frame = &info->frame : NULL;
334 __ompt_team_assign_id(kmp_team_t *team, ompt_parallel_id_t ompt_pid)
336 team->t.ompt_team_info.parallel_id = ompt_pid;