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 minimum work
8 // as indended for a few common data types.
15 template <class Tp
> void test_min_idx_reduction() {
16 const Tp length
= 1000;
17 const Tp nminimas
= 8;
18 std::vector
<float> a(length
, 3.0f
);
19 const Tp step
= length
/ nminimas
;
20 for (Tp i
= 0; i
< nminimas
; i
++) {
23 for (Tp i
= 0; i
< nminimas
; i
++) {
26 #pragma omp target teams distribute parallel for reduction(min : 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::min(idx
, j
);
33 assert(idx
== i
* step
&&
34 "#pragma omp target teams distribute parallel for "
35 "reduction(min:<identifier list>) does not work as intended.");
40 template <class Tp
> void test_min_val_reduction() {
41 const int length
= 1000;
42 const int half
= length
/ 2;
43 std::vector
<Tp
> a(length
, (Tp
)3);
45 Tp min_val
= std::numeric_limits
<Tp
>::max();
47 #pragma omp target teams distribute parallel for reduction(min : min_val) \
48 map(always, to : b[0 : length])
49 for (int i
= 0; i
< length
; i
++) {
50 min_val
= std::min(min_val
, b
[i
]);
52 assert(std::abs(((double)a
[half
+ 1]) - ((double)min_val
) - 1.0) < 1e-6 &&
53 "#pragma omp target teams distribute parallel for "
54 "reduction(min:<identifier list>) does not work as intended.");
58 // Reducing over indices
59 test_min_idx_reduction
<int>();
60 test_min_idx_reduction
<unsigned int>();
61 test_min_idx_reduction
<long>();
63 // Reducing over values
64 test_min_val_reduction
<int>();
65 test_min_val_reduction
<unsigned int>();
66 test_min_val_reduction
<long>();
67 test_min_val_reduction
<float>();
68 test_min_val_reduction
<double>();