Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to avoid reallocating ZCOMBUF[RS] at each call #90

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions src/trans/internal/trgtol_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -292,23 +292,44 @@ SUBROUTINE TRGTOL_COMM_HEAP(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
REAL(KIND=JPRB),OPTIONAL,INTENT(IN) :: PGP3B(:,:,:,:)
REAL(KIND=JPRB),OPTIONAL,INTENT(IN) :: PGP2(:,:,:)

REAL(KIND=JPRB), ALLOCATABLE :: ZCOMBUFS(:,:)
REAL(KIND=JPRB), ALLOCATABLE :: ZCOMBUFR(:,:)
REAL(KIND=JPRB), ALLOCATABLE, SAVE :: ZCOMBUFS_HEAP(:,:)
REAL(KIND=JPRB), ALLOCATABLE, SAVE :: ZCOMBUFR_HEAP(:,:)
INTEGER(KIND=JPIM), SAVE :: INRECV_PREV = -1
INTEGER(KIND=JPIM), SAVE :: INSEND_PREV = -1
INTEGER(KIND=JPIM), SAVE :: IRECVCOUNT_PREV = -1
INTEGER(KIND=JPIM), SAVE :: ISENDCOUNT_PREV = -1

IF ( .NOT. ALLOCATED(ZCOMBUFS_HEAP) ) THEN
ALLOCATE(ZCOMBUFS_HEAP(-1:KSENDCOUNT,KNSEND))
ISENDCOUNT_PREV = KSENDCOUNT
INSEND_PREV = KNSEND
ELSEIF ( KSENDCOUNT .NE. ISENDCOUNT_PREV .OR. KNSEND .NE. INSEND_PREV ) THEN
DEALLOCATE(ZCOMBUFS_HEAP)
ALLOCATE(ZCOMBUFS_HEAP(-1:KSENDCOUNT,KNSEND))
ISENDCOUNT_PREV = KSENDCOUNT
INSEND_PREV = KNSEND
ENDIF

ALLOCATE(ZCOMBUFS(-1:KSENDCOUNT,KNSEND))
! Now, force the OS to allocate this shared array right now, not when it starts to be used which is
! an OPEN-MP loop, that would cause a threads synchronization lock :
IF (KNSEND > 0 .AND. KSENDCOUNT >=-1) ZCOMBUFS(-1,1)=HUGE(1._JPRB)
ALLOCATE(ZCOMBUFR(-1:KRECVCOUNT,KNRECV))
IF (KNSEND > 0 .AND. KSENDCOUNT >= -1) ZCOMBUFS_HEAP(-1,1) = HUGE(1._JPRB)

IF ( .NOT. ALLOCATED(ZCOMBUFR_HEAP) ) THEN
ALLOCATE(ZCOMBUFR_HEAP(-1:KRECVCOUNT,KNRECV))
IRECVCOUNT_PREV = KRECVCOUNT
INRECV_PREV = KNRECV
ELSEIF ( KRECVCOUNT .NE. IRECVCOUNT_PREV .OR. KNRECV .NE. INRECV_PREV ) THEN
DEALLOCATE(ZCOMBUFR_HEAP)
ALLOCATE(ZCOMBUFR_HEAP(-1:KRECVCOUNT,KNRECV))
IRECVCOUNT_PREV = KRECVCOUNT
INRECV_PREV = KNRECV
ENDIF

CALL TRGTOL_COMM(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
& KSENDCOUNT,KRECVCOUNT,KNSEND,KNRECV,KSENDTOT,KRECVTOT,KSEND,KRECV,KINDEX,KNDOFF,KGPTRSEND,&
& ZCOMBUFS,ZCOMBUFR, &
& ZCOMBUFS_HEAP,ZCOMBUFR_HEAP, &
& KPTRGP,PGP,PGPUV,PGP3A,PGP3B,PGP2)

DEALLOCATE(ZCOMBUFR)
DEALLOCATE(ZCOMBUFS)

END SUBROUTINE TRGTOL_COMM_HEAP

SUBROUTINE TRGTOL_COMM_STACK(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
Expand Down Expand Up @@ -343,12 +364,12 @@ SUBROUTINE TRGTOL_COMM_STACK(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
REAL(KIND=JPRB),OPTIONAL,INTENT(IN) :: PGP3B(:,:,:,:)
REAL(KIND=JPRB),OPTIONAL,INTENT(IN) :: PGP2(:,:,:)

REAL(KIND=JPRB) :: ZCOMBUFS(-1:KSENDCOUNT,KNSEND)
REAL(KIND=JPRB) :: ZCOMBUFR(-1:KRECVCOUNT,KNRECV)
REAL(KIND=JPRB) :: ZCOMBUFS_STACK(-1:KSENDCOUNT,KNSEND)
REAL(KIND=JPRB) :: ZCOMBUFR_STACK(-1:KRECVCOUNT,KNRECV)

CALL TRGTOL_COMM(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
& KSENDCOUNT,KRECVCOUNT,KNSEND,KNRECV,KSENDTOT,KRECVTOT,KSEND,KRECV,KINDEX,KNDOFF,KGPTRSEND,&
& ZCOMBUFS,ZCOMBUFR, &
& ZCOMBUFS_STACK,ZCOMBUFR_STACK, &
& KPTRGP,PGP,PGPUV,PGP3A,PGP3B,PGP2)

END SUBROUTINE TRGTOL_COMM_STACK
Expand Down Expand Up @@ -796,8 +817,9 @@ SUBROUTINE TRGTOL_COMM(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&

!....Pack+send loop.........................................................

!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(JBLK,IFIRST,ILAST,&
!$OMP& INS,ISEND,ISETA,ISETB,ISETV,IFLD,IPOS,JFLD)
!$OMP PARALLEL PRIVATE(JBLK,IFIRST,ILAST,ISEND_FLD_START,ISEND_FLD_END,INS,ISEND,ISETA,ISETB,&
!$OMP& ISETV,IFLD,IFLDT,IPOS,JFLD,JK,JJ,JI)
!$OMP DO SCHEDULE(STATIC)
DO INS=1,KNSEND
ISEND=KSEND(INS)
CALL PE2SET(ISEND,ISETA,ISETB,ISETW(INS),ISETV)
Expand Down Expand Up @@ -825,16 +847,15 @@ SUBROUTINE TRGTOL_COMM(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
PCOMBUFS(0,INS) = IFLD

ENDDO
!$OMP END PARALLEL DO

!$OMP END DO
DO INS=1,KNSEND
ISEND=KSEND(INS)
IPOS=IPOSPLUS(INS)

ISEND_FLD_START=PCOMBUFS(-1,INS)
ISEND_FLD_END = PCOMBUFS(0,INS)

!$OMP PARALLEL DO SCHEDULE(STATIC) PRIVATE(IFLDT,JBLK,IFIRST,ILAST,JK,JJ,JI)
!$OMP DO SCHEDULE(STATIC)
DO JJ=ISEND_FLD_START,ISEND_FLD_END
IFLDT=IFLDA(JJ,INS)
DO JBLK=1,NGPBLKS
Expand Down Expand Up @@ -877,8 +898,12 @@ SUBROUTINE TRGTOL_COMM(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
ENDIF
ENDDO
ENDDO
!$OMP END PARALLEL DO
!$OMP END DO
ENDDO
!$OMP END PARALLEL

DO INS=1,KNSEND
ISEND=KSEND(INS)
IF (NTRANS_SYNC_LEVEL <= 1) THEN
CALL MPL_SEND(PCOMBUFS(-1:KSENDTOT(ISEND),INS),KDEST=NPRCIDS(ISEND), &
& KMP_TYPE=JP_NON_BLOCKING_STANDARD,KREQUEST=IREQ_SEND(INS), &
Expand Down
45 changes: 33 additions & 12 deletions src/trans/internal/trltog_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -315,24 +315,45 @@ SUBROUTINE TRLTOG_COMM_HEAP(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
INTEGER(KIND=JPIM), INTENT(IN) :: KSETWL(NPROC)
INTEGER(KIND=JPIM), INTENT(IN) :: KSETVL(NPROC)

REAL(KIND=JPRB), ALLOCATABLE :: ZCOMBUFS(:,:)
REAL(KIND=JPRB), ALLOCATABLE :: ZCOMBUFR(:,:)
REAL(KIND=JPRB), ALLOCATABLE, SAVE :: ZCOMBUFS_HEAP(:,:)
REAL(KIND=JPRB), ALLOCATABLE, SAVE :: ZCOMBUFR_HEAP(:,:)
INTEGER(KIND=JPIM), SAVE :: INRECV_PREV = -1
INTEGER(KIND=JPIM), SAVE :: INSEND_PREV = -1
INTEGER(KIND=JPIM), SAVE :: IRECVCOUNT_PREV = -1
INTEGER(KIND=JPIM), SAVE :: ISENDCOUNT_PREV = -1

IF ( .NOT. ALLOCATED(ZCOMBUFS_HEAP) ) THEN
ALLOCATE(ZCOMBUFS_HEAP(-1:KSENDCOUNT,KNSEND))
ISENDCOUNT_PREV = KSENDCOUNT
INSEND_PREV = KNSEND
ELSEIF ( KSENDCOUNT .NE. ISENDCOUNT_PREV .OR. KNSEND .NE. INSEND_PREV ) THEN
DEALLOCATE(ZCOMBUFS_HEAP)
ALLOCATE(ZCOMBUFS_HEAP(-1:KSENDCOUNT,KNSEND))
ISENDCOUNT_PREV = KSENDCOUNT
INSEND_PREV = KNSEND
ENDIF

ALLOCATE(ZCOMBUFS(-1:KSENDCOUNT,KNSEND))
! Now, force the OS to allocate this shared array right now, not when it starts to be used which is
! an OPEN-MP loop, that would cause a threads synchronization lock :
IF (KNSEND > 0 .AND. KSENDCOUNT >=-1) ZCOMBUFS(-1,1)=HUGE(1._JPRB)
ALLOCATE(ZCOMBUFR(-1:KRECVCOUNT,KNRECV))
IF (KNSEND > 0 .AND. KSENDCOUNT >= -1) ZCOMBUFS_HEAP(-1,1) = HUGE(1._JPRB)

IF ( .NOT. ALLOCATED(ZCOMBUFR_HEAP) ) THEN
ALLOCATE(ZCOMBUFR_HEAP(-1:KRECVCOUNT,KNRECV))
IRECVCOUNT_PREV = KRECVCOUNT
INRECV_PREV = KNRECV
ELSEIF ( KRECVCOUNT .NE. IRECVCOUNT_PREV .OR. KNRECV .NE. INRECV_PREV ) THEN
DEALLOCATE(ZCOMBUFR_HEAP)
ALLOCATE(ZCOMBUFR_HEAP(-1:KRECVCOUNT,KNRECV))
IRECVCOUNT_PREV = KRECVCOUNT
INRECV_PREV = KNRECV
ENDIF

CALL TRLTOG_COMM(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
& KSENDCOUNT,KRECVCOUNT,KNSEND,KNRECV,KSENDTOT,KRECVTOT,KSEND,KRECV,KINDEX,KNDOFF,KGPTRSEND,&
& ZCOMBUFS,ZCOMBUFR, &
& ZCOMBUFS_HEAP,ZCOMBUFR_HEAP, &
& KPTRGP,PGP,PGPUV,PGP3A,PGP3B,PGP2, &
& KSETAL, KSETBL,KSETWL,KSETVL)

DEALLOCATE(ZCOMBUFR)
DEALLOCATE(ZCOMBUFS)

END SUBROUTINE TRLTOG_COMM_HEAP

SUBROUTINE TRLTOG_COMM_STACK(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
Expand Down Expand Up @@ -372,12 +393,12 @@ SUBROUTINE TRLTOG_COMM_STACK(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
INTEGER(KIND=JPIM), INTENT(IN) :: KSETWL(NPROC)
INTEGER(KIND=JPIM), INTENT(IN) :: KSETVL(NPROC)

REAL(KIND=JPRB) :: ZCOMBUFS(-1:KSENDCOUNT,KNSEND)
REAL(KIND=JPRB) :: ZCOMBUFR(-1:KRECVCOUNT,KNRECV)
REAL(KIND=JPRB) :: ZCOMBUFS_STACK(-1:KSENDCOUNT,KNSEND)
REAL(KIND=JPRB) :: ZCOMBUFR_STACK(-1:KRECVCOUNT,KNRECV)

CALL TRLTOG_COMM(PGLAT,KF_FS,KF_GP,KF_SCALARS_G,KVSET,&
& KSENDCOUNT,KRECVCOUNT,KNSEND,KNRECV,KSENDTOT,KRECVTOT,KSEND,KRECV,KINDEX,KNDOFF,KGPTRSEND,&
& ZCOMBUFS,ZCOMBUFR, &
& ZCOMBUFS_STACK,ZCOMBUFR_STACK, &
& KPTRGP,PGP,PGPUV,PGP3A,PGP3B,PGP2, &
& KSETAL, KSETBL,KSETWL,KSETVL)

Expand Down
Loading