blob: fa66d9cae5d619d23b7077794864278cf9e34116 [file] [log] [blame]
Andrey Churbanove5f44922015-04-29 16:22:07 +00001/*****************************************************************************
2 * system include files
3 ****************************************************************************/
4
5#include <assert.h>
6
7#include <stdint.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11
Andrey Churbanove5f44922015-04-29 16:22:07 +000012/*****************************************************************************
13 * ompt include files
14 ****************************************************************************/
15
Jonathan Peyton7cc577a2016-12-14 22:39:11 +000016#include "ompt-specific.cpp"
Andrey Churbanove5f44922015-04-29 16:22:07 +000017
Andrey Churbanove5f44922015-04-29 16:22:07 +000018/*****************************************************************************
19 * macros
20 ****************************************************************************/
21
22#define ompt_get_callback_success 1
23#define ompt_get_callback_failure 0
24
25#define no_tool_present 0
26
27#define OMPT_API_ROUTINE static
28
Jonathan Peyton69e596a2015-10-29 20:56:24 +000029#ifndef OMPT_STR_MATCH
30#define OMPT_STR_MATCH(haystack, needle) (!strcasecmp(haystack, needle))
31#endif
Andrey Churbanove5f44922015-04-29 16:22:07 +000032
Andrey Churbanove5f44922015-04-29 16:22:07 +000033/*****************************************************************************
34 * types
35 ****************************************************************************/
36
37typedef struct {
Jonathan Peyton30419822017-05-12 18:01:32 +000038 const char *state_name;
39 ompt_state_t state_id;
Andrey Churbanove5f44922015-04-29 16:22:07 +000040} ompt_state_info_t;
41
Jonathan Peyton82a13bf2015-09-21 18:01:02 +000042enum tool_setting_e {
Jonathan Peyton30419822017-05-12 18:01:32 +000043 omp_tool_error,
44 omp_tool_unset,
45 omp_tool_disabled,
46 omp_tool_enabled
Jonathan Peyton82a13bf2015-09-21 18:01:02 +000047};
48
Jonathan Peyton30419822017-05-12 18:01:32 +000049typedef void (*ompt_initialize_t)(ompt_function_lookup_t ompt_fn_lookup,
50 const char *version,
51 unsigned int ompt_version);
Andrey Churbanove5f44922015-04-29 16:22:07 +000052
53/*****************************************************************************
54 * global variables
55 ****************************************************************************/
56
Jonathan Peytonb68a85d2015-09-21 18:11:22 +000057int ompt_enabled = 0;
Andrey Churbanove5f44922015-04-29 16:22:07 +000058
59ompt_state_info_t ompt_state_info[] = {
Jonathan Peyton30419822017-05-12 18:01:32 +000060#define ompt_state_macro(state, code) {#state, state},
Andrey Churbanove5f44922015-04-29 16:22:07 +000061 FOREACH_OMPT_STATE(ompt_state_macro)
62#undef ompt_state_macro
63};
64
Andrey Churbanove5f44922015-04-29 16:22:07 +000065ompt_callbacks_t ompt_callbacks;
66
Jonathan Peyton30419822017-05-12 18:01:32 +000067static ompt_initialize_t ompt_initialize_fn = NULL;
Andrey Churbanove5f44922015-04-29 16:22:07 +000068
69/*****************************************************************************
70 * forward declarations
71 ****************************************************************************/
72
73static ompt_interface_fn_t ompt_fn_lookup(const char *s);
74
Jonathan Peyton82a13bf2015-09-21 18:01:02 +000075OMPT_API_ROUTINE ompt_thread_id_t ompt_get_thread_id(void);
76
Jonathan Peyton82a13bf2015-09-21 18:01:02 +000077/*****************************************************************************
78 * initialization and finalization (private operations)
79 ****************************************************************************/
80
Jonathan Peyton69e596a2015-10-29 20:56:24 +000081/* On Unix-like systems that support weak symbols the following implementation
82 * of ompt_tool() will be used in case no tool-supplied implementation of
83 * this function is present in the address space of a process.
84 *
85 * On Windows, the ompt_tool_windows function is used to find the
86 * ompt_tool symbol across all modules loaded by a process. If ompt_tool is
87 * found, ompt_tool's return value is used to initialize the tool. Otherwise,
88 * NULL is returned and OMPT won't be enabled */
89#if OMPT_HAVE_WEAK_ATTRIBUTE
Jonathan Peyton61118492016-05-20 19:03:38 +000090_OMP_EXTERN
Jonathan Peyton30419822017-05-12 18:01:32 +000091__attribute__((weak)) ompt_initialize_t ompt_tool() {
Jonathan Peyton69e596a2015-10-29 20:56:24 +000092#if OMPT_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +000093 printf("ompt_tool() is called from the RTL\n");
Jonathan Peyton69e596a2015-10-29 20:56:24 +000094#endif
Jonathan Peyton30419822017-05-12 18:01:32 +000095 return NULL;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +000096}
97
Jonathan Peyton69e596a2015-10-29 20:56:24 +000098#elif OMPT_HAVE_PSAPI
99
100#include <psapi.h>
101#pragma comment(lib, "psapi.lib")
102#define ompt_tool ompt_tool_windows
103
104// The number of loaded modules to start enumeration with EnumProcessModules()
105#define NUM_MODULES 128
106
Jonathan Peyton30419822017-05-12 18:01:32 +0000107static ompt_initialize_t ompt_tool_windows() {
108 int i;
109 DWORD needed, new_size;
110 HMODULE *modules;
111 HANDLE process = GetCurrentProcess();
112 modules = (HMODULE *)malloc(NUM_MODULES * sizeof(HMODULE));
113 ompt_initialize_t (*ompt_tool_p)() = NULL;
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000114
115#if OMPT_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000116 printf("ompt_tool_windows(): looking for ompt_tool\n");
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000117#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000118 if (!EnumProcessModules(process, modules, NUM_MODULES * sizeof(HMODULE),
119 &needed)) {
120 // Regardless of the error reason use the stub initialization function
121 free(modules);
122 return NULL;
123 }
124 // Check if NUM_MODULES is enough to list all modules
125 new_size = needed / sizeof(HMODULE);
126 if (new_size > NUM_MODULES) {
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000127#if OMPT_DEBUG
128 printf("ompt_tool_windows(): resize buffer to %d bytes\n", needed);
129#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000130 modules = (HMODULE *)realloc(modules, needed);
131 // If resizing failed use the stub function.
132 if (!EnumProcessModules(process, modules, needed, &needed)) {
133 free(modules);
134 return NULL;
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000135 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000136 }
137 for (i = 0; i < new_size; ++i) {
138 (FARPROC &)ompt_tool_p = GetProcAddress(modules[i], "ompt_tool");
139 if (ompt_tool_p) {
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000140#if OMPT_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000141 TCHAR modName[MAX_PATH];
142 if (GetModuleFileName(modules[i], modName, MAX_PATH))
143 printf("ompt_tool_windows(): ompt_tool found in module %s\n", modName);
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000144#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000145 free(modules);
146 return ompt_tool_p();
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000147 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000148#if OMPT_DEBUG
149 else {
150 TCHAR modName[MAX_PATH];
151 if (GetModuleFileName(modules[i], modName, MAX_PATH))
152 printf("ompt_tool_windows(): ompt_tool not found in module %s\n",
153 modName);
154 }
155#endif
156 }
157 free(modules);
158 return NULL;
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000159}
160#else
Jonathan Peyton30419822017-05-12 18:01:32 +0000161#error Either __attribute__((weak)) or psapi.dll are required for OMPT support
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000162#endif // OMPT_HAVE_WEAK_ATTRIBUTE
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000163
Jonathan Peyton30419822017-05-12 18:01:32 +0000164void ompt_pre_init() {
165 //--------------------------------------------------
166 // Execute the pre-initialization logic only once.
167 //--------------------------------------------------
168 static int ompt_pre_initialized = 0;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000169
Jonathan Peyton30419822017-05-12 18:01:32 +0000170 if (ompt_pre_initialized)
171 return;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000172
Jonathan Peyton30419822017-05-12 18:01:32 +0000173 ompt_pre_initialized = 1;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000174
Jonathan Peyton30419822017-05-12 18:01:32 +0000175 //--------------------------------------------------
176 // Use a tool iff a tool is enabled and available.
177 //--------------------------------------------------
178 const char *ompt_env_var = getenv("OMP_TOOL");
179 tool_setting_e tool_setting = omp_tool_error;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000180
Jonathan Peyton30419822017-05-12 18:01:32 +0000181 if (!ompt_env_var || !strcmp(ompt_env_var, ""))
182 tool_setting = omp_tool_unset;
183 else if (OMPT_STR_MATCH(ompt_env_var, "disabled"))
184 tool_setting = omp_tool_disabled;
185 else if (OMPT_STR_MATCH(ompt_env_var, "enabled"))
186 tool_setting = omp_tool_enabled;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000187
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000188#if OMPT_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000189 printf("ompt_pre_init(): tool_setting = %d\n", tool_setting);
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000190#endif
Jonathan Peyton30419822017-05-12 18:01:32 +0000191 switch (tool_setting) {
192 case omp_tool_disabled:
193 break;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000194
Jonathan Peyton30419822017-05-12 18:01:32 +0000195 case omp_tool_unset:
196 case omp_tool_enabled:
197 ompt_initialize_fn = ompt_tool();
198 if (ompt_initialize_fn) {
199 ompt_enabled = 1;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000200 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000201 break;
202
203 case omp_tool_error:
204 fprintf(stderr, "Warning: OMP_TOOL has invalid value \"%s\".\n"
205 " legal values are (NULL,\"\",\"disabled\","
206 "\"enabled\").\n",
207 ompt_env_var);
208 break;
209 }
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000210#if OMPT_DEBUG
Jonathan Peyton30419822017-05-12 18:01:32 +0000211 printf("ompt_pre_init(): ompt_enabled = %d\n", ompt_enabled);
Jonathan Peyton69e596a2015-10-29 20:56:24 +0000212#endif
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000213}
214
Jonathan Peyton30419822017-05-12 18:01:32 +0000215void ompt_post_init() {
216 //--------------------------------------------------
217 // Execute the post-initialization logic only once.
218 //--------------------------------------------------
219 static int ompt_post_initialized = 0;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000220
Jonathan Peyton30419822017-05-12 18:01:32 +0000221 if (ompt_post_initialized)
222 return;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000223
Jonathan Peyton30419822017-05-12 18:01:32 +0000224 ompt_post_initialized = 1;
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000225
Jonathan Peyton30419822017-05-12 18:01:32 +0000226 //--------------------------------------------------
227 // Initialize the tool if so indicated.
228 //--------------------------------------------------
229 if (ompt_enabled) {
230 ompt_initialize_fn(ompt_fn_lookup, ompt_get_runtime_version(),
231 OMPT_VERSION);
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000232
Jonathan Peyton30419822017-05-12 18:01:32 +0000233 ompt_thread_t *root_thread = ompt_get_thread();
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000234
Jonathan Peyton30419822017-05-12 18:01:32 +0000235 ompt_set_thread_state(root_thread, ompt_state_overhead);
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000236
Jonathan Peyton30419822017-05-12 18:01:32 +0000237 if (ompt_callbacks.ompt_callback(ompt_event_thread_begin)) {
238 ompt_callbacks.ompt_callback(ompt_event_thread_begin)(
239 ompt_thread_initial, ompt_get_thread_id());
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000240 }
241
Jonathan Peyton30419822017-05-12 18:01:32 +0000242 ompt_set_thread_state(root_thread, ompt_state_work_serial);
243 }
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000244}
245
Jonathan Peyton30419822017-05-12 18:01:32 +0000246void ompt_fini() {
247 if (ompt_enabled) {
248 if (ompt_callbacks.ompt_callback(ompt_event_runtime_shutdown)) {
249 ompt_callbacks.ompt_callback(ompt_event_runtime_shutdown)();
250 }
251 }
252
253 ompt_enabled = 0;
254}
Jonathan Peyton82a13bf2015-09-21 18:01:02 +0000255
256/*****************************************************************************
257 * interface operations
258 ****************************************************************************/
Andrey Churbanove5f44922015-04-29 16:22:07 +0000259
260/*****************************************************************************
261 * state
262 ****************************************************************************/
263
264OMPT_API_ROUTINE int ompt_enumerate_state(int current_state, int *next_state,
Jonathan Peyton30419822017-05-12 18:01:32 +0000265 const char **next_state_name) {
266 const static int len = sizeof(ompt_state_info) / sizeof(ompt_state_info_t);
267 int i = 0;
Andrey Churbanove5f44922015-04-29 16:22:07 +0000268
Jonathan Peyton30419822017-05-12 18:01:32 +0000269 for (i = 0; i < len - 1; i++) {
270 if (ompt_state_info[i].state_id == current_state) {
271 *next_state = ompt_state_info[i + 1].state_id;
272 *next_state_name = ompt_state_info[i + 1].state_name;
273 return 1;
Andrey Churbanove5f44922015-04-29 16:22:07 +0000274 }
Jonathan Peyton30419822017-05-12 18:01:32 +0000275 }
Andrey Churbanove5f44922015-04-29 16:22:07 +0000276
Jonathan Peyton30419822017-05-12 18:01:32 +0000277 return 0;
Andrey Churbanove5f44922015-04-29 16:22:07 +0000278}
279
Andrey Churbanove5f44922015-04-29 16:22:07 +0000280/*****************************************************************************
281 * callbacks
282 ****************************************************************************/
283
Jonathan Peyton30419822017-05-12 18:01:32 +0000284OMPT_API_ROUTINE int ompt_set_callback(ompt_event_t evid, ompt_callback_t cb) {
285 switch (evid) {
Andrey Churbanove5f44922015-04-29 16:22:07 +0000286
287#define ompt_event_macro(event_name, callback_type, event_id) \
Jonathan Peyton30419822017-05-12 18:01:32 +0000288 case event_name: \
289 if (ompt_event_implementation_status(event_name)) { \
290 ompt_callbacks.ompt_callback(event_name) = (callback_type)cb; \
291 } \
292 return ompt_event_implementation_status(event_name);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000293
294 FOREACH_OMPT_EVENT(ompt_event_macro)
295
296#undef ompt_event_macro
297
Jonathan Peyton30419822017-05-12 18:01:32 +0000298 default:
299 return ompt_set_result_registration_error;
300 }
Andrey Churbanove5f44922015-04-29 16:22:07 +0000301}
302
Jonathan Peyton30419822017-05-12 18:01:32 +0000303OMPT_API_ROUTINE int ompt_get_callback(ompt_event_t evid, ompt_callback_t *cb) {
304 switch (evid) {
Andrey Churbanove5f44922015-04-29 16:22:07 +0000305
306#define ompt_event_macro(event_name, callback_type, event_id) \
Jonathan Peyton30419822017-05-12 18:01:32 +0000307 case event_name: \
308 if (ompt_event_implementation_status(event_name)) { \
309 ompt_callback_t mycb = \
310 (ompt_callback_t)ompt_callbacks.ompt_callback(event_name); \
311 if (mycb) { \
312 *cb = mycb; \
313 return ompt_get_callback_success; \
314 } \
315 } \
316 return ompt_get_callback_failure;
Andrey Churbanove5f44922015-04-29 16:22:07 +0000317
318 FOREACH_OMPT_EVENT(ompt_event_macro)
319
320#undef ompt_event_macro
321
Jonathan Peyton30419822017-05-12 18:01:32 +0000322 default:
323 return ompt_get_callback_failure;
324 }
Andrey Churbanove5f44922015-04-29 16:22:07 +0000325}
326
Andrey Churbanove5f44922015-04-29 16:22:07 +0000327/*****************************************************************************
328 * parallel regions
329 ****************************************************************************/
330
Jonathan Peyton30419822017-05-12 18:01:32 +0000331OMPT_API_ROUTINE ompt_parallel_id_t ompt_get_parallel_id(int ancestor_level) {
332 return __ompt_get_parallel_id_internal(ancestor_level);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000333}
334
Jonathan Peyton30419822017-05-12 18:01:32 +0000335OMPT_API_ROUTINE int ompt_get_parallel_team_size(int ancestor_level) {
336 return __ompt_get_parallel_team_size_internal(ancestor_level);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000337}
338
Jonathan Peyton30419822017-05-12 18:01:32 +0000339OMPT_API_ROUTINE void *ompt_get_parallel_function(int ancestor_level) {
340 return __ompt_get_parallel_function_internal(ancestor_level);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000341}
342
Jonathan Peyton30419822017-05-12 18:01:32 +0000343OMPT_API_ROUTINE ompt_state_t ompt_get_state(ompt_wait_id_t *ompt_wait_id) {
344 ompt_state_t thread_state = __ompt_get_state_internal(ompt_wait_id);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000345
Jonathan Peyton30419822017-05-12 18:01:32 +0000346 if (thread_state == ompt_state_undefined) {
347 thread_state = ompt_state_work_serial;
348 }
Andrey Churbanove5f44922015-04-29 16:22:07 +0000349
Jonathan Peyton30419822017-05-12 18:01:32 +0000350 return thread_state;
Andrey Churbanove5f44922015-04-29 16:22:07 +0000351}
352
Andrey Churbanove5f44922015-04-29 16:22:07 +0000353/*****************************************************************************
354 * threads
355 ****************************************************************************/
356
Jonathan Peyton30419822017-05-12 18:01:32 +0000357OMPT_API_ROUTINE void *ompt_get_idle_frame() {
358 return __ompt_get_idle_frame_internal();
Andrey Churbanove5f44922015-04-29 16:22:07 +0000359}
360
Andrey Churbanove5f44922015-04-29 16:22:07 +0000361/*****************************************************************************
362 * tasks
363 ****************************************************************************/
364
Jonathan Peyton30419822017-05-12 18:01:32 +0000365OMPT_API_ROUTINE ompt_thread_id_t ompt_get_thread_id(void) {
366 return __ompt_get_thread_id_internal();
Andrey Churbanove5f44922015-04-29 16:22:07 +0000367}
368
Jonathan Peyton30419822017-05-12 18:01:32 +0000369OMPT_API_ROUTINE ompt_task_id_t ompt_get_task_id(int depth) {
370 return __ompt_get_task_id_internal(depth);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000371}
372
Jonathan Peyton30419822017-05-12 18:01:32 +0000373OMPT_API_ROUTINE ompt_frame_t *ompt_get_task_frame(int depth) {
374 return __ompt_get_task_frame_internal(depth);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000375}
376
Jonathan Peyton30419822017-05-12 18:01:32 +0000377OMPT_API_ROUTINE void *ompt_get_task_function(int depth) {
378 return __ompt_get_task_function_internal(depth);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000379}
380
Andrey Churbanove5f44922015-04-29 16:22:07 +0000381/*****************************************************************************
382 * placeholders
383 ****************************************************************************/
384
Jonathan Peyton122dd762015-07-13 18:55:45 +0000385// Don't define this as static. The loader may choose to eliminate the symbol
Jonathan Peyton61118492016-05-20 19:03:38 +0000386// even though it is needed by tools.
387#define OMPT_API_PLACEHOLDER
Andrey Churbanove5f44922015-04-29 16:22:07 +0000388
Jonathan Peyton122dd762015-07-13 18:55:45 +0000389// Ensure that placeholders don't have mangled names in the symbol table.
390#ifdef __cplusplus
391extern "C" {
392#endif
393
Jonathan Peyton30419822017-05-12 18:01:32 +0000394OMPT_API_PLACEHOLDER void ompt_idle(void) {
395 // This function is a placeholder used to represent the calling context of
396 // idle OpenMP worker threads. It is not meant to be invoked.
397 assert(0);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000398}
399
Jonathan Peyton30419822017-05-12 18:01:32 +0000400OMPT_API_PLACEHOLDER void ompt_overhead(void) {
401 // This function is a placeholder used to represent the OpenMP context of
402 // threads working in the OpenMP runtime. It is not meant to be invoked.
403 assert(0);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000404}
405
Jonathan Peyton30419822017-05-12 18:01:32 +0000406OMPT_API_PLACEHOLDER void ompt_barrier_wait(void) {
407 // This function is a placeholder used to represent the OpenMP context of
408 // threads waiting for a barrier in the OpenMP runtime. It is not meant
409 // to be invoked.
410 assert(0);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000411}
412
Jonathan Peyton30419822017-05-12 18:01:32 +0000413OMPT_API_PLACEHOLDER void ompt_task_wait(void) {
414 // This function is a placeholder used to represent the OpenMP context of
415 // threads waiting for a task in the OpenMP runtime. It is not meant
416 // to be invoked.
417 assert(0);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000418}
419
Jonathan Peyton30419822017-05-12 18:01:32 +0000420OMPT_API_PLACEHOLDER void ompt_mutex_wait(void) {
421 // This function is a placeholder used to represent the OpenMP context of
422 // threads waiting for a mutex in the OpenMP runtime. It is not meant
423 // to be invoked.
424 assert(0);
Andrey Churbanove5f44922015-04-29 16:22:07 +0000425}
426
Jonathan Peyton122dd762015-07-13 18:55:45 +0000427#ifdef __cplusplus
428};
429#endif
430
Andrey Churbanove5f44922015-04-29 16:22:07 +0000431/*****************************************************************************
432 * compatability
433 ****************************************************************************/
434
Jonathan Peyton30419822017-05-12 18:01:32 +0000435OMPT_API_ROUTINE int ompt_get_ompt_version() { return OMPT_VERSION; }
Andrey Churbanove5f44922015-04-29 16:22:07 +0000436
437/*****************************************************************************
438 * application-facing API
439 ****************************************************************************/
440
Andrey Churbanove5f44922015-04-29 16:22:07 +0000441/*----------------------------------------------------------------------------
442 | control
443 ---------------------------------------------------------------------------*/
444
Jonathan Peyton30419822017-05-12 18:01:32 +0000445_OMP_EXTERN void ompt_control(uint64_t command, uint64_t modifier) {
446 if (ompt_enabled && ompt_callbacks.ompt_callback(ompt_event_control)) {
447 ompt_callbacks.ompt_callback(ompt_event_control)(command, modifier);
448 }
Andrey Churbanove5f44922015-04-29 16:22:07 +0000449}
450
Andrey Churbanove5f44922015-04-29 16:22:07 +0000451/*****************************************************************************
452 * API inquiry for tool
453 ****************************************************************************/
454
Jonathan Peyton30419822017-05-12 18:01:32 +0000455static ompt_interface_fn_t ompt_fn_lookup(const char *s) {
Andrey Churbanove5f44922015-04-29 16:22:07 +0000456
Jonathan Peyton30419822017-05-12 18:01:32 +0000457#define ompt_interface_fn(fn) \
458 if (strcmp(s, #fn) == 0) \
459 return (ompt_interface_fn_t)fn;
Andrey Churbanove5f44922015-04-29 16:22:07 +0000460
Jonathan Peyton30419822017-05-12 18:01:32 +0000461 FOREACH_OMPT_INQUIRY_FN(ompt_interface_fn)
Andrey Churbanove5f44922015-04-29 16:22:07 +0000462
Jonathan Peyton30419822017-05-12 18:01:32 +0000463 FOREACH_OMPT_PLACEHOLDER_FN(ompt_interface_fn)
Andrey Churbanove5f44922015-04-29 16:22:07 +0000464
Jonathan Peyton30419822017-05-12 18:01:32 +0000465 return (ompt_interface_fn_t)0;
Andrey Churbanove5f44922015-04-29 16:22:07 +0000466}