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 2648 for branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 – NEMO

Ignore:
Timestamp:
2011-03-03T17:13:18+01:00 (13 years ago)
Author:
cetlod
Message:

Changed OFF_SRC component to use dynamic memory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90

    r2574 r2648  
    55   !!====================================================================== 
    66   !! History :  3.3  ! 2010-05  (C. Ethe)  Full reorganization of the off-line: phasing with the on-line 
     7   !!            4.0  ! 2011-01  (C. Ethe, A. R. Porter, STFC Daresbury) dynamical allocation 
    78   !!---------------------------------------------------------------------- 
    89 
     
    2627   USE trabbl          ! bottom boundary layer          (tra_bbl_init routine) 
    2728   USE zdfini          ! vertical physics: initialization 
     29   USE sbcmod          ! surface boundary condition       (sbc_init     routine) 
    2830   USE phycst          ! physical constant                  (par_cst routine) 
    2931   USE dtadyn          ! Lecture and Interpolation of the dynamical fields 
     
    137139      !                             !--------------------------------------------! 
    138140#if defined key_iomput 
    139       CALL init_ioclient( ilocal_comm )       ! nemo local communicator (used or not) given by the io_server 
    140       narea = mynode( cltxt, ilocal_comm )    ! Nodes selection 
     141      CALL  init_ioclient( ilocal_comm )                 ! exchange io_server nemo local communicator with the io_server 
     142      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection 
    141143#else 
    142       narea = mynode( cltxt )                 ! Nodes selection (control print return in cltxt) 
     144      ilocal_comm = 0 
     145      narea = mynode( cltxt, numnam, nstop )                 ! Nodes selection (control print return in cltxt) 
    143146#endif 
     147 
    144148      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 ) 
    145149 
    146150      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print 
     151 
     152      ! Decide on size of grid now that we have our communicator size 
     153      ! If we're not using dynamic memory then mpp_partition does nothing. 
     154 
     155#if   defined key_mpp_mpi   ||   defined key_mpp_shmem 
     156      CALL nemo_partition(mppsize) 
     157#else 
     158      jpni = 1 
     159      jpnj = 1 
     160      jpnij = jpni*jpnj 
     161#endif 
     162      ! Calculate domain dimensions given calculated jpni and jpnj 
     163      ! This used to be done in par_oce.F90 when they were parameters rather 
     164      ! than variables 
     165      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci !: first  dim. 
     166      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj !: second dim. 
     167      jpim1 = jpi-1                                          !: inner domain indices 
     168      jpjm1 = jpj-1                                          !:   "           " 
     169      jpkm1 = jpk-1                                          !:   "           " 
     170      jpij  = jpi*jpj                                        !:  jpi x j 
     171 
     172      ! Now we know the dimensions of the grid, allocate arrays 
     173      CALL nemo_alloc() 
    147174 
    148175      IF(lwp) THEN                            ! open listing units 
     
    182209 
    183210      !                                     ! Ocean physics 
     211                            CALL     sbc_init   ! Forcings : surface module 
    184212#if ! defined key_degrad 
    185213                            CALL ldf_tra_init   ! Lateral ocean tracer physics 
     
    307335   END SUBROUTINE nemo_closefile 
    308336 
     337   SUBROUTINE nemo_alloc 
     338     !!---------------------------------------------------------------------- 
     339     !!                     ***  ROUTINE nemo_alloc  *** 
     340     !! 
     341     !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules 
     342     !! 
     343     !! ** Method  : 
     344     !!---------------------------------------------------------------------- 
     345     USE diawri,       ONLY: dia_wri_alloc 
     346     USE dom_oce,      ONLY: dom_oce_alloc 
     347     USE zdf_oce,      ONLY: zdf_oce_alloc 
     348     USE zdfmxl,       ONLY: zdf_mxl_alloc 
     349     USE ldftra_oce,   ONLY: ldftra_oce_alloc 
     350     USE trc_oce,      ONLY: trc_oce_alloc 
     351 
     352      USE wrk_nemo,    ONLY: wrk_alloc 
     353 
     354      INTEGER :: ierr 
     355      !!---------------------------------------------------------------------- 
     356 
     357      ierr =        oce_alloc       ()          ! ocean  
     358      ierr = ierr + dia_wri_alloc   () 
     359      ierr = ierr + dom_oce_alloc   ()          ! ocean domain 
     360      ierr = ierr + ldftra_oce_alloc()          ! ocean lateral  physics : tracers 
     361      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics 
     362      ierr = ierr + zdf_mxl_alloc   ()          ! ocean vertical physics 
     363      ! 
     364      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges 
     365      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays 
     366      ierr = ierr + wrk_alloc(numout, lwp) 
     367 
     368      IF( lk_mpp    )   CALL mpp_sum( ierr ) 
     369      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' ) 
     370      ! 
     371   END SUBROUTINE nemo_alloc 
     372 
     373   SUBROUTINE nemo_partition( num_pes ) 
     374      !!---------------------------------------------------------------------- 
     375      !!                 ***  ROUTINE nemo_partition  *** 
     376      !! 
     377      !! ** Purpose :    
     378      !! 
     379      !! ** Method  : 
     380      !!---------------------------------------------------------------------- 
     381      USE par_oce 
     382      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have 
     383      ! Local variables 
     384      INTEGER, PARAMETER :: nfactmax = 20 
     385      INTEGER :: nfact ! The no. of factors returned 
     386      INTEGER :: ierr  ! Error flag 
     387      INTEGER :: i 
     388      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value 
     389      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors 
     390      !!---------------------------------------------------------------------- 
     391 
     392      ierr = 0 
     393 
     394      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr ) 
     395 
     396      IF( nfact <= 1 ) THEN 
     397         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed' 
     398         WRITE (numout, *) '       : using grid of ',num_pes,' x 1' 
     399         jpnj = 1 
     400         jpni = num_pes 
     401      ELSE 
     402         ! Search through factors for the pair that are closest in value 
     403         mindiff = 1000000 
     404         imin    = 1 
     405         DO i=1,nfact-1,2 
     406            idiff = ABS(ifact(i) - ifact(i+1)) 
     407            IF(idiff < mindiff)THEN 
     408               mindiff = idiff 
     409               imin = i 
     410            END IF 
     411         END DO 
     412         jpnj = ifact(imin) 
     413         jpni = ifact(imin + 1) 
     414      ENDIF 
     415      jpnij = jpni*jpnj 
     416 
     417      WRITE(*,*) 'ARPDBG: jpni = ',jpni,'jpnj = ',jpnj,'jpnij = ',jpnij 
     418      ! 
     419   END SUBROUTINE nemo_partition 
     420 
     421 
     422   SUBROUTINE factorise( ifax, maxfax, nfax, n, ierr ) 
     423      !!---------------------------------------------------------------------- 
     424      !!                     ***  ROUTINE factorise  *** 
     425      !! 
     426      !! ** Purpose :   return the prime factors of n. 
     427      !!                nfax factors are returned in array ifax which is of  
     428      !!                maximum dimension maxfax. 
     429      !! ** Method  : 
     430      !!---------------------------------------------------------------------- 
     431      INTEGER, INTENT(in)  :: n, maxfax 
     432      INTEGER, INTENT(Out) :: ierr, nfax 
     433      INTEGER, INTENT(out) :: ifax(maxfax) 
     434      ! Local variables. 
     435      INTEGER :: i, ifac, l, nu 
     436      INTEGER, PARAMETER :: ntest = 14 
     437      INTEGER :: lfax(ntest) 
     438 
     439      ! lfax contains the set of allowed factors. 
     440      data (lfax(i),i=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  & 
     441         &                         128,   64,   32,   16,    8,   4,   2  / 
     442      !!---------------------------------------------------------------------- 
     443 
     444      ! Clear the error flag and initialise output vars 
     445      ierr = 0 
     446      ifax = 1 
     447      nfax = 0 
     448 
     449      ! Find the factors of n. 
     450      IF( n == 1 ) GOTO 20 
     451 
     452      ! nu holds the unfactorised part of the number. 
     453      ! nfax holds the number of factors found. 
     454      ! l points to the allowed factor list. 
     455      ! ifac holds the current factor. 
     456 
     457      nu   = n 
     458      nfax = 0 
     459 
     460      DO l = ntest, 1, -1 
     461         ! 
     462         ifac = lfax(l) 
     463         IF(ifac > nu)CYCLE 
     464 
     465         ! Test whether the factor will divide. 
     466 
     467         IF( MOD(nu,ifac) == 0 ) THEN 
     468            ! 
     469            nfax = nfax+1            ! Add the factor to the list 
     470            IF( nfax > maxfax ) THEN 
     471               ierr = 6 
     472               write (*,*) 'FACTOR: insufficient space in factor array ',nfax 
     473               return 
     474            ENDIF 
     475            ifax(nfax) = ifac 
     476            ! Store the other factor that goes with this one 
     477            nfax = nfax + 1 
     478            ifax(nfax) = nu / ifac 
     479            !WRITE (*,*) 'ARPDBG, factors ',nfax-1,' & ',nfax,' are ', & 
     480            !            ifax(nfax-1),' and ',ifax(nfax) 
     481         ENDIF 
     482         ! 
     483      END DO 
     484 
     485   20 CONTINUE      ! Label 20 is the exit point from the factor search loop. 
     486      ! 
     487      RETURN 
     488      ! 
     489   END SUBROUTINE factorise 
    309490   !!====================================================================== 
    310491END MODULE nemogcm 
Note: See TracChangeset for help on using the changeset viewer.