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.
nemogcm.F90 in branches/2012/dev_v3_4_STABLE_2012/NEMOGCM/NEMO/OPA_SRC – NEMO

source: branches/2012/dev_v3_4_STABLE_2012/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90 @ 4600

Last change on this file since 4600 was 4600, checked in by pabouttier, 10 years ago

Allow to initialize direct model from nemogcm_tam, see Ticket #1286

  • Property svn:keywords set to Id
File size: 36.3 KB
RevLine 
[2496]1MODULE nemogcm
[2442]2   !!======================================================================
[2496]3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
[2442]5   !!======================================================================
[1593]6   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
7   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
[3604]8   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
9   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
[1593]10   !!             -   ! 1992-06  (L.Terray)  coupling implementation
[3604]11   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
12   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
[2104]13   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
[1593]14   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
[3604]15   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
16   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
[1593]17   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
18   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
19   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
20   !!             -   ! 2004-08  (C. Talandier) New trends organization
21   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
22   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
23   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
24   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
25   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
26   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
[3604]27   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
[2236]28   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
[3294]29   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
30   !!            3.4  ! 2011-11  (C. Harris) decomposition changes for running with CICE
[1593]31   !!----------------------------------------------------------------------
[3]32
33   !!----------------------------------------------------------------------
[2496]34   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
35   !!   nemo_init      : initialization of the NEMO system
[3604]36   !!   nemo_ctl       : initialisation of the contol print
[2496]37   !!   nemo_closefile : close remaining open files
[2715]38   !!   nemo_alloc     : dynamical allocation
39   !!   nemo_partition : calculate MPP domain decomposition
40   !!   factorise      : calculate the factors of the no. of MPI processes
[3]41   !!----------------------------------------------------------------------
[2382]42   USE step_oce        ! module used in the ocean time stepping module
[888]43   USE sbc_oce         ! surface boundary condition: ocean
[2392]44   USE cla             ! cross land advection               (tra_cla routine)
[3]45   USE domcfg          ! domain configuration               (dom_cfg routine)
46   USE mppini          ! shared/distributed memory setting (mpp_init routine)
47   USE domain          ! domain initialization             (dom_init routine)
48   USE obcini          ! open boundary cond. initialization (obc_ini routine)
[3294]49   USE bdyini          ! open boundary cond. initialization (bdy_init routine)
50   USE bdydta          ! open boundary cond. initialization (bdy_dta_init routine)
51   USE bdytides        ! open boundary cond. initialization (tide_init routine)
[3]52   USE istate          ! initial state setting          (istate_init routine)
53   USE ldfdyn          ! lateral viscosity setting      (ldfdyn_init routine)
54   USE ldftra          ! lateral diffusivity setting    (ldftra_init routine)
[2392]55   USE zdfini          ! vertical physics setting          (zdf_init routine)
[3]56   USE phycst          ! physical constant                  (par_cst routine)
[2236]57   USE trdmod          ! momentum/tracers trends       (trd_mod_init routine)
[3604]58   USE asmbkg          ! writing out state trajectory
[2236]59   USE diaptr          ! poleward transports           (dia_ptr_init routine)
[3294]60   USE diadct          ! sections transports           (dia_dct_init routine)
[2236]61   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
[3558]62   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
[2496]63   USE step            ! NEMO time-stepping                 (stp     routine)
[532]64#if defined key_oasis3
[1359]65   USE cpl_oasis3      ! OASIS3 coupling
[599]66#elif defined key_oasis4
[1359]67   USE cpl_oasis4      ! OASIS4 coupling (not working)
[532]68#endif
[900]69   USE c1d             ! 1D configuration
70   USE step_c1d        ! Time stepping loop for the 1D configuration
[1594]71#if defined key_top
[1593]72   USE trcini          ! passive tracer initialisation
[1594]73#endif
[1593]74   USE lib_mpp         ! distributed memory computing
[1412]75#if defined key_iomput
76   USE mod_ioclient
[1359]77#endif
[3604]78   USE tamtrj          ! Output trajectory, needed for TAM
[268]79
[2715]80   IMPLICIT NONE
[3]81   PRIVATE
82
[2496]83   PUBLIC   nemo_gcm    ! called by model.F90
84   PUBLIC   nemo_init   ! needed by AGRIF
[3604]85   PUBLIC   nemo_alloc  ! needed by TAM
[4600]86   PUBLIC   nemo_closefile ! Needed by NEMOTAM
87   PUBLIC   nemo_partition ! needed by NEMOTAM
[467]88
[2498]89   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
[1593]90
[3]91   !!----------------------------------------------------------------------
[2715]92   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
[2392]93   !! $Id$
[2329]94   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
[3]95   !!----------------------------------------------------------------------
96CONTAINS
97
[2496]98   SUBROUTINE nemo_gcm
[3]99      !!----------------------------------------------------------------------
[2496]100      !!                     ***  ROUTINE nemo_gcm  ***
[3]101      !!
[3604]102      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
[1593]103      !!              curvilinear mesh on the sphere.
[3]104      !!
105      !! ** Method  : - model general initialization
106      !!              - launch the time-stepping (stp routine)
[1593]107      !!              - finalize the run by closing files and communications
[3]108      !!
[2715]109      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
[1593]110      !!              Madec, 2008, internal report, IPSL.
[3]111      !!----------------------------------------------------------------------
112      INTEGER ::   istp       ! time step index
[389]113      !!----------------------------------------------------------------------
[2382]114      !
[392]115#if defined key_agrif
[1593]116      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
[389]117#endif
118
[1593]119      !                            !-----------------------!
[2496]120      CALL nemo_init               !==  Initialisations  ==!
[1593]121      !                            !-----------------------!
[2715]122#if defined key_agrif
123      CALL Agrif_Declare_Var       ! AGRIF: set the meshes
124# if defined key_top
125      CALL Agrif_Declare_Var_Top   ! AGRIF: set the meshes
126# endif
127#endif
[682]128      ! check that all process are still there... If some process have an error,
129      ! they will never enter in step and other processes will wait until the end of the cpu time!
[900]130      IF( lk_mpp )   CALL mpp_max( nstop )
[682]131
[1593]132      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
133
134      !                            !-----------------------!
135      !                            !==   time stepping   ==!
136      !                            !-----------------------!
[900]137      istp = nit000
[2236]138#if defined key_c1d
[389]139         DO WHILE ( istp <= nitend .AND. nstop == 0 )
[900]140            CALL stp_c1d( istp )
[389]141            istp = istp + 1
142         END DO
[2236]143#else
144          IF( lk_asminc ) THEN
145             IF( ln_bkgwri ) CALL asm_bkg_wri( nit000 - 1 )    ! Output background fields
146             IF( ln_asmdin ) THEN                        ! Direct initialization
147                IF( ln_trainc ) CALL tra_asm_inc( nit000 - 1 )    ! Tracers
[3604]148                IF( ln_dyninc ) CALL dyn_asm_inc( nit000 - 1 )    ! Dynamics
[2236]149                IF( ln_sshinc ) CALL ssh_asm_inc( nit000 - 1 )    ! SSH
150             ENDIF
151          ENDIF
[3604]152
[389]153         DO WHILE ( istp <= nitend .AND. nstop == 0 )
[392]154#if defined key_agrif
[1593]155            CALL Agrif_Step( stp )           ! AGRIF: time stepping
[389]156#else
[1593]157            CALL stp( istp )                 ! standard time stepping
[389]158#endif
159            istp = istp + 1
[900]160            IF( lk_mpp )   CALL mpp_max( nstop )
[389]161         END DO
[2236]162#endif
163
164      IF( lk_diaobs ) CALL dia_obs_wri
[3604]165
[1593]166      !                            !------------------------!
167      !                            !==  finalize the run  ==!
168      !                            !------------------------!
169      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
170      !
171      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
[682]172         WRITE(numout,cform_err)
[3604]173         WRITE(numout,*) nstop, ' error have been found'
[389]174      ENDIF
[1593]175      !
[3294]176#if defined key_agrif
177      CALL Agrif_ParentGrid_To_ChildGrid()
178      IF( lk_diaobs ) CALL dia_obs_wri
179      IF( nn_timing == 1 )   CALL timing_finalize
180      CALL Agrif_ChildGrid_To_ParentGrid()
181#endif
182      IF( nn_timing == 1 )   CALL timing_finalize
183      !
[2496]184      CALL nemo_closefile
[532]185#if defined key_oasis3 || defined key_oasis4
[1976]186      CALL cpl_prism_finalize           ! end coupling and mpp communications with OASIS
[532]187#else
[1593]188      IF( lk_mpp )   CALL mppstop       ! end mpp communications
[532]189#endif
[900]190      !
[2496]191   END SUBROUTINE nemo_gcm
[389]192
193
[2496]194   SUBROUTINE nemo_init
[389]195      !!----------------------------------------------------------------------
[2496]196      !!                     ***  ROUTINE nemo_init  ***
[389]197      !!
[2496]198      !! ** Purpose :   initialization of the NEMO GCM
[389]199      !!----------------------------------------------------------------------
[2715]200      INTEGER ::   ji            ! dummy loop indices
201      INTEGER ::   ilocal_comm   ! local integer
202      CHARACTER(len=80), DIMENSION(16) ::   cltxt
[1593]203      !!
[1601]204      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
[3294]205         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
206         &             nn_bench, nn_timing
[3]207      !!----------------------------------------------------------------------
[1593]208      !
[2496]209      cltxt = ''
210      !
[1593]211      !                             ! open Namelist file
[1581]212      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
[1593]213      !
214      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
215      !
216      !                             !--------------------------------------------!
217      !                             !  set communicator & select the local node  !
218      !                             !--------------------------------------------!
[1412]219#if defined key_iomput
[2200]220      IF( Agrif_Root() ) THEN
[1412]221# if defined key_oasis3 || defined key_oasis4
[2715]222         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
[1412]223# endif
[2715]224         CALL  init_ioclient( ilocal_comm )                 ! exchange io_server nemo local communicator with the io_server
[2200]225      ENDIF
[2715]226      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection
[532]227#else
[1412]228# if defined key_oasis3 || defined key_oasis4
[2236]229      IF( Agrif_Root() ) THEN
[2715]230         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
[2236]231      ENDIF
[2715]232      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
[1412]233# else
[2082]234      ilocal_comm = 0
[2715]235      narea = mynode( cltxt, numnam, nstop )                 ! Nodes selection (control print return in cltxt)
[1412]236# endif
[532]237#endif
[2715]238      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
[3]239
[2715]240      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
[1579]241
[3604]242      ! If dimensions of processor grid weren't specified in the namelist file
[2715]243      ! then we calculate them here now that we have our communicator size
244      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
245#if   defined key_mpp_mpi
246         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
247#else
248         jpni  = 1
249         jpnj  = 1
250         jpnij = jpni*jpnj
251#endif
252      END IF
253
254      ! Calculate domain dimensions given calculated jpni and jpnj
255      ! This used to be done in par_oce.F90 when they were parameters rather
256      ! than variables
257      IF( Agrif_Root() ) THEN
258         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
[3294]259#if defined key_nemocice_decomp
[3604]260         jpj = ( jpjglo+1-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
[3294]261#else
[2715]262         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
[3294]263#endif
[2715]264         jpk = jpkdta                                             ! third dim
265         jpim1 = jpi-1                                            ! inner domain indices
266         jpjm1 = jpj-1                                            !   "           "
267         jpkm1 = jpk-1                                            !   "           "
268         jpij  = jpi*jpj                                          !  jpi x j
269      ENDIF
270
[1593]271      IF(lwp) THEN                            ! open listing units
272         !
[1581]273         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
[1593]274         !
[1579]275         WRITE(numout,*)
[3294]276         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
[1593]277         WRITE(numout,*) '                       NEMO team'
[1579]278         WRITE(numout,*) '            Ocean General Circulation Model'
[3294]279         WRITE(numout,*) '                  version 3.4  (2011) '
[1579]280         WRITE(numout,*)
281         WRITE(numout,*)
[3604]282         DO ji = 1, SIZE(cltxt)
[1593]283            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
[1579]284         END DO
[1593]285         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
286         !
[473]287      ENDIF
[2715]288
[3604]289      ! Now we know the dimensions of the grid and numout has been set we can
[2715]290      ! allocate arrays
291      CALL nemo_alloc()
292
[2496]293      !                             !-------------------------------!
294      !                             !  NEMO general initialization  !
295      !                             !-------------------------------!
[473]296
[2496]297      CALL nemo_ctl                          ! Control prints & Benchmark
[531]298
[2082]299      !                                      ! Domain decomposition
[1593]300      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
301      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
[3]302      ENDIF
[2382]303      !
[3294]304      IF( nn_timing == 1 )  CALL timing_init
305      !
[2082]306      !                                      ! General initialization
[2027]307                            CALL     phy_cst    ! Physical constants
308                            CALL     eos_init   ! Equation of state
309                            CALL     dom_cfg    ! Domain configuration
310                            CALL     dom_init   ! Domain
[413]311
[3294]312      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
313
[2027]314      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
315
[3604]316      IF( lk_obc        )   CALL     obc_init   ! Open boundaries
[3294]317      IF( lk_bdy        )   CALL     bdy_init       ! Open boundaries initialisation
318      IF( lk_bdy        )   CALL     bdy_dta_init   ! Open boundaries initialisation of external data arrays
319      IF( lk_bdy        )   CALL     tide_init      ! Open boundaries initialisation of tidal harmonic forcing
[2027]320
[3294]321                            CALL flush(numout)
322                            CALL dyn_nept_init  ! simplified form of Neptune effect
323                            CALL flush(numout)
324
[2027]325                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
326
[3]327      !                                     ! Ocean physics
[3604]328                            CALL     sbc_init   ! Forcings : surface module
[2082]329      !                                         ! Vertical physics
330                            CALL     zdf_init      ! namelist read
331                            CALL zdf_bfr_init      ! bottom friction
332      IF( lk_zdfric     )   CALL zdf_ric_init      ! Richardson number dependent Kz
[2329]333      IF( lk_zdftke     )   CALL zdf_tke_init      ! TKE closure scheme
334      IF( lk_zdfgls     )   CALL zdf_gls_init      ! GLS closure scheme
335      IF( lk_zdfkpp     )   CALL zdf_kpp_init      ! KPP closure scheme
[2082]336      IF( lk_zdftmx     )   CALL zdf_tmx_init      ! tidal vertical mixing
[3604]337      IF( lk_zdfddm .AND. .NOT. lk_zdfkpp )   &
[2082]338         &                  CALL zdf_ddm_init      ! double diffusive mixing
339      !                                         ! Lateral physics
340                            CALL ldf_tra_init      ! Lateral ocean tracer physics
341                            CALL ldf_dyn_init      ! Lateral ocean momentum physics
[2392]342      IF( lk_ldfslp     )   CALL ldf_slp_init      ! slope of lateral mixing
[2082]343
[2027]344      !                                     ! Active tracers
345                            CALL tra_qsr_init   ! penetrative solar radiation qsr
[2325]346                            CALL tra_bbc_init   ! bottom heat flux
[2027]347      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
[3294]348      IF( ln_tradmp     )   CALL tra_dmp_init   ! internal damping trends
[2027]349                            CALL tra_adv_init   ! horizontal & vertical advection
350                            CALL tra_ldf_init   ! lateral mixing
351                            CALL tra_zdf_init   ! vertical mixing and after tracer fields
352
353      !                                     ! Dynamics
354                            CALL dyn_adv_init   ! advection (vector or flux form)
[2104]355                            CALL dyn_vor_init   ! vorticity term including Coriolis
[2027]356                            CALL dyn_ldf_init   ! lateral mixing
[2104]357                            CALL dyn_hpg_init   ! horizontal gradient of Hydrostatic pressure
[2027]358                            CALL dyn_zdf_init   ! vertical diffusion
359                            CALL dyn_spg_init   ! surface pressure gradient
[3604]360
[2392]361      !                                     ! Misc. options
362      IF( nn_cla == 1   )   CALL cla_init       ! Cross Land Advection
[3604]363
[1594]364#if defined key_top
[2027]365      !                                     ! Passive tracers
[2082]366                            CALL     trc_init
[1594]367#endif
[2382]368      !                                     ! Diagnostics
[3294]369      IF( lk_floats     )   CALL     flo_init   ! drifting Floats
[2027]370                            CALL     iom_init   ! iom_put initialization
[2392]371      IF( lk_diaar5     )   CALL dia_ar5_init   ! ar5 diag
[2027]372                            CALL dia_ptr_init   ! Poleward TRansports initialization
[3294]373      IF( lk_diadct     )   CALL dia_dct_init   ! Sections tranports
[2148]374                            CALL dia_hsb_init   ! heat content, salt content and volume budgets
[2027]375                            CALL trd_mod_init   ! Mixed-layer/Vorticity/Integral constraints trends
[2392]376      IF( lk_diaobs     ) THEN                  ! Observation & model comparison
[2382]377                            CALL dia_obs_init            ! Initialize observational data
378                            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
[3604]379      ENDIF
[2382]380      !                                     ! Assimilation increments
[2392]381      IF( lk_asminc     )   CALL asm_inc_init   ! Initialize assimilation increments
[2382]382      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
[3604]383                            CALL tam_trj_init ! Trajectory handling
[1593]384      !
[2496]385   END SUBROUTINE nemo_init
[467]386
387
[2496]388   SUBROUTINE nemo_ctl
[467]389      !!----------------------------------------------------------------------
[2496]390      !!                     ***  ROUTINE nemo_ctl  ***
[467]391      !!
[3604]392      !! ** Purpose :   control print setting
[467]393      !!
[2442]394      !! ** Method  : - print namctl information and check some consistencies
[467]395      !!----------------------------------------------------------------------
[2442]396      !
[2496]397      IF(lwp) THEN                  ! control print
[531]398         WRITE(numout,*)
[2496]399         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
[531]400         WRITE(numout,*) '~~~~~~~ '
[1593]401         WRITE(numout,*) '   Namelist namctl'
[1601]402         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
403         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
404         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
405         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
406         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
407         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
408         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
409         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
410         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
[3352]411         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
[531]412      ENDIF
[2442]413      !
[1601]414      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
415      nictls    = nn_ictls
416      nictle    = nn_ictle
417      njctls    = nn_jctls
418      njctle    = nn_jctle
419      isplt     = nn_isplt
420      jsplt     = nn_jsplt
421      nbench    = nn_bench
[2442]422      !                             ! Parameter control
[1593]423      !
424      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
[3294]425         IF( lk_mpp .AND. jpnij > 1 ) THEN
[2496]426            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
[531]427         ELSE
428            IF( isplt == 1 .AND. jsplt == 1  ) THEN
[1593]429               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
430                  &           ' - the print control will be done over the whole domain' )
[531]431            ENDIF
[1593]432            ijsplt = isplt * jsplt            ! total number of processors ijsplt
[531]433         ENDIF
434         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
435         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
[1593]436         !
437         !                              ! indices used for the SUM control
438         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
[3604]439            lsp_area = .FALSE.
[1593]440         ELSE                                             ! print control done over a specific  area
[531]441            lsp_area = .TRUE.
442            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
443               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
444               nictls = 1
445            ENDIF
446            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
447               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
448               nictle = jpiglo
449            ENDIF
450            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
451               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
452               njctls = 1
453            ENDIF
454            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
455               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
456               njctle = jpjglo
457            ENDIF
[1593]458         ENDIF
459      ENDIF
[2442]460      !
[3604]461      IF( nbench == 1 ) THEN              ! Benchmark
[531]462         SELECT CASE ( cp_cfg )
[1593]463         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
464         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
465            &                                 ' key_gyre must be used or set nbench = 0' )
[531]466         END SELECT
467      ENDIF
[1593]468      !
[2496]469      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
470         &                                               'with the IOM Input/Output manager. '         ,   &
[2442]471         &                                               'Compile with key_iomput enabled' )
[2409]472      !
[3558]473      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
474         &                                               'f2003 standard. '                              ,  &
475         &                                               'Compile with key_nosignedzero enabled' )
476      !
[2496]477   END SUBROUTINE nemo_ctl
[467]478
479
[2496]480   SUBROUTINE nemo_closefile
[467]481      !!----------------------------------------------------------------------
[2496]482      !!                     ***  ROUTINE nemo_closefile  ***
[467]483      !!
484      !! ** Purpose :   Close the files
485      !!----------------------------------------------------------------------
[1593]486      !
487      IF( lk_mpp )   CALL mppsync
488      !
[1685]489      CALL iom_close                                 ! close all input/output files managed by iom_*
[1593]490      !
[3294]491      IF( numstp      /= -1 )   CLOSE( numstp      )   ! time-step file
492      IF( numsol      /= -1 )   CLOSE( numsol      )   ! solver file
493      IF( numnam      /= -1 )   CLOSE( numnam      )   ! oce namelist
494      IF( numnam_ice  /= -1 )   CLOSE( numnam_ice  )   ! ice namelist
495      IF( numevo_ice  /= -1 )   CLOSE( numevo_ice  )   ! ice variables (temp. evolution)
496      IF( numout      /=  6 )   CLOSE( numout      )   ! standard model output file
497      IF( numdct_vol  /= -1 )   CLOSE( numdct_vol  )   ! volume transports
498      IF( numdct_heat /= -1 )   CLOSE( numdct_heat )   ! heat transports
499      IF( numdct_salt /= -1 )   CLOSE( numdct_salt )   ! salt transports
500
[1593]501      !
[2442]502      numout = 6                                     ! redefine numout in case it is used after this point...
503      !
[2496]504   END SUBROUTINE nemo_closefile
[467]505
[2715]506
507   SUBROUTINE nemo_alloc
508      !!----------------------------------------------------------------------
509      !!                     ***  ROUTINE nemo_alloc  ***
510      !!
511      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
512      !!
513      !! ** Method  :
514      !!----------------------------------------------------------------------
515      USE diawri    , ONLY: dia_wri_alloc
516      USE dom_oce   , ONLY: dom_oce_alloc
517      USE ldfdyn_oce, ONLY: ldfdyn_oce_alloc
518      USE ldftra_oce, ONLY: ldftra_oce_alloc
519      USE trc_oce   , ONLY: trc_oce_alloc
520      !
521      INTEGER :: ierr
522      !!----------------------------------------------------------------------
523      !
[3604]524      ierr =        oce_alloc       ()          ! ocean
[2715]525      ierr = ierr + dia_wri_alloc   ()
526      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
527      ierr = ierr + ldfdyn_oce_alloc()          ! ocean lateral  physics : dynamics
528      ierr = ierr + ldftra_oce_alloc()          ! ocean lateral  physics : tracers
529      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
530      !
531      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
532      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
533      !
534      IF( lk_mpp    )   CALL mpp_sum( ierr )
535      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
536      !
537   END SUBROUTINE nemo_alloc
538
539
540   SUBROUTINE nemo_partition( num_pes )
541      !!----------------------------------------------------------------------
542      !!                 ***  ROUTINE nemo_partition  ***
543      !!
[3604]544      !! ** Purpose :
[2715]545      !!
546      !! ** Method  :
547      !!----------------------------------------------------------------------
548      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
549      !
550      INTEGER, PARAMETER :: nfactmax = 20
551      INTEGER :: nfact ! The no. of factors returned
552      INTEGER :: ierr  ! Error flag
553      INTEGER :: ji
554      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
555      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
556      !!----------------------------------------------------------------------
557
558      ierr = 0
559
560      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
561
562      IF( nfact <= 1 ) THEN
563         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
564         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
565         jpnj = 1
566         jpni = num_pes
567      ELSE
568         ! Search through factors for the pair that are closest in value
569         mindiff = 1000000
570         imin    = 1
571         DO ji = 1, nfact-1, 2
572            idiff = ABS( ifact(ji) - ifact(ji+1) )
573            IF( idiff < mindiff ) THEN
574               mindiff = idiff
575               imin = ji
576            ENDIF
577         END DO
578         jpnj = ifact(imin)
579         jpni = ifact(imin + 1)
580      ENDIF
581      !
582      jpnij = jpni*jpnj
583      !
584   END SUBROUTINE nemo_partition
585
586
587   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
588      !!----------------------------------------------------------------------
589      !!                     ***  ROUTINE factorise  ***
590      !!
591      !! ** Purpose :   return the prime factors of n.
[3604]592      !!                knfax factors are returned in array kfax which is of
[2715]593      !!                maximum dimension kmaxfax.
594      !! ** Method  :
595      !!----------------------------------------------------------------------
596      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
597      INTEGER                    , INTENT(  out) ::   kerr, knfax
598      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
599      !
600      INTEGER :: ifac, jl, inu
601      INTEGER, PARAMETER :: ntest = 14
602      INTEGER :: ilfax(ntest)
603
604      ! lfax contains the set of allowed factors.
605      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
606         &                            128,   64,   32,   16,    8,   4,   2  /
607      !!----------------------------------------------------------------------
608
609      ! Clear the error flag and initialise output vars
610      kerr = 0
611      kfax = 1
612      knfax = 0
613
614      ! Find the factors of n.
615      IF( kn == 1 )   GOTO 20
616
617      ! nu holds the unfactorised part of the number.
618      ! knfax holds the number of factors found.
619      ! l points to the allowed factor list.
620      ! ifac holds the current factor.
621
622      inu   = kn
623      knfax = 0
624
625      DO jl = ntest, 1, -1
626         !
627         ifac = ilfax(jl)
628         IF( ifac > inu )   CYCLE
629
630         ! Test whether the factor will divide.
631
632         IF( MOD(inu,ifac) == 0 ) THEN
633            !
634            knfax = knfax + 1            ! Add the factor to the list
635            IF( knfax > kmaxfax ) THEN
636               kerr = 6
637               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
638               return
639            ENDIF
640            kfax(knfax) = ifac
641            ! Store the other factor that goes with this one
642            knfax = knfax + 1
643            kfax(knfax) = inu / ifac
644            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
645         ENDIF
646         !
647      END DO
648
649   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
650      !
651   END SUBROUTINE factorise
652
[3294]653#if defined key_mpp_mpi
654   SUBROUTINE nemo_northcomms
655      !!======================================================================
656      !!                     ***  ROUTINE  nemo_northcomms  ***
657      !! nemo_northcomms    :  Setup for north fold exchanges with explicit peer to peer messaging
658      !!=====================================================================
659      !!----------------------------------------------------------------------
[3604]660      !!
[3294]661      !! ** Purpose :   Initialization of the northern neighbours lists.
662      !!----------------------------------------------------------------------
[3604]663      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
[3294]664      !!----------------------------------------------------------------------
665
666      INTEGER ::   ji, jj, jk, ij, jtyp    ! dummy loop indices
667      INTEGER ::   ijpj                    ! number of rows involved in north-fold exchange
668      INTEGER ::   northcomms_alloc        ! allocate return status
669      REAL(wp), ALLOCATABLE, DIMENSION ( :,: ) ::   znnbrs     ! workspace
670      LOGICAL,  ALLOCATABLE, DIMENSION ( : )   ::   lrankset   ! workspace
671
672      IF(lwp) WRITE(numout,*)
673      IF(lwp) WRITE(numout,*) 'nemo_northcomms : Initialization of the northern neighbours lists'
674      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
675
676      !!----------------------------------------------------------------------
677      ALLOCATE( znnbrs(jpi,jpj), stat = northcomms_alloc )
678      ALLOCATE( lrankset(jpnij), stat = northcomms_alloc )
679      IF( northcomms_alloc /= 0 ) THEN
680         WRITE(numout,cform_war)
681         WRITE(numout,*) 'northcomms_alloc : failed to allocate arrays'
682         CALL ctl_stop( 'STOP', 'nemo_northcomms : unable to allocate temporary arrays' )
683      ENDIF
684      nsndto = 0
685      isendto = -1
686      ijpj   = 4
687      !
688      ! This routine has been called because ln_nnogather has been set true ( nammpp )
689      ! However, these first few exchanges have to use the mpi_allgather method to
690      ! establish the neighbour lists to use in subsequent peer to peer exchanges.
691      ! Consequently, set l_north_nogather to be false here and set it true only after
692      ! the lists have been established.
693      !
694      l_north_nogather = .FALSE.
695      !
696      ! Exchange and store ranks on northern rows
697
698      DO jtyp = 1,4
699
700         lrankset = .FALSE.
701         znnbrs = narea
702         SELECT CASE (jtyp)
703            CASE(1)
704               CALL lbc_lnk( znnbrs, 'T', 1. )      ! Type 1: T,W-points
705            CASE(2)
706               CALL lbc_lnk( znnbrs, 'U', 1. )      ! Type 2: U-point
707            CASE(3)
708               CALL lbc_lnk( znnbrs, 'V', 1. )      ! Type 3: V-point
709            CASE(4)
710               CALL lbc_lnk( znnbrs, 'F', 1. )      ! Type 4: F-point
711         END SELECT
712
713         IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
714            DO jj = nlcj-ijpj+1, nlcj
715               ij = jj - nlcj + ijpj
716               DO ji = 1,jpi
717                  IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
718               &     lrankset(INT(znnbrs(ji,jj))) = .true.
719               END DO
720            END DO
721
722            DO jj = 1,jpnij
723               IF ( lrankset(jj) ) THEN
724                  nsndto(jtyp) = nsndto(jtyp) + 1
725                  IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
726                     CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
727                  &                 ' jpmaxngh will need to be increased ')
728                  ENDIF
729                  isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
730               ENDIF
731            END DO
732         ENDIF
733
734      END DO
735
736      !
737      ! Type 5: I-point
738      !
739      ! ICE point exchanges may involve some averaging. The neighbours list is
740      ! built up using two exchanges to ensure that the whole stencil is covered.
741      ! lrankset should not be reset between these 'J' and 'K' point exchanges
742
743      jtyp = 5
744      lrankset = .FALSE.
[3604]745      znnbrs = narea
[3294]746      CALL lbc_lnk( znnbrs, 'J', 1. ) ! first ice U-V point
747
748      IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
749         DO jj = nlcj-ijpj+1, nlcj
750            ij = jj - nlcj + ijpj
751            DO ji = 1,jpi
752               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
753            &     lrankset(INT(znnbrs(ji,jj))) = .true.
754         END DO
755        END DO
756      ENDIF
757
[3604]758      znnbrs = narea
[3294]759      CALL lbc_lnk( znnbrs, 'K', 1. ) ! second ice U-V point
760
761      IF ( njmppt(narea) .EQ. MAXVAL( njmppt )) THEN
762         DO jj = nlcj-ijpj+1, nlcj
763            ij = jj - nlcj + ijpj
764            DO ji = 1,jpi
765               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND.  INT(znnbrs(ji,jj)) .NE. narea ) &
766            &       lrankset( INT(znnbrs(ji,jj))) = .true.
767            END DO
768         END DO
769
770         DO jj = 1,jpnij
771            IF ( lrankset(jj) ) THEN
772               nsndto(jtyp) = nsndto(jtyp) + 1
773               IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
774                  CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
775               &                 ' jpmaxngh will need to be increased ')
776               ENDIF
777               isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
778            ENDIF
779         END DO
780         !
[3604]781         ! For northern row areas, set l_north_nogather so that all subsequent exchanges
[3294]782         ! can use peer to peer communications at the north fold
783         !
784         l_north_nogather = .TRUE.
785         !
786      ENDIF
787      DEALLOCATE( znnbrs )
788      DEALLOCATE( lrankset )
789
790   END SUBROUTINE nemo_northcomms
791#else
792   SUBROUTINE nemo_northcomms      ! Dummy routine
793      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
794   END SUBROUTINE nemo_northcomms
795#endif
[3]796   !!======================================================================
[2496]797END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.