brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 8e640b7 Raw
56 lines · cpp
1// Unonptimized, we need 24000000 bytes heap2// RUN: %libomptarget-compilexx-generic3// RUN: env LIBOMPTARGET_HEAP_SIZE=24000000 \4// RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic5// RUN: %libomptarget-compileoptxx-run-and-check-generic6 7// REQUIRES: libc8 9#include <iostream>10 11template <typename LOOP_BODY>12inline void forall(int Begin, int End, LOOP_BODY LoopBody) {13#pragma omp target parallel for schedule(static)14  for (int I = Begin; I < End; ++I) {15    LoopBody(I);16  }17}18 19#define N (1000)20 21//22// Demonstration of the RAJA abstraction using lambdas23// Requires data mapping onto the target section24//25int main() {26  double A[N], B[N], C[N];27 28  for (int I = 0; I < N; I++) {29    A[I] = I + 1;30    B[I] = -I;31    C[I] = -9;32  }33 34#pragma omp target data map(tofrom : C[0 : N]) map(to : A[0 : N], B[0 : N])35  {36    forall(0, N, [&](int I) { C[I] += A[I] + B[I]; });37  }38 39  int Fail = 0;40  for (int I = 0; I < N; I++) {41    if (C[I] != -8) {42      std::cout << "Failed at " << I << " with val " << C[I] << std::endl;43      Fail = 1;44    }45  }46 47  // CHECK: Succeeded48  if (Fail) {49    std::cout << "Failed" << std::endl;50  } else {51    std::cout << "Succeeded" << std::endl;52  }53 54  return 0;55}56