00001 #include <omp.h> 00002 #include <stdlib.h> 00003 00004 int 00005 main (void) 00006 { 00007 int i = 0, j = 0, k = ~0; 00008 double d = 1.0; 00009 #pragma omp parallel num_threads(4) reduction(+:i) reduction(*:d) reduction(&:k) 00010 { 00011 if (i != 0 || d != 1.0 || k != ~0) 00012 #pragma omp atomic 00013 j |= 1; 00014 00015 if (omp_get_num_threads () != 4) 00016 #pragma omp atomic 00017 j |= 2; 00018 00019 i = omp_get_thread_num (); 00020 d = i + 1; 00021 k = ~(1 << (2 * i)); 00022 } 00023 00024 if (j & 1) 00025 abort (); 00026 if ((j & 2) == 0) 00027 { 00028 if (i != (0 + 1 + 2 + 3)) 00029 abort (); 00030 if (d != (1.0 * 2.0 * 3.0 * 4.0)) 00031 abort (); 00032 if (k != (~0 ^ 0x55)) 00033 abort (); 00034 } 00035 return 0; 00036 }