LLVM OpenMP 20.0.0git
api_calls_without_ompt.c
Go to the documentation of this file.
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...)
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,
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,
45
46 printf("%" PRIu64 ": ompt_get_partition_place_nums()=%d\n", tvalue,
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,
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,
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");
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");
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");
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");
132 (ompt_enumerate_states_t)lookup("ompt_enumerate_states");
134 (ompt_enumerate_mutex_impls_t)lookup("ompt_enumerate_mutex_impls");
135
136 printf("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("0: ompt_event_runtime_shutdown\n");
142}
143
145 const char *runtime_version) {
147 &ompt_finalize, 0};
149}
static ompt_get_task_info_t ompt_get_task_info
static ompt_enumerate_states_t ompt_enumerate_states
static ompt_get_callback_t ompt_get_callback
static ompt_get_place_proc_ids_t ompt_get_place_proc_ids
static ompt_set_callback_t ompt_set_callback
static ompt_get_place_num_t ompt_get_place_num
static ompt_get_partition_place_nums_t ompt_get_partition_place_nums
int ompt_initialize(ompt_function_lookup_t lookup, int initial_device_num, ompt_data_t *tool_data)
void ompt_finalize(ompt_data_t *tool_data)
static ompt_get_num_procs_t ompt_get_num_procs
static ompt_get_num_places_t ompt_get_num_places
static ompt_get_unique_id_t ompt_get_unique_id
static ompt_get_state_t ompt_get_state
int main()
static ompt_get_parallel_info_t ompt_get_parallel_info
static ompt_get_proc_id_t ompt_get_proc_id
static ompt_get_thread_data_t ompt_get_thread_data
static ompt_enumerate_mutex_impls_t ompt_enumerate_mutex_impls
struct ompt_start_tool_result_t ompt_start_tool_result_t
static ompt_start_tool_result_t * ompt_start_tool_result
#define ompt_start_tool
int omp_get_num_threads()