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