Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / offloading / taskloop_offload_nowait.cpp
blob26a40298eea3eff74ece51f104e37b49e00b60a7
1 // RUN: %libomptarget-compilexx-and-run-generic
3 // REQUIRES: gpu
5 #include <cmath>
6 #include <cstdlib>
7 #include <iostream>
9 bool almost_equal(float x, float gold, float tol) {
10 if (std::signbit(x) != std::signbit(gold))
11 x = std::abs(gold) - std::abs(x);
13 return std::abs(gold) * (1 - tol) <= std::abs(x) &&
14 std::abs(x) <= std::abs(gold) * (1 + tol);
17 int main(int argc, char *argv[]) {
18 constexpr const int N0{2};
19 constexpr const int N1{182};
20 constexpr const float expected_value{N0 * N1};
21 float counter_N0{};
23 #pragma omp target data map(tofrom : counter_N0)
25 #pragma omp taskloop shared(counter_N0)
26 for (int i0 = 0; i0 < N0; i0++) {
27 #pragma omp target teams distribute parallel for map(tofrom : counter_N0) nowait
28 for (int i1 = 0; i1 < N1; i1++) {
29 #pragma omp atomic update
30 counter_N0 = counter_N0 + 1.;
35 if (!almost_equal(counter_N0, expected_value, 0.1)) {
36 std::cerr << "Expected: " << expected_value << " Got: " << counter_N0
37 << '\n';
38 return -1;
41 return 0;