1 // RUN: %libomptarget-compile-run-and-check-aarch64-unknown-linux-gnu
2 // RUN: %libomptarget-compile-run-and-check-powerpc64-ibm-linux-gnu
3 // RUN: %libomptarget-compile-run-and-check-powerpc64le-ibm-linux-gnu
4 // RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu
5 // RUN: %libomptarget-compile-run-and-check-nvptx64-nvidia-cuda
6 
7 #include <stdio.h>
8 #include <omp.h>
9 
10 #pragma omp declare target
11 int isHost;
12 #pragma omp end declare target
13 
main(void)14 int main(void) {
15   isHost = -1;
16 
17 #pragma omp target enter data map(to: isHost)
18 
19 #pragma omp target
20   { isHost = omp_is_initial_device(); }
21 #pragma omp target update from(isHost)
22 
23   if (isHost < 0) {
24     printf("Runtime error, isHost=%d\n", isHost);
25   }
26 
27 #pragma omp target exit data map(delete: isHost)
28 
29   // CHECK: Target region executed on the device
30   printf("Target region executed on the %s\n", isHost ? "host" : "device");
31 
32   return isHost;
33 }
34