| 1 |
/* { dg-additional-options "-fdump-tree-gimple" } */ |
| 2 |
|
| 3 |
/* Test that reduction on compute construct implies a copy of the reduction |
| 4 |
variable . */ |
| 5 |
|
| 6 |
#define n 1000 |
| 7 |
|
| 8 |
#if __cplusplus |
| 9 |
typedef bool BOOL; |
| 10 |
#else |
| 11 |
typedef _Bool BOOL; |
| 12 |
#endif |
| 13 |
|
| 14 |
int |
| 15 |
main(void) |
| 16 |
{ |
| 17 |
int i; |
| 18 |
int sum = 0; |
| 19 |
int prod = 1; |
| 20 |
int result = 0; |
| 21 |
int tmp = 1; |
| 22 |
int array[n]; |
| 23 |
|
| 24 |
double sumd = 0.0; |
| 25 |
double arrayd[n]; |
| 26 |
|
| 27 |
float sumf = 0.0; |
| 28 |
float arrayf[n]; |
| 29 |
|
| 30 |
char sumc; |
| 31 |
char arrayc[n]; |
| 32 |
|
| 33 |
BOOL lres; |
| 34 |
|
| 35 |
#pragma acc parallel reduction(+:sum, sumf, sumd, sumc) reduction(*:prod) |
| 36 |
for (i = 0; i < n; i++) |
| 37 |
{ |
| 38 |
sum += array[i]; |
| 39 |
sumf += arrayf[i]; |
| 40 |
sumd += arrayd[i]; |
| 41 |
sumc += arrayc[i]; |
| 42 |
prod *= array[i]; |
| 43 |
} |
| 44 |
|
| 45 |
#pragma acc parallel reduction (max:result) |
| 46 |
for (i = 0; i < n; i++) |
| 47 |
result = result > array[i] ? result : array[i]; |
| 48 |
|
| 49 |
#pragma acc parallel reduction (min:result) |
| 50 |
for (i = 0; i < n; i++) |
| 51 |
result = result < array[i] ? result : array[i]; |
| 52 |
|
| 53 |
#pragma acc parallel reduction (&:result) |
| 54 |
for (i = 0; i < n; i++) |
| 55 |
result &= array[i]; |
| 56 |
|
| 57 |
#pragma acc parallel reduction (|:result) |
| 58 |
for (i = 0; i < n; i++) |
| 59 |
result |= array[i]; |
| 60 |
|
| 61 |
#pragma acc parallel reduction (^:result) |
| 62 |
for (i = 0; i < n; i++) |
| 63 |
result ^= array[i]; |
| 64 |
|
| 65 |
#pragma acc parallel reduction (&&:lres) copy(tmp) |
| 66 |
for (i = 0; i < n; i++) |
| 67 |
lres = lres && (tmp > array[i]); |
| 68 |
|
| 69 |
#pragma acc parallel reduction (||:lres) copy(tmp) |
| 70 |
for (i = 0; i < n; i++) |
| 71 |
lres = lres || (tmp > array[i]); |
| 72 |
|
| 73 |
/* Same checks on serial construct. */ |
| 74 |
#pragma acc serial reduction(+:sum, sumf, sumd, sumc) reduction(*:prod) |
| 75 |
for (i = 0; i < n; i++) |
| 76 |
{ |
| 77 |
sum += array[i]; |
| 78 |
sumf += arrayf[i]; |
| 79 |
sumd += arrayd[i]; |
| 80 |
sumc += arrayc[i]; |
| 81 |
prod *= array[i]; |
| 82 |
} |
| 83 |
|
| 84 |
#pragma acc serial reduction (max:result) |
| 85 |
for (i = 0; i < n; i++) |
| 86 |
result = result > array[i] ? result : array[i]; |
| 87 |
|
| 88 |
#pragma acc serial reduction (min:result) |
| 89 |
for (i = 0; i < n; i++) |
| 90 |
result = result < array[i] ? result : array[i]; |
| 91 |
|
| 92 |
#pragma acc serial reduction (&:result) |
| 93 |
for (i = 0; i < n; i++) |
| 94 |
result &= array[i]; |
| 95 |
|
| 96 |
#pragma acc serial reduction (|:result) |
| 97 |
for (i = 0; i < n; i++) |
| 98 |
result |= array[i]; |
| 99 |
|
| 100 |
#pragma acc serial reduction (^:result) |
| 101 |
for (i = 0; i < n; i++) |
| 102 |
result ^= array[i]; |
| 103 |
|
| 104 |
#pragma acc serial reduction (&&:lres) copy(tmp) |
| 105 |
for (i = 0; i < n; i++) |
| 106 |
lres = lres && (tmp > array[i]); |
| 107 |
|
| 108 |
#pragma acc serial reduction (||:lres) copy(tmp) |
| 109 |
for (i = 0; i < n; i++) |
| 110 |
lres = lres || (tmp > array[i]); |
| 111 |
|
| 112 |
return 0; |
| 113 |
} |
| 114 |
|
| 115 |
/* { dg-final { scan-tree-dump-times "map\\(tofrom:sum \\\[len: \[0-9\]+\\\]\\)" 2 "gimple" } } */ |
| 116 |
/* { dg-final { scan-tree-dump-times "map\\(tofrom:sumf \\\[len: \[0-9\]+\\\]\\)" 2 "gimple" } } */ |
| 117 |
/* { dg-final { scan-tree-dump-times "map\\(tofrom:sumd \\\[len: \[0-9\]+\\\]\\)" 2 "gimple" } } */ |
| 118 |
/* { dg-final { scan-tree-dump-times "map\\(tofrom:sumc \\\[len: \[0-9\]+\\\]\\)" 2 "gimple" } } */ |
| 119 |
/* { dg-final { scan-tree-dump-times "map\\(tofrom:lres \\\[len: \[0-9\]+\\\]\\)" 4 "gimple" } } */ |
| 120 |
/* { dg-final { scan-tree-dump-times "map\\(tofrom:result \\\[len: \[0-9\]+\\\]\\)" 10 "gimple" } } */ |
| 121 |
/* { dg-final { scan-tree-dump-times "map\\(tofrom:prod \\\[len: \[0-9\]+\\\]\\)" 2 "gimple" } } */ |