1 | // RUN: %libomptarget-compilexx-and-run-generic |
2 | |
3 | // UNSUPPORTED: x86_64-pc-linux-gnu |
4 | // UNSUPPORTED: x86_64-pc-linux-gnu-LTO |
5 | |
6 | #include <cmath> |
7 | #include <cstdlib> |
8 | #include <iostream> |
9 | |
10 | bool almost_equal(float x, float gold, float tol) { |
11 | if (std::signbit(x: x) != std::signbit(x: gold)) |
12 | x = std::abs(x: gold) - std::abs(x: x); |
13 | |
14 | return std::abs(x: gold) * (1 - tol) <= std::abs(x: x) && |
15 | std::abs(x: x) <= std::abs(x: gold) * (1 + tol); |
16 | } |
17 | |
18 | int main(int argc, char *argv[]) { |
19 | constexpr const int N0{2}; |
20 | constexpr const int N1{182}; |
21 | constexpr const float expected_value{N0 * N1}; |
22 | float counter_N0{}; |
23 | |
24 | #pragma omp target data map(tofrom : counter_N0) |
25 | { |
26 | #pragma omp taskloop shared(counter_N0) |
27 | for (int i0 = 0; i0 < N0; i0++) { |
28 | #pragma omp target teams distribute parallel for map(tofrom : counter_N0) nowait |
29 | for (int i1 = 0; i1 < N1; i1++) { |
30 | #pragma omp atomic update |
31 | counter_N0 = counter_N0 + 1.; |
32 | } |
33 | } |
34 | } |
35 | |
36 | if (!almost_equal(x: counter_N0, gold: expected_value, tol: 0.1)) { |
37 | std::cerr << "Expected: " << expected_value << " Got: " << counter_N0 |
38 | << '\n'; |
39 | return -1; |
40 | } |
41 | |
42 | return 0; |
43 | } |
44 | |