xref: /openbsd-src/gnu/gcc/libgomp/testsuite/libgomp.c/reduction-4.c (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert #include <omp.h>
2*404b540aSrobert #include <stdlib.h>
3*404b540aSrobert 
4*404b540aSrobert int
main(void)5*404b540aSrobert main (void)
6*404b540aSrobert {
7*404b540aSrobert   int i = 0, j = 0, k = 0, l = 0;
8*404b540aSrobert #pragma omp parallel num_threads(4) reduction(-:i) reduction(|:k) \
9*404b540aSrobert 		     reduction(^:l)
10*404b540aSrobert   {
11*404b540aSrobert     if (i != 0 || k != 0 || l != 0)
12*404b540aSrobert #pragma omp atomic
13*404b540aSrobert       j |= 1;
14*404b540aSrobert 
15*404b540aSrobert     if (omp_get_num_threads () != 4)
16*404b540aSrobert #pragma omp atomic
17*404b540aSrobert       j |= 2;
18*404b540aSrobert 
19*404b540aSrobert     i = omp_get_thread_num ();
20*404b540aSrobert     k = 1 << (2 * i);
21*404b540aSrobert     l = 0xea << (3 * i);
22*404b540aSrobert   }
23*404b540aSrobert 
24*404b540aSrobert   if (j & 1)
25*404b540aSrobert     abort ();
26*404b540aSrobert   if ((j & 2) == 0)
27*404b540aSrobert     {
28*404b540aSrobert       if (i != (0 + 1 + 2 + 3))
29*404b540aSrobert 	abort ();
30*404b540aSrobert       if (k != 0x55)
31*404b540aSrobert 	abort ();
32*404b540aSrobert       if (l != 0x1e93a)
33*404b540aSrobert 	abort ();
34*404b540aSrobert     }
35*404b540aSrobert   return 0;
36*404b540aSrobert }
37