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/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OFF_SRC – NEMO

source: branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 @ 3154

Last change on this file since 3154 was 3154, checked in by cetlod, 13 years ago

Add timing for OFFLINE

File size: 22.5 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Off-line Ocean   : passive tracer evolution, dynamics read in files
5   !!======================================================================
6   !! History :  3.3  ! 2010-05  (C. Ethe)  Full reorganization of the off-line: phasing with the on-line
7   !!            4.0  ! 2011-01  (C. Ethe, A. R. Porter, STFC Daresbury) dynamical allocation
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   nemo_gcm        : off-line: solve ocean tracer only
12   !!   nemo_init       : initialization of the nemo model
13   !!   nemo_ctl        : initialisation of algorithm flag
14   !!   nemo_closefile  : close remaining files
15   !!----------------------------------------------------------------------
16   USE dom_oce         ! ocean space domain variables
17   USE oce             ! dynamics and tracers variables
18   USE c1d             ! 1D configuration
19   USE domcfg          ! domain configuration               (dom_cfg routine)
20   USE domain          ! domain initialization             (dom_init routine)
21   USE istate          ! initial state setting          (istate_init routine)
22   USE eosbn2          ! equation of state            (eos bn2 routine)
23   !              ! ocean physics
24   USE ldftra          ! lateral diffusivity setting    (ldf_tra_init routine)
25   USE ldfslp          ! slopes of neutral surfaces     (ldf_slp_init routine)
26   USE traqsr          ! solar radiation penetration    (tra_qsr_init routine)
27   USE trabbl          ! bottom boundary layer          (tra_bbl_init routine)
28   USE zdfini          ! vertical physics: initialization
29   USE sbcmod          ! surface boundary condition       (sbc_init     routine)
30   USE phycst          ! physical constant                  (par_cst routine)
31   USE dtadyn          ! Lecture and Interpolation of the dynamical fields
32   USE trcini          ! Initilization of the passive tracers
33   USE daymod          ! calendar                         (day     routine)
34   USE trcstp          ! passive tracer time-stepping      (trc_stp routine)
35   USE dtadyn          ! Lecture and interpolation of the dynamical fields
36   USE stpctl          ! time stepping control            (stp_ctl routine)
37   !              ! I/O & MPP
38   USE iom             ! I/O library
39   USE in_out_manager  ! I/O manager
40   USE mppini          ! shared/distributed memory setting (mpp_init routine)
41   USE lib_mpp         ! distributed memory computing
42#if defined key_iomput
43   USE mod_ioclient
44#endif
45   USE prtctl           ! Print control                    (prt_ctl_init routine)
46
47   IMPLICIT NONE
48   PRIVATE
49   
50   PUBLIC   nemo_gcm   ! called by nemo.F90
51
52   CHARACTER (len=64) ::   cform_aaa="( /, 'AAAAAAAA', / ) "   ! flag for output listing
53
54   !!----------------------------------------------------------------------
55   !! NEMO/OFF 3.3 , NEMO Consortium (2010)
56   !! $Id: nemogcm.F90 2528 2010-12-27 17:33:53Z rblod $
57   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
58   !!----------------------------------------------------------------------
59CONTAINS
60
61   SUBROUTINE nemo_gcm
62      !!----------------------------------------------------------------------
63      !!                     ***  ROUTINE nemo_gcm  ***
64      !!
65      !! ** Purpose :   nemo solves the primitive equations on an orthogonal
66      !!      curvilinear mesh on the sphere.
67      !!
68      !! ** Method  : - model general initialization
69      !!              - launch the time-stepping (dta_dyn and trc_stp)
70      !!              - finalize the run by closing files and communications
71      !!
72      !! References : Madec, Delecluse,Imbard, and Levy, 1997:  internal report, IPSL.
73      !!              Madec, 2008, internal report, IPSL.
74      !!----------------------------------------------------------------------
75      INTEGER :: istp, indic       ! time step index
76      !!----------------------------------------------------------------------
77
78      CALL nemo_init  ! Initializations
79
80      IF( lk_mpp )   CALL mpp_max( nstop )
81
82      ! check that all process are still there... If some process have an error,
83      ! they will never enter in step and other processes will wait until the end of the cpu time!
84      IF( lk_mpp )   CALL mpp_max( nstop )
85
86      !                            !-----------------------!
87      !                            !==   time stepping   ==!
88      !                            !-----------------------!
89      istp = nit000
90         !
91      DO WHILE ( istp <= nitend .AND. nstop == 0 )    ! time stepping
92         !
93         IF( istp /= nit000 )   CALL day      ( istp )         ! Calendar (day was already called at nit000 in day_init)
94                                CALL iom_setkt( istp )         ! say to iom that we are at time step kstp
95                                CALL dta_dyn  ( istp )         ! Interpolation of the dynamical fields
96                                CALL trc_stp  ( istp )         ! time-stepping
97                                CALL stp_ctl  ( istp, indic )  ! Time loop: control and print
98         istp = istp + 1
99         IF( lk_mpp )   CALL mpp_max( nstop )
100      END DO
101
102      !                            !------------------------!
103      !                            !==  finalize the run  ==!
104      !                            !------------------------!
105      IF(lwp) WRITE(numout,cform_aaa)                 ! Flag AAAAAAA
106
107      IF( nstop /= 0 .AND. lwp ) THEN                 ! error print
108         WRITE(numout,cform_err)
109         WRITE(numout,*) nstop, ' error have been found'
110      ENDIF
111      !
112      IF( nn_timing == 1 )   CALL timing_finalize
113      !
114      CALL nemo_closefile
115      !
116      IF( lk_mpp )   CALL mppstop                          ! Close all files (mpp)
117      !
118   END SUBROUTINE nemo_gcm
119
120
121   SUBROUTINE nemo_init
122      !!----------------------------------------------------------------------
123      !!                     ***  ROUTINE nemo_init ***
124      !!
125      !! ** Purpose :   initialization of the nemo model in off-line mode
126      !!----------------------------------------------------------------------
127      INTEGER ::   ji            ! dummy loop indices
128      INTEGER ::   ilocal_comm   ! local integer
129      CHARACTER(len=80), DIMENSION(16) ::   cltxt = ''
130      !!
131      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
132         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
133         &             nn_bench, nn_timing
134      !!----------------------------------------------------------------------
135      !
136      !                             ! open Namelist file     
137      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
138      !
139      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
140      !
141      !                             !--------------------------------------------!
142      !                             !  set communicator & select the local node  !
143      !                             !--------------------------------------------!
144#if defined key_iomput
145      CALL  init_ioclient( ilocal_comm )                 ! exchange io_server nemo local communicator with the io_server
146      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection
147#else
148      ilocal_comm = 0
149      narea = mynode( cltxt, numnam, nstop )                 ! Nodes selection (control print return in cltxt)
150#endif
151
152      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
153
154      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
155
156      ! If dimensions of processor grid weren't specified in the namelist file
157      ! then we calculate them here now that we have our communicator size
158      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
159#if   defined key_mpp_mpi   ||   defined key_mpp_shmem
160         CALL nemo_partition(mppsize)
161#else
162         jpni = 1
163         jpnj = 1
164         jpnij = jpni*jpnj
165#endif
166      END IF
167
168      ! Calculate domain dimensions given calculated jpni and jpnj
169      ! This used to be done in par_oce.F90 when they were parameters rather
170      ! than variables
171      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
172      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
173      jpk = jpkdta                                             ! third dim
174      jpim1 = jpi-1                                            ! inner domain indices
175      jpjm1 = jpj-1                                            !   "           "
176      jpkm1 = jpk-1                                            !   "           "
177      jpij  = jpi*jpj                                          !  jpi x j
178
179
180      IF(lwp) THEN                            ! open listing units
181         !
182         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
183         !
184         WRITE(numout,*)
185         WRITE(numout,*) '         CNRS - NERC - Met OFFICE - MERCATOR-ocean'
186         WRITE(numout,*) '                       NEMO team'
187         WRITE(numout,*) '            Ocean General Circulation Model'
188         WRITE(numout,*) '                  version 3.3  (2010) '
189         WRITE(numout,*)
190         WRITE(numout,*)
191         DO ji = 1, SIZE(cltxt) 
192            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
193         END DO
194         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
195         !
196      ENDIF
197
198      ! Now we know the dimensions of the grid and numout has been set we can
199      ! allocate arrays
200      CALL nemo_alloc()
201
202      !                             !--------------------------------!
203      !                             !  Model general initialization  !
204      !                             !--------------------------------!
205
206      CALL nemo_ctl                           ! Control prints & Benchmark
207
208      !                                      ! Domain decomposition
209      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
210      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
211      ENDIF
212      !
213      IF( nn_timing == 1 )  CALL timing_init
214      !
215
216      !                                      ! General initialization
217      IF( nn_timing == 1 )  CALL timing_start( 'nemo_init')
218      !
219                            CALL     phy_cst    ! Physical constants
220                            CALL     eos_init   ! Equation of state
221                            CALL     dom_cfg    ! Domain configuration
222                            CALL     dom_init   ! Domain
223                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
224
225      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
226
227      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
228
229      !                                     ! Ocean physics
230                            CALL     sbc_init   ! Forcings : surface module
231#if ! defined key_degrad
232                            CALL ldf_tra_init   ! Lateral ocean tracer physics
233#endif
234      IF( lk_ldfslp )       CALL ldf_slp_init   ! slope of lateral mixing
235
236      !                                     ! Active tracers
237                            CALL tra_qsr_init   ! penetrative solar radiation qsr
238      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
239
240      !                                     ! Passive tracers
241                            CALL     trc_init   ! Passive tracers initialization
242      !                                     ! Dynamics
243                            CALL dta_dyn_init   ! Initialization for the dynamics
244                            CALL     iom_init       ! iom_put initialization
245
246      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
247      !
248      IF( nn_timing == 1 )  CALL timing_stop( 'nemo_init')
249      !
250   END SUBROUTINE nemo_init
251
252
253   SUBROUTINE nemo_ctl
254      !!----------------------------------------------------------------------
255      !!                     ***  ROUTINE nemo_ctl  ***
256      !!
257      !! ** Purpose :   control print setting
258      !!
259      !! ** Method  : - print namctl information and check some consistencies
260      !!----------------------------------------------------------------------
261      !
262      IF(lwp) THEN                  ! Parameter print
263         WRITE(numout,*)
264         WRITE(numout,*) 'nemo_flg: Control prints & Benchmark'
265         WRITE(numout,*) '~~~~~~~ '
266         WRITE(numout,*) '   Namelist namctl'
267         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
268         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
269         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
270         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
271         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
272         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
273         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
274         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
275         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
276      ENDIF
277      !
278      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
279      nictls    = nn_ictls
280      nictle    = nn_ictle
281      njctls    = nn_jctls
282      njctle    = nn_jctle
283      isplt     = nn_isplt
284      jsplt     = nn_jsplt
285      nbench    = nn_bench
286      !                             ! Parameter control
287      !
288      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
289         IF( lk_mpp ) THEN
290            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real splitted domain
291         ELSE
292            IF( isplt == 1 .AND. jsplt == 1  ) THEN
293               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
294                  &           ' - the print control will be done over the whole domain' )
295            ENDIF
296            ijsplt = isplt * jsplt            ! total number of processors ijsplt
297         ENDIF
298         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
299         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
300         !
301         !                              ! indices used for the SUM control
302         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
303            lsp_area = .FALSE.
304         ELSE                                             ! print control done over a specific  area
305            lsp_area = .TRUE.
306            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
307               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
308               nictls = 1
309            ENDIF
310            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
311               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
312               nictle = jpiglo
313            ENDIF
314            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
315               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
316               njctls = 1
317            ENDIF
318            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
319               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
320               njctle = jpjglo
321            ENDIF
322         ENDIF
323      ENDIF
324      !
325      IF( nbench == 1 )   THEN            ! Benchmark
326         SELECT CASE ( cp_cfg )
327         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
328         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
329            &                                 ' key_gyre must be used or set nbench = 0' )
330         END SELECT
331      ENDIF
332      !
333      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
334         &                                               'with the IOM Input/Output manager. '        ,   &
335         &                                               'Compile with key_iomput enabled' )
336      !
337   END SUBROUTINE nemo_ctl
338
339
340   SUBROUTINE nemo_closefile
341      !!----------------------------------------------------------------------
342      !!                     ***  ROUTINE nemo_closefile  ***
343      !!
344      !! ** Purpose :   Close the files
345      !!----------------------------------------------------------------------
346      !
347      IF ( lk_mpp ) CALL mppsync
348      !
349      CALL iom_close                                 ! close all input/output files managed by iom_*
350      !
351      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
352      IF( numnam     /= -1 )   CLOSE( numnam     )   ! oce namelist
353      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
354      numout = 6                                     ! redefine numout in case it is used after this point...
355      !
356   END SUBROUTINE nemo_closefile
357
358
359   SUBROUTINE nemo_alloc
360      !!----------------------------------------------------------------------
361      !!                     ***  ROUTINE nemo_alloc  ***
362      !!
363      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
364      !!
365      !! ** Method  :
366      !!----------------------------------------------------------------------
367      USE diawri,       ONLY: dia_wri_alloc
368      USE dom_oce,      ONLY: dom_oce_alloc
369      USE zdf_oce,      ONLY: zdf_oce_alloc
370      USE ldftra_oce,   ONLY: ldftra_oce_alloc
371      USE trc_oce,      ONLY: trc_oce_alloc
372      USE wrk_nemo,    ONLY: wrk_alloc
373      !
374      INTEGER :: ierr
375      !!----------------------------------------------------------------------
376      !
377      ierr =        oce_alloc       ()          ! ocean
378      ierr = ierr + dia_wri_alloc   ()
379      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
380      ierr = ierr + ldftra_oce_alloc()          ! ocean lateral  physics : tracers
381      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
382      !
383      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
384      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
385      ierr = ierr + wrk_alloc(numout, lwp)
386      !
387      IF( lk_mpp    )   CALL mpp_sum( ierr )
388      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
389      !
390   END SUBROUTINE nemo_alloc
391
392
393   SUBROUTINE nemo_partition( num_pes )
394      !!----------------------------------------------------------------------
395      !!                 ***  ROUTINE nemo_partition  ***
396      !!
397      !! ** Purpose :   
398      !!
399      !! ** Method  :
400      !!----------------------------------------------------------------------
401      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
402      !
403      INTEGER, PARAMETER :: nfactmax = 20
404      INTEGER :: nfact ! The no. of factors returned
405      INTEGER :: ierr  ! Error flag
406      INTEGER :: ji
407      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
408      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
409      !!----------------------------------------------------------------------
410
411      ierr = 0
412
413      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
414
415      IF( nfact <= 1 ) THEN
416         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
417         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
418         jpnj = 1
419         jpni = num_pes
420      ELSE
421         ! Search through factors for the pair that are closest in value
422         mindiff = 1000000
423         imin    = 1
424         DO ji = 1, nfact-1, 2
425            idiff = ABS( ifact(ji) - ifact(ji+1) )
426            IF( idiff < mindiff ) THEN
427               mindiff = idiff
428               imin = ji
429            ENDIF
430         END DO
431         jpnj = ifact(imin)
432         jpni = ifact(imin + 1)
433      ENDIF
434      !
435      jpnij = jpni*jpnj
436      !
437   END SUBROUTINE nemo_partition
438
439
440   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
441      !!----------------------------------------------------------------------
442      !!                     ***  ROUTINE factorise  ***
443      !!
444      !! ** Purpose :   return the prime factors of n.
445      !!                knfax factors are returned in array kfax which is of
446      !!                maximum dimension kmaxfax.
447      !! ** Method  :
448      !!----------------------------------------------------------------------
449      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
450      INTEGER                    , INTENT(  out) ::   kerr, knfax
451      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
452      !
453      INTEGER :: ifac, jl, inu
454      INTEGER, PARAMETER :: ntest = 14
455      INTEGER :: ilfax(ntest)
456      !
457      ! lfax contains the set of allowed factors.
458      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
459         &                            128,   64,   32,   16,    8,   4,   2  /
460      !!----------------------------------------------------------------------
461
462      ! Clear the error flag and initialise output vars
463      kerr = 0
464      kfax = 1
465      knfax = 0
466
467      ! Find the factors of n.
468      IF( kn == 1 )   GOTO 20
469
470      ! nu holds the unfactorised part of the number.
471      ! knfax holds the number of factors found.
472      ! l points to the allowed factor list.
473      ! ifac holds the current factor.
474
475      inu   = kn
476      knfax = 0
477
478      DO jl = ntest, 1, -1
479         !
480         ifac = ilfax(jl)
481         IF( ifac > inu )   CYCLE
482
483         ! Test whether the factor will divide.
484
485         IF( MOD(inu,ifac) == 0 ) THEN
486            !
487            knfax = knfax + 1            ! Add the factor to the list
488            IF( knfax > kmaxfax ) THEN
489               kerr = 6
490               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
491               return
492            ENDIF
493            kfax(knfax) = ifac
494            ! Store the other factor that goes with this one
495            knfax = knfax + 1
496            kfax(knfax) = inu / ifac
497            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
498         ENDIF
499         !
500      END DO
501
502   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
503      !
504   END SUBROUTINE factorise
505
506   !!======================================================================
507END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.