1 // RUN: %libomptarget-compilexx-and-run-generic
2 // RUN: %libomptarget-compileoptxx-and-run-generic
4 // FIXME: This is a bug in host offload, this should run fine.
7 // This test validates that the OpenMP target reductions to find a maximum work
8 // as indended for a few common data types.
15 template <class Tp
> void test_max_idx_reduction() {
16 const Tp length
= 1000;
17 const Tp nmaximas
= 8;
18 std::vector
<float> a(length
, 3.0f
);
19 const Tp step
= length
/ nmaximas
;
20 for (Tp i
= 0; i
< nmaximas
; i
++) {
23 for (Tp i
= nmaximas
; i
> 0; i
--) {
26 #pragma omp target teams distribute parallel for reduction(max : idx) \
27 map(always, to : b[0 : length])
28 for (Tp j
= 0; j
< length
- 1; j
++) {
29 if (b
[j
] > b
[j
+ 1]) {
30 idx
= std::max(idx
, j
);
33 assert(idx
== (i
- 1) * step
&&
34 "#pragma omp target teams distribute parallel for "
35 "reduction(max:<identifier list>) does not work as intended.");
40 template <class Tp
> void test_max_val_reduction() {
41 const int length
= 1000;
42 const int half
= length
/ 2;
43 std::vector
<Tp
> a(length
, (Tp
)3);
45 Tp max_val
= std::numeric_limits
<Tp
>::lowest();
47 #pragma omp target teams distribute parallel for reduction(max : max_val) \
48 map(always, to : b[0 : length])
49 for (int i
= 0; i
< length
; i
++) {
50 max_val
= std::max(max_val
, b
[i
]);
52 assert(std::abs(((double)a
[half
+ 1]) - ((double)max_val
) + 1.0) < 1e-6 &&
53 "#pragma omp target teams distribute parallel for "
54 "reduction(max:<identifier list>) does not work as intended.");
58 // Reducing over indices
59 test_max_idx_reduction
<int>();
60 test_max_idx_reduction
<unsigned int>();
61 test_max_idx_reduction
<long>();
63 // Reducing over values
64 test_max_val_reduction
<int>();
65 test_max_val_reduction
<unsigned int>();
66 test_max_val_reduction
<long>();
67 test_max_val_reduction
<float>();
68 test_max_val_reduction
<double>();