brintos

brintos / llvm-project-archived public Read only

0
0
Text · 996 B · 49bbe87 Raw
36 lines · cpp
1// RUN: %libomptarget-compilexx-and-run-generic2 3// Taken from https://github.com/llvm/llvm-project/issues/542164 5// FIXME: https://github.com/llvm/llvm-project/issues/1612656// UNSUPPORTED: gpu7 8#include <algorithm>9#include <cstdlib>10#include <iostream>11 12bool almost_equal(float x, float gold, float rel_tol = 1e-09,13                  float abs_tol = 0.0) {14  return std::abs(x - gold) <=15         std::max(rel_tol * std::max(std::abs(x), std::abs(gold)), abs_tol);16}17void test_parallel_for__target() {18  const int N0{32768};19  const float expected_value{N0};20  float counter_N0{};21#pragma omp parallel for22  for (int i0 = 0; i0 < N0; i0++) {23#pragma omp target map(tofrom : counter_N0)24    {25#pragma omp atomic update26      counter_N0 = counter_N0 + 1.;27    }28  }29  if (!almost_equal(counter_N0, expected_value, 0.01)) {30    std::cerr << "Expected: " << expected_value << " Got: " << counter_N031              << std::endl;32    std::exit(112);33  }34}35int main() { test_parallel_for__target(); }36