1#include <omp.h>
2#include <stdlib.h>
3
4volatile int v;
5
6void
7foo (int f)
8{
9  int d = f ? omp_get_num_devices () : omp_get_default_device ();
10  int h = 5;
11  #pragma omp target device (d)
12  if (omp_get_level () != 0)
13    abort ();
14  #pragma omp target if (v > 1)
15  if (omp_get_level () != 0 || !omp_is_initial_device ())
16    abort ();
17  #pragma omp target device (d) if (v > 1)
18  if (omp_get_level () != 0 || !omp_is_initial_device ())
19    abort ();
20  #pragma omp target if (v <= 1)
21  if (omp_get_level () != 0)
22    abort ();
23  #pragma omp target device (d) if (v <= 1)
24  if (omp_get_level () != 0 || (f && !omp_is_initial_device ()))
25    abort ();
26  #pragma omp target if (0)
27  if (omp_get_level () != 0 || !omp_is_initial_device ())
28    abort ();
29  #pragma omp target device (d) if (0)
30  if (omp_get_level () != 0 || !omp_is_initial_device ())
31    abort ();
32  #pragma omp target if (1)
33  if (omp_get_level () != 0)
34    abort ();
35  #pragma omp target device (d) if (1)
36  if (omp_get_level () != 0 || (f && !omp_is_initial_device ()))
37    abort ();
38  #pragma omp target data device (d) map (to: h)
39  {
40    #pragma omp target device (d)
41    if (omp_get_level () != 0 || (f && !omp_is_initial_device ()) || h++ != 5)
42      abort ();
43    #pragma omp target update device (d) from (h)
44  }
45  #pragma omp target data if (v > 1) map (to: h)
46  {
47    #pragma omp target if (v > 1)
48    if (omp_get_level () != 0 || !omp_is_initial_device () || h++ != 6)
49      abort ();
50    #pragma omp target update if (v > 1) from (h)
51  }
52  #pragma omp target data device (d) if (v > 1) map (to: h)
53  {
54    #pragma omp target device (d) if (v > 1)
55    if (omp_get_level () != 0 || !omp_is_initial_device () || h++ != 7)
56      abort ();
57    #pragma omp target update device (d) if (v > 1) from (h)
58  }
59  #pragma omp target data if (v <= 1) map (to: h)
60  {
61    #pragma omp target if (v <= 1)
62    if (omp_get_level () != 0 || h++ != 8)
63      abort ();
64    #pragma omp target update if (v <= 1) from (h)
65  }
66  #pragma omp target data device (d) if (v <= 1) map (to: h)
67  {
68    #pragma omp target device (d) if (v <= 1)
69    if (omp_get_level () != 0 || (f && !omp_is_initial_device ()) || h++ != 9)
70      abort ();
71    #pragma omp target update device (d) if (v <= 1) from (h)
72  }
73  #pragma omp target data if (0) map (to: h)
74  {
75    #pragma omp target if (0)
76    if (omp_get_level () != 0 || !omp_is_initial_device () || h++ != 10)
77      abort ();
78    #pragma omp target update if (0) from (h)
79  }
80  #pragma omp target data device (d) if (0) map (to: h)
81  {
82    #pragma omp target device (d) if (0)
83    if (omp_get_level () != 0 || !omp_is_initial_device () || h++ != 11)
84      abort ();
85    #pragma omp target update device (d) if (0) from (h)
86  }
87  #pragma omp target data if (1) map (to: h)
88  {
89    #pragma omp target if (1)
90    if (omp_get_level () != 0 || h++ != 12)
91      abort ();
92    #pragma omp target update if (1) from (h)
93  }
94  #pragma omp target data device (d) if (1) map (to: h)
95  {
96    #pragma omp target device (d) if (1)
97    if (omp_get_level () != 0 || (f && !omp_is_initial_device ()) || h++ != 13)
98      abort ();
99    #pragma omp target update device (d) if (1) from (h)
100  }
101  if (h != 14)
102    abort ();
103}
104
105int
106main ()
107{
108  foo (0);
109  foo (1);
110  return 0;
111}
112