xref: /llvm-project/offload/test/api/omp_device_memory.c (revision adc4e45f2ecce13cf4ed9b4ab119492342b86faf)
1 // RUN: %libomptarget-compile-run-and-check-generic
2 
3 #include <omp.h>
4 #include <stdio.h>
5 
main()6 int main() {
7   const int N = 64;
8 
9   int *device_ptr =
10       omp_alloc(N * sizeof(int), llvm_omp_target_device_mem_alloc);
11 
12 #pragma omp target teams distribute parallel for is_device_ptr(device_ptr)
13   for (int i = 0; i < N; ++i) {
14     device_ptr[i] = 1;
15   }
16 
17   int sum = 0;
18 #pragma omp target parallel for reduction(+ : sum) is_device_ptr(device_ptr)
19   for (int i = 0; i < N; ++i)
20     sum += device_ptr[i];
21 
22   // CHECK: PASS
23   if (sum == N)
24     printf("PASS\n");
25 
26   omp_free(device_ptr, llvm_omp_target_device_mem_alloc);
27 }
28