Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / offloading / taskloop_offload_nowait.cpp
blob7069580bff4f7616bd57edaf52dd3b042767d5a1
1 // RUN: %libomptarget-compilexx-and-run-generic
3 // UNSUPPORTED: x86_64-pc-linux-gnu
4 // UNSUPPORTED: x86_64-pc-linux-gnu-LTO
6 #include <cmath>
7 #include <cstdlib>
8 #include <iostream>
10 bool almost_equal(float x, float gold, float tol) {
11 if (std::signbit(x) != std::signbit(gold))
12 x = std::abs(gold) - std::abs(x);
14 return std::abs(gold) * (1 - tol) <= std::abs(x) &&
15 std::abs(x) <= std::abs(gold) * (1 + tol);
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{};
24 #pragma omp target data map(tofrom : counter_N0)
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.;
36 if (!almost_equal(counter_N0, expected_value, 0.1)) {
37 std::cerr << "Expected: " << expected_value << " Got: " << counter_N0
38 << '\n';
39 return -1;
42 return 0;