1// RUN: %libomp-compile-and-run | FileCheck %s
2// REQUIRES: ompt
3
4#define _BSD_SOURCE
5#define _DEFAULT_SOURCE
6
7#include <stdio.h>
8#include <inttypes.h>
9#include <omp.h>
10#include <omp-tools.h>
11
12static ompt_set_callback_t ompt_set_callback;
13static ompt_get_callback_t ompt_get_callback;
14static ompt_get_state_t ompt_get_state;
15static ompt_get_task_info_t ompt_get_task_info;
16static ompt_get_thread_data_t ompt_get_thread_data;
17static ompt_get_parallel_info_t ompt_get_parallel_info;
18static ompt_get_unique_id_t ompt_get_unique_id;
19static ompt_get_num_procs_t ompt_get_num_procs;
20static ompt_get_num_places_t ompt_get_num_places;
21static ompt_get_place_proc_ids_t ompt_get_place_proc_ids;
22static ompt_get_place_num_t ompt_get_place_num;
23static ompt_get_partition_place_nums_t ompt_get_partition_place_nums;
24static ompt_get_proc_id_t ompt_get_proc_id;
25static ompt_enumerate_states_t ompt_enumerate_states;
26static ompt_enumerate_mutex_impls_t ompt_enumerate_mutex_impls;
27
28int main() {
29 // Call OpenMP API function to force initialization of OMPT.
30 // (omp_get_thread_num() does not work because it just returns 0 if the
31 // runtime isn't initialized yet...)
32 omp_get_num_threads();
33
34 ompt_data_t *tdata = ompt_get_thread_data();
35 uint64_t tvalue = tdata ? tdata->value : 0;
36
37 printf("%" PRIu64 ": ompt_get_num_places()=%d\n", tvalue,
38 ompt_get_num_places());
39
40 printf("%" PRIu64 ": ompt_get_place_proc_ids()=%d\n", tvalue,
41 ompt_get_place_proc_ids(0, 0, NULL));
42
43 printf("%" PRIu64 ": ompt_get_place_num()=%d\n", tvalue,
44 ompt_get_place_num());
45
46 printf("%" PRIu64 ": ompt_get_partition_place_nums()=%d\n", tvalue,
47 ompt_get_partition_place_nums(0, NULL));
48
49 printf("%" PRIu64 ": ompt_get_proc_id()=%d\n", tvalue, ompt_get_proc_id());
50
51 printf("%" PRIu64 ": ompt_get_num_procs()=%d\n", tvalue,
52 ompt_get_num_procs());
53
54 ompt_callback_t callback;
55 printf("%" PRIu64 ": ompt_get_callback()=%d\n", tvalue,
56 ompt_get_callback(ompt_callback_thread_begin, &callback));
57
58 printf("%" PRIu64 ": ompt_get_state()=%d\n", tvalue, ompt_get_state(NULL));
59
60 int state = ompt_state_undefined;
61 const char *state_name;
62 printf("%" PRIu64 ": ompt_enumerate_states()=%d\n", tvalue,
63 ompt_enumerate_states(state, &state, &state_name));
64
65 int impl = ompt_mutex_impl_none;
66 const char *impl_name;
67 printf("%" PRIu64 ": ompt_enumerate_mutex_impls()=%d\n", tvalue,
68 ompt_enumerate_mutex_impls(impl, &impl, &impl_name));
69
70 printf("%" PRIu64 ": ompt_get_thread_data()=%p\n", tvalue,
71 ompt_get_thread_data());
72
73 printf("%" PRIu64 ": ompt_get_parallel_info()=%d\n", tvalue,
74 ompt_get_parallel_info(0, NULL, NULL));
75
76 printf("%" PRIu64 ": ompt_get_task_info()=%d\n", tvalue,
77 ompt_get_task_info(0, NULL, NULL, NULL, NULL, NULL));
78
79 // Check if libomp supports the callbacks for this test.
80
81 // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
82
83 // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_get_num_places()={{[0-9]+}}
84
85 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_proc_ids()={{[0-9]+}}
86
87 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_num()=-1
88
89 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_partition_place_nums()=0
90
91 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_proc_id()=-1
92
93 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_num_procs()={{[0-9]+}}
94
95 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_callback()=0
96
97 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_state()=0
98
99 // CHECK: {{^}}[[MASTER_ID]]: ompt_enumerate_states()=1
100
101 // CHECK: {{^}}[[MASTER_ID]]: ompt_enumerate_mutex_impls()=1
102
103 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_thread_data()=[[NULL]]
104
105 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_parallel_info()=0
106
107 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_task_info()=0
108
109 return 0;
110}
111
112int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num,
113 ompt_data_t *tool_data) {
114 ompt_set_callback = (ompt_set_callback_t)lookup("ompt_set_callback");
115 ompt_get_callback = (ompt_get_callback_t)lookup("ompt_get_callback");
116 ompt_get_state = (ompt_get_state_t)lookup("ompt_get_state");
117 ompt_get_task_info = (ompt_get_task_info_t)lookup("ompt_get_task_info");
118 ompt_get_thread_data = (ompt_get_thread_data_t)lookup("ompt_get_thread_data");
119 ompt_get_parallel_info =
120 (ompt_get_parallel_info_t)lookup("ompt_get_parallel_info");
121 ompt_get_unique_id = (ompt_get_unique_id_t)lookup("ompt_get_unique_id");
122
123 ompt_get_num_procs = (ompt_get_num_procs_t)lookup("ompt_get_num_procs");
124 ompt_get_num_places = (ompt_get_num_places_t)lookup("ompt_get_num_places");
125 ompt_get_place_proc_ids =
126 (ompt_get_place_proc_ids_t)lookup("ompt_get_place_proc_ids");
127 ompt_get_place_num = (ompt_get_place_num_t)lookup("ompt_get_place_num");
128 ompt_get_partition_place_nums =
129 (ompt_get_partition_place_nums_t)lookup("ompt_get_partition_place_nums");
130 ompt_get_proc_id = (ompt_get_proc_id_t)lookup("ompt_get_proc_id");
131 ompt_enumerate_states =
132 (ompt_enumerate_states_t)lookup("ompt_enumerate_states");
133 ompt_enumerate_mutex_impls =
134 (ompt_enumerate_mutex_impls_t)lookup("ompt_enumerate_mutex_impls");
135
136 printf(format: "0: NULL_POINTER=%p\n", (void *)NULL);
137 return 0; // no success -> OMPT not enabled
138}
139
140void ompt_finalize(ompt_data_t *tool_data) {
141 printf(format: "0: ompt_event_runtime_shutdown\n");
142}
143
144ompt_start_tool_result_t *ompt_start_tool(unsigned int omp_version,
145 const char *runtime_version) {
146 static ompt_start_tool_result_t ompt_start_tool_result = {&ompt_initialize,
147 &ompt_finalize, 0};
148 return &ompt_start_tool_result;
149}
150

source code of openmp/runtime/test/ompt/misc/api_calls_without_ompt.c