1 // RUN: %libomp-compile && %libomp-run | FileCheck %s
2 // REQUIRES: ompt
3 #include "callback.h"
4 #include <omp.h>
5 
main()6 int main() {
7 #pragma omp parallel num_threads(1)
8   {
9     // ompt_get_callback()
10     ompt_callback_t callback;
11     ompt_get_callback(ompt_callback_thread_begin, &callback);
12     printf("%" PRIu64 ": &on_ompt_callback_thread_begin=%p\n",
13            ompt_get_thread_data()->value, &on_ompt_callback_thread_begin);
14     printf("%" PRIu64 ": ompt_get_callback() result=%p\n",
15            ompt_get_thread_data()->value, callback);
16 
17     // ompt_get_state()
18     printf("%" PRIu64 ": ompt_get_state()=%d\n", ompt_get_thread_data()->value,
19            ompt_get_state(NULL));
20 
21     // ompt_enumerate_states()
22     int state = ompt_state_undefined;
23     const char *state_name;
24     int steps = 0;
25     while (ompt_enumerate_states(state, &state, &state_name) && steps < 1000) {
26       steps++;
27       if (!state_name)
28         printf("%" PRIu64 ": state_name is NULL\n",
29                ompt_get_thread_data()->value);
30     }
31     if (steps >= 1000) {
32       // enumeration did not end after 1000 steps
33       printf("%" PRIu64 ": states enumeration did not end\n",
34              ompt_get_thread_data()->value);
35     }
36 
37     // ompt_enumerate_mutex_impls()
38     int impl = ompt_mutex_impl_none;
39     const char *impl_name;
40     steps = 0;
41     while (ompt_enumerate_mutex_impls(impl, &impl, &impl_name) &&
42            steps < 1000) {
43       steps++;
44       if (!impl_name)
45         printf("%" PRIu64 ": impl_name is NULL\n",
46                ompt_get_thread_data()->value);
47     }
48     if (steps >= 1000) {
49       // enumeration did not end after 1000 steps
50       printf("%" PRIu64 ": mutex_impls enumeration did not end\n",
51              ompt_get_thread_data()->value);
52     }
53   }
54 
55   // Check if libomp supports the callbacks for this test.
56 
57   // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
58 
59   // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: &on_ompt_callback_thread_begin
60   // CHECK-SAME: =[[FUNCTION_POINTER:0x[0-f]+]]
61   // CHECK: {{^}}[[THREAD_ID]]: ompt_get_callback() result=[[FUNCTION_POINTER]]
62 
63   // CHECK: {{^}}[[THREAD_ID]]: ompt_get_state()=1
64 
65   // CHECK-NOT: {{^}}[[THREAD_ID]]: state_name is NULL
66   // CHECK-NOT: {{^}}[[THREAD_ID]]: states enumeration did not end
67 
68   // CHECK-NOT: {{^}}[[THREAD_ID]]: impl_name is NULL
69   // CHECK-NOT: {{^}}[[THREAD_ID]]: mutex_impls enumeration did not end
70 
71   return 0;
72 }
73