3 /* Integer reductions. */
10 #define DO_PRAGMA(x) _Pragma (#x)
12 #define check_reduction_op(type, op, init, b) \
16 DO_PRAGMA (acc parallel vector_length (vl))\
17 DO_PRAGMA (acc loop reduction (op:res))\
18 for (i = 0; i < n; i++) \
22 for (i = 0; i < n; i++) \
30 test_reductions_int (void)
36 for (i
= 0; i
< n
; 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
]);
47 test_reductions_bool (void)
54 for (i
= 0; i
< n
; i
++)
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) \
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)); \
72 for (i = 0; i < n; i++) \
73 vres = op (vres, (b)); \
79 #define max(a, b) (((a) > (b)) ? (a) : (b))
80 #define min(a, b) (((a) < (b)) ? (a) : (b))
83 test_reductions_minmax (void)
89 for (i
= 0; i
< n
; i
++)
92 check_reduction_macro (int, min
, n
+ 1, array
[i
]);
93 check_reduction_macro (int, max
, -1, array
[i
]);
99 test_reductions_int ();
100 test_reductions_bool ();
101 test_reductions_minmax ();