testsuite/libgomp.c/critical-2.c

Go to the documentation of this file.
00001 // { dg-do run }
00002 // Test several constructs within a parallel.  At one point in development,
00003 // the critical directive clobbered the shared clause of the parallel.
00004 
00005 #include <omp.h>
00006 #include <stdlib.h>
00007 
00008 #define N       2000
00009 
00010 int main()
00011 {
00012   int A[N];
00013   int nthreads;
00014   int i;
00015 
00016 #pragma omp parallel shared (A, nthreads)
00017   {
00018     #pragma omp master
00019       nthreads = omp_get_num_threads ();
00020 
00021     #pragma omp for
00022       for (i = 0; i < N; i++)
00023         A[i] = 0;
00024 
00025     #pragma omp critical
00026       for (i = 0; i < N; i++)
00027         A[i] += 1;
00028   }
00029 
00030   for (i = 0; i < N; i++)
00031     if (A[i] != nthreads)
00032       abort ();
00033 
00034   return 0;
00035 }

Generated on Fri Apr 5 05:38:10 2013 for Libgomp by  doxygen 1.4.7