1 // RUN: %libomptarget-compilexx-and-run-generic 2 3 // Taken from https://github.com/llvm/llvm-project/issues/54216 4 5 6 // UNSUPPORTED: x86_64-pc-linux-gnu 7 // UNSUPPORTED: x86_64-pc-linux-gnu-oldDriver 8 9 #include <algorithm> 10 #include <cstdlib> 11 #include <iostream> 12 13 bool almost_equal(float x, float gold, float rel_tol = 1e-09, 14 float abs_tol = 0.0) { 15 return std::abs(x - gold) <= 16 std::max(rel_tol * std::max(std::abs(x), std::abs(gold)), abs_tol); 17 } 18 void test_parallel_for__target() { 19 const int N0{32768}; 20 const float expected_value{N0}; 21 float counter_N0{}; 22 #pragma omp parallel for 23 for (int i0 = 0; i0 < N0; i0++) { 24 #pragma omp target map(tofrom : counter_N0) 25 { 26 #pragma omp atomic update 27 counter_N0 = counter_N0 + 1.; 28 } 29 } 30 if (!almost_equal(counter_N0, expected_value, 0.01)) { 31 std::cerr << "Expected: " << expected_value << " Got: " << counter_N0 32 << std::endl; 33 std::exit(112); 34 } 35 } 36 int main() { test_parallel_for__target(); } 37