1 | SUBROUTINE exchange_horiz( ar, nbgp_local) |
---|
2 | |
---|
3 | !------------------------------------------------------------------------------! |
---|
4 | ! This file is part of PALM. |
---|
5 | ! |
---|
6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
8 | ! either version 3 of the License, or (at your option) any later version. |
---|
9 | ! |
---|
10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
13 | ! |
---|
14 | ! You should have received a copy of the GNU General Public License along with |
---|
15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | ! |
---|
17 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: exchange_horiz.f90 1349 2014-03-27 18:03:27Z heinze $ |
---|
27 | ! |
---|
28 | ! 1348 2014-03-27 18:01:03Z raasch |
---|
29 | ! bugfix: on_devide added to ONLY-list |
---|
30 | ! |
---|
31 | ! 1344 2014-03-26 17:33:09Z kanani |
---|
32 | ! Added missing parameters to ONLY-attribute |
---|
33 | ! |
---|
34 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
35 | ! ONLY-attribute added to USE-statements, |
---|
36 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
37 | ! kinds are defined in new module kinds, |
---|
38 | ! revision history before 2012 removed, |
---|
39 | ! comment fields (!:) to be used for variable explanations added to |
---|
40 | ! all variable declaration statements |
---|
41 | ! |
---|
42 | ! 1257 2013-11-08 15:18:40Z raasch |
---|
43 | ! openacc loop and loop vector clauses removed |
---|
44 | ! |
---|
45 | ! 1128 2013-04-12 06:19:32Z raasch |
---|
46 | ! modifications for asynchronous transfer, |
---|
47 | ! local variables req, wait_stat are global now, and have been moved to module |
---|
48 | ! pegrid |
---|
49 | ! |
---|
50 | ! 1113 2013-03-10 02:48:14Z raasch |
---|
51 | ! GPU-porting for single-core (1PE) mode |
---|
52 | ! |
---|
53 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
54 | ! code put under GPL (PALM 3.9) |
---|
55 | ! |
---|
56 | ! 841 2012-02-28 12:29:49Z maronga |
---|
57 | ! Excluded routine from compilation of namelist_file_check |
---|
58 | ! |
---|
59 | ! Revision 1.1 1997/07/24 11:13:29 raasch |
---|
60 | ! Initial revision |
---|
61 | ! |
---|
62 | ! |
---|
63 | ! Description: |
---|
64 | ! ------------ |
---|
65 | ! Exchange of lateral boundary values (parallel computers) and cyclic |
---|
66 | ! lateral boundary conditions, respectively. |
---|
67 | !------------------------------------------------------------------------------! |
---|
68 | |
---|
69 | USE control_parameters, & |
---|
70 | ONLY: bc_lr, bc_lr_cyc, bc_ns, bc_ns_cyc, grid_level, & |
---|
71 | mg_switch_to_pe0, on_device, synchronous_exchange |
---|
72 | |
---|
73 | USE cpulog, & |
---|
74 | ONLY: cpu_log, log_point_s |
---|
75 | |
---|
76 | USE indices, & |
---|
77 | ONLY: nxl, nxr, nyn, nys, nzb, nzt |
---|
78 | |
---|
79 | USE kinds |
---|
80 | |
---|
81 | USE pegrid |
---|
82 | |
---|
83 | IMPLICIT NONE |
---|
84 | |
---|
85 | |
---|
86 | INTEGER(iwp) :: i !: |
---|
87 | INTEGER(iwp) :: j !: |
---|
88 | INTEGER(iwp) :: k !: |
---|
89 | INTEGER(iwp) :: nbgp_local !: |
---|
90 | |
---|
91 | REAL(wp), DIMENSION(nzb:nzt+1,nys-nbgp_local:nyn+nbgp_local, & |
---|
92 | nxl-nbgp_local:nxr+nbgp_local) :: ar !: |
---|
93 | |
---|
94 | |
---|
95 | #if ! defined( __check ) |
---|
96 | |
---|
97 | CALL cpu_log( log_point_s(2), 'exchange_horiz', 'start' ) |
---|
98 | |
---|
99 | #if defined( __parallel ) |
---|
100 | |
---|
101 | ! |
---|
102 | !-- Exchange in x-direction of lateral boundaries |
---|
103 | IF ( pdims(1) == 1 .OR. mg_switch_to_pe0 ) THEN |
---|
104 | ! |
---|
105 | !-- One-dimensional decomposition along y, boundary values can be exchanged |
---|
106 | !-- within the PE memory |
---|
107 | IF ( bc_lr_cyc ) THEN |
---|
108 | ar(:,:,nxl-nbgp_local:nxl-1) = ar(:,:,nxr-nbgp_local+1:nxr) |
---|
109 | ar(:,:,nxr+1:nxr+nbgp_local) = ar(:,:,nxl:nxl+nbgp_local-1) |
---|
110 | ENDIF |
---|
111 | |
---|
112 | ELSE |
---|
113 | |
---|
114 | IF ( synchronous_exchange ) THEN |
---|
115 | ! |
---|
116 | !-- Send left boundary, receive right one (synchronous) |
---|
117 | CALL MPI_SENDRECV( & |
---|
118 | ar(nzb,nys-nbgp_local,nxl), 1, type_yz(grid_level), pleft, 0, & |
---|
119 | ar(nzb,nys-nbgp_local,nxr+1), 1, type_yz(grid_level), pright, 0, & |
---|
120 | comm2d, status, ierr ) |
---|
121 | ! |
---|
122 | !-- Send right boundary, receive left one (synchronous) |
---|
123 | CALL MPI_SENDRECV( ar(nzb,nys-nbgp_local,nxr+1-nbgp_local), 1, & |
---|
124 | type_yz(grid_level), pright, 1, & |
---|
125 | ar(nzb,nys-nbgp_local,nxl-nbgp_local), 1, & |
---|
126 | type_yz(grid_level), pleft, 1, & |
---|
127 | comm2d, status, ierr ) |
---|
128 | |
---|
129 | ELSE |
---|
130 | |
---|
131 | ! |
---|
132 | !-- In case of background communication switched on, exchange is done |
---|
133 | !-- either along x or along y |
---|
134 | IF ( send_receive == 'lr' .OR. send_receive == 'al' ) THEN |
---|
135 | |
---|
136 | IF ( .NOT. sendrecv_in_background ) THEN |
---|
137 | req(1:4) = 0 |
---|
138 | req_count = 0 |
---|
139 | ENDIF |
---|
140 | ! |
---|
141 | !-- Send left boundary, receive right one (asynchronous) |
---|
142 | CALL MPI_ISEND( ar(nzb,nys-nbgp_local,nxl), 1, type_yz(grid_level), & |
---|
143 | pleft, req_count, comm2d, req(req_count+1), ierr ) |
---|
144 | CALL MPI_IRECV( ar(nzb,nys-nbgp_local,nxr+1), 1, type_yz(grid_level), & |
---|
145 | pright, req_count, comm2d, req(req_count+2), ierr ) |
---|
146 | ! |
---|
147 | !-- Send right boundary, receive left one (asynchronous) |
---|
148 | CALL MPI_ISEND( ar(nzb,nys-nbgp_local,nxr+1-nbgp_local), 1, & |
---|
149 | type_yz(grid_level), pright, req_count+1, comm2d, & |
---|
150 | req(req_count+3), ierr ) |
---|
151 | CALL MPI_IRECV( ar(nzb,nys-nbgp_local,nxl-nbgp_local), 1, & |
---|
152 | type_yz(grid_level), pleft, req_count+1, comm2d, & |
---|
153 | req(req_count+4), ierr ) |
---|
154 | |
---|
155 | IF ( .NOT. sendrecv_in_background ) THEN |
---|
156 | CALL MPI_WAITALL( 4, req, wait_stat, ierr ) |
---|
157 | ELSE |
---|
158 | req_count = req_count + 4 |
---|
159 | ENDIF |
---|
160 | |
---|
161 | ENDIF |
---|
162 | |
---|
163 | ENDIF |
---|
164 | |
---|
165 | ENDIF |
---|
166 | |
---|
167 | |
---|
168 | IF ( pdims(2) == 1 .OR. mg_switch_to_pe0 ) THEN |
---|
169 | ! |
---|
170 | !-- One-dimensional decomposition along x, boundary values can be exchanged |
---|
171 | !-- within the PE memory |
---|
172 | IF ( bc_ns_cyc ) THEN |
---|
173 | ar(:,nys-nbgp_local:nys-1,:) = ar(:,nyn-nbgp_local+1:nyn,:) |
---|
174 | ar(:,nyn+1:nyn+nbgp_local,:) = ar(:,nys:nys+nbgp_local-1,:) |
---|
175 | ENDIF |
---|
176 | |
---|
177 | ELSE |
---|
178 | |
---|
179 | IF ( synchronous_exchange ) THEN |
---|
180 | ! |
---|
181 | !-- Send front boundary, receive rear one (synchronous) |
---|
182 | CALL MPI_SENDRECV( & |
---|
183 | ar(nzb,nys,nxl-nbgp_local), 1, type_xz(grid_level), psouth, 0, & |
---|
184 | ar(nzb,nyn+1,nxl-nbgp_local), 1, type_xz(grid_level), pnorth, 0, & |
---|
185 | comm2d, status, ierr ) |
---|
186 | ! |
---|
187 | !-- Send rear boundary, receive front one (synchronous) |
---|
188 | CALL MPI_SENDRECV( ar(nzb,nyn-nbgp_local+1,nxl-nbgp_local), 1, & |
---|
189 | type_xz(grid_level), pnorth, 1, & |
---|
190 | ar(nzb,nys-nbgp_local,nxl-nbgp_local), 1, & |
---|
191 | type_xz(grid_level), psouth, 1, & |
---|
192 | comm2d, status, ierr ) |
---|
193 | |
---|
194 | ELSE |
---|
195 | |
---|
196 | ! |
---|
197 | !-- In case of background communication switched on, exchange is done |
---|
198 | !-- either along x or along y |
---|
199 | IF ( send_receive == 'lr' .OR. send_receive == 'al' ) THEN |
---|
200 | |
---|
201 | IF ( .NOT. sendrecv_in_background ) THEN |
---|
202 | req(1:4) = 0 |
---|
203 | req_count = 0 |
---|
204 | ENDIF |
---|
205 | |
---|
206 | ! |
---|
207 | !-- Send front boundary, receive rear one (asynchronous) |
---|
208 | CALL MPI_ISEND( ar(nzb,nys,nxl-nbgp_local), 1, type_xz(grid_level), & |
---|
209 | psouth, req_count, comm2d, req(req_count+1), ierr ) |
---|
210 | CALL MPI_IRECV( ar(nzb,nyn+1,nxl-nbgp_local), 1, type_xz(grid_level), & |
---|
211 | pnorth, req_count, comm2d, req(req_count+2), ierr ) |
---|
212 | ! |
---|
213 | !-- Send rear boundary, receive front one (asynchronous) |
---|
214 | CALL MPI_ISEND( ar(nzb,nyn-nbgp_local+1,nxl-nbgp_local), 1, & |
---|
215 | type_xz(grid_level), pnorth, req_count+1, comm2d, & |
---|
216 | req(req_count+3), ierr ) |
---|
217 | CALL MPI_IRECV( ar(nzb,nys-nbgp_local,nxl-nbgp_local), 1, & |
---|
218 | type_xz(grid_level), psouth, req_count+1, comm2d, & |
---|
219 | req(req_count+4), ierr ) |
---|
220 | |
---|
221 | IF ( .NOT. sendrecv_in_background ) THEN |
---|
222 | CALL MPI_WAITALL( 4, req, wait_stat, ierr ) |
---|
223 | ELSE |
---|
224 | req_count = req_count + 4 |
---|
225 | ENDIF |
---|
226 | |
---|
227 | ENDIF |
---|
228 | |
---|
229 | ENDIF |
---|
230 | |
---|
231 | ENDIF |
---|
232 | |
---|
233 | #else |
---|
234 | |
---|
235 | ! |
---|
236 | !-- Lateral boundary conditions in the non-parallel case. |
---|
237 | !-- Case dependent, because in GPU mode still not all arrays are on device. This |
---|
238 | !-- workaround has to be removed later. Also, since PGI compiler 12.5 has problems |
---|
239 | !-- with array syntax, explicit loops are used. |
---|
240 | IF ( bc_lr == 'cyclic' ) THEN |
---|
241 | IF ( on_device ) THEN |
---|
242 | !$acc kernels present( ar ) |
---|
243 | !$acc loop independent |
---|
244 | DO i = 0, nbgp_local-1 |
---|
245 | DO j = nys-nbgp_local, nyn+nbgp_local |
---|
246 | DO k = nzb, nzt+1 |
---|
247 | ar(k,j,nxl-nbgp_local+i) = ar(k,j,nxr-nbgp_local+1+i) |
---|
248 | ar(k,j,nxr+1+i) = ar(k,j,nxl+i) |
---|
249 | ENDDO |
---|
250 | ENDDO |
---|
251 | ENDDO |
---|
252 | !$acc end kernels |
---|
253 | ELSE |
---|
254 | ar(:,:,nxl-nbgp_local:nxl-1) = ar(:,:,nxr-nbgp_local+1:nxr) |
---|
255 | ar(:,:,nxr+1:nxr+nbgp_local) = ar(:,:,nxl:nxl+nbgp_local-1) |
---|
256 | ENDIF |
---|
257 | ENDIF |
---|
258 | |
---|
259 | IF ( bc_ns == 'cyclic' ) THEN |
---|
260 | IF ( on_device ) THEN |
---|
261 | !$acc kernels present( ar ) |
---|
262 | DO i = nxl-nbgp_local, nxr+nbgp_local |
---|
263 | !$acc loop independent |
---|
264 | DO j = 0, nbgp_local-1 |
---|
265 | !$acc loop independent |
---|
266 | DO k = nzb, nzt+1 |
---|
267 | ar(k,nys-nbgp_local+j,i) = ar(k,nyn-nbgp_local+1+j,i) |
---|
268 | ar(k,nyn+1+j,i) = ar(k,nys+j,i) |
---|
269 | ENDDO |
---|
270 | ENDDO |
---|
271 | ENDDO |
---|
272 | !$acc end kernels |
---|
273 | ELSE |
---|
274 | ar(:,nys-nbgp_local:nys-1,:) = ar(:,nyn-nbgp_local+1:nyn,:) |
---|
275 | ar(:,nyn+1:nyn+nbgp_local,:) = ar(:,nys:nys+nbgp_local-1,:) |
---|
276 | ENDIF |
---|
277 | ENDIF |
---|
278 | |
---|
279 | #endif |
---|
280 | CALL cpu_log( log_point_s(2), 'exchange_horiz', 'stop' ) |
---|
281 | |
---|
282 | #endif |
---|
283 | END SUBROUTINE exchange_horiz |
---|