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/SAO_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/SAO_SRC/nemogcm.F90

    r9367 r9436  
    1414   !!   nemo_closefile: close remaining open files 
    1515   !!   nemo_alloc    : dynamical allocation 
    16    !!   nemo_partition: calculate MPP domain decomposition 
    17    !!   factorise     : calculate the factors of the no. of MPI processes 
    1816   !!---------------------------------------------------------------------- 
    1917   USE step_oce       ! module used in the ocean time stepping module (step.F90) 
     
    9391      INTEGER ::   ji                 ! dummy loop indices 
    9492      INTEGER ::   ios, ilocal_comm   ! local integer 
    95       INTEGER  ::   iiarea, ijarea     ! local integers 
    96       INTEGER  ::   iirest, ijrest     ! local integers 
    9793      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam 
    9894      ! 
     
    10096         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   & 
    10197         &             ln_timing, ln_diacfl 
    102       NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr 
     98      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_closea, ln_write_cfg, cn_domcfg_out, ln_use_jattr 
    10399      !!---------------------------------------------------------------------- 
    104100      ! 
     
    136132      ENDIF 
    137133      ! 
    138       jpk = jpkglo 
    139       ! 
    140 #if defined key_agrif 
    141       IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90) 
    142          jpiglo  = nbcellsx + 2 + 2*nbghostcells 
    143          jpjglo  = nbcellsy + 2 + 2*nbghostcells 
    144          jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci 
    145          jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj 
    146          nperio  = 0 
    147          jperio  = 0 
    148          ln_use_jattr = .false. 
    149       ENDIF 
    150 #endif 
    151134      ! 
    152135      !                             !--------------------------------------------! 
     
    174157         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm ) 
    175158      ELSE 
    176          ilocal_comm = 0 
    177          ! Nodes selection (control print return in cltxt) 
     159         ilocal_comm = 0                                    ! Nodes selection (control print return in cltxt) 
    178160         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop ) 
    179161      ENDIF 
     
    198180      ENDIF 
    199181 
    200       ! If dimensions of processor grid weren't specified in the namelist file 
    201       ! then we calculate them here now that we have our communicator size 
    202       IF( jpni < 1 .OR. jpnj < 1 ) THEN 
    203 #if   defined key_mpp_mpi 
    204          IF( Agrif_Root() )   CALL nemo_partition( mppsize ) 
    205 #else 
    206          jpni  = 1 
    207          jpnj  = 1 
    208          jpnij = jpni*jpnj 
    209 #endif 
    210       ENDIF 
    211       ! 
    212 #if defined key_agrif 
    213       IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90) 
    214          jpiglo  = nbcellsx + 2 + 2*nbghostcells 
    215          jpjglo  = nbcellsy + 2 + 2*nbghostcells 
    216          jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls 
    217          jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls 
    218          jpimax  = jpi 
    219          jpjmax  = jpj 
    220          nperio  = 0 
    221          jperio  = 0 
    222          ln_use_jattr = .false. 
    223       ENDIF 
    224 #endif 
    225  
    226       IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj 
    227          iiarea = 1 + MOD( narea - 1 , jpni ) 
    228          ijarea = 1 + ( narea - 1 ) / jpni 
    229          iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni ) 
    230          ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj ) 
    231 #if defined key_nemocice_decomp 
    232          jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim. 
    233          jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.  
    234          jpimax  = jpi 
    235          jpjmax  = jpj 
    236          IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls) 
    237          IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls) 
    238 #else 
    239          jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim. 
    240          jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
    241          jpimax  = jpi 
    242          jpjmax  = jpj 
    243          IF( iiarea > iirest ) jpi = jpi - 1 
    244          IF( ijarea > ijrest ) jpj = jpj - 1 
    245 #endif 
    246       ENDIF 
    247  
    248       jpk = jpkglo                                             ! third dim 
    249  
    250 #if defined key_agrif 
    251       ! simple trick to use same vertical grid as parent but different number of levels:  
    252       ! Save maximum number of levels in jpkglo, then define all vertical grids with this number. 
    253       ! Suppress once vertical online interpolation is ok 
    254       IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo ) 
    255 #endif 
    256       jpim1 = jpi-1                                            ! inner domain indices 
    257       jpjm1 = jpj-1                                            !   "           " 
    258       jpkm1 = MAX( 1, jpk-1 )                                  !   "           " 
    259       jpij  = jpi*jpj                                          !  jpi x j 
    260  
    261182      IF(lwp) THEN                            ! open listing units 
    262183         ! 
     
    267188         WRITE(numout,*) '                       NEMO team' 
    268189         WRITE(numout,*) '            Stand Alone Observation operator' 
    269          WRITE(numout,*) '                NEMO version 3.7  (2015) ' 
     190         WRITE(numout,*) '                NEMO version 4.0  (2017) ' 
    270191         WRITE(numout,*) 
    271192         WRITE(numout,*) 
     
    282203         ! 
    283204      ENDIF 
     205      !                                      ! Domain decomposition 
     206      CALL mpp_init                          ! MPP 
    284207 
    285208      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays 
     
    290213      !                             !-------------------------------! 
    291214 
    292       CALL nemo_ctl                             ! Control prints & Benchmark 
    293  
    294       !                                      ! Domain decomposition 
    295       CALL mpp_init 
    296       ! 
    297       IF( ln_timing    )   CALL timing_init     ! timing by routine 
     215      CALL nemo_ctl                          ! Control prints 
    298216      ! 
    299217      !                                         ! General initialization 
     218      IF( ln_timing    )   CALL timing_init     ! timing 
     219      IF( ln_timing    )   CALL timing_start( 'nemo_init') 
     220      ! 
    300221                           CALL phy_cst            ! Physical constants 
    301222                           CALL eos_init           ! Equation of state 
    302223                           CALL dom_init('SAO')    ! Domain 
    303224 
    304       IF( ln_nnogather )   CALL nemo_northcomms ! Initialise the northfold neighbour lists (must be done after the masks are defined) 
    305225 
    306226      IF( ln_ctl       )   CALL prt_ctl_init    ! Print control 
     
    322242         WRITE(numout,*) 
    323243         WRITE(numout,*) 'nemo_ctl: Control prints' 
    324          WRITE(numout,*) '~~~~~~~ ' 
     244         WRITE(numout,*) '~~~~~~~~' 
    325245         WRITE(numout,*) '   Namelist namctl' 
    326246         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl 
     
    351271         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg 
    352272         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg) 
     273         WRITE(numout,*) '         keep closed seas in the domain (if exist)     ln_closea     = ', ln_closea 
    353274         WRITE(numout,*) '      write configuration definition file           ln_write_cfg     = ', ln_write_cfg 
    354275         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out) 
    355276         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr 
    356277      ENDIF 
     278      IF( .NOT.ln_read_cfg )   ln_closea = .false.   ! dealing possible only with a domcfg file 
     279      ! 
    357280      !                             ! Parameter control 
    358281      ! 
     
    454377   END SUBROUTINE nemo_alloc 
    455378 
    456  
    457    SUBROUTINE nemo_partition( num_pes ) 
    458       !!---------------------------------------------------------------------- 
    459       !!                 ***  ROUTINE nemo_partition  *** 
    460       !! 
    461       !! ** Purpose : 
    462       !! 
    463       !! ** Method  : 
    464       !!---------------------------------------------------------------------- 
    465       INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have 
    466       ! 
    467       INTEGER, PARAMETER :: nfactmax = 20 
    468       INTEGER :: nfact ! The no. of factors returned 
    469       INTEGER :: ierr  ! Error flag 
    470       INTEGER :: ji 
    471       INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value 
    472       INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors 
    473       !!---------------------------------------------------------------------- 
    474       ! 
    475       ierr = 0 
    476       ! 
    477       CALL factorise( ifact, nfactmax, nfact, num_pes, ierr ) 
    478       ! 
    479       IF( nfact <= 1 ) THEN 
    480          WRITE (numout, *) 'WARNING: factorisation of number of PEs failed' 
    481          WRITE (numout, *) '       : using grid of ',num_pes,' x 1' 
    482          jpnj = 1 
    483          jpni = num_pes 
    484       ELSE 
    485          ! Search through factors for the pair that are closest in value 
    486          mindiff = 1000000 
    487          imin    = 1 
    488          DO ji = 1, nfact-1, 2 
    489             idiff = ABS( ifact(ji) - ifact(ji+1) ) 
    490             IF( idiff < mindiff ) THEN 
    491                mindiff = idiff 
    492                imin = ji 
    493             ENDIF 
    494          END DO 
    495          jpnj = ifact(imin) 
    496          jpni = ifact(imin + 1) 
    497       ENDIF 
    498       ! 
    499       jpnij = jpni*jpnj 
    500       ! 
    501    END SUBROUTINE nemo_partition 
    502  
    503  
    504    SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr ) 
    505       !!---------------------------------------------------------------------- 
    506       !!                     ***  ROUTINE factorise  *** 
    507       !! 
    508       !! ** Purpose :   return the prime factors of n. 
    509       !!                knfax factors are returned in array kfax which is of 
    510       !!                maximum dimension kmaxfax. 
    511       !! ** Method  : 
    512       !!---------------------------------------------------------------------- 
    513       INTEGER                    , INTENT(in   ) ::   kn, kmaxfax 
    514       INTEGER                    , INTENT(  out) ::   kerr, knfax 
    515       INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax 
    516       ! 
    517       INTEGER :: ifac, jl, inu 
    518       INTEGER, PARAMETER :: ntest = 14 
    519       INTEGER, DIMENSION(ntest) ::   ilfax 
    520       !!---------------------------------------------------------------------- 
    521       ! 
    522       ! lfax contains the set of allowed factors. 
    523       ilfax(:) = (/(2**jl,jl=ntest,1,-1)/) 
    524       ! 
    525       ! Clear the error flag and initialise output vars 
    526       kerr  = 0 
    527       kfax  = 1 
    528       knfax = 0 
    529       ! 
    530       ! Find the factors of n. 
    531       IF( kn .NE. 1 ) THEN 
    532  
    533          ! nu holds the unfactorised part of the number. 
    534          ! knfax holds the number of factors found. 
    535          ! l points to the allowed factor list. 
    536          ! ifac holds the current factor. 
    537          ! 
    538          inu   = kn 
    539          knfax = 0 
    540          ! 
    541          DO jl = ntest, 1, -1 
    542             ! 
    543             ifac = ilfax(jl) 
    544             IF( ifac > inu )   CYCLE 
    545     
    546             ! Test whether the factor will divide. 
    547     
    548             IF( MOD(inu,ifac) == 0 ) THEN 
    549                ! 
    550                knfax = knfax + 1            ! Add the factor to the list 
    551                IF( knfax > kmaxfax ) THEN 
    552                   kerr = 6 
    553                   write (*,*) 'FACTOR: insufficient space in factor array ', knfax 
    554                   return 
    555                ENDIF 
    556                kfax(knfax) = ifac 
    557                ! Store the other factor that goes with this one 
    558                knfax = knfax + 1 
    559                kfax(knfax) = inu / ifac 
    560                !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax) 
    561             ENDIF 
    562             ! 
    563          END DO 
    564          ! 
    565       ENDIF 
    566       ! 
    567    END SUBROUTINE factorise 
    568  
    569 #if defined key_mpp_mpi 
    570  
    571    SUBROUTINE nemo_northcomms 
    572       !!---------------------------------------------------------------------- 
    573       !!                     ***  ROUTINE  nemo_northcomms  *** 
    574       !! ** Purpose :   Setup for north fold exchanges with explicit  
    575       !!                point-to-point messaging 
    576       !! 
    577       !! ** Method :   Initialization of the northern neighbours lists. 
    578       !!---------------------------------------------------------------------- 
    579       !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE) 
    580       !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)  
    581       !!---------------------------------------------------------------------- 
    582       INTEGER  ::   sxM, dxM, sxT, dxT, jn 
    583       INTEGER  ::   njmppmax 
    584       !!---------------------------------------------------------------------- 
    585       ! 
    586       njmppmax = MAXVAL( njmppt ) 
    587       ! 
    588       !initializes the north-fold communication variables 
    589       isendto(:) = 0 
    590       nsndto     = 0 
    591       ! 
    592       !if I am a process in the north 
    593       IF ( njmpp == njmppmax ) THEN 
    594           !sxM is the first point (in the global domain) needed to compute the 
    595           !north-fold for the current process 
    596           sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1 
    597           !dxM is the last point (in the global domain) needed to compute the 
    598           !north-fold for the current process 
    599           dxM = jpiglo - nimppt(narea) + 2 
    600  
    601           !loop over the other north-fold processes to find the processes 
    602           !managing the points belonging to the sxT-dxT range 
    603    
    604           DO jn = 1, jpni 
    605                 !sxT is the first point (in the global domain) of the jn 
    606                 !process 
    607                 sxT = nfiimpp(jn, jpnj) 
    608                 !dxT is the last point (in the global domain) of the jn 
    609                 !process 
    610                 dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1 
    611                 IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN 
    612                    nsndto = nsndto + 1 
    613                    isendto(nsndto) = jn 
    614                 ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN 
    615                    nsndto = nsndto + 1 
    616                    isendto(nsndto) = jn 
    617                 ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN 
    618                    nsndto = nsndto + 1 
    619                    isendto(nsndto) = jn 
    620                 ENDIF 
    621           END DO 
    622           nfsloop = 1 
    623           nfeloop = nlci 
    624           DO jn = 2,jpni-1 
    625            IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN 
    626               IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN 
    627                  nfsloop = nldi 
    628               ENDIF 
    629               IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN 
    630                  nfeloop = nlei 
    631               ENDIF 
    632            ENDIF 
    633         END DO 
    634  
    635       ENDIF 
    636       l_north_nogather = .TRUE. 
    637    END SUBROUTINE nemo_northcomms 
    638  
    639 #else 
    640    SUBROUTINE nemo_northcomms      ! Dummy routine 
    641       WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?' 
    642    END SUBROUTINE nemo_northcomms 
    643 #endif 
    644  
    645379   !!====================================================================== 
    646380END MODULE nemogcm 
Note: See TracChangeset for help on using the changeset viewer.