Retro68/gcc/libgomp/testsuite/libgomp.oacc-c-c++-common/reduction-1.c

134 lines
4.1 KiB
C
Raw Normal View History

2015-08-28 15:33:40 +00:00
/* { dg-do run } */
/* Integer reductions. */
#include <stdlib.h>
2017-04-10 11:32:00 +00:00
#include "reduction.h"
2019-06-02 15:48:37 +00:00
#define ng 8
#define nw 4
#define vl 32
2015-08-28 15:33:40 +00:00
static void
2017-04-10 11:32:00 +00:00
test_reductions (void)
2015-08-28 15:33:40 +00:00
{
2017-04-10 11:32:00 +00:00
const int n = 10;
2015-08-28 15:33:40 +00:00
int i;
int array[n];
for (i = 0; i < n; i++)
2017-04-10 11:32:00 +00:00
array[i] = i+1;
/* Gang reductions. */
check_reduction_op (int, +, 0, array[i], num_gangs (ng), gang);
check_reduction_op (int, *, 1, array[i], num_gangs (ng), gang);
check_reduction_op (int, &, -1, array[i], num_gangs (ng), gang);
check_reduction_op (int, |, 0, array[i], num_gangs (ng), gang);
check_reduction_op (int, ^, 0, array[i], num_gangs (ng), gang);
/* Worker reductions. */
check_reduction_op (int, +, 0, array[i], num_workers (nw), worker);
check_reduction_op (int, *, 1, array[i], num_workers (nw), worker);
check_reduction_op (int, &, -1, array[i], num_workers (nw), worker);
check_reduction_op (int, |, 0, array[i], num_workers (nw), worker);
check_reduction_op (int, ^, 0, array[i], num_workers (nw), worker);
/* Vector reductions. */
check_reduction_op (int, +, 0, array[i], vector_length (vl), vector);
check_reduction_op (int, *, 1, array[i], vector_length (vl), vector);
check_reduction_op (int, &, -1, array[i], vector_length (vl), vector);
check_reduction_op (int, |, 0, array[i], vector_length (vl), vector);
check_reduction_op (int, ^, 0, array[i], vector_length (vl), vector);
/* Combined reductions. */
check_reduction_op (int, +, 0, array[i], num_gangs (ng) num_workers (nw)
vector_length (vl), gang worker vector);
check_reduction_op (int, *, 1, array[i], num_gangs (ng) num_workers (nw)
vector_length (vl), gang worker vector);
check_reduction_op (int, &, -1, array[i], num_gangs (ng) num_workers (nw)
vector_length (vl), gang worker vector);
check_reduction_op (int, |, 0, array[i], num_gangs (ng) num_workers (nw)
vector_length (vl), gang worker vector);
check_reduction_op (int, ^, 0, array[i], num_gangs (ng) num_workers (nw)
vector_length (vl), gang worker vector);
2015-08-28 15:33:40 +00:00
}
static void
test_reductions_bool (void)
{
const int n = 1000;
int i;
int array[n];
int cmp_val;
for (i = 0; i < n; i++)
array[i] = i;
cmp_val = 5;
2017-04-10 11:32:00 +00:00
/* Gang reductions. */
check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_gangs (ng),
gang);
check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_gangs (ng),
gang);
/* Worker reductions. */
check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_workers (nw),
worker);
check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_workers (nw),
worker);
/* Vector reductions. */
check_reduction_op (int, &&, 1, (cmp_val > array[i]), vector_length (vl),
vector);
check_reduction_op (int, ||, 0, (cmp_val > array[i]), vector_length (vl),
vector);
/* Combined reductions. */
check_reduction_op (int, &&, 1, (cmp_val > array[i]), num_gangs (ng)
num_workers (nw) vector_length (vl), gang worker vector);
check_reduction_op (int, ||, 0, (cmp_val > array[i]), num_gangs (ng)
num_workers (nw) vector_length (vl), gang worker vector);
}
2015-08-28 15:33:40 +00:00
static void
test_reductions_minmax (void)
{
const int n = 1000;
int i;
int array[n];
for (i = 0; i < n; i++)
array[i] = i;
2017-04-10 11:32:00 +00:00
/* Gang reductions. */
check_reduction_macro (int, min, n + 1, array[i], num_gangs (ng), gang);
check_reduction_macro (int, max, -1, array[i], num_gangs (ng), gang);
/* Worker reductions. */
check_reduction_macro (int, min, n + 1, array[i], num_workers (nw), worker);
check_reduction_macro (int, max, -1, array[i], num_workers (nw), worker);
/* Vector reductions. */
check_reduction_macro (int, min, n + 1, array[i], vector_length (vl),
vector);
check_reduction_macro (int, max, -1, array[i], vector_length (vl), vector);
/* Combined reductions. */
check_reduction_macro (int, min, n + 1, array[i], num_gangs (ng)
num_workers (nw) vector_length (vl), gang worker
vector);
check_reduction_macro (int, max, -1, array[i], num_gangs (ng)
num_workers (nw) vector_length (vl), gang worker
vector);
2015-08-28 15:33:40 +00:00
}
int
main (void)
{
2017-04-10 11:32:00 +00:00
test_reductions ();
2015-08-28 15:33:40 +00:00
test_reductions_bool ();
test_reductions_minmax ();
return 0;
}