gcc/libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-3.c
Nathan Sidwell 2d25681660 reduction-dbl.c: New.
* libgomp.oacc-c-c++-common/reduction-dbl.c: New.
	* libgomp.oacc-c-c++-common/reduction-flt.c: New.
	* libgomp.oacc-c-c++-common/reduction-cplx-dbl.c: Use typedef.
	* libgomp.oacc-c-c++-common/reduction-cplx-flt.c: Use typedef.
	* libgomp.oacc-c-c++-common/reduction-2.c: Uncomment broken tests
	and fix.
	* libgomp.oacc-c-c++-common/reduction-3.c: Likewise.
	* libgomp.oacc-c-c++-common/reduction-4.c: Likewise.

From-SVN: r230621
2015-11-19 18:58:39 +00:00

94 lines
1.8 KiB
C

/* { dg-do run } */
/* double reductions. */
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define vl 32
int
main(void)
{
const int n = 1000;
int i;
double vresult, result, array[n];
bool lvresult, lresult;
for (i = 0; i < n; i++)
array[i] = i;
result = 0;
vresult = 0;
/* 'max' reductions. */
#pragma acc parallel vector_length (vl) copy(result)
#pragma acc loop reduction (max:result)
for (i = 0; i < n; i++)
result = result > array[i] ? result : array[i];
/* Verify the reduction. */
for (i = 0; i < n; i++)
vresult = vresult > array[i] ? vresult : array[i];
if (result != vresult)
abort ();
result = 0;
vresult = 0;
/* 'min' reductions. */
#pragma acc parallel vector_length (vl) copy(result)
#pragma acc loop reduction (min:result)
for (i = 0; i < n; i++)
result = result < array[i] ? result : array[i];
/* Verify the reduction. */
for (i = 0; i < n; i++)
vresult = vresult < array[i] ? vresult : array[i];
if (result != vresult)
abort ();
result = 5;
vresult = 5;
lresult = false;
lvresult = false;
/* '&&' reductions. */
#pragma acc parallel vector_length (vl) copy(lresult)
#pragma acc loop reduction (&&:lresult)
for (i = 0; i < n; i++)
lresult = lresult && (result > array[i]);
/* Verify the reduction. */
for (i = 0; i < n; i++)
lvresult = lresult && (result > array[i]);
if (lresult != lvresult)
abort ();
result = 5;
vresult = 5;
lresult = false;
lvresult = false;
/* '||' reductions. */
#pragma acc parallel vector_length (vl) copy(lresult)
#pragma acc loop reduction (||:lresult)
for (i = 0; i < n; i++)
lresult = lresult || (result > array[i]);
/* Verify the reduction. */
for (i = 0; i < n; i++)
lvresult = lresult || (result > array[i]);
if (lresult != lvresult)
abort ();
return 0;
}