Use DO_PRAGMA in libgomp.oacc-c-c++-common/reduction-1.c
[official-gcc.git] / libgomp / testsuite / libgomp.oacc-c-c++-common / reduction-1.c
blob4501f8e9f37131967b377b90135ed761548d7772
1 /* { dg-do run } */
3 /* Integer reductions. */
5 #include <stdlib.h>
6 #include <stdbool.h>
8 #define vl 32
10 #define DO_PRAGMA(x) _Pragma (#x)
12 #define check_reduction_op(type, op, init, b) \
13 { \
14 type res, vres; \
15 res = (init); \
16 DO_PRAGMA (acc parallel vector_length (vl))\
17 DO_PRAGMA (acc loop reduction (op:res))\
18 for (i = 0; i < n; i++) \
19 res = res op (b); \
21 vres = (init); \
22 for (i = 0; i < n; i++) \
23 vres = vres op (b); \
25 if (res != vres) \
26 abort (); \
29 static void
30 test_reductions_int (void)
32 const int n = 1000;
33 int i;
34 int array[n];
36 for (i = 0; i < n; i++)
37 array[i] = i;
39 check_reduction_op (int, +, 0, array[i]);
40 check_reduction_op (int, *, 1, array[i]);
41 check_reduction_op (int, &, -1, array[i]);
42 check_reduction_op (int, |, 0, array[i]);
43 check_reduction_op (int, ^, 0, array[i]);
46 static void
47 test_reductions_bool (void)
49 const int n = 1000;
50 int i;
51 int array[n];
52 int cmp_val;
54 for (i = 0; i < n; i++)
55 array[i] = i;
57 cmp_val = 5;
58 check_reduction_op (bool, &&, true, (cmp_val > array[i]));
59 check_reduction_op (bool, ||, false, (cmp_val > array[i]));
62 #define check_reduction_macro(type, op, init, b) \
63 { \
64 type res, vres; \
65 res = (init); \
66 DO_PRAGMA (acc parallel vector_length (vl))\
67 DO_PRAGMA (acc loop reduction (op:res))\
68 for (i = 0; i < n; i++) \
69 res = op (res, (b)); \
71 vres = (init); \
72 for (i = 0; i < n; i++) \
73 vres = op (vres, (b)); \
75 if (res != vres) \
76 abort (); \
79 #define max(a, b) (((a) > (b)) ? (a) : (b))
80 #define min(a, b) (((a) < (b)) ? (a) : (b))
82 static void
83 test_reductions_minmax (void)
85 const int n = 1000;
86 int i;
87 int array[n];
89 for (i = 0; i < n; i++)
90 array[i] = i;
92 check_reduction_macro (int, min, n + 1, array[i]);
93 check_reduction_macro (int, max, -1, array[i]);
96 int
97 main (void)
99 test_reductions_int ();
100 test_reductions_bool ();
101 test_reductions_minmax ();
102 return 0;