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