1// RUN: %libomptarget-compilexx-and-run-generic
2
3// REQUIRES: gpu
4
5#include <cmath>
6#include <cstdlib>
7#include <iostream>
8
9bool almost_equal(float x, float gold, float tol) {
10 if (std::signbit(x: x) != std::signbit(x: gold))
11 x = std::abs(x: gold) - std::abs(x: x);
12
13 return std::abs(x: gold) * (1 - tol) <= std::abs(x: x) &&
14 std::abs(x: x) <= std::abs(x: gold) * (1 + tol);
15}
16
17int 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{};
22
23#pragma omp target data map(tofrom : counter_N0)
24 {
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.;
31 }
32 }
33 }
34
35 if (!almost_equal(x: counter_N0, gold: expected_value, tol: 0.1)) {
36 std::cerr << "Expected: " << expected_value << " Got: " << counter_N0
37 << '\n';
38 return -1;
39 }
40
41 return 0;
42}
43

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of offload/test/offloading/taskloop_offload_nowait.cpp