source: palm/trunk/SOURCE/exchange_horiz.f90 @ 1318

Last change on this file since 1318 was 1318, checked in by raasch, 8 years ago

former files/routines cpu_log and cpu_statistics combined to one module,
which also includes the former data module cpulog from the modules-file,
module interfaces removed

  • Property svn:keywords set to Id
File size: 10.2 KB
Line 
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! module interfaces removed
23!
24! Former revisions:
25! -----------------
26! $Id: exchange_horiz.f90 1318 2014-03-17 13:35:16Z raasch $
27!
28! 1257 2013-11-08 15:18:40Z raasch
29! openacc loop and loop vector clauses removed
30!
31! 1128 2013-04-12 06:19:32Z raasch
32! modifications for asynchronous transfer,
33! local variables req, wait_stat are global now, and have been moved to module
34! pegrid
35!
36! 1113 2013-03-10 02:48:14Z raasch
37! GPU-porting for single-core (1PE) mode
38!
39! 1036 2012-10-22 13:43:42Z raasch
40! code put under GPL (PALM 3.9)
41!
42! 841 2012-02-28 12:29:49Z maronga
43! Excluded routine from compilation of namelist_file_check
44!
45! 709 2011-03-30 09:31:40Z raasch
46! formatting adjustments
47!
48! 707 2011-03-29 11:39:40Z raasch
49! grid_level directly used as index for MPI data type arrays,
50! bc_lr/ns replaced by bc_lr/ns_cyc
51!
52! 689 2011-02-20 19:31:12z gryschka
53! Bugfix for some logical expressions
54! (syntax was not compatible with all compilers)
55!
56! 683 2011-02-09 14:25:15Z raasch
57! optional synchronous exchange (sendrecv) implemented, code partly reformatted
58!
59! 667 2010-12-23 12:06:00Z suehring/gryschka
60! Dynamic exchange of ghost points with nbgp_local to ensure that no useless
61! ghost points exchanged in case of multigrid. type_yz(0) and type_xz(0)
62! used for normal grid, the remaining types used for the several grid levels.
63! Exchange is done via MPI-Vectors with a dynamic value of ghost points which
64! depend on the advection scheme. Exchange of left and right PEs is 10% faster
65! with MPI-Vectors than without.
66!
67! 75 2007-03-22 09:54:05Z raasch
68! Special cases for additional gridpoints along x or y in case of non-cyclic
69! boundary conditions are not regarded any more
70!
71! RCS Log replace by Id keyword, revision history cleaned up
72!
73! Revision 1.16  2006/02/23 12:19:08  raasch
74! anz_yz renamed ngp_yz
75!
76! Revision 1.1  1997/07/24 11:13:29  raasch
77! Initial revision
78!
79!
80! Description:
81! ------------
82! Exchange of lateral boundary values (parallel computers) and cyclic
83! lateral boundary conditions, respectively.
84!------------------------------------------------------------------------------!
85
86    USE control_parameters
87    USE cpulog
88    USE indices
89    USE pegrid
90
91    IMPLICIT NONE
92
93
94    INTEGER ::  i, j, k, nbgp_local
95    REAL, DIMENSION(nzb:nzt+1,nys-nbgp_local:nyn+nbgp_local, &
96                    nxl-nbgp_local:nxr+nbgp_local) ::  ar
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 == 'lr'  .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
Note: See TracBrowser for help on using the repository browser.