testsuite/libgomp.c++/reduction-2.C

Go to the documentation of this file.
00001 #include <omp.h>
00002 #include <stdlib.h>
00003 
00004 int
00005 main (void)
00006 {
00007   int i = 0, j = 0, k = ~0, l;
00008   double d = 1.0;
00009 #pragma omp parallel num_threads(4)
00010   {
00011 #pragma omp single
00012     {
00013       i = 16;
00014       k ^= (1 << 16);
00015       d += 32.0;
00016     }
00017 
00018 #pragma omp for reduction(+:i) reduction(*:d) reduction(&:k)
00019     for (l = 0; l < 4; l++)
00020       {
00021     if (omp_get_num_threads () == 4 && (i != 0 || d != 1.0 || k != ~0))
00022 #pragma omp atomic
00023       j |= 1;
00024   
00025     if (l == omp_get_thread_num ())
00026       {
00027         i = omp_get_thread_num ();
00028         d = i + 1;
00029         k = ~(1 << (2 * i));
00030       }
00031       }
00032 
00033     if (omp_get_num_threads () == 4)
00034       {
00035     if (i != (16 + 0 + 1 + 2 + 3))
00036 #pragma omp atomic
00037       j |= 2;
00038     if (d != (33.0 * 1.0 * 2.0 * 3.0 * 4.0))
00039 #pragma omp atomic
00040       j |= 4;
00041     if (k != (~0 ^ 0x55 ^ (1 << 16)))
00042 #pragma omp atomic
00043       j |= 8;
00044       }
00045   }
00046 
00047   if (j)
00048     abort ();
00049   return 0;
00050 }

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