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