1 // RUN: %libomptarget-compile-run-and-check-generic 2 3 // REQUIRES: libc 4 5 #include <stdio.h> 6 #include <stdlib.h> 7 8 #pragma omp declare target to(malloc) 9 #pragma omp declare target to(free) 10 main()11int main() { 12 unsigned h_x; 13 unsigned *d_x; 14 #pragma omp target map(from : d_x) 15 { 16 d_x = (unsigned *)malloc(sizeof(unsigned)); 17 *d_x = 1; 18 } 19 20 #pragma omp target is_device_ptr(d_x) map(from : h_x) 21 { h_x = *d_x; } 22 23 #pragma omp target is_device_ptr(d_x) 24 { free(d_x); } 25 26 #pragma omp target teams num_teams(64) 27 #pragma omp parallel num_threads(32) 28 { 29 int *ptr = (int *)malloc(sizeof(int)); 30 *ptr = 42; 31 free(ptr); 32 } 33 34 // CHECK: PASS 35 if (h_x == 1) 36 fputs("PASS\n", stdout); 37 } 38