LLVM OpenMP 20.0.0git
nested_thread_num.c
Go to the documentation of this file.
1// RUN: %libomp-compile-and-run | FileCheck %s
2// RUN: %libomp-compile-and-run | %sort-threads | FileCheck --check-prefix=THREADS %s
3// REQUIRES: ompt
4// UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7
5#define TEST_NEED_PRINT_FRAME_FROM_OUTLINED_FN
6#include "callback.h"
7#include <omp.h>
8#include <unistd.h>
9
10int main() {
11 int condition = 0;
13 print_frame(0);
14
15#pragma omp parallel num_threads(2)
16 {
17 print_frame_from_outlined_fn(1);
18 print_ids(0);
19 print_ids(1);
20 print_frame(0);
21
22// get all implicit task events before starting nested:
23#pragma omp barrier
24
25#pragma omp parallel num_threads(2)
26 {
27 print_frame_from_outlined_fn(1);
28 print_ids(0);
29 print_ids(1);
30 print_ids(2);
31 print_frame(0);
34#pragma omp barrier
36 print_ids(0);
37 }
39 print_ids(0);
40 }
42
43 return 0;
44}
45// Check if libomp supports the callbacks for this test.
46// CHECK-NOT: {{^}}0: Could not register callback
47
48// CHECK: 0: NULL_POINTER=[[NULL:.*$]]
49
50// make sure initial data pointers are null
51// CHECK-NOT: 0: parallel_data initially not null
52// CHECK-NOT: 0: task_data initially not null
53// CHECK-NOT: 0: thread_data initially not null
54
55// CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin:
56// CHECK-SAME: parent_task_id=[[PARENT_TASK_ID:[0-9]+]],
57// CHECK-SAME: parent_task_frame.exit=[[NULL]],
58// CHECK-SAME: parent_task_frame.reenter={{0x[0-f]+}},
59// CHECK-SAME: parallel_id=[[PARALLEL_ID:[0-9]+]],
60// CHECK-SAME: requested_team_size=2,
61// CHECK-SAME: codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}},
62// CHECK-SAME: invoker=[[PARALLEL_INVOKER:[0-9]+]]
63
64// CHECK-DAG: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin:
65// CHECK-DAG: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end:
66
67// Note that we cannot ensure that the worker threads have already called
68// barrier_end and implicit_task_end before parallel_end!
69
70// CHECK-DAG: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_implicit_task_begin:
71// CHECK-DAG: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_begin:
72
73// CHECK: ompt_event_parallel_end: parallel_id=[[PARALLEL_ID]],
74// CHECK-SAME: task_id=[[PARENT_TASK_ID]], invoker=[[PARALLEL_INVOKER]]
75// CHECK: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]]
76
77// THREADS: {{^}}0: NULL_POINTER=[[NULL:.*$]]
78// THREADS: __builtin_frame_address(0)=[[MAIN_REENTER:0x[0-f]+]]
79// THREADS: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin:
80// THREADS-SAME: parent_task_id=[[PARENT_TASK_ID:[0-9]+]],
81// THREADS-SAME: parent_task_frame.exit=[[NULL]],
82// THREADS-SAME: parent_task_frame.reenter=0x{{[0-f]+}},
83// THREADS-SAME: parallel_id=[[PARALLEL_ID:[0-9]+]], requested_team_size=2,
84// THREADS-SAME: codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}},
85// THREADS-SAME: invoker=[[PARALLEL_INVOKER:[0-9]+]]
86
87// nested parallel masters
88// THREADS: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin:
89// THREADS-SAME: parallel_id=[[PARALLEL_ID]],
90// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID:[0-9]+]],
91// THREADS-SAME: team_size=2, thread_num=0
92
93// THREADS: __builtin_frame_address({{.}})=[[EXIT:0x[0-f]+]]
94
95// THREADS: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]],
96// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]],
97// THREADS-SAME: reenter_frame=[[NULL]],
98// THREADS-SAME: thread_num=0
99
100// THREADS: {{^}}[[MASTER_ID]]: task level 1:
101// THREADS-SAME: parallel_id=[[IMPLICIT_PARALLEL_ID:[0-9]+]],
102// THREADS-SAME: task_id=[[PARENT_TASK_ID]], exit_frame=[[NULL]],
103// THREADS-SAME: reenter_frame=0x{{[0-f]+}}
104
105// THREADS: __builtin_frame_address(0)=[[REENTER:0x[0-f]+]]
106
107// THREADS: {{^}}[[MASTER_ID]]: ompt_event_parallel_begin:
108// THREADS-SAME: parent_task_id=[[IMPLICIT_TASK_ID]],
109// THREADS-SAME: parent_task_frame.exit=[[EXIT]],
110// THREADS-SAME: parent_task_frame.reenter=0x{{[0-f]+}},
111// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID:[0-9]+]],
112// THREADS-SAME: requested_team_size=2,
113// THREADS-SAME: codeptr_ra=[[NESTED_RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}},
114// THREADS-SAME: invoker=[[PARALLEL_INVOKER]]
115
116// THREADS: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin:
117// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
118// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID:[0-9]+]], team_size=2,
119// THREADS-SAME: thread_num=0
120
121// THREADS: __builtin_frame_address({{.}})=[[NESTED_EXIT:0x[0-f]+]]
122
123// THREADS: {{^}}[[MASTER_ID]]: task level 0:
124// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
125// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID]],
126// THREADS-SAME: exit_frame=[[NESTED_EXIT]], reenter_frame=[[NULL]],
127// THREADS-SAME: thread_num=0
128
129// THREADS: {{^}}[[MASTER_ID]]: task level 1: parallel_id=[[PARALLEL_ID]],
130// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]],
131// THREADS-SAME: reenter_frame=0x{{[0-f]+}}
132
133// THREADS: {{^}}[[MASTER_ID]]: task level 2:
134// THREADS-SAME: parallel_id=[[IMPLICIT_PARALLEL_ID]],
135// THREADS-SAME: task_id=[[PARENT_TASK_ID]], exit_frame=[[NULL]],
136// THREADS-SAME: reenter_frame=0x{{[0-f]+}}
137
138// THREADS: __builtin_frame_address(0)=[[NESTED_REENTER:0x[0-f]+]]
139
140// THREADS-NOT: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end
141// explicit barrier
142
143// THREADS: {{^}}[[MASTER_ID]]: ompt_event_barrier_explicit_begin:
144// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
145// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID]],
146// THREADS-SAME: codeptr_ra=[[BARRIER_RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}}
147
148// THREADS: {{^}}[[MASTER_ID]]: task level 0:
149// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
150// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID]],
151// THREADS-SAME: exit_frame=[[NESTED_EXIT]], reenter_frame=0x{{[0-f]+}}
152
153// THREADS: {{^}}[[MASTER_ID]]: ompt_event_barrier_explicit_end:
154// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
155// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID]]
156
157// THREADS: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[BARRIER_RETURN_ADDRESS]]
158
159// THREADS: {{^}}[[MASTER_ID]]: task level 0:
160// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
161// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID]],
162// THREADS-SAME: exit_frame=[[NESTED_EXIT]], reenter_frame=[[NULL]]
163
164// implicit barrier
165// THREADS: {{^}}[[MASTER_ID]]: ompt_event_barrier_implicit_parallel_begin:
166// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
167// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID]],
168// THREADS-SAME: codeptr_ra=[[NESTED_RETURN_ADDRESS]]{{[0-f][0-f]}}
169
170// THREADS: {{^}}[[MASTER_ID]]: task level 0:
171// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
172// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID]],
173// THREADS-SAME: exit_frame=[[NULL]], reenter_frame=[[NULL]]
174
175// THREADS: {{^}}[[MASTER_ID]]: ompt_event_barrier_implicit_parallel_end:
176// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[NESTED_IMPLICIT_TASK_ID]],
177// THREADS-SAME: codeptr_ra=[[NESTED_RETURN_ADDRESS]]{{[0-f][0-f]}}
178
179// THREADS: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end:
180// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[NESTED_IMPLICIT_TASK_ID]]
181
182// THREADS: {{^}}[[MASTER_ID]]: ompt_event_parallel_end:
183// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
184// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]],
185// THREADS-SAME: invoker=[[PARALLEL_INVOKER]],
186// THREADS-SAME: codeptr_ra=[[NESTED_RETURN_ADDRESS]]{{[0-f][0-f]}}
187
188// THREADS: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[NESTED_RETURN_ADDRESS]]
189
190// THREADS-NOT: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end
191
192// THREADS: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]],
193// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]],
194// THREADS-SAME: reenter_frame=[[NULL]]
195
196// implicit barrier
197// THREADS: {{^}}[[MASTER_ID]]: ompt_event_barrier_implicit_parallel_begin:
198// THREADS-SAME: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]],
199// THREADS-SAME: codeptr_ra=[[RETURN_ADDRESS]]{{[0-f][0-f]}}
200
201// THREADS: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]],
202// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[NULL]],
203// THREADS-SAME: reenter_frame=[[NULL]]
204
205// THREADS: {{^}}[[MASTER_ID]]: ompt_event_barrier_implicit_parallel_end:
206// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]],
207// THREADS-SAME: codeptr_ra=[[RETURN_ADDRESS]]{{[0-f][0-f]}}
208
209// THREADS: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end:
210// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
211
212// THREADS: {{^}}[[MASTER_ID]]: ompt_event_parallel_end:
213// THREADS-SAME: parallel_id=[[PARALLEL_ID]], task_id=[[PARENT_TASK_ID]],
214// THREADS-SAME: invoker=[[PARALLEL_INVOKER]],
215// THREADS-SAME: codeptr_ra=[[RETURN_ADDRESS]]{{[0-f][0-f]}}
216
217// THREADS: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]]
218
219// Worker of first nesting level
220
221// THREADS: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_implicit_task_begin:
222// THREADS-SAME: parallel_id=[[PARALLEL_ID]],
223// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID:[0-9]+]], team_size=2,
224// THREADS-SAME: thread_num=[[OUTER_THREADNUM:[0-9]+]]
225
226// THREADS: {{^}}[[THREAD_ID]]: task level 0: parallel_id=[[PARALLEL_ID]],
227// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]],
228// THREADS-SAME: thread_num=[[OUTER_THREADNUM]]
229
230// THREADS: {{^}}[[THREAD_ID]]: task level 1:
231// THREADS-SAME: parallel_id=[[IMPLICIT_PARALLEL_ID]],
232// THREADS-SAME: task_id=[[PARENT_TASK_ID]]
233
234// THREADS: {{^}}[[THREAD_ID]]: ompt_event_parallel_begin:
235// THREADS-SAME: parent_task_id=[[IMPLICIT_TASK_ID]],
236// THREADS-SAME: parent_task_frame.exit={{0x[0-f]+}},
237// THREADS-SAME: parent_task_frame.reenter={{0x[0-f]+}},
238// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID:[0-9]+]], requested_team_size=2,
239// THREADS-SAME: codeptr_ra=[[NESTED_RETURN_ADDRESS]]{{[0-f][0-f]}},
240// THREADS-SAME: invoker=[[PARALLEL_INVOKER]]
241
242// THREADS: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_begin:
243// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
244// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID:[0-9]+]], team_size=2,
245// THREADS-SAME: thread_num=[[INNER_THREADNUM:[0-9]+]]
246
247// THREADS: {{^}}[[THREAD_ID]]: task level 0:
248// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
249// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID]],
250// THREADS-SAME: thread_num=[[INNER_THREADNUM]]
251
252// THREADS: {{^}}[[THREAD_ID]]: task level 1: parallel_id=[[PARALLEL_ID]],
253// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]],
254// THREADS-SAME: thread_num=[[OUTER_THREADNUM]]
255
256// THREADS: {{^}}[[THREAD_ID]]: task level 2:
257// THREADS-SAME: parallel_id=[[IMPLICIT_PARALLEL_ID]],
258// THREADS-SAME: task_id=[[PARENT_TASK_ID]]
259
260// THREADS-NOT: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end
261
262// THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_begin:
263// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
264// THREADS-SAME: task_id=[[NESTED_IMPLICIT_TASK_ID]]
265
266// THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_end:
267// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[NESTED_IMPLICIT_TASK_ID]]
268
269// THREADS: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end:
270// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[NESTED_IMPLICIT_TASK_ID]]
271
272// THREADS: {{^}}[[THREAD_ID]]: ompt_event_parallel_end:
273// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
274// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]], invoker=[[PARALLEL_INVOKER]]
275
276// THREADS-NOT: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end
277
278// THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_begin:
279// THREADS-SAME: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]]
280
281// THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_end:
282// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
283
284// THREADS: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end:
285// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
286
287// nested parallel worker threads
288
289// THREADS: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_implicit_task_begin:
290// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID:[0-9]+]],
291// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID:[0-9]+]]
292// THREADS-SAME: thread_num=[[THREADNUM:[0-9]+]]
293
294// THREADS: {{^}}[[THREAD_ID]]: task level 0:
295// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
296// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]]
297// THREADS-SAME: thread_num=[[THREADNUM]]
298
299// can't reliably tell which parallel region is the parent...
300
301// THREADS: {{^}}[[THREAD_ID]]: task level 1: parallel_id={{[0-9]+}},
302// THREADS-SAME: task_id={{[0-9]+}}
303// THREADS-SAME: thread_num={{[01]}}
304
305// THREADS: {{^}}[[THREAD_ID]]: task level 2:
306// THREADS-SAME: parallel_id=[[IMPLICIT_PARALLEL_ID]],
307// THREADS-SAME: task_id=[[PARENT_TASK_ID]]
308// THREADS-SAME: thread_num=0
309
310// THREADS-NOT: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end
311
312// THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_begin:
313// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
314// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]]
315
316// THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_end:
317// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
318
319// THREADS: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end:
320// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
321
322// other nested parallel worker threads
323
324// THREADS: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_implicit_task_begin:
325// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID:[0-9]+]],
326// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID:[0-9]+]]
327// THREADS-SAME: thread_num=[[THREADNUM:[0-9]+]]
328
329// THREADS: {{^}}[[THREAD_ID]]: task level 0:
330// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
331// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]]
332// THREADS-SAME: thread_num=[[THREADNUM]]
333
334// can't reliably tell which parallel region is the parent...
335
336// THREADS: {{^}}[[THREAD_ID]]: task level 1: parallel_id={{[0-9]+}},
337// THREADS-SAME: task_id={{[0-9]+}}
338// THREADS-SAME: thread_num={{[01]}}
339
340// THREADS: {{^}}[[THREAD_ID]]: task level 2:
341// THREADS-SAME: parallel_id=[[IMPLICIT_PARALLEL_ID]],
342// THREADS-SAME: task_id=[[PARENT_TASK_ID]]
343// THREADS-SAME: thread_num=0
344
345// THREADS-NOT: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end
346
347// THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_begin:
348// THREADS-SAME: parallel_id=[[NESTED_PARALLEL_ID]],
349// THREADS-SAME: task_id=[[IMPLICIT_TASK_ID]]
350
351// THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_end:
352// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
353
354// THREADS: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end:
355// THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
356
#define print_frame(level)
Definition: callback.h:172
#define print_fuzzy_address(id)
Definition: callback.h:307
static void print_ids(int level)
Definition: callback.h:150
int condition
#define omp_set_nested
Definition: kmp_stub.cpp:36
int main()
#define OMPT_WAIT(s, v)
Definition: ompt-signal.h:20
#define OMPT_SIGNAL(s)
Definition: ompt-signal.h:12