1// RUN: %libomp-compile-and-run
2#include <stdio.h>
3#include <stdlib.h>
4#include <omp.h>
5
6int a;
7
8void inc_a() {
9#pragma omp task
10 {
11#pragma omp atomic
12 a++;
13 }
14}
15
16int main() {
17 int n;
18 int nth_outer;
19 omp_set_max_active_levels(2);
20 omp_set_dynamic(0);
21
22 for (n = 0; n < 200; ++n) {
23 a = 0;
24#pragma omp parallel num_threads(8)
25 {
26 if (omp_get_thread_num() == 0)
27 nth_outer = omp_get_num_threads();
28#pragma omp parallel num_threads(2)
29 {
30 int i;
31#pragma omp master
32 for (i = 0; i < 50; ++i)
33 inc_a();
34 }
35 }
36 if (a != nth_outer * 50) {
37 fprintf(stderr, format: "error: a (%d) != %d\n", a, nth_outer * 50);
38 return EXIT_FAILURE;
39 }
40 }
41
42 return EXIT_SUCCESS;
43}
44

source code of openmp/runtime/test/tasking/issue-87307.c