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/2013/dev_r3940_CNRS4_IOCRS/NEMOGCM/NEMO/OPA_SRC – NEMO

source: branches/2013/dev_r3940_CNRS4_IOCRS/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90 @ 4015

Last change on this file since 4015 was 4015, checked in by cetlod, 11 years ago

2013/dev_r3940_CNRS4_IOCRS: 1st step, add new routines for outputs coarsening

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