xref: /llvm-project/offload/test/api/omp_host_pinned_memory_alloc.c (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
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 *hst_ptr = omp_alloc(N * sizeof(int), llvm_omp_target_host_mem_alloc);
10 
11   for (int i = 0; i < N; ++i)
12     hst_ptr[i] = 2;
13 
14 #pragma omp target teams distribute parallel for map(tofrom : hst_ptr[0 : N])
15   for (int i = 0; i < N; ++i)
16     hst_ptr[i] -= 1;
17 
18   int sum = 0;
19   for (int i = 0; i < N; ++i)
20     sum += hst_ptr[i];
21 
22   omp_free(hst_ptr, llvm_omp_target_host_mem_alloc);
23   // CHECK: PASS
24   if (sum == N)
25     printf("PASS\n");
26 }
27