1 | // RUN: %libomptarget-compilexx-and-run-generic |
---|---|
2 | |
3 | // Taken from https://github.com/llvm/llvm-project/issues/54216 |
4 | |
5 | #include <algorithm> |
6 | #include <cstdlib> |
7 | #include <iostream> |
8 | |
9 | bool almost_equal(float x, float gold, float rel_tol = 1e-09, |
10 | float abs_tol = 0.0) { |
11 | return std::abs(x: x - gold) <= |
12 | std::max(a: rel_tol * std::max(a: std::abs(x: x), b: std::abs(x: gold)), b: abs_tol); |
13 | } |
14 | void test_parallel_for__target() { |
15 | const int N0{32768}; |
16 | const float expected_value{N0}; |
17 | float counter_N0{}; |
18 | #pragma omp parallel for |
19 | for (int i0 = 0; i0 < N0; i0++) { |
20 | #pragma omp target map(tofrom : counter_N0) |
21 | { |
22 | #pragma omp atomic update |
23 | counter_N0 = counter_N0 + 1.; |
24 | } |
25 | } |
26 | if (!almost_equal(x: counter_N0, gold: expected_value, rel_tol: 0.01)) { |
27 | std::cerr << "Expected: "<< expected_value << " Got: "<< counter_N0 |
28 | << std::endl; |
29 | std::exit(status: 112); |
30 | } |
31 | } |
32 | int main() { test_parallel_for__target(); } |
33 |