Rebase.
[official-gcc.git] / libgomp / testsuite / libgomp.c / critical-2.c
blob530a891f6b0099084026fa8b94ca7a50a1e7369d
1 // { dg-do run }
2 // Test several constructs within a parallel. At one point in development,
3 // the critical directive clobbered the shared clause of the parallel.
5 #include <omp.h>
6 #include <stdlib.h>
8 #define N 2000
10 int main()
12 int A[N];
13 int nthreads;
14 int i;
16 #pragma omp parallel shared (A, nthreads)
18 #pragma omp master
19 nthreads = omp_get_num_threads ();
21 #pragma omp for
22 for (i = 0; i < N; i++)
23 A[i] = 0;
25 #pragma omp critical
26 for (i = 0; i < N; i++)
27 A[i] += 1;
30 for (i = 0; i < N; i++)
31 if (A[i] != nthreads)
32 abort ();
34 return 0;