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

source: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90 @ 3318

Last change on this file since 3318 was 3318, checked in by gm, 12 years ago

Ediag branche: #927 split TRA/DYN trd computation

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