LLVM OpenMP 22.0.0git
api_calls_from_other_thread.cpp
Go to the documentation of this file.
1// clang-format off
2// RUN: %libomp-cxx-compile-and-run | FileCheck %s
3// REQUIRES: ompt, linux
4// clang-format on
5
6#include <thread>
7#include "callback.h"
8
9void f() {
10 ompt_data_t *tdata = ompt_get_thread_data();
11 uint64_t tvalue = tdata ? tdata->value : 0;
12
13 printf("%" PRIu64 ": ompt_get_num_places()=%d\n", tvalue,
15
16 printf("%" PRIu64 ": ompt_get_place_proc_ids()=%d\n", tvalue,
17 ompt_get_place_proc_ids(0, 0, NULL));
18
19 printf("%" PRIu64 ": ompt_get_place_num()=%d\n", tvalue,
21
22 printf("%" PRIu64 ": ompt_get_partition_place_nums()=%d\n", tvalue,
24
25 printf("%" PRIu64 ": ompt_get_proc_id()=%d\n", tvalue, ompt_get_proc_id());
26
27 printf("%" PRIu64 ": ompt_get_num_procs()=%d\n", tvalue,
29
30 ompt_callback_t callback;
31 printf("%" PRIu64 ": ompt_get_callback()=%d\n", tvalue,
32 ompt_get_callback(ompt_callback_thread_begin, &callback));
33
34 printf("%" PRIu64 ": ompt_get_state()=%d\n", tvalue, ompt_get_state(NULL));
35
36 int state = ompt_state_undefined;
37 const char *state_name;
38 printf("%" PRIu64 ": ompt_enumerate_states()=%d\n", tvalue,
39 ompt_enumerate_states(state, &state, &state_name));
40
41 int impl = ompt_mutex_impl_none;
42 const char *impl_name;
43 printf("%" PRIu64 ": ompt_enumerate_mutex_impls()=%d\n", tvalue,
44 ompt_enumerate_mutex_impls(impl, &impl, &impl_name));
45
46 printf("%" PRIu64 ": ompt_get_thread_data()=%p\n", tvalue,
48
49 printf("%" PRIu64 ": ompt_get_parallel_info()=%d\n", tvalue,
50 ompt_get_parallel_info(0, NULL, NULL));
51
52 printf("%" PRIu64 ": ompt_get_task_info()=%d\n", tvalue,
53 ompt_get_task_info(0, NULL, NULL, NULL, NULL, NULL));
54}
55
56int main() {
57#pragma omp parallel num_threads(1)
58 {}
59
60 std::thread t1(f);
61 t1.join();
62
63 // clang-format off
64 // Check if libomp supports the callbacks for this test.
65
66 // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
67
68 // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_get_num_places()={{[0-9]+}}
69
70 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_proc_ids()={{[0-9]+}}
71
72 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_place_num()=-1
73
74 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_partition_place_nums()=0
75
76 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_proc_id()=-1
77
78 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_num_procs()={{[0-9]+}}
79
80 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_callback()=1
81
82 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_state()=0
83
84 // CHECK: {{^}}[[MASTER_ID]]: ompt_enumerate_states()=1
85
86 // CHECK: {{^}}[[MASTER_ID]]: ompt_enumerate_mutex_impls()=1
87
88 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_thread_data()=[[NULL]]
89
90 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_parallel_info()=0
91
92 // CHECK: {{^}}[[MASTER_ID]]: ompt_get_task_info()=0
93 // clang-format on
94
95 return 0;
96}
static ompt_get_task_info_t ompt_get_task_info
Definition callback.h:156
static ompt_enumerate_states_t ompt_enumerate_states
Definition callback.h:168
static ompt_get_callback_t ompt_get_callback
Definition callback.h:154
static ompt_get_place_proc_ids_t ompt_get_place_proc_ids
Definition callback.h:164
static ompt_get_place_num_t ompt_get_place_num
Definition callback.h:165
static ompt_get_partition_place_nums_t ompt_get_partition_place_nums
Definition callback.h:166
static ompt_get_num_procs_t ompt_get_num_procs
Definition callback.h:162
static ompt_get_num_places_t ompt_get_num_places
Definition callback.h:163
static ompt_get_state_t ompt_get_state
Definition callback.h:155
static ompt_get_parallel_info_t ompt_get_parallel_info
Definition callback.h:159
static ompt_get_proc_id_t ompt_get_proc_id
Definition callback.h:167
static ompt_get_thread_data_t ompt_get_thread_data
Definition callback.h:158
static ompt_enumerate_mutex_impls_t ompt_enumerate_mutex_impls
Definition callback.h:169