LLVM OpenMP 22.0.0git
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
17int condition = 0;
18
19void 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...)
24
25 // Call alloca() to force availability of frame pointer
26 void *p = alloca(0);
27
29 // Wait for both initial threads to arrive that will eventually become the
30 // master threads in the following parallel region.
32
33#pragma omp parallel num_threads(2)
34 {
35 // Wait for all threads to arrive so that no worker thread can be reused...
38 }
39}
40
41int 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
int condition
void f()
int main()
void const char const char int ITT_FORMAT __itt_group_sync p
#define OMPT_WAIT(s, v)
Definition: ompt-signal.h:20
#define OMPT_SIGNAL(s)
Definition: ompt-signal.h:13
int omp_get_num_threads()