Skip gnat.dg/prot7.adb on hppa.
[official-gcc.git] / libgomp / testsuite / libgomp.c-c++-common / reduction-3.c
blob0f09aab40eca42acf2e43f0c807f61f925d371c5
1 /* C / C++'s logical AND and OR operators take any scalar argument
2 which compares (un)equal to 0 - the result 1 or 0 and of type int.
4 In this testcase, the int result is again converted to a floating-poing
5 or complex type.
7 While having a floating-point/complex array element with || and && can make
8 sense, having a non-integer/non-bool reduction variable is odd but valid.
10 Test: integer reduction variable + FP array. */
12 #define N 1024
13 _Complex float rcf[N];
14 _Complex double rcd[N];
15 float rf[N];
16 double rd[N];
18 int
19 reduction_or ()
21 char orf = 0;
22 short ord = 0;
23 int orfc = 0;
24 long ordc = 0;
26 #pragma omp parallel reduction(||: orf)
27 for (int i=0; i < N; ++i)
28 orf = orf || rf[i];
30 #pragma omp parallel for reduction(||: ord)
31 for (int i=0; i < N; ++i)
32 ord = ord || rcd[i];
34 #pragma omp parallel for simd reduction(||: orfc)
35 for (int i=0; i < N; ++i)
36 orfc = orfc || rcf[i];
38 #pragma omp parallel loop reduction(||: ordc)
39 for (int i=0; i < N; ++i)
40 ordc = ordc || rcd[i];
42 return orf + ord + __real__ orfc + __real__ ordc;
45 int
46 reduction_or_teams ()
48 char orf = 0;
49 short ord = 0;
50 int orfc = 0;
51 long ordc = 0;
53 #pragma omp teams distribute parallel for reduction(||: orf)
54 for (int i=0; i < N; ++i)
55 orf = orf || rf[i];
57 #pragma omp teams distribute parallel for simd reduction(||: ord)
58 for (int i=0; i < N; ++i)
59 ord = ord || rcd[i];
61 #pragma omp teams distribute parallel for reduction(||: orfc)
62 for (int i=0; i < N; ++i)
63 orfc = orfc || rcf[i];
65 #pragma omp teams distribute parallel for simd reduction(||: ordc)
66 for (int i=0; i < N; ++i)
67 ordc = ordc || rcd[i];
69 return orf + ord + __real__ orfc + __real__ ordc;
72 int
73 reduction_and ()
75 unsigned char andf = 1;
76 unsigned short andd = 1;
77 unsigned int andfc = 1;
78 unsigned long anddc = 1;
80 #pragma omp parallel reduction(&&: andf)
81 for (int i=0; i < N; ++i)
82 andf = andf && rf[i];
84 #pragma omp parallel for reduction(&&: andd)
85 for (int i=0; i < N; ++i)
86 andd = andd && rcd[i];
88 #pragma omp parallel for simd reduction(&&: andfc)
89 for (int i=0; i < N; ++i)
90 andfc = andfc && rcf[i];
92 #pragma omp parallel loop reduction(&&: anddc)
93 for (int i=0; i < N; ++i)
94 anddc = anddc && rcd[i];
96 return andf + andd + __real__ andfc + __real__ anddc;
99 int
100 reduction_and_teams ()
102 unsigned char andf = 1;
103 unsigned short andd = 1;
104 unsigned int andfc = 1;
105 unsigned long anddc = 1;
107 #pragma omp teams distribute parallel for reduction(&&: andf)
108 for (int i=0; i < N; ++i)
109 andf = andf && rf[i];
111 #pragma omp teams distribute parallel for simd reduction(&&: andd)
112 for (int i=0; i < N; ++i)
113 andd = andd && rcd[i];
115 #pragma omp teams distribute parallel for reduction(&&: andfc)
116 for (int i=0; i < N; ++i)
117 andfc = andfc && rcf[i];
119 #pragma omp teams distribute parallel for simd reduction(&&: anddc)
120 for (int i=0; i < N; ++i)
121 anddc = anddc && rcd[i];
123 return andf + andd + __real__ andfc + __real__ anddc;
127 main ()
129 for (int i = 0; i < N; ++i)
131 rf[i] = 0;
132 rd[i] = 0;
133 rcf[i] = 0;
134 rcd[i] = 0;
137 if (reduction_or () != 0)
138 __builtin_abort ();
139 if (reduction_or_teams () != 0)
140 __builtin_abort ();
141 if (reduction_and () != 0)
142 __builtin_abort ();
143 if (reduction_and_teams () != 0)
144 __builtin_abort ();
146 rf[10] = 1.0;
147 rd[15] = 1.0;
148 rcf[10] = 1.0;
149 rcd[15] = 1.0i;
151 if (reduction_or () != 4)
152 __builtin_abort ();
153 if (reduction_or_teams () != 4)
154 __builtin_abort ();
155 if (reduction_and () != 0)
156 __builtin_abort ();
157 if (reduction_and_teams () != 0)
158 __builtin_abort ();
160 for (int i = 0; i < N; ++i)
162 rf[i] = 1;
163 rd[i] = 1;
164 rcf[i] = 1;
165 rcd[i] = 1;
168 if (reduction_or () != 4)
169 __builtin_abort ();
170 if (reduction_or_teams () != 4)
171 __builtin_abort ();
172 if (reduction_and () != 4)
173 __builtin_abort ();
174 if (reduction_and_teams () != 4)
175 __builtin_abort ();
177 rf[10] = 0.0;
178 rd[15] = 0.0;
179 rcf[10] = 0.0;
180 rcd[15] = 0.0;
182 if (reduction_or () != 4)
183 __builtin_abort ();
184 if (reduction_or_teams () != 4)
185 __builtin_abort ();
186 if (reduction_and () != 0)
187 __builtin_abort ();
188 if (reduction_and_teams () != 0)
189 __builtin_abort ();
191 return 0;