Skip to content

Commit

Permalink
Merge pull request NCAR#5 from climbfuji/dycore_bugfixes_for_gsd_deve…
Browse files Browse the repository at this point in the history
…lop_20200629

Two FV3 dycore bug fixes for gsd/develop 2020/06/29
  • Loading branch information
DomHeinzeller committed Jun 29, 2020
2 parents 658b139 + 33049d8 commit 3c8a27d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
37 changes: 30 additions & 7 deletions model/fv_regional_bc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3431,6 +3431,7 @@ subroutine remap_scalar_nggps_regional_bc(Atm &
print *, 'clwmr = ', liq_wat
print *, ' o3mr = ', o3mr
print *, 'ncnst = ', ncnst
print *, 'ntracers = ', ntracers
endif

if ( sphum/=1 ) then
Expand Down Expand Up @@ -6482,8 +6483,7 @@ subroutine exch_uv(domain, bd, npz, u, v)
real, intent(inout) :: u (bd%isd:bd%ied ,bd%jsd:bd%jed+1,1:npz)
real, intent(inout) :: v (bd%isd:bd%ied+1,bd%jsd:bd%jed ,1:npz)

integer,parameter :: ibufexch=2500000
real,dimension(ibufexch) :: buf1,buf2,buf3,buf4
real, dimension(:), allocatable :: buf1,buf2,buf3,buf4
integer :: ihandle1,ihandle2,ihandle3,ihandle4
integer,dimension(MPI_STATUS_SIZE) :: istat
integer :: ic, i, j, k, is, ie, js, je
Expand All @@ -6508,18 +6508,33 @@ subroutine exch_uv(domain, bd, npz, u, v)
js=bd%js
je=bd%je

! The size of these buffers must match the number of indices
! required below to send/receive the data. In particular,
! buf1 and buf4 must be of the same size (sim. for buf2 and buf3).
! Changes to the code below should be tested with debug flags
! enabled (out-of-bounds reads/writes).
allocate(buf1(1:24*npz))
allocate(buf2(1:36*npz))
allocate(buf3(1:36*npz))
allocate(buf4(1:24*npz))

! FIXME: MPI_COMM_WORLD

#ifdef OVERLOAD_R4
#define _DYN_MPI_REAL MPI_REAL
#else
#define _DYN_MPI_REAL MPI_DOUBLE_PRECISION
#endif

! Receive from north
if( north_pe /= NULL_PE )then
call MPI_Irecv(buf1,ibufexch,MPI_REAL,north_pe,north_pe &
call MPI_Irecv(buf1,size(buf1),_DYN_MPI_REAL,north_pe,north_pe &
,MPI_COMM_WORLD,ihandle1,irecv)
endif

! Receive from south
if( south_pe /= NULL_PE )then
call MPI_Irecv(buf2,ibufexch,MPI_REAL,south_pe,south_pe &
call MPI_Irecv(buf2,size(buf2),_DYN_MPI_REAL,south_pe,south_pe &
,MPI_COMM_WORLD,ihandle2,irecv)
endif

Expand Down Expand Up @@ -6549,9 +6564,10 @@ subroutine exch_uv(domain, bd, npz, u, v)
buf3(ic)=v(i,j,k)
enddo
enddo

enddo
call MPI_Issend(buf3,ic,MPI_REAL,north_pe,mype &
if (ic/=size(buf2).or.ic/=size(buf3)) &
call mpp_error(FATAL,'Buffer sizes buf2 and buf3 in routine exch_uv do not match actual message size')
call MPI_Issend(buf3,size(buf3),_DYN_MPI_REAL,north_pe,mype &
,MPI_COMM_WORLD,ihandle3,isend)
endif

Expand Down Expand Up @@ -6583,7 +6599,9 @@ subroutine exch_uv(domain, bd, npz, u, v)
enddo

enddo
call MPI_Issend(buf4,ic,MPI_REAL,south_pe,mype &
if (ic/=size(buf1).or.ic/=size(buf4)) &
call mpp_error(FATAL,'Buffer sizes buf1 and buf4 in routine exch_uv do not match actual message size')
call MPI_Issend(buf4,size(buf4),_DYN_MPI_REAL,south_pe,mype &
,MPI_COMM_WORLD,ihandle4,isend)
endif

Expand Down Expand Up @@ -6649,6 +6667,11 @@ subroutine exch_uv(domain, bd, npz, u, v)
enddo
endif

deallocate(buf1)
deallocate(buf2)
deallocate(buf3)
deallocate(buf4)

end subroutine exch_uv

!---------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions tools/fv_diagnostics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ subroutine fv_diag(Atm, zvir, Time, print_freq)
isc, iec, jsc, jec, 0, npz, 1.)
call prt_maxmin('Bottom DZ (m)', Atm(n)%delz(isc:iec,jsc:jec,npz), &
isc, iec, jsc, jec, 0, 1, 1.)
! call prt_maxmin('Top DZ (m)', Atm(n)%delz(isc:iec,jsc:jec,1), &
! call prt_maxmin('Top DZ (m)', Atm(n)%delz(is:ie,js:jec,1), &
! isc, iec, jsc, jec, 0, 1, 1.)
endif

Expand Down Expand Up @@ -5572,7 +5572,7 @@ subroutine max_vorticity(is, ie, js, je, ng, km, zvir, sphum, delz, q, hydrostat
real, intent(in):: grav, zvir, z_bot, z_top
real, intent(in), dimension(is-ng:ie+ng,js-ng:je+ng,km):: pt
real, intent(in), dimension(is:ie,js:je,km):: vort
real, intent(in):: delz(is-ng:ie+ng,js-ng:je+ng,km)
real, intent(in):: delz(is:ie,js:je,km)
real, intent(in):: q(is-ng:ie+ng,js-ng:je+ng,km,*)
real, intent(in):: phis(is-ng:ie+ng,js-ng:je+ng)
real, intent(in):: peln(is:ie,km+1,js:je)
Expand Down Expand Up @@ -5630,7 +5630,7 @@ subroutine max_uh(is, ie, js, je, ng, km, zvir, sphum, uphmax,uphmin, &
real, intent(in):: grav, zvir, z_bot, z_top
real, intent(in), dimension(is-ng:ie+ng,js-ng:je+ng,km):: pt, w
real, intent(in), dimension(is:ie,js:je,km):: vort
real, intent(in):: delz(is-ng:ie+ng,js-ng:je+ng,km)
real, intent(in):: delz(is:ie,js:je,km)
real, intent(in):: q(is-ng:ie+ng,js-ng:je+ng,km,*)
real, intent(in):: phis(is-ng:ie+ng,js-ng:je+ng)
real, intent(in):: peln(is:ie,km+1,js:je)
Expand Down

0 comments on commit 3c8a27d

Please sign in to comment.