1 #include <omp.h>
2 #include <stdlib.h>
3 
4 int
main()5 main ()
6 {
7   int d = omp_get_default_device ();
8   int id = omp_get_initial_device ();
9 
10   if (d < 0 || d >= omp_get_num_devices ())
11     d = id;
12 
13   int a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
14   int *b = a;
15   int shared_mem = 0;
16   #pragma omp target map (alloc: shared_mem)
17   shared_mem = 1;
18   if (omp_target_is_present (b, d) != shared_mem)
19     abort ();
20   #pragma omp target enter data map (to: a)
21   if (omp_target_is_present (b, d) == 0)
22     abort ();
23   #pragma omp target enter data map (alloc: b[:0])
24   if (omp_target_is_present (b, d) == 0)
25     abort ();
26   #pragma omp target exit data map (release: b[:0])
27   if (omp_target_is_present (b, d) == 0)
28     abort ();
29   #pragma omp target exit data map (release: b[:0])
30   if (omp_target_is_present (b, d) != shared_mem)
31     abort ();
32   #pragma omp target enter data map (to: a)
33   if (omp_target_is_present (b, d) == 0)
34     abort ();
35   #pragma omp target enter data map (always, to: b[:0])
36   if (omp_target_is_present (b, d) == 0)
37     abort ();
38   #pragma omp target exit data map (delete: b[:0])
39   if (omp_target_is_present (b, d) != shared_mem)
40     abort ();
41   #pragma omp target exit data map (from: b[:0])
42   return 0;
43 }
44