[rtsan] Add fork/execve interceptors (#117198)
[llvm-project.git] / openmp / runtime / test / ompt / parallel / nested_thread_num.c
blob7ba7077e6f032edab476c76528dcce6b4f2557d0
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>
10 int main() {
11 int condition = 0;
12 omp_set_nested(1);
13 print_frame(0);
15 #pragma omp parallel num_threads(2)
17 print_frame_from_outlined_fn(1);
18 print_ids(0);
19 print_ids(1);
20 print_frame(0);
22 // get all implicit task events before starting nested:
23 #pragma omp barrier
25 #pragma omp parallel num_threads(2)
27 print_frame_from_outlined_fn(1);
28 print_ids(0);
29 print_ids(1);
30 print_ids(2);
31 print_frame(0);
32 OMPT_SIGNAL(condition);
33 OMPT_WAIT(condition, 4);
34 #pragma omp barrier
35 print_fuzzy_address(1);
36 print_ids(0);
38 print_fuzzy_address(2);
39 print_ids(0);
41 print_fuzzy_address(3);
43 return 0;
45 // Check if libomp supports the callbacks for this test.
46 // CHECK-NOT: {{^}}0: Could not register callback
48 // CHECK: 0: NULL_POINTER=[[NULL:.*$]]
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
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]+]]
64 // CHECK-DAG: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin:
65 // CHECK-DAG: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end:
67 // Note that we cannot ensure that the worker threads have already called
68 // barrier_end and implicit_task_end before parallel_end!
70 // CHECK-DAG: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_implicit_task_begin:
71 // CHECK-DAG: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_begin:
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]]
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]+]]
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
93 // THREADS: __builtin_frame_address({{.}})=[[EXIT:0x[0-f]+]]
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
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]+}}
105 // THREADS: __builtin_frame_address(0)=[[REENTER:0x[0-f]+]]
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]]
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
121 // THREADS: __builtin_frame_address({{.}})=[[NESTED_EXIT:0x[0-f]+]]
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
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]+}}
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]+}}
138 // THREADS: __builtin_frame_address(0)=[[NESTED_REENTER:0x[0-f]+]]
140 // THREADS-NOT: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end
141 // explicit barrier
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]}}
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]+}}
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]]
157 // THREADS: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[BARRIER_RETURN_ADDRESS]]
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]]
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]}}
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]]
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]}}
179 // THREADS: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end:
180 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[NESTED_IMPLICIT_TASK_ID]]
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]}}
188 // THREADS: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[NESTED_RETURN_ADDRESS]]
190 // THREADS-NOT: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end
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]]
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]}}
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]]
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]}}
209 // THREADS: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end:
210 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
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]}}
217 // THREADS: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]]
219 // Worker of first nesting level
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]+]]
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]]
230 // THREADS: {{^}}[[THREAD_ID]]: task level 1:
231 // THREADS-SAME: parallel_id=[[IMPLICIT_PARALLEL_ID]],
232 // THREADS-SAME: task_id=[[PARENT_TASK_ID]]
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]]
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]+]]
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]]
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]]
256 // THREADS: {{^}}[[THREAD_ID]]: task level 2:
257 // THREADS-SAME: parallel_id=[[IMPLICIT_PARALLEL_ID]],
258 // THREADS-SAME: task_id=[[PARENT_TASK_ID]]
260 // THREADS-NOT: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end
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]]
266 // THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_end:
267 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[NESTED_IMPLICIT_TASK_ID]]
269 // THREADS: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end:
270 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[NESTED_IMPLICIT_TASK_ID]]
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]]
276 // THREADS-NOT: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end
278 // THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_begin:
279 // THREADS-SAME: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]]
281 // THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_end:
282 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
284 // THREADS: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end:
285 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
287 // nested parallel worker threads
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]+]]
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]]
299 // can't reliably tell which parallel region is the parent...
301 // THREADS: {{^}}[[THREAD_ID]]: task level 1: parallel_id={{[0-9]+}},
302 // THREADS-SAME: task_id={{[0-9]+}}
303 // THREADS-SAME: thread_num={{[01]}}
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
310 // THREADS-NOT: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end
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]]
316 // THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_end:
317 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
319 // THREADS: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end:
320 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
322 // other nested parallel worker threads
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]+]]
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]]
334 // can't reliably tell which parallel region is the parent...
336 // THREADS: {{^}}[[THREAD_ID]]: task level 1: parallel_id={{[0-9]+}},
337 // THREADS-SAME: task_id={{[0-9]+}}
338 // THREADS-SAME: thread_num={{[01]}}
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
345 // THREADS-NOT: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end
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]]
351 // THREADS: {{^}}[[THREAD_ID]]: ompt_event_barrier_implicit_parallel_end:
352 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]
354 // THREADS: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end:
355 // THREADS-SAME: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]]