testsuite/libgomp.c/atomic-3.c

Go to the documentation of this file.
00001 /* { dg-do run } */
00002 /* { dg-options "-fopenmp -O0" } */
00003 
00004 #include <omp.h>
00005 #include <stdlib.h>
00006 
00007 short e[64];
00008 int g;
00009 _Complex double d, f;
00010 int num_threads;
00011 
00012 __attribute__((noinline)) void
00013 foo (int x, long long y)
00014 {
00015 #pragma omp parallel num_threads (4)
00016   {
00017     int i;
00018     #pragma omp barrier
00019     for (i = 0; i < 2400; i++)
00020       {
00021     if (i == 0)
00022       num_threads = omp_get_num_threads ();
00023     #pragma omp atomic
00024       e[0] += x;
00025     #pragma omp atomic
00026       e[16] += x;
00027     #pragma omp atomic
00028       g += y;
00029     #pragma omp atomic
00030       __real__ d += x;
00031     #pragma omp atomic
00032       __imag__ f += x;
00033       }
00034   }
00035 }
00036 
00037 int
00038 main (void)
00039 {
00040   int i;
00041   foo (3, 3LL);
00042   if (g != 3 * 2400 * num_threads
00043       || __real__ d != g || __imag__ d != 0
00044       || __real__ f != 0 || __imag__ f != g)
00045     abort ();
00046   for (i = 0; i < 64; i++)
00047     if (e[i] != ((i && i != 16) ? 0 : g))
00048       abort ();
00049   return 0;
00050 }

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