| 1 |
/* { dg-additional-options "-foffload-options=nvptx-none=-latomic" { target { offload_target_nvptx } } } */ |
| 2 |
/* C / C++'s logical AND and OR operators take any scalar argument |
| 3 |
which compares (un)equal to 0 - the result 1 or 0 and of type int. |
| 4 |
|
| 5 |
In this testcase, the int result is again converted to a floating-poing |
| 6 |
or complex type. |
| 7 |
|
| 8 |
While having a floating-point/complex array element with || and && can make |
| 9 |
sense, having a non-integer/non-bool reduction variable is odd but valid. |
| 10 |
|
| 11 |
Test: FP reduction variable + FP array - as reduction-1.c but with target */ |
| 12 |
|
| 13 |
#define N 1024 |
| 14 |
_Complex float rcf[N]; |
| 15 |
_Complex double rcd[N]; |
| 16 |
float rf[N]; |
| 17 |
double rd[N]; |
| 18 |
|
| 19 |
int |
| 20 |
reduction_or () |
| 21 |
{ |
| 22 |
float orf = 0; |
| 23 |
double ord = 0; |
| 24 |
_Complex float orfc = 0; |
| 25 |
_Complex double ordc = 0; |
| 26 |
|
| 27 |
#pragma omp target parallel reduction(||: orf) map(orf) |
| 28 |
for (int i=0; i < N; ++i) |
| 29 |
orf = orf || rf[i]; |
| 30 |
|
| 31 |
#pragma omp target parallel for reduction(||: ord) map(ord) |
| 32 |
for (int i=0; i < N; ++i) |
| 33 |
ord = ord || rcd[i]; |
| 34 |
|
| 35 |
#pragma omp target parallel for simd reduction(||: orfc) map(orfc) |
| 36 |
for (int i=0; i < N; ++i) |
| 37 |
orfc = orfc || rcf[i]; |
| 38 |
|
| 39 |
#pragma omp target parallel loop reduction(||: ordc) map(ordc) |
| 40 |
for (int i=0; i < N; ++i) |
| 41 |
ordc = ordc || rcd[i]; |
| 42 |
|
| 43 |
return orf + ord + __real__ orfc + __real__ ordc; |
| 44 |
} |
| 45 |
|
| 46 |
int |
| 47 |
reduction_or_teams () |
| 48 |
{ |
| 49 |
float orf = 0; |
| 50 |
double ord = 0; |
| 51 |
_Complex float orfc = 0; |
| 52 |
_Complex double ordc = 0; |
| 53 |
|
| 54 |
#pragma omp target teams distribute parallel for reduction(||: orf) map(orf) |
| 55 |
for (int i=0; i < N; ++i) |
| 56 |
orf = orf || rf[i]; |
| 57 |
|
| 58 |
#pragma omp target teams distribute parallel for simd reduction(||: ord) map(ord) |
| 59 |
for (int i=0; i < N; ++i) |
| 60 |
ord = ord || rcd[i]; |
| 61 |
|
| 62 |
#pragma omp target teams distribute parallel for reduction(||: orfc) map(orfc) |
| 63 |
for (int i=0; i < N; ++i) |
| 64 |
orfc = orfc || rcf[i]; |
| 65 |
|
| 66 |
#pragma omp target teams distribute parallel for simd reduction(||: ordc) map(ordc) |
| 67 |
for (int i=0; i < N; ++i) |
| 68 |
ordc = ordc || rcd[i]; |
| 69 |
|
| 70 |
return orf + ord + __real__ orfc + __real__ ordc; |
| 71 |
} |
| 72 |
|
| 73 |
int |
| 74 |
reduction_and () |
| 75 |
{ |
| 76 |
float andf = 1; |
| 77 |
double andd = 1; |
| 78 |
_Complex float andfc = 1; |
| 79 |
_Complex double anddc = 1; |
| 80 |
|
| 81 |
#pragma omp target parallel reduction(&&: andf) map(andf) |
| 82 |
for (int i=0; i < N; ++i) |
| 83 |
andf = andf && rf[i]; |
| 84 |
|
| 85 |
#pragma omp target parallel for reduction(&&: andd) map(andd) |
| 86 |
for (int i=0; i < N; ++i) |
| 87 |
andd = andd && rcd[i]; |
| 88 |
|
| 89 |
#pragma omp target parallel for simd reduction(&&: andfc) map(andfc) |
| 90 |
for (int i=0; i < N; ++i) |
| 91 |
andfc = andfc && rcf[i]; |
| 92 |
|
| 93 |
#pragma omp target parallel loop reduction(&&: anddc) map(anddc) |
| 94 |
for (int i=0; i < N; ++i) |
| 95 |
anddc = anddc && rcd[i]; |
| 96 |
|
| 97 |
return andf + andd + __real__ andfc + __real__ anddc; |
| 98 |
} |
| 99 |
|
| 100 |
int |
| 101 |
reduction_and_teams () |
| 102 |
{ |
| 103 |
float andf = 1; |
| 104 |
double andd = 1; |
| 105 |
_Complex float andfc = 1; |
| 106 |
_Complex double anddc = 1; |
| 107 |
|
| 108 |
#pragma omp target teams distribute parallel for reduction(&&: andf) map(andf) |
| 109 |
for (int i=0; i < N; ++i) |
| 110 |
andf = andf && rf[i]; |
| 111 |
|
| 112 |
#pragma omp target teams distribute parallel for simd reduction(&&: andd) map(andd) |
| 113 |
for (int i=0; i < N; ++i) |
| 114 |
andd = andd && rcd[i]; |
| 115 |
|
| 116 |
#pragma omp target teams distribute parallel for reduction(&&: andfc) map(andfc) |
| 117 |
for (int i=0; i < N; ++i) |
| 118 |
andfc = andfc && rcf[i]; |
| 119 |
|
| 120 |
#pragma omp target teams distribute parallel for simd reduction(&&: anddc) map(anddc) |
| 121 |
for (int i=0; i < N; ++i) |
| 122 |
anddc = anddc && rcd[i]; |
| 123 |
|
| 124 |
return andf + andd + __real__ andfc + __real__ anddc; |
| 125 |
} |
| 126 |
|
| 127 |
int |
| 128 |
main () |
| 129 |
{ |
| 130 |
for (int i = 0; i < N; ++i) |
| 131 |
{ |
| 132 |
rf[i] = 0; |
| 133 |
rd[i] = 0; |
| 134 |
rcf[i] = 0; |
| 135 |
rcd[i] = 0; |
| 136 |
} |
| 137 |
|
| 138 |
if (reduction_or () != 0) |
| 139 |
__builtin_abort (); |
| 140 |
if (reduction_or_teams () != 0) |
| 141 |
__builtin_abort (); |
| 142 |
if (reduction_and () != 0) |
| 143 |
__builtin_abort (); |
| 144 |
if (reduction_and_teams () != 0) |
| 145 |
__builtin_abort (); |
| 146 |
|
| 147 |
rf[10] = 1.0; |
| 148 |
rd[15] = 1.0; |
| 149 |
rcf[10] = 1.0; |
| 150 |
rcd[15] = 1.0i; |
| 151 |
|
| 152 |
if (reduction_or () != 4) |
| 153 |
__builtin_abort (); |
| 154 |
if (reduction_or_teams () != 4) |
| 155 |
__builtin_abort (); |
| 156 |
if (reduction_and () != 0) |
| 157 |
__builtin_abort (); |
| 158 |
if (reduction_and_teams () != 0) |
| 159 |
__builtin_abort (); |
| 160 |
|
| 161 |
for (int i = 0; i < N; ++i) |
| 162 |
{ |
| 163 |
rf[i] = 1; |
| 164 |
rd[i] = 1; |
| 165 |
rcf[i] = 1; |
| 166 |
rcd[i] = 1; |
| 167 |
} |
| 168 |
|
| 169 |
if (reduction_or () != 4) |
| 170 |
__builtin_abort (); |
| 171 |
if (reduction_or_teams () != 4) |
| 172 |
__builtin_abort (); |
| 173 |
if (reduction_and () != 4) |
| 174 |
__builtin_abort (); |
| 175 |
if (reduction_and_teams () != 4) |
| 176 |
__builtin_abort (); |
| 177 |
|
| 178 |
rf[10] = 0.0; |
| 179 |
rd[15] = 0.0; |
| 180 |
rcf[10] = 0.0; |
| 181 |
rcd[15] = 0.0; |
| 182 |
|
| 183 |
if (reduction_or () != 4) |
| 184 |
__builtin_abort (); |
| 185 |
if (reduction_or_teams () != 4) |
| 186 |
__builtin_abort (); |
| 187 |
if (reduction_and () != 0) |
| 188 |
__builtin_abort (); |
| 189 |
if (reduction_and_teams () != 0) |
| 190 |
__builtin_abort (); |
| 191 |
|
| 192 |
return 0; |
| 193 |
} |