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/OPA_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/OPA_SRC/nemogcm.F90

    r9367 r9436  
    2828   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase 
    2929   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation 
    30    !!            3.4  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE) add nemo_nfdcom 
    3130   !!             -   ! 2011-11  (C. Harris) decomposition changes for running with CICE 
    3231   !!            3.6  ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening  
    33    !!             -   ! 2013-06  (I. Epicoco, S. Mocavero, CMCC) nemo_nfdcom: setup avoiding MPI communication  
    3432   !!             -   ! 2014-12  (G. Madec) remove KPP scheme and cross-land advection (cla) 
    3533   !!            4.0  ! 2016-10  (G. Madec, S. Flavoni)  domain configuration / user defined interface 
     
    4240   !!   nemo_closefile: close remaining open files 
    4341   !!   nemo_alloc    : dynamical allocation 
    44    !!   nemo_partition: calculate MPP domain decomposition 
    45    !!   factorise     : calculate the factors of the no. of MPI processes 
    46    !!   nemo_nfdcom   : Setup for north fold exchanges with explicit point-to-point messaging 
    4742   !!---------------------------------------------------------------------- 
    4843   USE step_oce       ! module used in the ocean time stepping module (step.F90) 
     
    239234      INTEGER  ::   ji                 ! dummy loop indices 
    240235      INTEGER  ::   ios, ilocal_comm   ! local integers 
    241       INTEGER  ::   iiarea, ijarea     !   -       - 
    242       INTEGER  ::   iirest, ijrest     !   -       - 
    243236      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam 
    244237      !! 
     
    329322      ENDIF 
    330323 
    331       ! If dimensions of processor grid weren't specified in the namelist file 
    332       ! then we calculate them here now that we have our communicator size 
    333       IF( jpni < 1 .OR. jpnj < 1 ) THEN 
    334 #if   defined key_mpp_mpi 
    335          IF( Agrif_Root() )   CALL nemo_partition( mppsize ) 
    336 #else 
    337          jpni  = 1 
    338          jpnj  = 1 
    339          jpnij = jpni*jpnj 
    340 #endif 
    341       ENDIF 
    342       ! 
    343 #if defined key_agrif 
    344       IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90) 
    345          jpiglo  = nbcellsx + 2 + 2*nbghostcells 
    346          jpjglo  = nbcellsy + 2 + 2*nbghostcells 
    347          jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls 
    348          jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls 
    349          jpimax  = jpi 
    350          jpjmax  = jpj 
    351          nperio  = 0 
    352          jperio  = 0 
    353          ln_use_jattr = .false. 
    354       ENDIF 
    355 #endif 
    356  
    357       IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj 
    358          iiarea = 1 + MOD( narea - 1 , jpni ) 
    359          ijarea = 1 + ( narea - 1 ) / jpni 
    360          iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni ) 
    361          ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj ) 
    362 #if defined key_nemocice_decomp 
    363          jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim. 
    364          jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.  
    365          jpimax  = jpi 
    366          jpjmax  = jpj 
    367          IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls) 
    368          IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls) 
    369 #else 
    370          jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim. 
    371          jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
    372          jpimax  = jpi 
    373          jpjmax  = jpj 
    374          IF( iiarea > iirest ) jpi = jpi - 1 
    375          IF( ijarea > ijrest ) jpj = jpj - 1 
    376 #endif 
    377       ENDIF 
    378  
    379       jpk = jpkglo                                             ! third dim 
    380  
    381 #if defined key_agrif 
    382       ! simple trick to use same vertical grid as parent but different number of levels:  
    383       ! Save maximum number of levels in jpkglo, then define all vertical grids with this number. 
    384       ! Suppress once vertical online interpolation is ok 
    385       IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo ) 
    386 #endif 
    387       jpim1 = jpi-1                                            ! inner domain indices 
    388       jpjm1 = jpj-1                                            !   "           " 
    389       jpkm1 = MAX( 1, jpk-1 )                                  !   "           " 
    390       jpij  = jpi*jpj                                          !  jpi x j 
    391  
    392324      IF(lwp) THEN                            ! open listing units 
    393325         ! 
     
    413345         ! 
    414346      ENDIF 
     347      !                                      ! Domain decomposition 
     348      CALL mpp_init                          ! MPP 
    415349 
    416350      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays 
     
    422356 
    423357      CALL nemo_ctl                          ! Control prints 
    424  
    425       !                                      ! Domain decomposition 
    426       CALL mpp_init                             ! MPP 
    427       IF( ln_nnogather )   CALL nemo_nfdcom     ! northfold neighbour lists 
    428358      ! 
    429359      !                                      ! General initialization 
     
    681611   END SUBROUTINE nemo_alloc 
    682612 
    683  
    684    SUBROUTINE nemo_partition( num_pes ) 
    685       !!---------------------------------------------------------------------- 
    686       !!                 ***  ROUTINE nemo_partition  *** 
    687       !! 
    688       !! ** Purpose : 
    689       !! 
    690       !! ** Method  : 
    691       !!---------------------------------------------------------------------- 
    692       INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have 
    693       ! 
    694       INTEGER, PARAMETER :: nfactmax = 20 
    695       INTEGER :: nfact ! The no. of factors returned 
    696       INTEGER :: ierr  ! Error flag 
    697       INTEGER :: ji 
    698       INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value 
    699       INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors 
    700       !!---------------------------------------------------------------------- 
    701       ! 
    702       ierr = 0 
    703       ! 
    704       CALL factorise( ifact, nfactmax, nfact, num_pes, ierr ) 
    705       ! 
    706       IF( nfact <= 1 ) THEN 
    707          WRITE (numout, *) 'WARNING: factorisation of number of PEs failed' 
    708          WRITE (numout, *) '       : using grid of ',num_pes,' x 1' 
    709          jpnj = 1 
    710          jpni = num_pes 
    711       ELSE 
    712          ! Search through factors for the pair that are closest in value 
    713          mindiff = 1000000 
    714          imin    = 1 
    715          DO ji = 1, nfact-1, 2 
    716             idiff = ABS( ifact(ji) - ifact(ji+1) ) 
    717             IF( idiff < mindiff ) THEN 
    718                mindiff = idiff 
    719                imin = ji 
    720             ENDIF 
    721          END DO 
    722          jpnj = ifact(imin) 
    723          jpni = ifact(imin + 1) 
    724       ENDIF 
    725       ! 
    726       jpnij = jpni*jpnj 
    727       ! 
    728    END SUBROUTINE nemo_partition 
    729  
    730  
    731    SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr ) 
    732       !!---------------------------------------------------------------------- 
    733       !!                     ***  ROUTINE factorise  *** 
    734       !! 
    735       !! ** Purpose :   return the prime factors of n. 
    736       !!                knfax factors are returned in array kfax which is of 
    737       !!                maximum dimension kmaxfax. 
    738       !! ** Method  : 
    739       !!---------------------------------------------------------------------- 
    740       INTEGER                    , INTENT(in   ) ::   kn, kmaxfax 
    741       INTEGER                    , INTENT(  out) ::   kerr, knfax 
    742       INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax 
    743       ! 
    744       INTEGER :: ifac, jl, inu 
    745       INTEGER, PARAMETER :: ntest = 14 
    746       INTEGER, DIMENSION(ntest) ::   ilfax 
    747       !!---------------------------------------------------------------------- 
    748       ! 
    749       ! lfax contains the set of allowed factors. 
    750       ilfax(:) = (/(2**jl,jl=ntest,1,-1)/) 
    751       ! 
    752       ! Clear the error flag and initialise output vars 
    753       kerr  = 0 
    754       kfax  = 1 
    755       knfax = 0 
    756       ! 
    757       IF( kn /= 1 ) THEN      ! Find the factors of n 
    758          ! 
    759          ! nu holds the unfactorised part of the number. 
    760          ! knfax holds the number of factors found. 
    761          ! l points to the allowed factor list. 
    762          ! ifac holds the current factor. 
    763          ! 
    764          inu   = kn 
    765          knfax = 0 
    766          ! 
    767          DO jl = ntest, 1, -1 
    768             ! 
    769             ifac = ilfax(jl) 
    770             IF( ifac > inu )   CYCLE 
    771             ! 
    772             ! Test whether the factor will divide. 
    773             ! 
    774             IF( MOD(inu,ifac) == 0 ) THEN 
    775                ! 
    776                knfax = knfax + 1            ! Add the factor to the list 
    777                IF( knfax > kmaxfax ) THEN 
    778                   kerr = 6 
    779                   write (*,*) 'FACTOR: insufficient space in factor array ', knfax 
    780                   return 
    781                ENDIF 
    782                kfax(knfax) = ifac 
    783                ! Store the other factor that goes with this one 
    784                knfax = knfax + 1 
    785                kfax(knfax) = inu / ifac 
    786                !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax) 
    787             ENDIF 
    788             ! 
    789          END DO 
    790          ! 
    791       ENDIF 
    792       ! 
    793    END SUBROUTINE factorise 
    794  
    795 #if defined key_mpp_mpi 
    796  
    797    SUBROUTINE nemo_nfdcom 
    798       !!---------------------------------------------------------------------- 
    799       !!                     ***  ROUTINE  nemo_nfdcom  *** 
    800       !! ** Purpose :   Setup for north fold exchanges with explicit  
    801       !!                point-to-point messaging 
    802       !! 
    803       !! ** Method :   Initialization of the northern neighbours lists. 
    804       !!---------------------------------------------------------------------- 
    805       !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE) 
    806       !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)  
    807       !!---------------------------------------------------------------------- 
    808       INTEGER  ::   sxM, dxM, sxT, dxT, jn 
    809       INTEGER  ::   njmppmax 
    810       !!---------------------------------------------------------------------- 
    811       ! 
    812       njmppmax = MAXVAL( njmppt ) 
    813       ! 
    814       !initializes the north-fold communication variables 
    815       isendto(:) = 0 
    816       nsndto     = 0 
    817       ! 
    818       IF ( njmpp == njmppmax ) THEN      ! if I am a process in the north 
    819          ! 
    820          !sxM is the first point (in the global domain) needed to compute the north-fold for the current process 
    821          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1 
    822          !dxM is the last point (in the global domain) needed to compute the north-fold for the current process 
    823          dxM = jpiglo - nimppt(narea) + 2 
    824          ! 
    825          ! loop over the other north-fold processes to find the processes 
    826          ! managing the points belonging to the sxT-dxT range 
    827          ! 
    828          DO jn = 1, jpni 
    829             ! 
    830             sxT = nfiimpp(jn, jpnj)                            ! sxT = 1st  point (in the global domain) of the jn process 
    831             dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1    ! dxT = last point (in the global domain) of the jn process 
    832             ! 
    833             IF    ( sxT < sxM  .AND.  sxM < dxT ) THEN 
    834                nsndto          = nsndto + 1 
    835                isendto(nsndto) = jn 
    836             ELSEIF( sxM <= sxT  .AND.  dxM >= dxT ) THEN 
    837                nsndto          = nsndto + 1 
    838                isendto(nsndto) = jn 
    839             ELSEIF( dxM <  dxT  .AND.  sxT <  dxM ) THEN 
    840                nsndto          = nsndto + 1 
    841                isendto(nsndto) = jn 
    842             ENDIF 
    843             ! 
    844          END DO 
    845          nfsloop = 1 
    846          nfeloop = nlci 
    847          DO jn = 2,jpni-1 
    848             IF( nfipproc(jn,jpnj) == (narea - 1) ) THEN 
    849                IF( nfipproc(jn-1,jpnj) == -1 )   nfsloop = nldi 
    850                IF( nfipproc(jn+1,jpnj) == -1 )   nfeloop = nlei 
    851             ENDIF 
    852          END DO 
    853          ! 
    854       ENDIF 
    855       l_north_nogather = .TRUE. 
    856       ! 
    857    END SUBROUTINE nemo_nfdcom 
    858  
    859 #else 
    860    SUBROUTINE nemo_nfdcom      ! Dummy routine 
    861       WRITE(*,*) 'nemo_nfdcom: You should not have seen this print! error?' 
    862    END SUBROUTINE nemo_nfdcom 
    863 #endif 
    864  
    865613   !!====================================================================== 
    866614END MODULE nemogcm 
Note: See TracChangeset for help on using the changeset viewer.