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 @ 2648

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

Changed OFF_SRC component to use dynamic memory

File size: 21.8 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(10) ::   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      ! Decide on size of grid now that we have our communicator size
153      ! If we're not using dynamic memory then mpp_partition does nothing.
154
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      ! Calculate domain dimensions given calculated jpni and jpnj
163      ! This used to be done in par_oce.F90 when they were parameters rather
164      ! than variables
165      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci !: first  dim.
166      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj !: second dim.
167      jpim1 = jpi-1                                          !: inner domain indices
168      jpjm1 = jpj-1                                          !:   "           "
169      jpkm1 = jpk-1                                          !:   "           "
170      jpij  = jpi*jpj                                        !:  jpi x j
171
172      ! Now we know the dimensions of the grid, allocate arrays
173      CALL nemo_alloc()
174
175      IF(lwp) THEN                            ! open listing units
176         !
177         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
178         !
179         WRITE(numout,*)
180         WRITE(numout,*) '         CNRS - NERC - Met OFFICE - MERCATOR-ocean'
181         WRITE(numout,*) '                       NEMO team'
182         WRITE(numout,*) '            Ocean General Circulation Model'
183         WRITE(numout,*) '                  version 3.3  (2010) '
184         WRITE(numout,*)
185         WRITE(numout,*)
186         DO ji = 1, SIZE(cltxt) 
187            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
188         END DO
189         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
190         !
191      ENDIF
192      !                             !--------------------------------!
193      !                             !  Model general initialization  !
194      !                             !--------------------------------!
195
196      CALL nemo_ctl                           ! Control prints & Benchmark
197
198      !                                      ! Domain decomposition
199      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
200      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
201      ENDIF
202      !
203      !                                      ! General initialization
204                            CALL     phy_cst    ! Physical constants
205                            CALL     eos_init   ! Equation of state
206                            CALL     dom_cfg    ! Domain configuration
207                            CALL     dom_init   ! Domain
208                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
209
210      !                                     ! Ocean physics
211                            CALL     sbc_init   ! Forcings : surface module
212#if ! defined key_degrad
213                            CALL ldf_tra_init   ! Lateral ocean tracer physics
214#endif
215      IF( lk_ldfslp )       CALL ldf_slp_init   ! slope of lateral mixing
216
217      !                                     ! Active tracers
218                            CALL tra_qsr_init   ! penetrative solar radiation qsr
219      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
220
221      !                                     ! Passive tracers
222                            CALL     trc_init   ! Passive tracers initialization
223      !                                     ! Dynamics
224                            CALL dta_dyn_init   ! Initialization for the dynamics
225                            CALL     iom_init       ! iom_put initialization
226
227      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
228      !
229   END SUBROUTINE nemo_init
230
231
232   SUBROUTINE nemo_ctl
233      !!----------------------------------------------------------------------
234      !!                     ***  ROUTINE nemo_ctl  ***
235      !!
236      !! ** Purpose :   control print setting
237      !!
238      !! ** Method  : - print namctl information and check some consistencies
239      !!----------------------------------------------------------------------
240      !
241      IF(lwp) THEN                  ! Parameter print
242         WRITE(numout,*)
243         WRITE(numout,*) 'nemo_flg: Control prints & Benchmark'
244         WRITE(numout,*) '~~~~~~~ '
245         WRITE(numout,*) '   Namelist namctl'
246         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
247         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
248         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
249         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
250         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
251         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
252         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
253         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
254         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
255      ENDIF
256      !
257      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
258      nictls    = nn_ictls
259      nictle    = nn_ictle
260      njctls    = nn_jctls
261      njctle    = nn_jctle
262      isplt     = nn_isplt
263      jsplt     = nn_jsplt
264      nbench    = nn_bench
265      !                             ! Parameter control
266      !
267      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
268         IF( lk_mpp ) THEN
269            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real splitted domain
270         ELSE
271            IF( isplt == 1 .AND. jsplt == 1  ) THEN
272               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
273                  &           ' - the print control will be done over the whole domain' )
274            ENDIF
275            ijsplt = isplt * jsplt            ! total number of processors ijsplt
276         ENDIF
277         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
278         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
279         !
280         !                              ! indices used for the SUM control
281         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
282            lsp_area = .FALSE.
283         ELSE                                             ! print control done over a specific  area
284            lsp_area = .TRUE.
285            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
286               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
287               nictls = 1
288            ENDIF
289            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
290               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
291               nictle = jpiglo
292            ENDIF
293            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
294               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
295               njctls = 1
296            ENDIF
297            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
298               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
299               njctle = jpjglo
300            ENDIF
301         ENDIF
302      ENDIF
303      !
304      IF( nbench == 1 )   THEN            ! Benchmark
305         SELECT CASE ( cp_cfg )
306         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
307         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
308            &                                 ' key_gyre must be used or set nbench = 0' )
309         END SELECT
310      ENDIF
311      !
312      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
313         &                                               'with the IOM Input/Output manager. '        ,   &
314         &                                               'Compile with key_iomput enabled' )
315      !
316   END SUBROUTINE nemo_ctl
317
318
319   SUBROUTINE nemo_closefile
320      !!----------------------------------------------------------------------
321      !!                     ***  ROUTINE nemo_closefile  ***
322      !!
323      !! ** Purpose :   Close the files
324      !!----------------------------------------------------------------------
325      !
326      IF ( lk_mpp ) CALL mppsync
327      !
328      CALL iom_close                                 ! close all input/output files managed by iom_*
329      !
330      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
331      IF( numnam     /= -1 )   CLOSE( numnam     )   ! oce namelist
332      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
333      numout = 6                                     ! redefine numout in case it is used after this point...
334      !
335   END SUBROUTINE nemo_closefile
336
337   SUBROUTINE nemo_alloc
338     !!----------------------------------------------------------------------
339     !!                     ***  ROUTINE nemo_alloc  ***
340     !!
341     !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
342     !!
343     !! ** Method  :
344     !!----------------------------------------------------------------------
345     USE diawri,       ONLY: dia_wri_alloc
346     USE dom_oce,      ONLY: dom_oce_alloc
347     USE zdf_oce,      ONLY: zdf_oce_alloc
348     USE zdfmxl,       ONLY: zdf_mxl_alloc
349     USE ldftra_oce,   ONLY: ldftra_oce_alloc
350     USE trc_oce,      ONLY: trc_oce_alloc
351
352      USE wrk_nemo,    ONLY: wrk_alloc
353
354      INTEGER :: ierr
355      !!----------------------------------------------------------------------
356
357      ierr =        oce_alloc       ()          ! ocean
358      ierr = ierr + dia_wri_alloc   ()
359      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
360      ierr = ierr + ldftra_oce_alloc()          ! ocean lateral  physics : tracers
361      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
362      ierr = ierr + zdf_mxl_alloc   ()          ! ocean vertical physics
363      !
364      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
365      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
366      ierr = ierr + wrk_alloc(numout, lwp)
367
368      IF( lk_mpp    )   CALL mpp_sum( ierr )
369      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
370      !
371   END SUBROUTINE nemo_alloc
372
373   SUBROUTINE nemo_partition( num_pes )
374      !!----------------------------------------------------------------------
375      !!                 ***  ROUTINE nemo_partition  ***
376      !!
377      !! ** Purpose :   
378      !!
379      !! ** Method  :
380      !!----------------------------------------------------------------------
381      USE par_oce
382      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
383      ! Local variables
384      INTEGER, PARAMETER :: nfactmax = 20
385      INTEGER :: nfact ! The no. of factors returned
386      INTEGER :: ierr  ! Error flag
387      INTEGER :: i
388      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
389      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
390      !!----------------------------------------------------------------------
391
392      ierr = 0
393
394      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
395
396      IF( nfact <= 1 ) THEN
397         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
398         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
399         jpnj = 1
400         jpni = num_pes
401      ELSE
402         ! Search through factors for the pair that are closest in value
403         mindiff = 1000000
404         imin    = 1
405         DO i=1,nfact-1,2
406            idiff = ABS(ifact(i) - ifact(i+1))
407            IF(idiff < mindiff)THEN
408               mindiff = idiff
409               imin = i
410            END IF
411         END DO
412         jpnj = ifact(imin)
413         jpni = ifact(imin + 1)
414      ENDIF
415      jpnij = jpni*jpnj
416
417      WRITE(*,*) 'ARPDBG: jpni = ',jpni,'jpnj = ',jpnj,'jpnij = ',jpnij
418      !
419   END SUBROUTINE nemo_partition
420
421
422   SUBROUTINE factorise( ifax, maxfax, nfax, n, ierr )
423      !!----------------------------------------------------------------------
424      !!                     ***  ROUTINE factorise  ***
425      !!
426      !! ** Purpose :   return the prime factors of n.
427      !!                nfax factors are returned in array ifax which is of
428      !!                maximum dimension maxfax.
429      !! ** Method  :
430      !!----------------------------------------------------------------------
431      INTEGER, INTENT(in)  :: n, maxfax
432      INTEGER, INTENT(Out) :: ierr, nfax
433      INTEGER, INTENT(out) :: ifax(maxfax)
434      ! Local variables.
435      INTEGER :: i, ifac, l, nu
436      INTEGER, PARAMETER :: ntest = 14
437      INTEGER :: lfax(ntest)
438
439      ! lfax contains the set of allowed factors.
440      data (lfax(i),i=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
441         &                         128,   64,   32,   16,    8,   4,   2  /
442      !!----------------------------------------------------------------------
443
444      ! Clear the error flag and initialise output vars
445      ierr = 0
446      ifax = 1
447      nfax = 0
448
449      ! Find the factors of n.
450      IF( n == 1 ) GOTO 20
451
452      ! nu holds the unfactorised part of the number.
453      ! nfax holds the number of factors found.
454      ! l points to the allowed factor list.
455      ! ifac holds the current factor.
456
457      nu   = n
458      nfax = 0
459
460      DO l = ntest, 1, -1
461         !
462         ifac = lfax(l)
463         IF(ifac > nu)CYCLE
464
465         ! Test whether the factor will divide.
466
467         IF( MOD(nu,ifac) == 0 ) THEN
468            !
469            nfax = nfax+1            ! Add the factor to the list
470            IF( nfax > maxfax ) THEN
471               ierr = 6
472               write (*,*) 'FACTOR: insufficient space in factor array ',nfax
473               return
474            ENDIF
475            ifax(nfax) = ifac
476            ! Store the other factor that goes with this one
477            nfax = nfax + 1
478            ifax(nfax) = nu / ifac
479            !WRITE (*,*) 'ARPDBG, factors ',nfax-1,' & ',nfax,' are ', &
480            !            ifax(nfax-1),' and ',ifax(nfax)
481         ENDIF
482         !
483      END DO
484
485   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
486      !
487      RETURN
488      !
489   END SUBROUTINE factorise
490   !!======================================================================
491END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.