1 // RUN: %libomptarget-compilexx-run-and-check-generic 2 3 #include <iostream> 4 5 template <typename LOOP_BODY> 6 inline void forall(int Begin, int End, LOOP_BODY LoopBody) { 7 #pragma omp target parallel for schedule(static) 8 for (int I = Begin; I < End; ++I) { 9 LoopBody(I); 10 } 11 } 12 13 #define N (1000) 14 15 // 16 // Demonstration of the RAJA abstraction using lambdas 17 // Requires data mapping onto the target section 18 // 19 int main() { 20 double A[N], B[N], C[N]; 21 22 for (int I = 0; I < N; I++) { 23 A[I] = I + 1; 24 B[I] = -I; 25 C[I] = -9; 26 } 27 28 #pragma omp target data map(tofrom : C [0:N]) map(to : A [0:N], B [0:N]) 29 { 30 forall(0, N, [&](int I) { C[I] += A[I] + B[I]; }); 31 } 32 33 int Fail = 0; 34 for (int I = 0; I < N; I++) { 35 if (C[I] != -8) { 36 std::cout << "Failed at " << I << " with val " << C[I] << std::endl; 37 Fail = 1; 38 } 39 } 40 41 // CHECK: Succeeded 42 if (Fail) { 43 std::cout << "Failed" << std::endl; 44 } else { 45 std::cout << "Succeeded" << std::endl; 46 } 47 48 return 0; 49 } 50