[VectorCombine] foldInsExtVectorToShuffle - canonicalize new shuffle(undef,x) ->...
[llvm-project.git] / flang / test / Semantics / OpenMP / symbol08.f90
blob69ccd17391b54fec5120f8018578a0ff67b01939
1 ! RUN: %python %S/../test_symbols.py %s %flang_fc1 -fopenmp
3 ! 2.15.1.1 Predetermined rules for associated do-loops index variable
4 ! a) The loop iteration variable(s) in the associated do-loop(s) of a do,
5 ! parallel do, taskloop, or distribute construct is (are) private.
6 ! b) The loop iteration variable in the associated do-loop of a simd construct
7 ! with just one associated do-loop is linear with a linear-step that is the
8 ! increment of the associated do-loop.
9 ! c) The loop iteration variables in the associated do-loops of a simd
10 ! construct with multiple associated do-loops are lastprivate.
11 ! d) A loop iteration variable for a sequential loop in a parallel or task
12 ! generating construct is private in the innermost such construct that
13 ! encloses the loop.
14 ! - TBD
16 ! All the tests assume that the do-loops association for collapse/ordered
17 ! clause has been performed (the number of nested do-loops >= n).
19 ! Rule a)
20 ! TODO: nested constructs (k should be private too)
21 !DEF: /test_do (Subroutine) Subprogram
22 subroutine test_do
23 implicit none
24 !DEF: /test_do/a ObjectEntity REAL(4)
25 real a(20,20,20)
26 !DEF: /test_do/i ObjectEntity INTEGER(4)
27 !DEF: /test_do/j ObjectEntity INTEGER(4)
28 !DEF: /test_do/k ObjectEntity INTEGER(4)
29 integer i, j, k
30 !$omp parallel
31 !DEF: /test_do/OtherConstruct1/i HostAssoc INTEGER(4)
32 i = 99
33 !$omp do collapse(2)
34 !DEF: /test_do/OtherConstruct1/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
35 do i=1,5
36 !DEF: /test_do/OtherConstruct1/OtherConstruct1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
37 do j=6,10
38 !DEF: /test_do/OtherConstruct1/a HostAssoc REAL(4)
39 a(1,1,1) = 0.
40 !DEF: /test_do/OtherConstruct1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
41 do k=11,15
42 !REF: /test_do/OtherConstruct1/a
43 !REF: /test_do/OtherConstruct1/k
44 !REF: /test_do/OtherConstruct1/OtherConstruct1/j
45 !REF: /test_do/OtherConstruct1/OtherConstruct1/i
46 a(k,j,i) = 1.
47 end do
48 end do
49 end do
50 !$omp end parallel
51 end subroutine test_do
53 ! Rule a)
54 !DEF: /test_pardo (Subroutine) Subprogram
55 subroutine test_pardo
56 implicit none
57 !DEF: /test_pardo/a ObjectEntity REAL(4)
58 real a(20,20,20)
59 !DEF: /test_pardo/i ObjectEntity INTEGER(4)
60 !DEF: /test_pardo/j ObjectEntity INTEGER(4)
61 !DEF: /test_pardo/k ObjectEntity INTEGER(4)
62 integer i, j, k
63 !$omp parallel do collapse(2) private(k) ordered(2)
64 !DEF: /test_pardo/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
65 do i=1,5
66 !DEF: /test_pardo/OtherConstruct1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
67 do j=6,10
68 !DEF: /test_pardo/OtherConstruct1/a HostAssoc REAL(4)
69 a(1,1,1) = 0.
70 !DEF: /test_pardo/OtherConstruct1/k (OmpPrivate) HostAssoc INTEGER(4)
71 do k=11,15
72 !REF: /test_pardo/OtherConstruct1/a
73 !REF: /test_pardo/OtherConstruct1/k
74 !REF: /test_pardo/OtherConstruct1/j
75 !REF: /test_pardo/OtherConstruct1/i
76 a(k,j,i) = 1.
77 end do
78 end do
79 end do
80 end subroutine test_pardo
82 ! Rule a)
83 !DEF: /test_taskloop (Subroutine) Subprogram
84 subroutine test_taskloop
85 implicit none
86 !DEF: /test_taskloop/a ObjectEntity REAL(4)
87 real a(5,5)
88 !DEF: /test_taskloop/i ObjectEntity INTEGER(4)
89 !DEF: /test_taskloop/j ObjectEntity INTEGER(4)
90 integer i, j
91 !$omp taskloop private(j)
92 !DEF: /test_taskloop/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
93 do i=1,5
94 !DEF: /test_taskloop/OtherConstruct1/j (OmpPrivate) HostAssoc INTEGER(4)
95 !REF: /test_taskloop/OtherConstruct1/i
96 do j=1,i
97 !DEF: /test_taskloop/OtherConstruct1/a (OmpFirstPrivate, OmpImplicit) HostAssoc REAL(4)
98 !REF: /test_taskloop/OtherConstruct1/j
99 !REF: /test_taskloop/OtherConstruct1/i
100 a(j,i) = 3.14
101 end do
102 end do
103 !$omp end taskloop
104 end subroutine test_taskloop
106 ! Rule a); OpenMP 4.5 Examples teams.2.f90
107 ! TODO: reduction; data-mapping attributes
108 !DEF: /dotprod (Subroutine) Subprogram
109 !DEF: /dotprod/b (OmpMapTo) ObjectEntity REAL(4)
110 !DEF: /dotprod/c (OmpMapTo) ObjectEntity REAL(4)
111 !DEF: /dotprod/n ObjectEntity INTEGER(4)
112 !DEF: /dotprod/block_size ObjectEntity INTEGER(4)
113 !DEF: /dotprod/num_teams ObjectEntity INTEGER(4)
114 !DEF: /dotprod/block_threads ObjectEntity INTEGER(4)
115 subroutine dotprod (b, c, n, block_size, num_teams, block_threads)
116 implicit none
117 !REF: /dotprod/n
118 integer n
119 !REF: /dotprod/b
120 !REF: /dotprod/n
121 !REF: /dotprod/c
122 !DEF: /dotprod/sum (OmpMapToFrom) ObjectEntity REAL(4)
123 real b(n), c(n), sum
124 !REF: /dotprod/block_size
125 !REF: /dotprod/num_teams
126 !REF: /dotprod/block_threads
127 !DEF: /dotprod/i ObjectEntity INTEGER(4)
128 !DEF: /dotprod/i0 ObjectEntity INTEGER(4)
129 integer block_size, num_teams, block_threads, i, i0
130 !REF: /dotprod/sum
131 sum = 0.0e0
132 !$omp target map(to:b,c) map(tofrom:sum)
133 !$omp teams num_teams(num_teams) thread_limit(block_threads) reduction(+:sum)
134 !$omp distribute
135 !DEF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/i0 (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
136 !REF: /dotprod/n
137 !REF: /dotprod/block_size
138 do i0=1,n,block_size
139 !$omp parallel do reduction(+:sum)
140 !DEF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
141 !DEF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/OtherConstruct1/i0 HostAssoc INTEGER(4)
142 !DEF: /dotprod/min ELEMENTAL, INTRINSIC, PURE (Function) ProcEntity
143 !DEF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/OtherConstruct1/block_size HostAssoc INTEGER(4)
144 !DEF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/OtherConstruct1/n HostAssoc INTEGER(4)
145 do i=i0,min(i0+block_size, n)
146 !DEF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/OtherConstruct1/sum (OmpReduction) HostAssoc REAL(4)
147 !DEF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/OtherConstruct1/b HostAssoc REAL(4)
148 !REF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/OtherConstruct1/i
149 !DEF: /dotprod/OtherConstruct1/OtherConstruct1/OtherConstruct1/OtherConstruct1/c HostAssoc REAL(4)
150 sum = sum+b(i)*c(i)
151 end do
152 end do
153 !$omp end teams
154 !$omp end target
155 !REF: /dotprod/sum
156 print *, sum
157 end subroutine dotprod
159 ! Rule b)
160 ! TODO: nested constructs (j, k should be private too)
161 !DEF: /test_simd (Subroutine) Subprogram
162 subroutine test_simd
163 implicit none
164 !DEF: /test_simd/a ObjectEntity REAL(4)
165 real a(20,20,20)
166 !DEF: /test_simd/i ObjectEntity INTEGER(4)
167 !DEF: /test_simd/j ObjectEntity INTEGER(4)
168 !DEF: /test_simd/k ObjectEntity INTEGER(4)
169 integer i, j, k
170 !$omp parallel do simd
171 !DEF: /test_simd/OtherConstruct1/i (OmpLinear, OmpPreDetermined) HostAssoc INTEGER(4)
172 do i=1,5
173 !DEF: /test_simd/OtherConstruct1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
174 do j=6,10
175 !DEF: /test_simd/OtherConstruct1/k (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
176 do k=11,15
177 !DEF: /test_simd/OtherConstruct1/a HostAssoc REAL(4)
178 !REF: /test_simd/OtherConstruct1/k
179 !REF: /test_simd/OtherConstruct1/j
180 !REF: /test_simd/OtherConstruct1/i
181 a(k,j,i) = 3.14
182 end do
183 end do
184 end do
185 end subroutine test_simd
187 ! Rule c)
188 !DEF: /test_simd_multi (Subroutine) Subprogram
189 subroutine test_simd_multi
190 implicit none
191 !DEF: /test_simd_multi/a ObjectEntity REAL(4)
192 real a(20,20,20)
193 !DEF: /test_simd_multi/i ObjectEntity INTEGER(4)
194 !DEF: /test_simd_multi/j ObjectEntity INTEGER(4)
195 !DEF: /test_simd_multi/k ObjectEntity INTEGER(4)
196 integer i, j, k
197 !$omp parallel do simd collapse(3)
198 !DEF: /test_simd_multi/OtherConstruct1/i (OmpLastPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
199 do i=1,5
200 !DEF: /test_simd_multi/OtherConstruct1/j (OmpLastPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
201 do j=6,10
202 !DEF: /test_simd_multi/OtherConstruct1/k (OmpLastPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
203 do k=11,15
204 !DEF: /test_simd_multi/OtherConstruct1/a HostAssoc REAL(4)
205 !REF: /test_simd_multi/OtherConstruct1/k
206 !REF: /test_simd_multi/OtherConstruct1/j
207 !REF: /test_simd_multi/OtherConstruct1/i
208 a(k,j,i) = 3.14
209 end do
210 end do
211 end do
212 end subroutine test_simd_multi
214 ! Rule d)
215 !DEF: /test_seq_loop (Subroutine) Subprogram
216 subroutine test_seq_loop
217 implicit none
218 !DEF: /test_seq_loop/i ObjectEntity INTEGER(4)
219 !DEF: /test_seq_loop/j ObjectEntity INTEGER(4)
220 integer i, j
221 !REF: /test_seq_loop/i
222 i = -1
223 !REF: /test_seq_loop/j
224 j = -1
225 !$omp parallel
226 !DEF: /test_seq_loop/OtherConstruct1/i HostAssoc INTEGER(4)
227 !DEF: /test_seq_loop/OtherConstruct1/j HostAssoc INTEGER(4)
228 print *, i, j
229 !$omp parallel
230 !DEF: /test_seq_loop/OtherConstruct1/OtherConstruct1/i HostAssoc INTEGER(4)
231 !DEF: /test_seq_loop/OtherConstruct1/OtherConstruct1/j (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
232 print *, i, j
233 !$omp do
234 !DEF: /test_seq_loop/OtherConstruct1/OtherConstruct1/OtherConstruct1/i (OmpPrivate, OmpPreDetermined) HostAssoc INTEGER(4)
235 do i=1,10
236 !REF: /test_seq_loop/OtherConstruct1/OtherConstruct1/j
237 do j=1,10
238 end do
239 end do
240 !REF: /test_seq_loop/OtherConstruct1/OtherConstruct1/i
241 !REF: /test_seq_loop/OtherConstruct1/OtherConstruct1/j
242 print *, i, j
243 !$omp end parallel
244 !REF: /test_seq_loop/OtherConstruct1/i
245 !REF: /test_seq_loop/OtherConstruct1/j
246 print *, i, j
247 !$omp end parallel
248 !REF: /test_seq_loop/i
249 !REF: /test_seq_loop/j
250 print *, i, j
251 end subroutine test_seq_loop