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