xref: /llvm-project/flang/test/Semantics/OpenMP/ordered03.f90 (revision b08b252a023eeead07b3e77ce799c3a7d783a0b3)
1! RUN: %python %S/../test_errors.py %s %flang -fopenmp
2! OpenMP Version 5.1
3! Check OpenMP construct validity for the following directives:
4! 2.19.9 Ordered Construct
5
6subroutine sub1()
7  integer :: i, j, N = 10
8  real :: arrayA(10), arrayB(10)
9  real, external :: foo, bar
10
11  !$omp do ordered(1)
12  do i = 1, N
13    !$omp ordered depend(source)
14    arrayA(i) = foo(i)
15    !$omp ordered depend(sink: i - 1)
16    arrayB(i) = bar(i - 1)
17  end do
18  !$omp end do
19
20  !$omp do ordered(1)
21  do i = 1, N
22    !$omp target
23    do j = 1, N
24      !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
25      !$omp ordered depend(source)
26      arrayA(i) = foo(i)
27      !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
28      !$omp ordered depend(sink: i - 1)
29      arrayB(i) = bar(i - 1)
30    end do
31    !$omp end target
32  end do
33  !$omp end do
34
35  !$omp target
36  !$omp parallel do ordered(1)
37  do i = 1, N
38    !$omp ordered depend(source)
39    arrayA(i) = foo(i)
40    !$omp ordered depend(sink: i - 1)
41    arrayB(i) = bar(i - 1)
42  end do
43  !$omp end parallel do
44  !$omp end target
45
46  !$omp target parallel do ordered(1)
47  do i = 1, N
48    !$omp ordered depend(source)
49    arrayA(i) = foo(i)
50    !$omp ordered depend(sink: i - 1)
51    arrayB(i) = bar(i - 1)
52  end do
53  !$omp end target parallel do
54
55  !ERROR: ORDERED clause is not allowed on the TARGET TEAMS DISTRIBUTE PARALLEL DO directive
56  !$omp target teams distribute parallel do ordered(1)
57  do i = 1, N
58    !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
59    !$omp ordered depend(source)
60    arrayA(i) = foo(i)
61    !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
62    !$omp ordered depend(sink: i - 1)
63    arrayB(i) = bar(i - 1)
64  end do
65  !$omp end target teams distribute parallel do
66
67  !$omp do ordered
68  do i = 1, N
69    !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
70    !$omp ordered depend(source)
71    arrayA(i) = foo(i)
72    !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
73    !$omp ordered depend(sink: i - 1)
74    arrayB(i) = bar(i - 1)
75  end do
76  !$omp end do
77
78  !$omp parallel do ordered
79  do i = 1, N
80    !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
81    !$omp ordered depend(source)
82    arrayA(i) = foo(i)
83    !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
84    !$omp ordered depend(sink: i - 1)
85    arrayB(i) = bar(i - 1)
86  end do
87  !$omp end parallel do
88
89  !$omp target parallel do ordered
90  do i = 1, N
91    !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
92    !$omp ordered depend(source)
93    arrayA(i) = foo(i)
94    !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
95    !$omp ordered depend(sink: i - 1)
96    arrayB(i) = bar(i - 1)
97  end do
98  !$omp end target parallel do
99
100  !$omp do ordered(1)
101  do i = 1, N
102    !ERROR: The number of variables in the SINK iteration vector does not match the parameter specified in ORDERED clause
103    !ERROR: The iteration vector element 'j' is not an induction variable within the ORDERED loop nest
104    !$omp ordered depend(sink: i - 1) depend(sink: i - 1, j)
105    arrayB(i) = bar(i - 1, j)
106  end do
107  !$omp end do
108
109  !$omp do ordered(2)
110  do i = 1, N
111    do j = 1, N
112      !ERROR: The number of variables in the SINK iteration vector does not match the parameter specified in ORDERED clause
113      !$omp ordered depend(sink: i - 1) depend(sink: i - 1, j)
114      arrayB(i) = foo(i - 1) + bar(i - 1, j)
115    end do
116  end do
117  !$omp end do
118
119  !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
120  !$omp ordered depend(source)
121
122  !ERROR: An ORDERED construct with the DEPEND clause must be closely nested in a worksharing-loop (or parallel worksharing-loop) construct with ORDERED clause with a parameter
123  !ERROR: The iteration vector element 'i' is not an induction variable within the ORDERED loop nest
124  !$omp ordered depend(sink: i - 1)
125end
126