1 // RUN: %libomp-compile-and-run | FileCheck %s
5 #define _DEFAULT_SOURCE
10 #include <omp-tools.h>
12 static ompt_set_callback_t ompt_set_callback
;
13 static ompt_get_callback_t ompt_get_callback
;
14 static ompt_get_state_t ompt_get_state
;
15 static ompt_get_task_info_t ompt_get_task_info
;
16 static ompt_get_thread_data_t ompt_get_thread_data
;
17 static ompt_get_parallel_info_t ompt_get_parallel_info
;
18 static ompt_get_unique_id_t ompt_get_unique_id
;
19 static ompt_get_num_procs_t ompt_get_num_procs
;
20 static ompt_get_num_places_t ompt_get_num_places
;
21 static ompt_get_place_proc_ids_t ompt_get_place_proc_ids
;
22 static ompt_get_place_num_t ompt_get_place_num
;
23 static ompt_get_partition_place_nums_t ompt_get_partition_place_nums
;
24 static ompt_get_proc_id_t ompt_get_proc_id
;
25 static ompt_enumerate_states_t ompt_enumerate_states
;
26 static ompt_enumerate_mutex_impls_t ompt_enumerate_mutex_impls
;
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();
34 ompt_data_t
*tdata
= ompt_get_thread_data();
35 uint64_t tvalue
= tdata
? tdata
->value
: 0;
37 printf("%" PRIu64
": ompt_get_num_places()=%d\n", tvalue
,
38 ompt_get_num_places());
40 printf("%" PRIu64
": ompt_get_place_proc_ids()=%d\n", tvalue
,
41 ompt_get_place_proc_ids(0, 0, NULL
));
43 printf("%" PRIu64
": ompt_get_place_num()=%d\n", tvalue
,
44 ompt_get_place_num());
46 printf("%" PRIu64
": ompt_get_partition_place_nums()=%d\n", tvalue
,
47 ompt_get_partition_place_nums(0, NULL
));
49 printf("%" PRIu64
": ompt_get_proc_id()=%d\n", tvalue
, ompt_get_proc_id());
51 printf("%" PRIu64
": ompt_get_num_procs()=%d\n", tvalue
,
52 ompt_get_num_procs());
54 ompt_callback_t callback
;
55 printf("%" PRIu64
": ompt_get_callback()=%d\n", tvalue
,
56 ompt_get_callback(ompt_callback_thread_begin
, &callback
));
58 printf("%" PRIu64
": ompt_get_state()=%d\n", tvalue
, ompt_get_state(NULL
));
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
));
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
));
70 printf("%" PRIu64
": ompt_get_thread_data()=%p\n", tvalue
,
71 ompt_get_thread_data());
73 printf("%" PRIu64
": ompt_get_parallel_info()=%d\n", tvalue
,
74 ompt_get_parallel_info(0, NULL
, NULL
));
76 printf("%" PRIu64
": ompt_get_task_info()=%d\n", tvalue
,
77 ompt_get_task_info(0, NULL
, NULL
, NULL
, NULL
, NULL
));
79 // Check if libomp supports the callbacks for this test.
81 // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
83 // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_get_num_places()={{[0-9]+}}
85 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_proc_ids()={{[0-9]+}}
87 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_num()=-1
89 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_partition_place_nums()=0
91 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_proc_id()=-1
93 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_num_procs()={{[0-9]+}}
95 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_callback()=0
97 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_state()=0
99 // CHECK: {{^}}[[MASTER_ID]]: ompt_enumerate_states()=1
101 // CHECK: {{^}}[[MASTER_ID]]: ompt_enumerate_mutex_impls()=1
103 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_thread_data()=[[NULL]]
105 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_parallel_info()=0
107 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_task_info()=0
112 int 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");
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");
136 printf("0: NULL_POINTER=%p\n", (void *)NULL
);
137 return 0; // no success -> OMPT not enabled
140 void ompt_finalize(ompt_data_t
*tool_data
) {
141 printf("0: ompt_event_runtime_shutdown\n");
144 ompt_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
,
148 return &ompt_start_tool_result
;