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

source: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 @ 2669

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

offline:minor updates to take into account mpp improvement

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