LLVM OpenMP
22.0.0git
runtime
test
ompt
misc
interoperability.cpp
Go to the documentation of this file.
1
// clang-format off
2
// RUN: %libomp-cxx-compile-and-run | %sort-threads | FileCheck %s
3
// REQUIRES: ompt
4
// clang-format on
5
6
#include <iostream>
7
#include <thread>
8
#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
9
#include <alloca.h>
10
#else
11
#include <cstdlib>
12
#endif
13
14
#include "
callback.h
"
15
#include "omp.h"
16
17
int
condition
= 0;
18
19
void
f
() {
20
// Call OpenMP API function to force initialization of OMPT.
21
// (omp_get_thread_num() does not work because it just returns 0 if the
22
// runtime isn't initialized yet...)
23
omp_get_num_threads
();
24
25
// Call alloca() to force availability of frame pointer
26
void
*
p
= alloca(0);
27
28
OMPT_SIGNAL
(
condition
);
29
// Wait for both initial threads to arrive that will eventually become the
30
// master threads in the following parallel region.
31
OMPT_WAIT
(
condition
, 2);
32
33
#pragma omp parallel num_threads(2)
34
{
35
// Wait for all threads to arrive so that no worker thread can be reused...
36
OMPT_SIGNAL
(
condition
);
37
OMPT_WAIT
(
condition
, 6);
38
}
39
}
40
41
int
main
() {
42
std::thread t1(
f
);
43
std::thread t2(
f
);
44
t1.join();
45
t2.join();
46
}
47
48
// clang-format off
49
// Check if libomp supports the callbacks for this test.
50
// CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_schedule'
51
// CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_begin'
52
// CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_end'
53
// CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task'
54
// CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_thread_begin'
55
56
// CHECK: 0: NULL_POINTER=[[NULL:.*$]]
57
58
// first master thread
59
// CHECK: {{^}}[[MASTER_ID_1:[0-9]+]]: ompt_event_thread_begin:
60
// CHECK-SAME: thread_type=ompt_thread_initial=1, thread_id=[[MASTER_ID_1]]
61
62
63
// CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_initial_task_begin: parallel_id={{[0-f]+}}
64
// CHECK-SAME: task_id=[[PARENT_TASK_ID_1:[0-9]+]], actual_parallelism=1,
65
// CHECK-SAME: index=1, flags=1
66
67
// CHECK: {{^}}[[MASTER_ID_1]]: ompt_event_parallel_begin:
68
// CHECK-SAME: parent_task_id=[[PARENT_TASK_ID_1]]
69
// CHECK-SAME: parent_task_frame.exit=[[NULL]]
70
// CHECK-SAME: parent_task_frame.reenter={{(0x)?[0-f]+}}
71
// CHECK-SAME: parallel_id=[[PARALLEL_ID_1:[0-9]+]], requested_team_size=2
72
// CHECK-SAME: codeptr_ra={{(0x)?[0-f]+}}, invoker={{.*}}
73
74
// CHECK: {{^}}[[MASTER_ID_1]]: ompt_event_parallel_end:
75
// CHECK-SAME: parallel_id=[[PARALLEL_ID_1]], task_id=[[PARENT_TASK_ID_1]]
76
// CHECK-SAME: invoker={{[0-9]+}}
77
78
// CHECK: {{^}}[[MASTER_ID_1]]: ompt_event_initial_task_end:
79
// CHECK-SAME: parallel_id={{[0-f]+}}, task_id=[[PARENT_TASK_ID_1]],
80
// CHECK-SAME: actual_parallelism=0, index=1
81
82
// CHECK: {{^}}[[MASTER_ID_1]]: ompt_event_thread_end:
83
// CHECK-SAME: thread_id=[[MASTER_ID_1]]
84
85
// second master thread
86
// CHECK: {{^}}[[MASTER_ID_2:[0-9]+]]: ompt_event_thread_begin:
87
// CHECK-SAME: thread_type=ompt_thread_initial=1, thread_id=[[MASTER_ID_2]]
88
89
// CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_initial_task_begin: parallel_id={{[0-f]+}}
90
// CHECK-SAME: task_id=[[PARENT_TASK_ID_2:[0-9]+]], actual_parallelism=1,
91
// CHECK-SAME: index=1, flags=1
92
93
// CHECK: {{^}}[[MASTER_ID_2]]: ompt_event_parallel_begin:
94
// CHECK-SAME: parent_task_id=[[PARENT_TASK_ID_2]]
95
// CHECK-SAME: parent_task_frame.exit=[[NULL]]
96
// CHECK-SAME: parent_task_frame.reenter={{(0x)?[0-f]+}}
97
// CHECK-SAME: parallel_id=[[PARALLEL_ID_2:[0-9]+]]
98
// CHECK-SAME: requested_team_size=2, codeptr_ra={{(0x)?[0-f]+}}
99
// CHECK-SAME: invoker={{.*}}
100
101
// CHECK: {{^}}[[MASTER_ID_2]]: ompt_event_parallel_end:
102
// CHECK-SAME: parallel_id=[[PARALLEL_ID_2]], task_id=[[PARENT_TASK_ID_2]]
103
// CHECK-SAME: invoker={{[0-9]+}}
104
105
// CHECK: {{^}}[[MASTER_ID_2]]: ompt_event_initial_task_end:
106
// CHECK-SAME: parallel_id={{[0-f]+}}, task_id=[[PARENT_TASK_ID_2]],
107
// CHECK-SAME: actual_parallelism=0, index=1
108
109
// CHECK: {{^}}[[MASTER_ID_2]]: ompt_event_thread_end:
110
// CHECK-SAME: thread_id=[[MASTER_ID_2]]
111
112
// first worker thread
113
// CHECK: {{^}}[[THREAD_ID_1:[0-9]+]]: ompt_event_thread_begin:
114
// CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[THREAD_ID_1]]
115
// CHECK-NOT: {{^}}[[THREAD_ID_1:[0-9]+]]: ompt_event_initial_task_end:
116
117
// CHECK: {{^}}[[THREAD_ID_1]]: ompt_event_thread_end:
118
// CHECK-SAME: thread_id=[[THREAD_ID_1]]
119
120
// second worker thread
121
// CHECK: {{^}}[[THREAD_ID_2:[0-9]+]]: ompt_event_thread_begin:
122
// CHECK-SAME: thread_type=ompt_thread_worker=2, thread_id=[[THREAD_ID_2]]
123
124
// CHECK: {{^}}[[THREAD_ID_2]]: ompt_event_thread_end:
125
// CHECK-SAME: thread_id=[[THREAD_ID_2]]
126
// clang-format on
callback.h
condition
int condition
Definition:
interoperability.cpp:17
f
void f()
Definition:
interoperability.cpp:19
main
int main()
Definition:
interoperability.cpp:41
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition:
ittnotify_static.h:154
OMPT_WAIT
#define OMPT_WAIT(s, v)
Definition:
ompt-signal.h:20
OMPT_SIGNAL
#define OMPT_SIGNAL(s)
Definition:
ompt-signal.h:13
omp_get_num_threads
int omp_get_num_threads()
Generated on Tue Sep 2 2025 18:35:25 for LLVM OpenMP by
1.9.6