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 9436 for branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 – NEMO

Ignore:
Timestamp:
2018-03-27T15:30:51+02:00 (6 years ago)
Author:
acc
Message:

Branch 2017/dev_merge_2017. Reorganisation of nemogcm.F90 and mppini.F90 to better separate domain decomposition functions from the rest of the initialisation. Stage 1: Main reorganisation; see ticket #2070

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90

    r9367 r9436  
    1616   !!   nemo_closefile: close remaining open files 
    1717   !!   nemo_alloc    : dynamical allocation 
    18    !!   nemo_partition: calculate MPP domain decomposition 
    19    !!   factorise     : calculate the factors of the no. of MPI processes 
    20    !!   nemo_nfdcom   : Setup for north fold exchanges with explicit point-to-point messaging 
    2118   !!---------------------------------------------------------------------- 
    2219   USE step_oce       ! module used in the ocean time stepping module 
     
    175172      INTEGER  ::   ji                 ! dummy loop indices 
    176173      INTEGER  ::   ios, ilocal_comm   ! local integers 
    177       INTEGER  ::   iiarea, ijarea     !   -       - 
    178       INTEGER  ::   iirest, ijrest     !   -       - 
    179174      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam 
    180175      CHARACTER(len=80)                 ::   clname 
     
    273268      ENDIF 
    274269 
    275       ! If dimensions of processor grid weren't specified in the namelist file 
    276       ! then we calculate them here now that we have our communicator size 
    277       IF( jpni < 1 .OR. jpnj < 1 ) THEN 
    278 #if   defined key_mpp_mpi 
    279          IF( Agrif_Root() )   CALL nemo_partition( mppsize ) 
    280 #else 
    281          jpni  = 1 
    282          jpnj  = 1 
    283          jpnij = jpni*jpnj 
    284 #endif 
    285       ENDIF 
    286       ! 
    287 #if defined key_agrif 
    288       IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90) 
    289          jpiglo  = nbcellsx + 2 + 2*nbghostcells 
    290          jpjglo  = nbcellsy + 2 + 2*nbghostcells 
    291          jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls 
    292          jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls 
    293          jpimax  = jpi 
    294          jpjmax  = jpj 
    295          nperio  = 0 
    296          jperio  = 0 
    297          ln_use_jattr = .false. 
    298       ENDIF 
    299 #endif 
    300  
    301       IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj 
    302          iiarea = 1 + MOD( narea - 1 , jpni ) 
    303          ijarea = 1 + ( narea - 1 ) / jpni 
    304          iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni ) 
    305          ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj ) 
    306 #if defined key_nemocice_decomp 
    307          jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim. 
    308          jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.  
    309          jpimax  = jpi 
    310          jpjmax  = jpj 
    311          IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls) 
    312          IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls) 
    313 #else 
    314          jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim. 
    315          jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
    316          jpimax  = jpi 
    317          jpjmax  = jpj 
    318          IF( iiarea > iirest ) jpi = jpi - 1 
    319          IF( ijarea > ijrest ) jpj = jpj - 1 
    320 #endif 
    321       ENDIF 
    322  
    323       jpk = jpkglo                                             ! third dim 
    324  
    325 #if defined key_agrif 
    326       ! simple trick to use same vertical grid as parent but different number of levels:  
    327       ! Save maximum number of levels in jpkglo, then define all vertical grids with this number. 
    328       ! Suppress once vertical online interpolation is ok 
    329       IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo ) 
    330 #endif 
    331       jpim1 = jpi-1                                            ! inner domain indices 
    332       jpjm1 = jpj-1                                            !   "           " 
    333       jpkm1 = MAX( 1, jpk-1 )                                  !   "           " 
    334       jpij  = jpi*jpj                                          !  jpi x j 
    335  
    336270      IF(lwp) THEN                            ! open listing units 
    337271         ! 
     
    360294         ! 
    361295      ENDIF 
     296      !                                      ! Domain decomposition 
     297      CALL mpp_init                          ! MPP 
    362298 
    363299      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays 
     
    369305 
    370306      CALL nemo_ctl                          ! Control prints 
    371  
    372       !                                      ! Domain decomposition 
    373       CALL mpp_init                             ! MPP 
    374       IF( ln_nnogather )   CALL nemo_nfdcom     ! northfold neighbour lists 
    375       ! 
    376307      ! 
    377308      !                                      ! General initialization 
     
    552483   END SUBROUTINE nemo_alloc 
    553484 
    554  
    555    SUBROUTINE nemo_partition( num_pes ) 
    556       !!---------------------------------------------------------------------- 
    557       !!                 ***  ROUTINE nemo_partition  *** 
    558       !! 
    559       !! ** Purpose : 
    560       !! 
    561       !! ** Method  : 
    562       !!---------------------------------------------------------------------- 
    563       INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have 
    564       ! 
    565       INTEGER, PARAMETER :: nfactmax = 20 
    566       INTEGER :: nfact ! The no. of factors returned 
    567       INTEGER :: ierr  ! Error flag 
    568       INTEGER :: ji 
    569       INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value 
    570       INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors 
    571       !!---------------------------------------------------------------------- 
    572       ! 
    573       ierr = 0 
    574       ! 
    575       CALL factorise( ifact, nfactmax, nfact, num_pes, ierr ) 
    576       ! 
    577       IF( nfact <= 1 ) THEN 
    578          WRITE (numout, *) 'WARNING: factorisation of number of PEs failed' 
    579          WRITE (numout, *) '       : using grid of ',num_pes,' x 1' 
    580          jpnj = 1 
    581          jpni = num_pes 
    582       ELSE 
    583          ! Search through factors for the pair that are closest in value 
    584          mindiff = 1000000 
    585          imin    = 1 
    586          DO ji = 1, nfact-1, 2 
    587             idiff = ABS( ifact(ji) - ifact(ji+1) ) 
    588             IF( idiff < mindiff ) THEN 
    589                mindiff = idiff 
    590                imin = ji 
    591             ENDIF 
    592          END DO 
    593          jpnj = ifact(imin) 
    594          jpni = ifact(imin + 1) 
    595       ENDIF 
    596       ! 
    597       jpnij = jpni*jpnj 
    598       ! 
    599    END SUBROUTINE nemo_partition 
    600  
    601  
    602    SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr ) 
    603       !!---------------------------------------------------------------------- 
    604       !!                     ***  ROUTINE factorise  *** 
    605       !! 
    606       !! ** Purpose :   return the prime factors of n. 
    607       !!                knfax factors are returned in array kfax which is of 
    608       !!                maximum dimension kmaxfax. 
    609       !! ** Method  : 
    610       !!---------------------------------------------------------------------- 
    611       INTEGER                    , INTENT(in   ) ::   kn, kmaxfax 
    612       INTEGER                    , INTENT(  out) ::   kerr, knfax 
    613       INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax 
    614       ! 
    615       INTEGER :: ifac, jl, inu 
    616       INTEGER, PARAMETER :: ntest = 14 
    617       INTEGER, DIMENSION(ntest) ::   ilfax 
    618       !!---------------------------------------------------------------------- 
    619       ! 
    620       ! lfax contains the set of allowed factors. 
    621       ilfax(:) = (/(2**jl,jl=ntest,1,-1)/) 
    622       ! 
    623       ! Clear the error flag and initialise output vars 
    624       kerr  = 0 
    625       kfax  = 1 
    626       knfax = 0 
    627       ! 
    628       IF( kn /= 1 ) THEN      ! Find the factors of n 
    629          ! 
    630          ! nu holds the unfactorised part of the number. 
    631          ! knfax holds the number of factors found. 
    632          ! l points to the allowed factor list. 
    633          ! ifac holds the current factor. 
    634          ! 
    635          inu   = kn 
    636          knfax = 0 
    637          ! 
    638          DO jl = ntest, 1, -1 
    639             ! 
    640             ifac = ilfax(jl) 
    641             IF( ifac > inu )   CYCLE 
    642             ! 
    643             ! Test whether the factor will divide. 
    644             ! 
    645             IF( MOD(inu,ifac) == 0 ) THEN 
    646                ! 
    647                knfax = knfax + 1            ! Add the factor to the list 
    648                IF( knfax > kmaxfax ) THEN 
    649                   kerr = 6 
    650                   write (*,*) 'FACTOR: insufficient space in factor array ', knfax 
    651                   return 
    652                ENDIF 
    653                kfax(knfax) = ifac 
    654                ! Store the other factor that goes with this one 
    655                knfax = knfax + 1 
    656                kfax(knfax) = inu / ifac 
    657                !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax) 
    658             ENDIF 
    659             ! 
    660          END DO 
    661          ! 
    662       ENDIF 
    663       ! 
    664    END SUBROUTINE factorise 
    665  
    666 #if defined key_mpp_mpi 
    667  
    668    SUBROUTINE nemo_nfdcom 
    669       !!---------------------------------------------------------------------- 
    670       !!                     ***  ROUTINE  nemo_nfdcom  *** 
    671       !! ** Purpose :   Setup for north fold exchanges with explicit  
    672       !!                point-to-point messaging 
    673       !! 
    674       !! ** Method :   Initialization of the northern neighbours lists. 
    675       !!---------------------------------------------------------------------- 
    676       !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE) 
    677       !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)  
    678       !!---------------------------------------------------------------------- 
    679       INTEGER  ::   sxM, dxM, sxT, dxT, jn 
    680       INTEGER  ::   njmppmax 
    681       !!---------------------------------------------------------------------- 
    682       ! 
    683       njmppmax = MAXVAL( njmppt ) 
    684       ! 
    685       !initializes the north-fold communication variables 
    686       isendto(:) = 0 
    687       nsndto     = 0 
    688       ! 
    689       IF ( njmpp == njmppmax ) THEN      ! if I am a process in the north 
    690          ! 
    691          !sxM is the first point (in the global domain) needed to compute the north-fold for the current process 
    692          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1 
    693          !dxM is the last point (in the global domain) needed to compute the north-fold for the current process 
    694          dxM = jpiglo - nimppt(narea) + 2 
    695          ! 
    696          ! loop over the other north-fold processes to find the processes 
    697          ! managing the points belonging to the sxT-dxT range 
    698          ! 
    699          DO jn = 1, jpni 
    700             ! 
    701             sxT = nfiimpp(jn, jpnj)                            ! sxT = 1st  point (in the global domain) of the jn process 
    702             dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1    ! dxT = last point (in the global domain) of the jn process 
    703             ! 
    704             IF    ( sxT < sxM  .AND.  sxM < dxT ) THEN 
    705                nsndto          = nsndto + 1 
    706                isendto(nsndto) = jn 
    707             ELSEIF( sxM <= sxT  .AND.  dxM >= dxT ) THEN 
    708                nsndto          = nsndto + 1 
    709                isendto(nsndto) = jn 
    710             ELSEIF( dxM <  dxT  .AND.  sxT <  dxM ) THEN 
    711                nsndto          = nsndto + 1 
    712                isendto(nsndto) = jn 
    713             ENDIF 
    714             ! 
    715          END DO 
    716          nfsloop = 1 
    717          nfeloop = nlci 
    718          DO jn = 2,jpni-1 
    719             IF( nfipproc(jn,jpnj) == (narea - 1) ) THEN 
    720                IF( nfipproc(jn-1,jpnj) == -1 )   nfsloop = nldi 
    721                IF( nfipproc(jn+1,jpnj) == -1 )   nfeloop = nlei 
    722             ENDIF 
    723          END DO 
    724          ! 
    725       ENDIF 
    726       l_north_nogather = .TRUE. 
    727       ! 
    728    END SUBROUTINE nemo_nfdcom 
    729  
    730 #else 
    731    SUBROUTINE nemo_nfdcom      ! Dummy routine 
    732       WRITE(*,*) 'nemo_nfdcom: You should not have seen this print! error?' 
    733    END SUBROUTINE nemo_nfdcom 
    734 #endif 
    735  
    736485   !!====================================================================== 
    737486END MODULE nemogcm 
Note: See TracChangeset for help on using the changeset viewer.