ompt-specific.c
Go to the documentation of this file.00001 #include "kmp.h"
00002 #include "ompt-internal.h"
00003 #include "ompt-specific.h"
00004
00005 #if 0
00006 inline
00007 kmp_info_t *ompt_get_thread_gtid(int gtid)
00008 {
00009 return (gtid >= 0) ? __kmp_thread_from_gtid(gtid) : NULL;
00010 }
00011
00012
00013 inline
00014 kmp_info_t *ompt_get_thread()
00015 {
00016 int gtid = __kmp_gtid_get_specific();
00017 return ompt_get_thread_gtid(gtid);
00018 }
00019 #endif
00020
00021
00022
00023
00024
00025
00026 kmp_team_t *ompt_team(int ancestor_level)
00027 {
00028 int i;
00029 kmp_info_t *th = ompt_get_thread();
00030 kmp_team_t *team = th ? th->th.th_team : NULL;
00031
00032 for (i = 0; team && (i < ancestor_level); i++) {
00033 team = team->t.t_parent;
00034 }
00035 return team;
00036 }
00037
00038
00039
00040
00041
00042
00043 kmp_taskdata_t *ompt_task(int ancestor_level)
00044 {
00045 int i;
00046 kmp_info_t *th = ompt_get_thread();
00047 kmp_taskdata_t *task = th ? th->th.th_current_task : NULL;
00048
00049 for (i = 0; task && (i < ancestor_level); i++) {
00050 task = task->td_parent;
00051 }
00052 return task;
00053 }
00054
00055
00056 ompt_state_t __ompt_get_state_internal(ompt_wait_id_t *ompt_wait_id)
00057 {
00058 kmp_info_t *ti = ompt_get_thread();
00059
00060 if (ti) {
00061 *ompt_wait_id = ti->th.ompt_thread_info.wait_id;
00062 return ti->th.ompt_thread_info.state;
00063 } else {
00064 return ompt_state_undefined;
00065 }
00066 }
00067
00068
00069
00070 void *__ompt_get_idle_frame_internal(void)
00071 {
00072 kmp_info_t *ti = ompt_get_thread();
00073
00074 return ti ? ti->th.ompt_thread_info.idle_frame : NULL;
00075 }
00076
00077
00078 ompt_lw_taskteam_t *__ompt_get_lw_taskteam(int *ancestor_level)
00079 {
00080 int level = *ancestor_level;
00081 kmp_info_t *ti = ompt_get_thread();
00082 if (ti) {
00083 ompt_lw_taskteam_t *lwt = ti->th.ompt_thread_info.lw_taskteam;
00084 while (lwt) {
00085 if (level == 0) return lwt;
00086 lwt = lwt->parent;
00087 level--;
00088 }
00089 *ancestor_level = level;
00090 }
00091 return NULL;
00092 }
00093
00094
00095 void *__ompt_get_parallel_function_internal(int ancestor_level)
00096 {
00097 int level = ancestor_level;
00098 ompt_lw_taskteam_t *lwt = __ompt_get_lw_taskteam(&level);
00099 if (lwt) {
00100 return lwt->ompt_team_info.microtask;
00101 } else {
00102 kmp_team_t *team = ompt_team(level);
00103 return (void *) (team ? team->t.t_pkfn : NULL);
00104 }
00105 }
00106
00107
00108 ompt_parallel_id_t __ompt_get_parallel_id_internal(int ancestor_level)
00109 {
00110 int level = ancestor_level;
00111 ompt_lw_taskteam_t *lwt = __ompt_get_lw_taskteam(&level);
00112 if (lwt) {
00113 return lwt->ompt_team_info.parallel_id;
00114 } else {
00115 kmp_team_t *team = ompt_team(level);
00116 return team ? team->t.ompt_team_info.parallel_id : ompt_parallel_id_none;
00117 }
00118 }
00119
00120
00121 ompt_task_id_t __ompt_get_task_id_internal(int ancestor_level)
00122 {
00123 int level = ancestor_level;
00124 ompt_lw_taskteam_t *lwt = __ompt_get_lw_taskteam(&level);
00125 if (lwt) {
00126 return lwt->ompt_task_info.task_id;
00127 } else {
00128 kmp_taskdata_t *task = ompt_task(level);
00129 return task ? task->ompt_task_info.task_id : ompt_task_id_none;
00130 }
00131 }
00132
00133
00134 void *__ompt_get_task_function_internal(int ancestor_level)
00135 {
00136 kmp_taskdata_t *td = ompt_task(ancestor_level);
00137 kmp_task_t *task = td ? KMP_TASKDATA_TO_TASK(td) : NULL;
00138
00139 return (void *) (task ? task->routine : NULL);
00140 }
00141
00142
00143 ompt_frame_t *__ompt_get_task_frame_internal(int ancestor_level)
00144 {
00145 kmp_taskdata_t *task = ompt_task(ancestor_level);
00146
00147 return task ? &task->ompt_task_info.frame : NULL;
00148 }
00149
00150
00151 #define OMPT_THREAD_ID_BITS 20
00152 #define CREATE_ID(ti,tid) ( ((ti) << OMPT_THREAD_ID_BITS) | (tid) )
00153 #define NEXT_ID(ti,tid) ((((ti)->th.ompt_thread_info.next_parallel_id++) << OMPT_THREAD_ID_BITS) | (tid))
00154
00155 ompt_parallel_id_t __ompt_parallel_id_new(kmp_info_t *ti, int gtid)
00156 {
00157 uint64_t nid = 0;
00158 uint64_t nid2 = gtid+1;
00159 if (ti) {
00160 kmp_team_t *team = ti->th.th_team;
00161 nid = ti->th.ompt_thread_info.next_parallel_id;
00162
00163
00164
00165
00166
00167 }
00168 nid++;
00169 ompt_parallel_id_t idnew = ti ? CREATE_ID(nid2, nid) : 0;
00170
00171 if (ti) {
00172 ti->th.ompt_thread_info.next_parallel_id = nid;
00173
00174 }
00175 return idnew;
00176 }
00177
00178
00179 void __ompt_team_assign_id(kmp_team_t *team, ompt_parallel_id_t ompt_pid)
00180 {
00181 team->t.ompt_team_info.parallel_id = ompt_pid;
00182 }
00183
00184
00185 void __ompt_thread_assign_wait_id(void *variable)
00186 {
00187 int gtid = __kmp_gtid_get_specific();
00188 kmp_info_t *ti = ompt_get_thread_gtid(gtid);
00189
00190 ti->th.ompt_thread_info.wait_id = (ompt_wait_id_t)(variable);
00191 }
00192
00193
00194 void __ompt_lw_taskteam_init(ompt_lw_taskteam_t *lwt, kmp_info_t *thr,
00195 int gtid, microtask_t microtask,
00196 ompt_parallel_id_t ompt_pid)
00197 {
00198 lwt->ompt_team_info.parallel_id = ompt_pid;
00199 lwt->ompt_team_info.microtask = (void *) microtask;
00200 lwt->ompt_task_info.task_id = 0;
00201 lwt->ompt_task_info.frame.reenter_runtime_frame = 0;
00202 lwt->ompt_task_info.frame.exit_runtime_frame = 0;
00203 lwt->parent = 0;
00204 }
00205
00206
00207 void __ompt_lw_taskteam_link(ompt_lw_taskteam_t *lwt, kmp_info_t *thr)
00208 {
00209 ompt_lw_taskteam_t *my_parent = thr->th.ompt_thread_info.lw_taskteam;
00210 lwt->parent = my_parent;
00211 thr->th.ompt_thread_info.lw_taskteam = lwt;
00212 }
00213
00214
00215 void __ompt_lw_taskteam_unlink(ompt_lw_taskteam_t *lwt, kmp_info_t *thr)
00216 {
00217 thr->th.ompt_thread_info.lw_taskteam = lwt->parent;
00218 }
00219
00220
00221 int __ompt_get_runtime_version_internal(char *buffer, int length)
00222 {
00223 int slen = strlen(__kmp_version_lib_ver) + 1;
00224 int extra = slen - length;
00225 int result = (extra > 0) ? extra : 0;
00226 int copylen = slen - result;
00227
00228
00229 strncpy(buffer, __kmp_version_lib_ver, copylen);
00230 buffer[copylen-1] = NULL;
00231
00232 return result;
00233 }