1 // RUN: %libomp-compile-and-run
4 #include "omp_testsuite.h"
6 int test_omp_sections_reduction()
12 double dt
=0.5; /* base of geometric row for + and - test*/
13 double rounding_error
= 1.E
-9;
26 /* int my_islarger; */
40 known_sum
= (999*1000)/2+7;
43 #pragma omp sections private(i) reduction(+:sum)
53 for (i
=300;i
<700;i
++) {
59 for (i
=700;i
<1000;i
++) {
67 fprintf(stderr
,"Error in sum with integers: Result was %d"
68 " instead of %d\n", sum
,known_sum
);
74 #pragma omp sections private(i) reduction(-:diff)
84 for (i
=300;i
<700;i
++) {
90 for (i
=700;i
<1000;i
++) {
98 fprintf(stderr
,"Error in Difference with integers: Result was %d"
99 " instead of 0.\n",diff
);
105 dknown_sum
= (1-dpt
)/(1-dt
);
108 #pragma omp sections private(i) reduction(+:dsum)
124 for (i
=12;i
<20;++i
) {
130 if( fabs(dsum
-dknown_sum
) > rounding_error
) {
132 fprintf(stderr
,"Error in sum with doubles: Result was %f"
133 " instead of %f (Difference: %E)\n",
134 dsum
, dknown_sum
, dsum
-dknown_sum
);
141 fprintf(stderr
,"\n");
142 ddiff
= (1-dpt
)/(1-dt
);
145 #pragma omp sections private(i) reduction(-:ddiff)
161 for (i
=12;i
<20;++i
) {
168 if(fabs(ddiff
) > rounding_error
) {
170 fprintf(stderr
,"Error in Difference with doubles: Result was %E"
171 " instead of 0.0\n",ddiff
);
174 known_product
= 3628800;
177 #pragma omp sections private(i) reduction(*:product)
199 if(known_product
!= product
) {
201 fprintf(stderr
,"Error in Product with integers: Result was %d"
202 " instead of %d\n",product
,known_product
);
205 for(i
=0;i
<1000;i
++) {
211 #pragma omp sections private(i) reduction(&&:logic_and)
215 for (i
=1;i
<300;i
++) {
216 logic_and
= (logic_and
&& logics
[i
]);
221 for (i
=300;i
<700;i
++) {
222 logic_and
= (logic_and
&& logics
[i
]);
227 for (i
=700;i
<1000;i
++) {
228 logic_and
= (logic_and
&& logics
[i
]);
235 fprintf(stderr
,"Error in logic AND part 1\n");
243 #pragma omp sections private(i) reduction(&&:logic_and)
247 for (i
=1;i
<300;i
++) {
248 logic_and
= (logic_and
&& logics
[i
]);
253 for (i
=300;i
<700;i
++) {
254 logic_and
= (logic_and
&& logics
[i
]);
259 for (i
=700;i
<1000;i
++) {
260 logic_and
= (logic_and
&& logics
[i
]);
267 fprintf(stderr
,"Error in logic AND part 2\n");
270 for(i
=0;i
<1000;i
++) {
276 #pragma omp sections private(i) reduction(||:logic_or)
280 for (i
=1;i
<300;i
++) {
281 logic_or
= (logic_or
|| logics
[i
]);
286 for (i
=300;i
<700;i
++) {
287 logic_or
= (logic_or
|| logics
[i
]);
292 for (i
=700;i
<1000;i
++) {
293 logic_or
= (logic_or
|| logics
[i
]);
300 fprintf(stderr
,"\nError in logic OR part 1\n");
308 #pragma omp sections private(i) reduction(||:logic_or)
312 for (i
=1;i
<300;i
++) {
313 logic_or
= (logic_or
|| logics
[i
]);
318 for (i
=300;i
<700;i
++) {
319 logic_or
= (logic_or
|| logics
[i
]);
324 for (i
=700;i
<1000;i
++) {
325 logic_or
= (logic_or
|| logics
[i
]);
332 fprintf(stderr
,"Error in logic OR part 2\n");
335 for(i
=0;i
<1000;++i
) {
341 #pragma omp sections private(i) reduction(&:bit_and)
346 bit_and
= (bit_and
& logics
[i
]);
351 for(i
=300;i
<700;++i
) {
352 bit_and
= (bit_and
& logics
[i
]);
357 for(i
=700;i
<1000;++i
) {
358 bit_and
= (bit_and
& logics
[i
]);
365 fprintf(stderr
,"Error in BIT AND part 1\n");
373 #pragma omp sections private(i) reduction(&:bit_and)
378 bit_and
= bit_and
& logics
[i
];
383 for(i
=300;i
<700;++i
) {
384 bit_and
= bit_and
& logics
[i
];
389 for(i
=700;i
<1000;++i
) {
390 bit_and
= bit_and
& logics
[i
];
397 fprintf(stderr
,"Error in BIT AND part 2\n");
400 for(i
=0;i
<1000;i
++) {
406 #pragma omp sections private(i) reduction(|:bit_or)
411 bit_or
= bit_or
| logics
[i
];
416 for(i
=300;i
<700;++i
) {
417 bit_or
= bit_or
| logics
[i
];
422 for(i
=700;i
<1000;++i
) {
423 bit_or
= bit_or
| logics
[i
];
430 fprintf(stderr
,"Error in BIT OR part 1\n");
437 #pragma omp sections private(i) reduction(|:bit_or)
442 bit_or
= bit_or
| logics
[i
];
447 for(i
=300;i
<700;++i
) {
448 bit_or
= bit_or
| logics
[i
];
453 for(i
=700;i
<1000;++i
) {
454 bit_or
= bit_or
| logics
[i
];
461 fprintf(stderr
,"Error in BIT OR part 2\n");
464 for(i
=0;i
<1000;i
++) {
470 #pragma omp sections private(i) reduction(^:exclusiv_bit_or)
475 exclusiv_bit_or
= exclusiv_bit_or
^ logics
[i
];
480 for(i
=300;i
<700;++i
) {
481 exclusiv_bit_or
= exclusiv_bit_or
^ logics
[i
];
486 for(i
=700;i
<1000;++i
) {
487 exclusiv_bit_or
= exclusiv_bit_or
^ logics
[i
];
492 if(exclusiv_bit_or
) {
494 fprintf(stderr
,"Error in EXCLUSIV BIT OR part 1\n");
502 #pragma omp sections private(i) reduction(^:exclusiv_bit_or)
507 exclusiv_bit_or
= exclusiv_bit_or
^ logics
[i
];
512 for(i
=300;i
<700;++i
) {
513 exclusiv_bit_or
= exclusiv_bit_or
^ logics
[i
];
518 for(i
=700;i
<1000;++i
) {
519 exclusiv_bit_or
= exclusiv_bit_or
^ logics
[i
];
524 if(!exclusiv_bit_or
) {
526 fprintf(stderr
,"Error in EXCLUSIV BIT OR part 2\n");
529 /*printf("\nResult:%d\n",result);*/
537 for(i
= 0; i
< REPETITIONS
; i
++) {
538 if(!test_omp_sections_reduction()) {