New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 11286 for branches/UKMO/AMM15_v3_6_STABLE_package_collate_xeps/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90 – NEMO

Ignore:
Timestamp:
2019-07-18T11:54:22+02:00 (5 years ago)
Author:
dford
Message:

Merge in latest version of AMM15_v3_6_STABLE_package_collate.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/UKMO/AMM15_v3_6_STABLE_package_collate_xeps/NEMOGCM/NEMO/OPA_SRC/SBC/cpl_oasis3.F90

    r8058 r11286  
    2424   !!   cpl_finalize : finalize the coupled mode communication 
    2525   !!---------------------------------------------------------------------- 
    26 #if defined key_oasis3 
     26#if defined key_oasis3 || defined key_oasis3mct 
    2727   USE mod_oasis                    ! OASIS3-MCT module 
    2828#endif 
     
    3232   USE lbclnk                       ! ocean lateral boundary conditions (or mpp link) 
    3333 
     34#if defined key_cpl_rootexchg    
     35   USE lib_mpp, only : mppsync    
     36   USE lib_mpp, only : mppscatter,mppgather    
     37#endif     
     38 
    3439   IMPLICIT NONE 
    3540   PRIVATE 
     
    4146   PUBLIC   cpl_freq 
    4247   PUBLIC   cpl_finalize 
     48#if defined key_mpp_mpi    
     49   INCLUDE 'mpif.h'    
     50#endif    
     51       
     52   INTEGER, PARAMETER         :: localRoot  = 0    
     53   LOGICAL                    :: commRank            ! true for ranks doing OASIS communication    
     54#if defined key_cpl_rootexchg    
     55   LOGICAL                    :: rootexchg =.true.   ! logical switch     
     56#else    
     57   LOGICAL                    :: rootexchg =.false.  ! logical switch     
     58#endif     
    4359 
    4460   INTEGER, PUBLIC            ::   OASIS_Rcv  = 1    !: return code if received field 
     
    4662   INTEGER                    ::   ncomp_id          ! id returned by oasis_init_comp 
    4763   INTEGER                    ::   nerror            ! return error code 
    48 #if ! defined key_oasis3 
     64#if ! defined key_oasis3 && ! defined key_oasis3mct 
    4965   ! OASIS Variables not used. defined only for compilation purpose 
    5066   INTEGER                    ::   OASIS_Out         = -1 
     
    6581   INTEGER                    ::   nsnd         ! total number of fields sent  
    6682   INTEGER                    ::   ncplmodel    ! Maximum number of models to/from which NEMO is potentialy sending/receiving data 
    67    INTEGER, PUBLIC, PARAMETER ::   nmaxfld=50   ! Maximum number of coupling fields 
     83   INTEGER, PUBLIC, PARAMETER ::   nmaxfld=55   ! Maximum number of coupling fields 
    6884   INTEGER, PUBLIC, PARAMETER ::   nmaxcat=5    ! Maximum number of coupling fields 
    6985   INTEGER, PUBLIC, PARAMETER ::   nmaxcpl=5    ! Maximum number of coupling fields 
     
    8298 
    8399   REAL(wp), DIMENSION(:,:), ALLOCATABLE ::   exfld   ! Temporary buffer for receiving 
     100   REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::   tbuf  ! Temporary buffer for sending / receiving     
     101   INTEGER, PUBLIC :: localComm     
    84102 
    85103   !!---------------------------------------------------------------------- 
     
    120138      IF ( nerror /= OASIS_Ok ) & 
    121139         CALL oasis_abort (ncomp_id, 'cpl_init','Failure in oasis_get_localcomm' ) 
     140      localComm = kl_comm 
    122141      ! 
    123142   END SUBROUTINE cpl_init 
     
    149168      IF(lwp) WRITE(numout,*) 
    150169 
     170      commRank = .false.    
     171      IF ( rootexchg ) THEN    
     172         IF ( nproc == localRoot ) commRank = .true.    
     173      ELSE    
     174         commRank = .true.    
     175      ENDIF    
     176 
    151177      ncplmodel = kcplmodel 
    152178      IF( kcplmodel > nmaxcpl ) THEN 
     
    172198      ishape(:,2) = (/ 1, nlej-nldj+1 /) 
    173199      ! 
    174       ! ... Allocate memory for data exchange 
    175       ! 
    176       ALLOCATE(exfld(nlei-nldi+1, nlej-nldj+1), stat = nerror) 
    177       IF( nerror > 0 ) THEN 
    178          CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in allocating exfld')   ;   RETURN 
    179       ENDIF 
    180200      ! 
    181201      ! ----------------------------------------------------------------- 
     
    183203      ! ----------------------------------------------------------------- 
    184204       
     205      IF ( rootexchg ) THEN    
     206        
     207         paral(1) = 2              ! box partitioning    
     208         paral(2) = 0              ! NEMO lower left corner global offset         
     209         paral(3) = jpiglo         ! local extent in i     
     210         paral(4) = jpjglo         ! local extent in j    
     211         paral(5) = jpiglo         ! global extent in x    
     212        
     213      ELSE     
    185214      paral(1) = 2                                              ! box partitioning 
    186215      paral(2) = jpiglo * (nldj-1+njmpp-1) + (nldi-1+nimpp-1)   ! NEMO lower left corner global offset     
     
    196225      ENDIF 
    197226       
    198       CALL oasis_def_partition ( id_part, paral, nerror ) 
     227      ENDIF  
     228      IF ( commRank )  CALL oasis_def_partition ( id_part, paral, nerror )    
     229        
     230      ! ... Allocate memory for data exchange    
     231      !    
     232      ALLOCATE(exfld(paral(3), paral(4)), stat = nerror)    
     233      IF( nerror > 0 ) THEN    
     234         CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in allocating exfld')   ;   RETURN    
     235      ENDIF    
     236      IF ( rootexchg ) THEN    
     237         ! Should possibly use one of the work arrays for tbuf really    
     238         ALLOCATE(tbuf(jpi, jpj, jpnij), stat = nerror)    
     239         IF( nerror > 0 ) THEN    
     240            CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in allocating tbuf') ; RETURN    
     241         ENDIF    
     242      ENDIF                 
     243      !    
     244      IF (commRank ) THEN  
    199245      ! 
    200246      ! ... Announce send variables.  
     
    288334         ENDIF 
    289335      END DO 
     336      !   
     337      ENDIF  ! commRank=true   
    290338       
    291339      !------------------------------------------------------------------ 
     
    293341      !------------------------------------------------------------------ 
    294342       
    295       CALL oasis_enddef(nerror) 
    296       IF( nerror /= OASIS_Ok )   CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in oasis_enddef') 
     343      IF ( commRank ) THEN         
     344         CALL oasis_enddef(nerror)    
     345         IF( nerror /= OASIS_Ok )   CALL oasis_abort ( ncomp_id, 'cpl_define', 'Failure in oasis_enddef')    
     346      ENDIF    
    297347      ! 
    298348   END SUBROUTINE cpl_define 
     
    311361      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   pdata 
    312362      !! 
    313       INTEGER                                   ::   jc,jm     ! local loop index 
     363      INTEGER                                   ::   jn,jc,jm  ! local loop index 
    314364      !!-------------------------------------------------------------------- 
    315365      ! 
     
    320370         
    321371            IF( ssnd(kid)%nid(jc,jm) /= -1 ) THEN 
    322                CALL oasis_put ( ssnd(kid)%nid(jc,jm), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo ) 
     372               IF ( rootexchg ) THEN    
     373                  !    
     374                  ! collect data on the local root process    
     375                  !    
     376                  CALL mppgather (pdata(:,:,jc),localRoot,tbuf)     
     377                  CALL mppsync     
     378                          
     379                  IF ( nproc == localRoot ) THEN    
     380                     DO jn = 1, jpnij    
     381                        exfld(nimppt(jn)-1+nldit(jn):nimppt(jn)+nleit(jn)-1,njmppt(jn)-1+nldjt(jn):njmppt(jn)+nlejt(jn)-1)= &    
     382                          tbuf(nldit(jn):nleit(jn),nldjt(jn):nlejt(jn),jn)    
     383                     ENDDO    
     384                     ! snd data to OASIS3    
     385                     CALL oasis_put ( ssnd(kid)%nid(jc,jm), kstep, exfld, kinfo )    
     386                  ENDIF    
     387               ELSE    
     388                  ! snd data to OASIS3    
     389                  CALL oasis_put ( ssnd(kid)%nid(jc,jm), kstep, pdata(nldi:nlei, nldj:nlej,jc), kinfo )    
     390               ENDIF    
    323391                
    324392               IF ( ln_ctl ) THEN         
     
    358426      INTEGER                   , INTENT(  out) ::   kinfo     ! OASIS3 info argument 
    359427      !! 
    360       INTEGER                                   ::   jc,jm     ! local loop index 
     428      INTEGER                                   ::   jn,jc,jm  ! local loop index 
    361429      LOGICAL                                   ::   llaction, llfisrt 
    362430      !!-------------------------------------------------------------------- 
     
    372440 
    373441            IF( srcv(kid)%nid(jc,jm) /= -1 ) THEN 
    374  
    375                CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, exfld, kinfo )          
     442               !    
     443               ! receive data from OASIS3    
     444               !    
     445               IF ( commRank )   CALL oasis_get ( srcv(kid)%nid(jc,jm), kstep, exfld, kinfo )    
     446               IF ( rootexchg )  CALL MPI_BCAST ( kinfo, 1, MPI_INTEGER, localRoot, localComm, nerror )  
    376447                
    377448               llaction =  kinfo == OASIS_Recvd   .OR. kinfo == OASIS_FromRest .OR.   & 
     
    384455                  kinfo = OASIS_Rcv 
    385456                  IF( llfisrt ) THEN  
    386                      pdata(nldi:nlei,nldj:nlej,jc) =                                 exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm) 
     457                     IF ( rootexchg ) THEN    
     458                        ! distribute data to processes    
     459                        !    
     460                        IF ( nproc == localRoot ) THEN    
     461                           DO jn = 1, jpnij    
     462                              tbuf(nldit(jn):nleit(jn),nldjt(jn):nlejt(jn),jn)=          &    
     463                              exfld(nimppt(jn)-1+nldit(jn):nimppt(jn)+nleit(jn)-1,njmppt(jn)-1+nldjt(jn):njmppt(jn)+nlejt(jn)-1)    
     464                              ! NOTE: we are missing combining this with pmask (see else below)    
     465                           ENDDO    
     466                        ENDIF    
     467                        CALL mppscatter(tbuf,localRoot,pdata(:,:,jc))     
     468                        CALL mppsync    
     469                     ELSE    
     470                        pdata(nldi:nlei, nldj:nlej, jc) = exfld(:,:) * pmask(nldi:nlei,nldj:nlej,jm)    
     471                     ENDIF    
    387472                     llfisrt = .FALSE. 
    388473                  ELSE 
     
    462547#if defined key_oa3mct_v3 
    463548         CALL oasis_get_freqs(id, mop, 1, itmp, info) 
    464 #else 
     549#endif 
     550#if defined key_oasis3 
    465551         CALL oasis_get_freqs(id,      1, itmp, info) 
    466552#endif 
    467553         cpl_freq = itmp(1) 
     554#if defined key_oasis3mct   
     555         cpl_freq = namflddti( id )   
     556#endif  
    468557      ENDIF 
    469558      ! 
     
    481570      ! 
    482571      DEALLOCATE( exfld ) 
     572      IF ( rootexchg ) DEALLOCATE ( tbuf ) 
    483573      IF (nstop == 0) THEN 
    484574         CALL oasis_terminate( nerror )          
     
    489579   END SUBROUTINE cpl_finalize 
    490580 
    491 #if ! defined key_oasis3 
     581#if ! defined key_oasis3 && ! defined key_oasis3mct 
    492582 
    493583   !!---------------------------------------------------------------------- 
Note: See TracChangeset for help on using the changeset viewer.