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