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) nowait 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 #pragma omp barrier 00036 if (i != (16 + 0 + 1 + 2 + 3)) 00037 #pragma omp atomic 00038 j |= 2; 00039 if (d != (33.0 * 1.0 * 2.0 * 3.0 * 4.0)) 00040 #pragma omp atomic 00041 j |= 4; 00042 if (k != (~0 ^ 0x55 ^ (1 << 16))) 00043 #pragma omp atomic 00044 j |= 8; 00045 } 00046 } 00047 00048 if (j) 00049 abort (); 00050 return 0; 00051 }