1! RUN: %S/test_errors.sh %s %t %flang -fopenmp
2! REQUIRES: shell
3! OpenMP Version 4.5
4! 2.7.1 Loop Construct restrictions on single directive.
5
6
7program omp_do
8
9  integer n
10  integer i,j,k
11  !$omp do
12  do i=1,10
13    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
14    !$omp single
15    do j=1,10
16      print *,"hello"
17    end do
18    !$omp end single
19  end do
20  !$omp end do
21
22  !$omp parallel do
23  do i=1,10
24    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
25    !$omp single
26    do j=1,10
27      print *,"hello"
28    end do
29    !$omp end single
30  end do
31  !$omp end parallel do
32
33  !$omp parallel do simd
34  do i=1,10
35    !ERROR: The only OpenMP constructs that can be encountered during execution of a 'SIMD' region are the `ATOMIC` construct, the `LOOP` construct, the `SIMD` construct and the `ORDERED` construct with the `SIMD` clause.
36    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
37    !$omp single
38    do j=1,10
39      print *,"hello"
40    end do
41    !$omp end single
42  end do
43  !$omp end parallel do simd
44
45  !ERROR: `DISTRIBUTE` region has to be strictly nested inside `TEAMS` region.
46  !$omp distribute parallel do
47  do i=1,10
48    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
49    !$omp single
50    do j=1,10
51      print *,"hello"
52    end do
53    !$omp end single
54  end do
55  !$omp end distribute parallel do
56
57  !ERROR: `DISTRIBUTE` region has to be strictly nested inside `TEAMS` region.
58  !$omp distribute parallel do simd
59  do i=1,10
60    !ERROR: The only OpenMP constructs that can be encountered during execution of a 'SIMD' region are the `ATOMIC` construct, the `LOOP` construct, the `SIMD` construct and the `ORDERED` construct with the `SIMD` clause.
61    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
62    !$omp single
63    do j=1,10
64      print *,"hello"
65    end do
66    !$omp end single
67  end do
68  !$omp end distribute parallel do simd
69
70  !$omp target parallel do
71  do i=1,10
72    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
73    !$omp single
74    do j=1,10
75      print *,"hello"
76    end do
77    !$omp end single
78  end do
79  !$omp end target parallel do
80
81  !$omp target parallel do simd
82  do i=1,10
83    !ERROR: The only OpenMP constructs that can be encountered during execution of a 'SIMD' region are the `ATOMIC` construct, the `LOOP` construct, the `SIMD` construct and the `ORDERED` construct with the `SIMD` clause.
84    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
85    !$omp single
86    do j=1,10
87      print *,"hello"
88    end do
89    !$omp end single
90  end do
91  !$omp end target parallel do simd
92
93  !$omp target teams distribute parallel do
94  do i=1,10
95    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
96    !$omp single
97    do j=1,10
98      print *,"hello"
99    end do
100    !$omp end single
101  end do
102  !$omp end target teams distribute parallel do
103
104  !$omp target teams distribute parallel do simd
105  do i=1,10
106    !ERROR: The only OpenMP constructs that can be encountered during execution of a 'SIMD' region are the `ATOMIC` construct, the `LOOP` construct, the `SIMD` construct and the `ORDERED` construct with the `SIMD` clause.
107    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
108    !$omp single
109    do j=1,10
110      print *,"hello"
111    end do
112    !$omp end single
113  end do
114  !$omp end target teams distribute parallel do simd
115
116  !$omp do
117  do i=1,10
118    !$omp task
119    do j=1,10
120      !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
121      !$omp single
122      do k=1,10
123        print *,"hello"
124      end do
125      !$omp end single
126    end do
127    !$omp end task
128  end do
129  !$omp end do
130
131  !$omp do
132  do i=1,10
133    !$omp parallel
134    do j=1,10
135      !$omp single
136      do k=1,10
137        print *,"hello"
138      end do
139      !$omp end single
140    end do
141    !$omp end parallel
142  end do
143  !$omp end do
144
145!$omp do
146do i=1,10
147  !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
148  !$omp single
149  do j=1,10
150    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
151    !$omp single
152    do k=1,10
153      print *,"hello"
154    end do
155    !$omp end single
156  end do
157  !$omp end single
158
159  !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
160  !$omp single
161    do k=1,10
162      print *,"hello"
163    end do
164  !$omp end single
165
166  !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
167  !$omp do
168    do k=1,10
169      print *,"hello"
170    end do
171  !$omp end do
172end do
173!$omp end do
174
175  !$omp parallel default(shared)
176  !$omp do
177  do i = 1, n
178    !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
179    !$omp single
180    call work(i, 1)
181    !$omp end single
182  end do
183  !$omp end do
184  !$omp end parallel
185
186  !$omp parallel default(shared)
187  !$omp do
188  do i = 1, n
189    !$omp task
190    do j=1,10
191      !ERROR: A worksharing region may not be closely nested inside a worksharing, explicit task, taskloop, critical, ordered, atomic, or master region
192      !$omp single
193      call work(i, 1)
194      !$omp end single
195    end do
196    !$omp end task
197  end do
198  !$omp end do
199  !$omp end parallel
200
201end program omp_do
202