1 // RUN: %libomptarget-compilexx-run-and-check-generic
2 
3 // UNSUPPORTED: x86_64-pc-linux-gnu
4 
5 #include <omp.h>
6 
7 #include <cassert>
8 #include <iostream>
9 
10 int main(int argc, char *argv[]) {
11 #pragma omp parallel for
12   for (int i = 0; i < 16; ++i) {
13     for (int n = 1; n < (1 << 13); n <<= 1) {
14       void *p = omp_target_alloc(n * sizeof(int), 0);
15       omp_target_free(p, 0);
16     }
17   }
18 
19 #pragma omp parallel for
20   for (int i = 0; i < 16; ++i) {
21     for (int n = 1; n < (1 << 13); n <<= 1) {
22       int *p = (int *)omp_target_alloc(n * sizeof(int), 0);
23 #pragma omp target teams distribute parallel for is_device_ptr(p)
24       for (int j = 0; j < n; ++j) {
25         p[j] = i;
26       }
27       int buffer[n];
28 #pragma omp target teams distribute parallel for is_device_ptr(p)              \
29     map(from                                                                   \
30         : buffer)
31       for (int j = 0; j < n; ++j) {
32         buffer[j] = p[j];
33       }
34       for (int j = 0; j < n; ++j) {
35         assert(buffer[j] == i);
36       }
37       omp_target_free(p, 0);
38     }
39   }
40 
41   std::cout << "PASS\n";
42   return 0;
43 }
44 
45 // CHECK: PASS
46