18 #include "ompt-internal.h" 19 #include "ompt-specific.c" 27 #define ompt_get_callback_success 1 28 #define ompt_get_callback_failure 0 30 #define no_tool_present 0 32 #define OMPT_API_ROUTINE static 41 const char *state_name;
42 ompt_state_t state_id;
51 ompt_status_t ompt_status = ompt_status_ready;
54 ompt_state_info_t ompt_state_info[] = {
55 #define ompt_state_macro(state, code) { # state, state }, 56 FOREACH_OMPT_STATE(ompt_state_macro)
57 #undef ompt_state_macro 61 ompt_callbacks_t ompt_callbacks;
69 static ompt_interface_fn_t ompt_fn_lookup(
const char *s);
76 OMPT_API_ROUTINE
int ompt_enumerate_state(
int current_state,
int *next_state,
77 const char **next_state_name)
79 const static int len =
sizeof(ompt_state_info) /
sizeof(ompt_state_info_t);
82 for (i = 0; i < len - 1; i++) {
83 if (ompt_state_info[i].state_id == current_state) {
84 *next_state = ompt_state_info[i+1].state_id;
85 *next_state_name = ompt_state_info[i+1].state_name;
99 OMPT_API_ROUTINE
int ompt_set_callback(ompt_event_t evid, ompt_callback_t cb)
103 #define ompt_event_macro(event_name, callback_type, event_id) \ 105 if (ompt_event_implementation_status(event_name)) { \ 106 ompt_callbacks.ompt_callback(event_name) = (callback_type) cb; \ 108 return ompt_event_implementation_status(event_name); 110 FOREACH_OMPT_EVENT(ompt_event_macro)
112 #undef ompt_event_macro 114 default:
return ompt_set_result_registration_error;
119 OMPT_API_ROUTINE
int ompt_get_callback(ompt_event_t evid, ompt_callback_t *cb)
123 #define ompt_event_macro(event_name, callback_type, event_id) \ 125 if (ompt_event_implementation_status(event_name)) { \ 126 ompt_callback_t mycb = \ 127 (ompt_callback_t) ompt_callbacks.ompt_callback(event_name); \ 130 return ompt_get_callback_success; \ 133 return ompt_get_callback_failure; 135 FOREACH_OMPT_EVENT(ompt_event_macro)
137 #undef ompt_event_macro 139 default:
return ompt_get_callback_failure;
149 _OMP_EXTERN __attribute__ (( weak ))
150 int ompt_initialize(ompt_function_lookup_t ompt_fn_lookup, const
char *version,
151 unsigned int ompt_version)
153 return no_tool_present;
156 enum tool_setting_e {
165 static int ompt_initialized = 0;
167 if (ompt_initialized)
return;
169 const char *ompt_env_var = getenv(
"OMP_TOOL");
170 tool_setting_e tool_setting = omp_tool_error;
172 if (!ompt_env_var || !strcmp(ompt_env_var,
""))
173 tool_setting = omp_tool_unset;
174 else if (!strcmp(ompt_env_var,
"disabled"))
175 tool_setting = omp_tool_disabled;
176 else if (!strcmp(ompt_env_var,
"enabled"))
177 tool_setting = omp_tool_enabled;
179 switch(tool_setting) {
180 case omp_tool_disabled:
181 ompt_status = ompt_status_disabled;
185 case omp_tool_enabled:
187 const char *runtime_version = __ompt_get_runtime_version_internal();
189 ompt_initialize(ompt_fn_lookup, runtime_version, OMPT_VERSION);
192 ompt_status = ompt_status_track_callback;
193 __ompt_init_internal();
200 "Warning: OMP_TOOL has invalid value \"%s\".\n" 201 " legal values are (NULL,\"\",\"disabled\"," 202 "\"enabled\").\n", ompt_env_var);
206 ompt_initialized = 1;
212 if (ompt_status == ompt_status_track_callback) {
213 if (ompt_callbacks.ompt_callback(ompt_event_runtime_shutdown)) {
214 ompt_callbacks.ompt_callback(ompt_event_runtime_shutdown)();
218 ompt_status = ompt_status_disabled;
227 OMPT_API_ROUTINE ompt_parallel_id_t ompt_get_parallel_id(
int ancestor_level)
229 return __ompt_get_parallel_id_internal(ancestor_level);
233 OMPT_API_ROUTINE
int ompt_get_parallel_team_size(
int ancestor_level)
235 return __ompt_get_parallel_team_size_internal(ancestor_level);
239 OMPT_API_ROUTINE
void *ompt_get_parallel_function(
int ancestor_level)
241 return __ompt_get_parallel_function_internal(ancestor_level);
245 OMPT_API_ROUTINE ompt_state_t ompt_get_state(ompt_wait_id_t *ompt_wait_id)
247 ompt_state_t thread_state = __ompt_get_state_internal(ompt_wait_id);
249 if (thread_state == ompt_state_undefined) {
250 thread_state = ompt_state_work_serial;
263 OMPT_API_ROUTINE
void *ompt_get_idle_frame()
265 return __ompt_get_idle_frame_internal();
275 OMPT_API_ROUTINE ompt_thread_id_t ompt_get_thread_id(
void)
277 return __ompt_get_thread_id_internal();
280 OMPT_API_ROUTINE ompt_task_id_t ompt_get_task_id(
int depth)
282 return __ompt_get_task_id_internal(depth);
286 OMPT_API_ROUTINE ompt_frame_t *ompt_get_task_frame(
int depth)
288 return __ompt_get_task_frame_internal(depth);
292 OMPT_API_ROUTINE
void *ompt_get_task_function(
int depth)
294 return __ompt_get_task_function_internal(depth);
304 #define OMPT_API_PLACEHOLDER 312 OMPT_API_PLACEHOLDER
void ompt_idle(
void)
320 OMPT_API_PLACEHOLDER
void ompt_overhead(
void)
328 OMPT_API_PLACEHOLDER
void ompt_barrier_wait(
void)
337 OMPT_API_PLACEHOLDER
void ompt_task_wait(
void)
346 OMPT_API_PLACEHOLDER
void ompt_mutex_wait(
void)
363 OMPT_API_ROUTINE
int ompt_get_ompt_version()
379 _OMP_EXTERN
void ompt_control(uint64_t command, uint64_t modifier)
381 if (ompt_status == ompt_status_track_callback &&
382 ompt_callbacks.ompt_callback(ompt_event_control)) {
383 ompt_callbacks.ompt_callback(ompt_event_control)(command, modifier);
393 static ompt_interface_fn_t ompt_fn_lookup(
const char *s)
396 #define ompt_interface_fn(fn) \ 397 if (strcmp(s, #fn) == 0) return (ompt_interface_fn_t) fn; 399 FOREACH_OMPT_INQUIRY_FN(ompt_interface_fn)
401 FOREACH_OMPT_PLACEHOLDER_FN(ompt_interface_fn)
403 return (ompt_interface_fn_t) 0;