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