1 // RUN: %libomptarget-compilexx-run-and-check-generic
2 
3 // Error on the gpu that crashes the host
4 // UNSUPPORTED: amdgcn-amd-amdhsa
5 // UNSUPPORTED: amdgcn-amd-amdhsa-newDriver
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(0, N, [&](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