Mercurial > hg > CbC > CbC_gcc
comparison libgomp/testsuite/libgomp.c/reduction-3.c @ 0:a06113de4d67
first commit
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2009 14:47:48 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a06113de4d67 |
---|---|
1 #include <omp.h> | |
2 #include <stdlib.h> | |
3 | |
4 int | |
5 main (void) | |
6 { | |
7 int i = 0, j = 0, k = ~0, l; | |
8 double d = 1.0; | |
9 #pragma omp parallel num_threads(4) | |
10 { | |
11 #pragma omp single | |
12 { | |
13 i = 16; | |
14 k ^= (1 << 16); | |
15 d += 32.0; | |
16 } | |
17 | |
18 #pragma omp for reduction(+:i) reduction(*:d) reduction(&:k) nowait | |
19 for (l = 0; l < 4; l++) | |
20 { | |
21 if (omp_get_num_threads () == 4 && (i != 0 || d != 1.0 || k != ~0)) | |
22 #pragma omp atomic | |
23 j |= 1; | |
24 | |
25 if (l == omp_get_thread_num ()) | |
26 { | |
27 i = omp_get_thread_num (); | |
28 d = i + 1; | |
29 k = ~(1 << (2 * i)); | |
30 } | |
31 } | |
32 | |
33 if (omp_get_num_threads () == 4) | |
34 { | |
35 #pragma omp barrier | |
36 if (i != (16 + 0 + 1 + 2 + 3)) | |
37 #pragma omp atomic | |
38 j |= 2; | |
39 if (d != (33.0 * 1.0 * 2.0 * 3.0 * 4.0)) | |
40 #pragma omp atomic | |
41 j |= 4; | |
42 if (k != (~0 ^ 0x55 ^ (1 << 16))) | |
43 #pragma omp atomic | |
44 j |= 8; | |
45 } | |
46 } | |
47 | |
48 if (j) | |
49 abort (); | |
50 return 0; | |
51 } |