1 #include <omp.h> 2 #include <stdlib.h> 3 4 int main(void)5main (void) 6 { 7 int i = 0, j = 0, k = ~0; 8 double d = 1.0; 9 #pragma omp parallel num_threads(4) reduction(+:i) reduction(*:d) reduction(&:k) 10 { 11 if (i != 0 || d != 1.0 || k != ~0) 12 #pragma omp atomic 13 j |= 1; 14 15 if (omp_get_num_threads () != 4) 16 #pragma omp atomic 17 j |= 2; 18 19 i = omp_get_thread_num (); 20 d = i + 1; 21 k = ~(1 << (2 * i)); 22 } 23 24 if (j & 1) 25 abort (); 26 if ((j & 2) == 0) 27 { 28 if (i != (0 + 1 + 2 + 3)) 29 abort (); 30 if (d != (1.0 * 2.0 * 3.0 * 4.0)) 31 abort (); 32 if (k != (~0 ^ 0x55)) 33 abort (); 34 } 35 return 0; 36 } 37