xref: /llvm-project/offload/test/offloading/parallel_offloading_map.cpp (revision 8823448807f3b1a1362d1417e062d763734e02f5)
1 // RUN: %libomptarget-compilexx-run-and-check-generic
2 
3 // REQUIRES: gpu
4 
5 #include <cassert>
6 #include <iostream>
7 
main(int argc,char * argv[])8 int main(int argc, char *argv[]) {
9   constexpr const int num_threads = 64, N = 128;
10   int array[num_threads] = {0};
11 
12 #pragma omp parallel for
13   for (int i = 0; i < num_threads; ++i) {
14     int tmp[N];
15 
16     for (int j = 0; j < N; ++j) {
17       tmp[j] = i;
18     }
19 
20 #pragma omp target teams distribute parallel for map(tofrom : tmp)
21     for (int j = 0; j < N; ++j) {
22       tmp[j] += j;
23     }
24 
25     for (int j = 0; j < N; ++j) {
26       array[i] += tmp[j];
27     }
28   }
29 
30   // Verify
31   for (int i = 0; i < num_threads; ++i) {
32     const int ref = (0 + N - 1) * N / 2 + i * N;
33     assert(array[i] == ref);
34   }
35 
36   std::cout << "PASS\n";
37 
38   return 0;
39 }
40 
41 // CHECK: PASS
42