xfail scan-tree-dump-not throw in g++.dg/pr99966.C on hppa*64*-*-*
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / reduction-5.c
blob52f23e35b9a96f6c1f723e7fdbea35032a211c65
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.
5 In this testcase, the int result is again converted to a floating-poing
6 or complex type.
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.
11 Test: FP reduction variable + FP array - as reduction-1.c but with target */
13 #define N 1024
14 _Complex float rcf[N];
15 _Complex double rcd[N];
16 float rf[N];
17 double rd[N];
19 int
20 reduction_or ()
22 float orf = 0;
23 double ord = 0;
24 _Complex float orfc = 0;
25 _Complex double ordc = 0;
27 #pragma omp target parallel reduction(||: orf) map(orf)
28 for (int i=0; i < N; ++i)
29 orf = orf || rf[i];
31 #pragma omp target parallel for reduction(||: ord) map(ord)
32 for (int i=0; i < N; ++i)
33 ord = ord || rcd[i];
35 #pragma omp target parallel for simd reduction(||: orfc) map(orfc)
36 for (int i=0; i < N; ++i)
37 orfc = orfc || rcf[i];
39 #pragma omp target parallel loop reduction(||: ordc) map(ordc)
40 for (int i=0; i < N; ++i)
41 ordc = ordc || rcd[i];
43 return orf + ord + __real__ orfc + __real__ ordc;
46 int
47 reduction_or_teams ()
49 float orf = 0;
50 double ord = 0;
51 _Complex float orfc = 0;
52 _Complex double ordc = 0;
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];
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];
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];
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];
70 return orf + ord + __real__ orfc + __real__ ordc;
73 int
74 reduction_and ()
76 float andf = 1;
77 double andd = 1;
78 _Complex float andfc = 1;
79 _Complex double anddc = 1;
81 #pragma omp target parallel reduction(&&: andf) map(andf)
82 for (int i=0; i < N; ++i)
83 andf = andf && rf[i];
85 #pragma omp target parallel for reduction(&&: andd) map(andd)
86 for (int i=0; i < N; ++i)
87 andd = andd && rcd[i];
89 #pragma omp target parallel for simd reduction(&&: andfc) map(andfc)
90 for (int i=0; i < N; ++i)
91 andfc = andfc && rcf[i];
93 #pragma omp target parallel loop reduction(&&: anddc) map(anddc)
94 for (int i=0; i < N; ++i)
95 anddc = anddc && rcd[i];
97 return andf + andd + __real__ andfc + __real__ anddc;
101 reduction_and_teams ()
103 float andf = 1;
104 double andd = 1;
105 _Complex float andfc = 1;
106 _Complex double anddc = 1;
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];
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];
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];
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];
124 return andf + andd + __real__ andfc + __real__ anddc;
128 main ()
130 for (int i = 0; i < N; ++i)
132 rf[i] = 0;
133 rd[i] = 0;
134 rcf[i] = 0;
135 rcd[i] = 0;
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 ();
147 rf[10] = 1.0;
148 rd[15] = 1.0;
149 rcf[10] = 1.0;
150 rcd[15] = 1.0i;
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 ();
161 for (int i = 0; i < N; ++i)
163 rf[i] = 1;
164 rd[i] = 1;
165 rcf[i] = 1;
166 rcd[i] = 1;
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 ();
178 rf[10] = 0.0;
179 rd[15] = 0.0;
180 rcf[10] = 0.0;
181 rcd[15] = 0.0;
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 ();
192 return 0;