Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / mapping / map_back_race.cpp
blob8a988d3be3b4f9565559d0d28b7fba8ceb9273e8
1 // RUN: %libomptarget-compilexx-and-run-generic
3 // Taken from https://github.com/llvm/llvm-project/issues/54216
5 #include <algorithm>
6 #include <cstdlib>
7 #include <iostream>
9 bool almost_equal(float x, float gold, float rel_tol = 1e-09,
10 float abs_tol = 0.0) {
11 return std::abs(x - gold) <=
12 std::max(rel_tol * std::max(std::abs(x), std::abs(gold)), abs_tol);
14 void test_parallel_for__target() {
15 const int N0{32768};
16 const float expected_value{N0};
17 float counter_N0{};
18 #pragma omp parallel for
19 for (int i0 = 0; i0 < N0; i0++) {
20 #pragma omp target map(tofrom : counter_N0)
22 #pragma omp atomic update
23 counter_N0 = counter_N0 + 1.;
26 if (!almost_equal(counter_N0, expected_value, 0.01)) {
27 std::cerr << "Expected: " << expected_value << " Got: " << counter_N0
28 << std::endl;
29 std::exit(112);
32 int main() { test_parallel_for__target(); }