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