1 #include <omp.h>
2 #include <stdlib.h>
3
4 int
5 main ()
6 {
7 int d = omp_get_default_device ();
8 int id = omp_get_initial_device ();
9 int a[0];
10 int b[] = { 24, 42 };
11 void *p1 = NULL, *p2 = NULL;
12
13 if (d < 0 || d >= omp_get_num_devices ())
14 d = id;
15
16 void *p = omp_target_alloc (sizeof (int), d);
17 if (p == NULL)
18 return 0;
19
20 if (omp_target_associate_ptr (a, p, sizeof (int), 0, d) != 0)
21 return 0;
22
23 if (omp_get_mapped_ptr (a, d) != (d == id ? a : p))
24 abort ();
25
26 if (omp_target_disassociate_ptr (a, d) != 0)
27 abort ();
28
29 if (omp_get_mapped_ptr (a, d) != (d == id ? a : NULL))
30 abort ();
31
32 #pragma omp target data map(alloc: a, b[1:0]) device(d)
33 {
34 #pragma omp target map(from: p1, p2) map(alloc: a, b[1:0]) device(d)
35 {
36 p1 = &a;
37 p2 = &b[1];
38 }
39
40 /* This is probably expected to be p1/p2 instead of NULL. Zero-length arrays
41 as list items of the map clause are currently not inserted into the mem
42 map ?! However by returning NULL, omp_get_mapped_ptr is consistent with
43 omp_target_is_present. */
44 if (omp_get_mapped_ptr (a, d) != NULL
45 || omp_get_mapped_ptr (&b[1], d) != NULL)
46 abort ();
47 }
48
49 omp_target_free (p, d);
50 return 0;
51 }