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