| 1 | // RUN: %libomptarget-compile-run-and-check-generic |
| 2 | // RUN: %libomptarget-compileopt-run-and-check-generic |
| 3 | |
| 4 | #include <omp.h> |
| 5 | #include <stdio.h> |
| 6 | |
| 7 | int main() { |
| 8 | const int N = 64; |
| 9 | |
| 10 | // Allocates device managed memory that is shared between the host and device. |
| 11 | int *shared_ptr = |
| 12 | omp_alloc(N * sizeof(int), llvm_omp_target_shared_mem_alloc); |
| 13 | |
| 14 | #pragma omp target teams distribute parallel for is_device_ptr(shared_ptr) |
| 15 | for (int i = 0; i < N; ++i) { |
| 16 | shared_ptr[i] = 1; |
| 17 | } |
| 18 | |
| 19 | int sum = 0; |
| 20 | for (int i = 0; i < N; ++i) |
| 21 | sum += shared_ptr[i]; |
| 22 | |
| 23 | // CHECK: PASS |
| 24 | if (sum == N) |
| 25 | printf(format: "PASS\n" ); |
| 26 | |
| 27 | omp_free(shared_ptr, llvm_omp_target_shared_mem_alloc); |
| 28 | } |
| 29 | |