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

Last change on this file since 3655 was 3655, checked in by knoop, 5 years ago

Bugfix: made "unit" and "found" intend INOUT in module interface subroutines + automatic copyright update

  • Property svn:keywords set to Id
File size: 14.1 KB
RevLine 
[1682]1!> @file exchange_horiz.f90
[1320]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]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!
[3655]17! Copyright 1997-2019 Leibniz Universitaet Hannover
[1320]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[1]21! -----------------
[1678]22!
[2119]23!
[1321]24! Former revisions:
25! -----------------
26! $Id: exchange_horiz.f90 3655 2019-01-07 16:51:22Z knoop $
[3634]27! OpenACC port for SPEC
28!
29! 3241 2018-09-12 15:02:00Z raasch
[3241]30! unused variables removed
31!
32! 2718 2018-01-02 08:49:38Z maronga
[2716]33! Corrected "Former revisions" section
34!
35! 2696 2017-12-14 17:12:51Z kanani
36! Change in file header (GPL part)
[2696]37! 3D-Integer exchange on multigrid level (MS)
38!
39! 2298 2017-06-29 09:28:18Z raasch
[2298]40! sendrecv_in_background related parts removed
41!
42! 2119 2017-01-17 16:51:50Z raasch
[1321]43!
[2119]44! 2118 2017-01-17 16:38:49Z raasch
45! OpenACC directives and related code removed
46!
[2001]47! 2000 2016-08-20 18:09:15Z knoop
48! Forced header and separation lines into 80 columns
49!
[1805]50! 1804 2016-04-05 16:30:18Z maronga
51! Removed code for parameter file check (__check)
52!
[1683]53! 1682 2015-10-07 23:56:08Z knoop
54! Code annotations made doxygen readable
55!
[1678]56! 1677 2015-10-02 13:25:23Z boeske
57! Added new routine for exchange of three-dimensional integer arrays
58!
[1570]59! 1569 2015-03-12 07:54:38Z raasch
60! bugfix in background communication part
61!
[1349]62! 1348 2014-03-27 18:01:03Z raasch
[1569]63! bugfix: on_device added to ONLY-list
[1349]64!
[1345]65! 1344 2014-03-26 17:33:09Z kanani
66! Added missing parameters to ONLY-attribute
67!
[1321]68! 1320 2014-03-20 08:40:49Z raasch
[1320]69! ONLY-attribute added to USE-statements,
70! kind-parameters added to all INTEGER and REAL declaration statements,
71! kinds are defined in new module kinds,
72! revision history before 2012 removed,
73! comment fields (!:) to be used for variable explanations added to
74! all variable declaration statements
[668]75!
[1258]76! 1257 2013-11-08 15:18:40Z raasch
77! openacc loop and loop vector clauses removed
78!
[1132]79! 1128 2013-04-12 06:19:32Z raasch
80! modifications for asynchronous transfer,
81! local variables req, wait_stat are global now, and have been moved to module
82! pegrid
83!
[1114]84! 1113 2013-03-10 02:48:14Z raasch
85! GPU-porting for single-core (1PE) mode
86!
[1037]87! 1036 2012-10-22 13:43:42Z raasch
88! code put under GPL (PALM 3.9)
89!
[842]90! 841 2012-02-28 12:29:49Z maronga
91! Excluded routine from compilation of namelist_file_check
92!
[1]93! Revision 1.1  1997/07/24 11:13:29  raasch
94! Initial revision
95!
96!
97! Description:
98! ------------
[1682]99!> Exchange of lateral boundary values (parallel computers) and cyclic
100!> lateral boundary conditions, respectively.
[1]101!------------------------------------------------------------------------------!
[1682]102 SUBROUTINE exchange_horiz( ar, nbgp_local)
103 
[1]104
[1320]105    USE control_parameters,                                                    &
[3241]106        ONLY:  bc_lr_cyc, bc_ns_cyc, grid_level, mg_switch_to_pe0,             &
107               synchronous_exchange
[1320]108               
109    USE cpulog,                                                                &
110        ONLY:  cpu_log, log_point_s
111       
112    USE indices,                                                               &
113        ONLY:  nxl, nxr, nyn, nys, nzb, nzt
114       
115    USE kinds
116   
[1]117    USE pegrid
118
119    IMPLICIT NONE
120
[841]121
[3634]122#ifdef _OPENACC
123    INTEGER(iwp) ::  i           !<
124#endif
[1682]125    INTEGER(iwp) ::  nbgp_local  !<
[1320]126   
127    REAL(wp), DIMENSION(nzb:nzt+1,nys-nbgp_local:nyn+nbgp_local,               &
[1682]128                        nxl-nbgp_local:nxr+nbgp_local) ::  ar  !<
[1320]129                       
[841]130
[1]131    CALL cpu_log( log_point_s(2), 'exchange_horiz', 'start' )
132
[3634]133#ifdef _OPENACC
134    !$ACC UPDATE IF_PRESENT &
135    !$ACC HOST(ar(:,:,nxr-nbgp_local+1:nxr)) &
136    !$ACC HOST(ar(:,:,nxl:nxl+nbgp_local-1))
137    DO i = nxl-nbgp_local, nxr+nbgp_local
138       !$ACC UPDATE IF_PRESENT &
139       !$ACC HOST(ar(:,nyn-nbgp_local+1:nyn,i)) &
140       !$ACC HOST(ar(:,nys:nys+nbgp_local-1,i))
141    ENDDO
142#endif
143
[1]144#if defined( __parallel )
145
146!
[1128]147!-- Exchange in x-direction of lateral boundaries
[1]148    IF ( pdims(1) == 1  .OR.  mg_switch_to_pe0 )  THEN
149!
150!--    One-dimensional decomposition along y, boundary values can be exchanged
151!--    within the PE memory
[707]152       IF ( bc_lr_cyc )  THEN
[667]153          ar(:,:,nxl-nbgp_local:nxl-1) = ar(:,:,nxr-nbgp_local+1:nxr)
154          ar(:,:,nxr+1:nxr+nbgp_local) = ar(:,:,nxl:nxl+nbgp_local-1)
[1]155       ENDIF
156
157    ELSE
[75]158
[683]159       IF ( synchronous_exchange )  THEN
[1]160!
[683]161!--       Send left boundary, receive right one (synchronous)
162          CALL MPI_SENDRECV(                                                   &
[707]163              ar(nzb,nys-nbgp_local,nxl),   1, type_yz(grid_level), pleft,  0, &
164              ar(nzb,nys-nbgp_local,nxr+1), 1, type_yz(grid_level), pright, 0, &
165              comm2d, status, ierr )
[1]166!
[683]167!--       Send right boundary, receive left one (synchronous)
[1320]168          CALL MPI_SENDRECV( ar(nzb,nys-nbgp_local,nxr+1-nbgp_local), 1,       &
169                             type_yz(grid_level), pright, 1,                   &
170                             ar(nzb,nys-nbgp_local,nxl-nbgp_local), 1,         &
171                             type_yz(grid_level), pleft,  1,                   &
[707]172                             comm2d, status, ierr )
[667]173
[683]174       ELSE
[667]175
[683]176!
[2298]177!--       Asynchroneous exchange
[1128]178          IF ( send_receive == 'lr'  .OR.  send_receive == 'al' )  THEN
179
[2298]180             req(1:4)  = 0
181             req_count = 0
[683]182!
[1128]183!--          Send left boundary, receive right one (asynchronous)
184             CALL MPI_ISEND( ar(nzb,nys-nbgp_local,nxl),   1, type_yz(grid_level), &
185                             pleft, req_count, comm2d, req(req_count+1), ierr )
186             CALL MPI_IRECV( ar(nzb,nys-nbgp_local,nxr+1), 1, type_yz(grid_level), &
187                             pright, req_count, comm2d, req(req_count+2), ierr )
188!
189!--          Send right boundary, receive left one (asynchronous)
[1320]190             CALL MPI_ISEND( ar(nzb,nys-nbgp_local,nxr+1-nbgp_local), 1,       &
191                             type_yz(grid_level), pright, req_count+1, comm2d, &
[1128]192                             req(req_count+3), ierr )
[1320]193             CALL MPI_IRECV( ar(nzb,nys-nbgp_local,nxl-nbgp_local),   1,       &
194                             type_yz(grid_level), pleft,  req_count+1, comm2d, &
[1128]195                             req(req_count+4), ierr )
[667]196
[2298]197             CALL MPI_WAITALL( 4, req, wait_stat, ierr )
[75]198
[1128]199          ENDIF
200
[683]201       ENDIF
202
[1]203    ENDIF
204
205
206    IF ( pdims(2) == 1  .OR.  mg_switch_to_pe0 )  THEN
207!
208!--    One-dimensional decomposition along x, boundary values can be exchanged
209!--    within the PE memory
[707]210       IF ( bc_ns_cyc )  THEN
[667]211          ar(:,nys-nbgp_local:nys-1,:) = ar(:,nyn-nbgp_local+1:nyn,:)
212          ar(:,nyn+1:nyn+nbgp_local,:) = ar(:,nys:nys+nbgp_local-1,:)
[1]213       ENDIF
214
215    ELSE
216
[683]217       IF ( synchronous_exchange )  THEN
[1]218!
[683]219!--       Send front boundary, receive rear one (synchronous)
220          CALL MPI_SENDRECV(                                                   &
[707]221              ar(nzb,nys,nxl-nbgp_local),   1, type_xz(grid_level), psouth, 0, &
222              ar(nzb,nyn+1,nxl-nbgp_local), 1, type_xz(grid_level), pnorth, 0, &
223              comm2d, status, ierr )
[683]224!
225!--       Send rear boundary, receive front one (synchronous)
[1320]226          CALL MPI_SENDRECV( ar(nzb,nyn-nbgp_local+1,nxl-nbgp_local), 1,       &
227                             type_xz(grid_level), pnorth, 1,                   &
228                             ar(nzb,nys-nbgp_local,nxl-nbgp_local),   1,       &
229                             type_xz(grid_level), psouth, 1,                   &
[707]230                             comm2d, status, ierr )
[667]231
[683]232       ELSE
233
[1]234!
[2298]235!--       Asynchroneous exchange
[1569]236          IF ( send_receive == 'ns'  .OR.  send_receive == 'al' )  THEN
[1128]237
[2298]238             req(1:4)  = 0
239             req_count = 0
[1128]240
[683]241!
[1128]242!--          Send front boundary, receive rear one (asynchronous)
243             CALL MPI_ISEND( ar(nzb,nys,nxl-nbgp_local),   1, type_xz(grid_level), &
244                             psouth, req_count, comm2d, req(req_count+1), ierr )
245             CALL MPI_IRECV( ar(nzb,nyn+1,nxl-nbgp_local), 1, type_xz(grid_level), &
246                             pnorth, req_count, comm2d, req(req_count+2), ierr )
247!
248!--          Send rear boundary, receive front one (asynchronous)
[1320]249             CALL MPI_ISEND( ar(nzb,nyn-nbgp_local+1,nxl-nbgp_local), 1,       &
250                             type_xz(grid_level), pnorth, req_count+1, comm2d, &
[1128]251                             req(req_count+3), ierr )
[1320]252             CALL MPI_IRECV( ar(nzb,nys-nbgp_local,nxl-nbgp_local),   1,       &
253                             type_xz(grid_level), psouth, req_count+1, comm2d, &
[1128]254                             req(req_count+4), ierr )
[75]255
[2298]256             CALL MPI_WAITALL( 4, req, wait_stat, ierr )
[683]257
[1128]258          ENDIF
259
[683]260       ENDIF
261
[1]262    ENDIF
263
264#else
265
266!
[1113]267!-- Lateral boundary conditions in the non-parallel case.
268!-- Case dependent, because in GPU mode still not all arrays are on device. This
269!-- workaround has to be removed later. Also, since PGI compiler 12.5 has problems
270!-- with array syntax, explicit loops are used.
[3241]271    IF ( bc_lr_cyc )  THEN
[2118]272       ar(:,:,nxl-nbgp_local:nxl-1) = ar(:,:,nxr-nbgp_local+1:nxr)
273       ar(:,:,nxr+1:nxr+nbgp_local) = ar(:,:,nxl:nxl+nbgp_local-1)
[1]274    ENDIF
275
[3241]276    IF ( bc_ns_cyc )  THEN
[2118]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,:)
[1]279    ENDIF
280
281#endif
[3634]282
283#ifdef _OPENACC
284    !$ACC UPDATE IF_PRESENT &
285    !$ACC DEVICE(ar(:,:,nxl-nbgp_local:nxl-1)) &
286    !$ACC DEVICE(ar(:,:,nxr+1:nxr+nbgp_local))
287    DO i = nxl-nbgp_local, nxr+nbgp_local
288       !$ACC UPDATE IF_PRESENT &
289       !$ACC DEVICE(ar(:,nys-nbgp_local:nys-1,i)) &
290       !$ACC DEVICE(ar(:,nyn+1:nyn+nbgp_local,i))
291    ENDDO
292#endif
293
[1]294    CALL cpu_log( log_point_s(2), 'exchange_horiz', 'stop' )
295
296 END SUBROUTINE exchange_horiz
[1677]297
298
[1682]299!------------------------------------------------------------------------------!
300! Description:
301! ------------
302!> @todo Missing subroutine description.
303!------------------------------------------------------------------------------!
[2696]304 SUBROUTINE exchange_horiz_int( ar, nys_l, nyn_l, nxl_l, nxr_l, nzt_l, nbgp_local)
[1677]305
306    USE control_parameters,                                                    &
[3241]307        ONLY:  bc_lr_cyc, bc_ns_cyc, grid_level
[1677]308                       
309    USE indices,                                                               &
[3241]310        ONLY:  nzb
[1677]311       
312    USE kinds
313   
314    USE pegrid
315
316    IMPLICIT NONE
317
[2696]318    INTEGER(iwp) ::  nxl_l       !< local index bound at current grid level, left side
319    INTEGER(iwp) ::  nxr_l       !< local index bound at current grid level, right side
320    INTEGER(iwp) ::  nyn_l       !< local index bound at current grid level, north side
321    INTEGER(iwp) ::  nys_l       !< local index bound at current grid level, south side
322    INTEGER(iwp) ::  nzt_l       !< local index bound at current grid level, top
[1682]323    INTEGER(iwp) ::  nbgp_local  !< number of ghost points
[1677]324   
[2696]325    INTEGER(iwp), DIMENSION(nzb:nzt_l+1,nys_l-nbgp_local:nyn_l+nbgp_local,     &
326                            nxl_l-nbgp_local:nxr_l+nbgp_local) ::  ar  !< treated array
[1677]327
328
329#if defined( __parallel )
330    IF ( pdims(1) == 1 )  THEN
331!
332!--    One-dimensional decomposition along y, boundary values can be exchanged
333!--    within the PE memory
334       IF ( bc_lr_cyc )  THEN
[2696]335          ar(:,:,nxl_l-nbgp_local:nxl_l-1) = ar(:,:,nxr_l-nbgp_local+1:nxr_l)
336          ar(:,:,nxr_l+1:nxr_l+nbgp_local) = ar(:,:,nxl_l:nxl_l+nbgp_local-1)
[1677]337       ENDIF
338    ELSE
339!
340!--    Send left boundary, receive right one (synchronous)
[2696]341       CALL MPI_SENDRECV(                                                          &
342           ar(nzb,nys_l-nbgp_local,nxl_l),   1, type_yz_int(grid_level), pleft,  0,&
343           ar(nzb,nys_l-nbgp_local,nxr_l+1), 1, type_yz_int(grid_level), pright, 0,&
[1677]344           comm2d, status, ierr )
345!
346!--    Send right boundary, receive left one (synchronous)
[2696]347       CALL MPI_SENDRECV(                                                          &
348           ar(nzb,nys_l-nbgp_local,nxr_l+1-nbgp_local), 1, type_yz_int(grid_level),&
349           pright, 1,                                                              &
350           ar(nzb,nys_l-nbgp_local,nxl_l-nbgp_local),   1, type_yz_int(grid_level),&
351           pleft,  1,                                                              &
[1677]352           comm2d, status, ierr )
353    ENDIF
354
355
356    IF ( pdims(2) == 1 )  THEN
357!
358!--    One-dimensional decomposition along x, boundary values can be exchanged
359!--    within the PE memory
360       IF ( bc_ns_cyc )  THEN
[2696]361          ar(:,nys_l-nbgp_local:nys_l-1,:) = ar(:,nyn_l-nbgp_local+1:nyn_l,:)
362          ar(:,nyn_l+1:nyn_l+nbgp_local,:) = ar(:,nys_l:nys_l+nbgp_local-1,:)
[1677]363       ENDIF
364
365    ELSE
366
367!
368!--    Send front boundary, receive rear one (synchronous)
[2696]369       CALL MPI_SENDRECV(                                                          &
370           ar(nzb,nys_l,nxl_l-nbgp_local),   1, type_xz_int(grid_level), psouth, 0,&
371           ar(nzb,nyn_l+1,nxl_l-nbgp_local), 1, type_xz_int(grid_level), pnorth, 0,&
[1677]372           comm2d, status, ierr )
373!
374!--    Send rear boundary, receive front one (synchronous)
[2696]375       CALL MPI_SENDRECV( ar(nzb,nyn_l-nbgp_local+1,nxl_l-nbgp_local), 1,          &
376                          type_xz_int(grid_level), pnorth, 1,                      &
377                          ar(nzb,nys_l-nbgp_local,nxl_l-nbgp_local),   1,          &
378                          type_xz_int(grid_level), psouth, 1,                      &
[1677]379                          comm2d, status, ierr )
380
381    ENDIF
382
383#else
384
[3241]385    IF ( bc_lr_cyc )  THEN
[2696]386       ar(:,:,nxl_l-nbgp_local:nxl_l-1) = ar(:,:,nxr_l-nbgp_local+1:nxr_l)
387       ar(:,:,nxr_l+1:nxr_l+nbgp_local) = ar(:,:,nxl_l:nxl_l+nbgp_local-1)
[1677]388    ENDIF
389
[3241]390    IF ( bc_ns_cyc )  THEN
[2696]391       ar(:,nys_l-nbgp_local:nys_l-1,:) = ar(:,nyn_l-nbgp_local+1:nyn_l,:)
392       ar(:,nyn_l+1:nyn_l+nbgp_local,:) = ar(:,nys_l:nys_l+nbgp_local-1,:)
[1677]393    ENDIF
394
395#endif
396
397
[1933]398 END SUBROUTINE exchange_horiz_int
Note: See TracBrowser for help on using the repository browser.