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)) 46 ompt_team_info_t *__ompt_get_teaminfo(
int depth,
int *size) {
47 kmp_info_t *thr = ompt_get_thread();
50 kmp_team *team = thr->th.th_team;
54 ompt_lw_taskteam_t *lwt = LWT_FROM_TEAM(team);
64 team = team->t.t_parent;
66 lwt = LWT_FROM_TEAM(team);
79 return &lwt->ompt_team_info;
83 *size = team->t.t_nproc;
86 return &team->t.ompt_team_info;
93 ompt_task_info_t *__ompt_get_taskinfo(
int depth) {
94 ompt_task_info_t *info = NULL;
95 kmp_info_t *thr = ompt_get_thread();
98 kmp_taskdata_t *taskdata = thr->th.th_current_task;
99 ompt_lw_taskteam_t *lwt = LWT_FROM_TEAM(taskdata->td_team);
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;
135 ompt_parallel_id_t __ompt_thread_id_new() {
136 static uint64_t ompt_thread_id = 1;
137 return NEXT_ID(&ompt_thread_id, 0);
140 void __ompt_thread_begin(ompt_thread_type_t thread_type,
int gtid) {
141 ompt_callbacks.ompt_callback(ompt_event_thread_begin)(
142 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
145 void __ompt_thread_end(ompt_thread_type_t thread_type,
int gtid) {
146 ompt_callbacks.ompt_callback(ompt_event_thread_end)(
147 thread_type, GTID_TO_OMPT_THREAD_ID(gtid));
150 ompt_thread_id_t __ompt_get_thread_id_internal() {
154 int id = __kmp_get_gtid();
157 return GTID_TO_OMPT_THREAD_ID(
id);
164 void __ompt_thread_assign_wait_id(
void *variable) {
165 int gtid = __kmp_gtid_get_specific();
166 kmp_info_t *ti = ompt_get_thread_gtid(gtid);
168 ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t)variable;
171 ompt_state_t __ompt_get_state_internal(ompt_wait_id_t *ompt_wait_id) {
172 kmp_info_t *ti = ompt_get_thread();
176 *ompt_wait_id = ti->th.ompt_thread_info.wait_id;
177 return ti->th.ompt_thread_info.state;
179 return ompt_state_undefined;
186 void *__ompt_get_idle_frame_internal(
void) {
187 kmp_info_t *ti = ompt_get_thread();
188 return ti ? ti->th.ompt_thread_info.idle_frame : NULL;
195 ompt_parallel_id_t __ompt_parallel_id_new(
int gtid) {
196 static uint64_t ompt_parallel_id = 1;
197 return gtid >= 0 ? NEXT_ID(&ompt_parallel_id, gtid) : 0;
200 void *__ompt_get_parallel_function_internal(
int depth) {
201 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
202 void *
function = info ? info->microtask : NULL;
206 ompt_parallel_id_t __ompt_get_parallel_id_internal(
int depth) {
207 ompt_team_info_t *info = __ompt_get_teaminfo(depth, NULL);
208 ompt_parallel_id_t
id = info ? info->parallel_id : 0;
212 int __ompt_get_parallel_team_size_internal(
int depth) {
217 (void)__ompt_get_teaminfo(depth, &size);
225 void __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
int gtid,
226 void *microtask, ompt_parallel_id_t ompt_pid) {
227 lwt->ompt_team_info.parallel_id = ompt_pid;
228 lwt->ompt_team_info.microtask = microtask;
229 lwt->ompt_task_info.task_id = 0;
230 lwt->ompt_task_info.frame.reenter_runtime_frame = NULL;
231 lwt->ompt_task_info.frame.exit_runtime_frame = NULL;
232 lwt->ompt_task_info.function = NULL;
236 void __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr) {
237 ompt_lw_taskteam_t *my_parent = thr->th.th_team->t.ompt_serialized_team_info;
238 lwt->parent = my_parent;
239 thr->th.th_team->t.ompt_serialized_team_info = lwt;
242 ompt_lw_taskteam_t *__ompt_lw_taskteam_unlink(kmp_info_t *thr) {
243 ompt_lw_taskteam_t *lwtask = thr->th.th_team->t.ompt_serialized_team_info;
245 thr->th.th_team->t.ompt_serialized_team_info = lwtask->parent;
253 ompt_task_id_t __ompt_task_id_new(
int gtid) {
254 static uint64_t ompt_task_id = 1;
255 return NEXT_ID(&ompt_task_id, gtid);
258 ompt_task_id_t __ompt_get_task_id_internal(
int depth) {
259 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
260 ompt_task_id_t task_id = info ? info->task_id : 0;
264 void *__ompt_get_task_function_internal(
int depth) {
265 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
266 void *
function = info ? info->function : NULL;
270 ompt_frame_t *__ompt_get_task_frame_internal(
int depth) {
271 ompt_task_info_t *info = __ompt_get_taskinfo(depth);
272 ompt_frame_t *frame = info ? frame = &info->frame : NULL;
280 void __ompt_team_assign_id(kmp_team_t *team, ompt_parallel_id_t ompt_pid) {
281 team->t.ompt_team_info.parallel_id = ompt_pid;