Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / mapping / lambda_mapping.cpp
blob63b1719fbbc36ff91b61ed3c998d0ff226d971ae
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
7 #include <iostream>
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);
17 #define N (1000)
20 // Demonstration of the RAJA abstraction using lambdas
21 // Requires data mapping onto the target section
23 int main() {
24 double A[N], B[N], C[N];
26 for (int I = 0; I < N; I++) {
27 A[I] = I + 1;
28 B[I] = -I;
29 C[I] = -9;
32 #pragma omp target data map(tofrom : C[0 : N]) map(to : A[0 : N], B[0 : N])
34 forall(0, N, [&](int I) { C[I] += A[I] + B[I]; });
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;
45 // CHECK: Succeeded
46 if (Fail) {
47 std::cout << "Failed" << std::endl;
48 } else {
49 std::cout << "Succeeded" << std::endl;
52 return 0;