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/OFF_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/OFF_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   !!   istate_init   : simple initialization to zero of ocean fields 
    2219   !!   stp_ctl       : reduced step control (no dynamics in off-line) 
     
    157154      INTEGER  ::   ji                 ! dummy loop indices 
    158155      INTEGER  ::   ios, ilocal_comm   ! local integers 
    159       INTEGER  ::   iiarea, ijarea     !   -       - 
    160       INTEGER  ::   iirest, ijrest     !   -       - 
    161156      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam 
    162157      !! 
     
    232227      ENDIF 
    233228 
    234       ! If dimensions of processor grid weren't specified in the namelist file  
    235       ! then we calculate them here now that we have our communicator size 
    236       IF( jpni < 1  .OR.  jpnj < 1 ) THEN 
    237 #if   defined key_mpp_mpi 
    238          CALL nemo_partition( mppsize ) 
    239 #else 
    240          jpni  = 1 
    241          jpnj  = 1 
    242          jpnij = jpni*jpnj 
    243 #endif 
    244       ENDIF 
    245  
    246       iiarea = 1 + MOD( narea - 1 , jpni ) 
    247       ijarea = 1 + ( narea - 1 ) / jpni 
    248       iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni ) 
    249       ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj ) 
    250 #if defined key_nemocice_decomp 
    251       jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim. 
    252       jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.  
    253       jpimax  = jpi 
    254       jpjmax  = jpj 
    255       IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls) 
    256       IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls) 
    257 #else 
    258       jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim. 
    259       jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim. 
    260       jpimax  = jpi 
    261       jpjmax  = jpj 
    262       IF( iiarea > iirest ) jpi = jpi - 1 
    263       IF( ijarea > ijrest ) jpj = jpj - 1 
    264 #endif 
    265  
    266       jpk   = jpkglo                                           ! third dim 
    267  
    268       jpim1 = jpi-1                                            ! inner domain indices 
    269       jpjm1 = jpj-1                                            !   "           " 
    270       jpkm1 = MAX( 1, jpk-1 )                                  !   "           " 
    271       jpij  = jpi*jpj                                          !  jpi x j 
    272  
    273  
    274229      IF(lwp) THEN                            ! open listing units 
    275230         ! 
     
    295250         ! 
    296251      ENDIF 
     252      !                                      ! Domain decomposition 
     253      CALL mpp_init                          ! MPP 
    297254 
    298255      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays 
     
    304261 
    305262      CALL nemo_ctl                          ! Control prints 
    306  
    307       !                                      ! Domain decomposition 
    308       CALL mpp_init                             ! MPP 
    309       IF( ln_nnogather )   CALL nemo_nfdcom     ! northfold neighbour lists 
    310263      ! 
    311264      !                                      ! General initialization 
     
    385338         WRITE(numout,*) '      read domain configuration file              ln_read_cfg      = ', ln_read_cfg 
    386339         WRITE(numout,*) '         filename to be read                         cn_domcfg     = ', TRIM(cn_domcfg) 
    387          WRITE(numout,*) '         keep closed seas in the domain (if exist)   ln_closea     = ', TRIM(cn_domcfg) 
     340         WRITE(numout,*) '         keep closed seas in the domain (if exist)   ln_closea     = ', ln_closea 
    388341         WRITE(numout,*) '      create a configuration definition file      ln_write_cfg     = ', ln_write_cfg 
    389342         WRITE(numout,*) '         filename to be written                      cn_domcfg_out = ', TRIM(cn_domcfg_out) 
     
    486439   END SUBROUTINE nemo_alloc 
    487440 
    488  
    489    SUBROUTINE nemo_partition( num_pes ) 
    490       !!---------------------------------------------------------------------- 
    491       !!                 ***  ROUTINE nemo_partition  *** 
    492       !! 
    493       !! ** Purpose :    
    494       !! 
    495       !! ** Method  : 
    496       !!---------------------------------------------------------------------- 
    497       INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have 
    498       ! 
    499       INTEGER, PARAMETER :: nfactmax = 20 
    500       INTEGER :: nfact ! The no. of factors returned 
    501       INTEGER :: ierr  ! Error flag 
    502       INTEGER :: ji 
    503       INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value 
    504       INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors 
    505       !!---------------------------------------------------------------------- 
    506       ! 
    507       ierr = 0 
    508       ! 
    509       CALL factorise( ifact, nfactmax, nfact, num_pes, ierr ) 
    510       ! 
    511       IF( nfact <= 1 ) THEN 
    512          WRITE (numout, *) 'WARNING: factorisation of number of PEs failed' 
    513          WRITE (numout, *) '       : using grid of ',num_pes,' x 1' 
    514          jpnj = 1 
    515          jpni = num_pes 
    516       ELSE 
    517          ! Search through factors for the pair that are closest in value 
    518          mindiff = 1000000 
    519          imin    = 1 
    520          DO ji = 1, nfact-1, 2 
    521             idiff = ABS( ifact(ji) - ifact(ji+1) ) 
    522             IF( idiff < mindiff ) THEN 
    523                mindiff = idiff 
    524                imin = ji 
    525             ENDIF 
    526          END DO 
    527          jpnj = ifact(imin) 
    528          jpni = ifact(imin + 1) 
    529       ENDIF 
    530       ! 
    531       jpnij = jpni*jpnj 
    532       ! 
    533    END SUBROUTINE nemo_partition 
    534  
    535  
    536    SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr ) 
    537       !!---------------------------------------------------------------------- 
    538       !!                     ***  ROUTINE factorise  *** 
    539       !! 
    540       !! ** Purpose :   return the prime factors of n. 
    541       !!                knfax factors are returned in array kfax which is of 
    542       !!                maximum dimension kmaxfax. 
    543       !! ** Method  : 
    544       !!---------------------------------------------------------------------- 
    545       INTEGER                    , INTENT(in   ) ::   kn, kmaxfax 
    546       INTEGER                    , INTENT(  out) ::   kerr, knfax 
    547       INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax 
    548       ! 
    549       INTEGER :: ifac, jl, inu 
    550       INTEGER, PARAMETER :: ntest = 14 
    551       INTEGER, DIMENSION(ntest) ::   ilfax 
    552       !!---------------------------------------------------------------------- 
    553       ! 
    554       ! lfax contains the set of allowed factors. 
    555       ilfax(:) = (/(2**jl,jl=ntest,1,-1)/) 
    556       ! 
    557       ! Clear the error flag and initialise output vars 
    558       kerr  = 0 
    559       kfax  = 1 
    560       knfax = 0 
    561       ! 
    562       IF( kn /= 1 ) THEN      ! Find the factors of n 
    563          ! 
    564          ! nu holds the unfactorised part of the number. 
    565          ! knfax holds the number of factors found. 
    566          ! l points to the allowed factor list. 
    567          ! ifac holds the current factor. 
    568          ! 
    569          inu   = kn 
    570          knfax = 0 
    571          ! 
    572          DO jl = ntest, 1, -1 
    573             ! 
    574             ifac = ilfax(jl) 
    575             IF( ifac > inu )   CYCLE 
    576             ! 
    577             ! Test whether the factor will divide. 
    578             ! 
    579             IF( MOD(inu,ifac) == 0 ) THEN 
    580                ! 
    581                knfax = knfax + 1            ! Add the factor to the list 
    582                IF( knfax > kmaxfax ) THEN 
    583                   kerr = 6 
    584                   write (*,*) 'FACTOR: insufficient space in factor array ', knfax 
    585                   return 
    586                ENDIF 
    587                kfax(knfax) = ifac 
    588                ! Store the other factor that goes with this one 
    589                knfax = knfax + 1 
    590                kfax(knfax) = inu / ifac 
    591                !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax) 
    592             ENDIF 
    593             ! 
    594          END DO 
    595          ! 
    596       ENDIF 
    597       ! 
    598    END SUBROUTINE factorise 
    599  
    600 #if defined key_mpp_mpi 
    601  
    602    SUBROUTINE nemo_nfdcom 
    603       !!---------------------------------------------------------------------- 
    604       !!                     ***  ROUTINE  nemo_nfdcom  *** 
    605       !! ** Purpose :   Setup for north fold exchanges with explicit  
    606       !!                point-to-point messaging 
    607       !! 
    608       !! ** Method :   Initialization of the northern neighbours lists. 
    609       !!---------------------------------------------------------------------- 
    610       !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE) 
    611       !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)  
    612       !!---------------------------------------------------------------------- 
    613       INTEGER  ::   sxM, dxM, sxT, dxT, jn 
    614       INTEGER  ::   njmppmax 
    615       !!---------------------------------------------------------------------- 
    616       ! 
    617       njmppmax = MAXVAL( njmppt ) 
    618       ! 
    619       !initializes the north-fold communication variables 
    620       isendto(:) = 0 
    621       nsndto     = 0 
    622       ! 
    623       IF ( njmpp == njmppmax ) THEN      ! if I am a process in the north 
    624          ! 
    625          !sxM is the first point (in the global domain) needed to compute the north-fold for the current process 
    626          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1 
    627          !dxM is the last point (in the global domain) needed to compute the north-fold for the current process 
    628          dxM = jpiglo - nimppt(narea) + 2 
    629          ! 
    630          ! loop over the other north-fold processes to find the processes 
    631          ! managing the points belonging to the sxT-dxT range 
    632          ! 
    633          DO jn = 1, jpni 
    634             ! 
    635             sxT = nfiimpp(jn, jpnj)                            ! sxT = 1st  point (in the global domain) of the jn process 
    636             dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1    ! dxT = last point (in the global domain) of the jn process 
    637             ! 
    638             IF    ( sxT < sxM  .AND.  sxM < dxT ) THEN 
    639                nsndto          = nsndto + 1 
    640                isendto(nsndto) = jn 
    641             ELSEIF( sxM <= sxT  .AND.  dxM >= dxT ) THEN 
    642                nsndto          = nsndto + 1 
    643                isendto(nsndto) = jn 
    644             ELSEIF( dxM <  dxT  .AND.  sxT <  dxM ) THEN 
    645                nsndto          = nsndto + 1 
    646                isendto(nsndto) = jn 
    647             ENDIF 
    648             ! 
    649          END DO 
    650          nfsloop = 1 
    651          nfeloop = nlci 
    652          DO jn = 2,jpni-1 
    653             IF( nfipproc(jn,jpnj) == (narea - 1) ) THEN 
    654                IF( nfipproc(jn-1,jpnj) == -1 )   nfsloop = nldi 
    655                IF( nfipproc(jn+1,jpnj) == -1 )   nfeloop = nlei 
    656             ENDIF 
    657          END DO 
    658          ! 
    659       ENDIF 
    660       l_north_nogather = .TRUE. 
    661       ! 
    662    END SUBROUTINE nemo_nfdcom 
    663  
    664 #else 
    665    SUBROUTINE nemo_nfdcom      ! Dummy routine 
    666       WRITE(*,*) 'nemo_nfdcom: You should not have seen this print! error?' 
    667    END SUBROUTINE nemo_nfdcom 
    668 #endif 
    669  
    670441   SUBROUTINE istate_init 
    671442      !!---------------------------------------------------------------------- 
     
    715486      ! 
    716487   END SUBROUTINE stp_ctl 
    717  
    718488   !!====================================================================== 
    719489END MODULE nemogcm 
Note: See TracChangeset for help on using the changeset viewer.