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

source: branches/2017/dev_r8126_ROBUST08_no_ghost/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 @ 8314

Last change on this file since 8314 was 8314, checked in by acc, 7 years ago

Branch 2017/dev_r8126_ROBUST08_no_ghost. Merge in changes from branches/2017/dev_r8126_ROBUST10_MPPINI to combine mppini and mppini_2 functionalities into a single routine. SETTE-like test performed with ORCA2LIMPISCES using an 8x8 partition with 60 processors to confirm consistency of results when using land suppression. The dev_r8126_ROBUST10_MPPINI branch will not be needed in the 2017 merge if dev_r8126_ROBUST08_no_ghost is included.

  • Property svn:keywords set to Id
File size: 31.4 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   !!            3.4  ! 2011-01  (C. Ethe, A. R. Porter, STFC Daresbury) dynamical allocation
8   !!            4.0  ! 2016-10  (C. Ethe, G. Madec, S. Flavoni)  domain configuration / user defined interface
9   !!----------------------------------------------------------------------
10
11   !!----------------------------------------------------------------------
12   !!   nemo_gcm        : off-line: solve ocean tracer only
13   !!   nemo_init       : initialization of the nemo model
14   !!   nemo_ctl        : initialisation of algorithm flag
15   !!   nemo_closefile  : close remaining files
16   !!----------------------------------------------------------------------
17   USE dom_oce         ! ocean space domain variables
18   USE oce             ! dynamics and tracers variables
19   USE trc_oce         ! Shared ocean/passive tracers variables
20   USE c1d             ! 1D configuration
21   USE domain          ! domain initialization from coordinate & bathymetry (dom_init routine)
22   USE usrdef_nam      ! user defined configuration
23   USE eosbn2          ! equation of state            (eos bn2 routine)
24   !              ! ocean physics
25   USE ldftra          ! lateral diffusivity setting    (ldf_tra_init routine)
26   USE ldfslp          ! slopes of neutral surfaces     (ldf_slp_init routine)
27   USE traqsr          ! solar radiation penetration    (tra_qsr_init routine)
28   USE trabbl          ! bottom boundary layer          (tra_bbl_init routine)
29   USE traldf          ! lateral physics                (tra_ldf_init routine)
30   USE zdfini          ! vertical physics: initialization
31   USE sbcmod          ! surface boundary condition       (sbc_init     routine)
32   USE phycst          ! physical constant                  (par_cst routine)
33   USE dtadyn          ! Lecture and Interpolation of the dynamical fields
34   USE trcini          ! Initilization of the passive tracers
35   USE daymod          ! calendar                         (day     routine)
36   USE trcstp          ! passive tracer time-stepping      (trc_stp routine)
37   USE dtadyn          ! Lecture and interpolation of the dynamical fields
38   !              ! Passive tracers needs
39   USE trc             ! passive tracer : variables
40   USE trcnam          ! passive tracer : namelist
41   USE trcrst          ! passive tracer restart
42   USE diaptr          ! Need to initialise this as some variables are used in if statements later
43   USE sbc_oce  , ONLY : ln_rnf
44   USE sbcrnf          ! surface boundary condition : runoffs
45   !              ! I/O & MPP
46   USE iom             ! I/O library
47   USE in_out_manager  ! I/O manager
48   USE mppini          ! shared/distributed memory setting (mpp_init routine)
49   USE lib_mpp         ! distributed memory computing
50#if defined key_iomput
51   USE xios
52#endif
53   USE prtctl          ! Print control                    (prt_ctl_init routine)
54   USE timing          ! Timing
55   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
56   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
57
58
59
60   IMPLICIT NONE
61   PRIVATE
62   
63   PUBLIC   nemo_gcm   ! called by nemo.F90
64
65   CHARACTER (len=64) ::   cform_aaa="( /, 'AAAAAAAA', / ) "   ! flag for output listing
66
67   !!----------------------------------------------------------------------
68   !! NEMO/OPA 3.7 , NEMO Consortium (2016)
69   !! $Id$
70   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
71   !!----------------------------------------------------------------------
72CONTAINS
73
74   SUBROUTINE nemo_gcm
75      !!----------------------------------------------------------------------
76      !!                     ***  ROUTINE nemo_gcm  ***
77      !!
78      !! ** Purpose :   nemo solves the primitive equations on an orthogonal
79      !!      curvilinear mesh on the sphere.
80      !!
81      !! ** Method  : - model general initialization
82      !!              - launch the time-stepping (dta_dyn and trc_stp)
83      !!              - finalize the run by closing files and communications
84      !!
85      !! References : Madec, Delecluse,Imbard, and Levy, 1997:  internal report, IPSL.
86      !!              Madec, 2008, internal report, IPSL.
87      !!----------------------------------------------------------------------
88      INTEGER :: istp, indic       ! time step index
89      !!----------------------------------------------------------------------
90
91      CALL nemo_init  ! Initializations
92
93      ! check that all process are still there... If some process have an error,
94      ! they will never enter in step and other processes will wait until the end of the cpu time!
95      IF( lk_mpp )   CALL mpp_max( nstop )
96
97      !                            !-----------------------!
98      !                            !==   time stepping   ==!
99      !                            !-----------------------!
100      istp = nit000
101      !
102      ! Initialize arrays of runoffs structures and read data from the namelist
103      IF ( ln_rnf ) CALL sbc_rnf(istp)
104      !
105      CALL iom_init( cxios_context )            ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
106      !
107      DO WHILE ( istp <= nitend .AND. nstop == 0 )    ! time stepping
108         !
109         IF( istp /= nit000 )   CALL day        ( istp )         ! Calendar (day was already called at nit000 in day_init)
110                                CALL iom_setkt  ( istp - nit000 + 1, "nemo" )   ! say to iom that we are at time step kstp
111                                CALL dta_dyn    ( istp )         ! Interpolation of the dynamical fields
112         IF( .NOT.ln_linssh )   CALL dta_dyn_swp( istp )         ! swap of sea  surface height and vertical scale factors
113
114                                CALL trc_stp    ( istp )         ! time-stepping
115                                CALL stp_ctl    ( istp, indic )  ! Time loop: control and print
116         istp = istp + 1
117         IF( lk_mpp )   CALL mpp_max( nstop )
118      END DO
119#if defined key_iomput
120      CALL iom_context_finalize( cxios_context ) ! needed for XIOS+AGRIF
121#endif
122
123      !                            !------------------------!
124      !                            !==  finalize the run  ==!
125      !                            !------------------------!
126      IF(lwp) WRITE(numout,cform_aaa)                 ! Flag AAAAAAA
127
128      IF( nstop /= 0 .AND. lwp ) THEN                 ! error print
129         WRITE(numout,cform_err)
130         WRITE(numout,*) nstop, ' error have been found'
131      ENDIF
132      !
133      IF( nn_timing == 1 )   CALL timing_finalize
134      !
135      CALL nemo_closefile
136      !
137# if defined key_iomput
138      CALL xios_finalize             ! end mpp communications
139# else
140      IF( lk_mpp )   CALL mppstop       ! end mpp communications
141# endif
142      !
143   END SUBROUTINE nemo_gcm
144
145
146   SUBROUTINE nemo_init
147      !!----------------------------------------------------------------------
148      !!                     ***  ROUTINE nemo_init ***
149      !!
150      !! ** Purpose :   initialization of the nemo model in off-line mode
151      !!----------------------------------------------------------------------
152      INTEGER ::   ji            ! dummy loop indices
153      INTEGER ::   ilocal_comm   ! local integer
154      INTEGER ::   ios, inum
155      REAL(wp) ::   ziglo, zjglo, zkglo, zperio   ! local scalars
156      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
157      !!
158      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
159         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
160         &             nn_timing, nn_diacfl
161
162      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
163      !!----------------------------------------------------------------------
164      cltxt  = ''
165      cltxt2 = ''
166      clnam  = '' 
167      cxios_context = 'nemo'
168      !
169      !                             ! Open reference namelist and configuration namelist files
170      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
171      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
172      !
173      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
174      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
175901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
176
177      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
178      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
179902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
180
181      !
182      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
183      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
184903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
185
186      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
187      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
188904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
189
190
191      !                             !--------------------------!
192      !                             !  Set global domain size  !   (control print return in cltxt2)
193      !
194      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
195         CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
196         !
197      ELSE                                ! user-defined namelist
198         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
199      ENDIF
200      jpk    = jpkglo
201      !
202      !
203      l_offline = .true.            !  passive tracers are run offline
204      !
205      !                             !--------------------------------------------!
206      !                             !  set communicator & select the local node  !
207      !                             !  NB: mynode also opens output.namelist.dyn !
208      !                             !      on unit number numond on first proc   !
209      !                             !--------------------------------------------!
210#if defined key_iomput
211      CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )
212      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection
213#else
214      ilocal_comm = 0
215      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
216#endif
217
218      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
219
220      lwm = (narea == 1)                      ! control of output namelists
221      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
222
223      IF(lwm) THEN
224         ! write merged namelists from earlier to output namelist now that the
225         ! file has been opened in call to mynode. nammpp has already been
226         ! written in mynode (if lk_mpp_mpi)
227         WRITE( numond, namctl )
228         WRITE( numond, namcfg )
229         IF( .NOT.ln_read_cfg ) THEN
230            DO ji = 1, SIZE(clnam)
231               IF( TRIM(clnam (ji)) /= '' )   WRITE(numond, * ) clnam(ji)    ! namusr_def print
232            END DO
233         ENDIF
234      ENDIF
235
236      ! If dimensions of processor grid weren't specified in the namelist file
237      ! then we calculate them here now that we have our communicator size
238      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
239#if   defined key_mpp_mpi
240         CALL nemo_partition(mppsize)
241#else
242         jpni = 1
243         jpnj = 1
244         jpnij = jpni*jpnj
245#endif
246      END IF
247
248      ! Calculate domain dimensions given calculated jpni and jpnj
249      ! This used to be done in par_oce.F90 when they were parameters rather
250      ! than variables
251      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
252      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
253      jpim1 = jpi-1                                            ! inner domain indices
254      jpjm1 = jpj-1                                            !   "           "
255      jpkm1 = jpk-1                                            !   "           "
256      jpij  = jpi*jpj                                          !  jpi x j
257
258
259      IF(lwp) THEN                            ! open listing units
260         !
261         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
262         !
263         WRITE(numout,*)
264         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
265         WRITE(numout,*) '                       NEMO team'
266         WRITE(numout,*) '            Ocean General Circulation Model'
267         WRITE(numout,*) '                  version 3.6  (2015) '
268         WRITE(numout,*)
269         WRITE(numout,*)
270         DO ji = 1, SIZE(cltxt) 
271            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
272         END DO
273         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
274         !
275      ENDIF
276
277      ! Now we know the dimensions of the grid and numout has been set we can
278      ! allocate arrays
279      CALL nemo_alloc()
280
281      !                             !--------------------------------!
282      !                             !  Model general initialization  !
283      !                             !--------------------------------!
284
285      CALL nemo_ctl                           ! Control prints & Benchmark
286
287      !                                      ! Domain decomposition
288      CALL mpp_init
289      !
290      IF( nn_timing == 1 )  CALL timing_init
291      !
292
293      !                                      ! General initialization
294      IF( nn_timing == 1 )  CALL timing_start( 'nemo_init')
295      !
296                            CALL     phy_cst    ! Physical constants
297                            CALL     eos_init   ! Equation of state
298      IF( lk_c1d        )   CALL     c1d_init   ! 1D column configuration
299
300                            CALL     dom_init   ! Domain
301
302                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
303
304      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
305
306      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
307
308                            CALL     sbc_init   ! Forcings : surface module
309
310                            CALL ldf_tra_init   ! Lateral ocean tracer physics
311                            CALL ldf_eiv_init   ! Eddy induced velocity param
312                            CALL tra_ldf_init   ! lateral mixing
313      IF( l_ldfslp )        CALL ldf_slp_init   ! slope of lateral mixing
314
315                            CALL tra_qsr_init   ! penetrative solar radiation qsr
316      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
317
318                            CALL trc_nam_run    ! Needed to get restart parameters for passive tracers
319                            CALL trc_rst_cal( nit000, 'READ' )   ! calendar
320                            CALL dta_dyn_init   ! Initialization for the dynamics
321
322                            CALL     trc_init   ! Passive tracers initialization
323                            CALL dia_ptr_init   ! Initialise diaptr as some variables are used
324      !                                         ! in various advection and diffusion routines
325      IF(lwp) WRITE(numout,cform_aaa)           ! Flag AAAAAAA
326      !
327      IF( nn_timing == 1 )  CALL timing_stop( 'nemo_init')
328      !
329   END SUBROUTINE nemo_init
330
331
332   SUBROUTINE nemo_ctl
333      !!----------------------------------------------------------------------
334      !!                     ***  ROUTINE nemo_ctl  ***
335      !!
336      !! ** Purpose :   control print setting
337      !!
338      !! ** Method  : - print namctl information and check some consistencies
339      !!----------------------------------------------------------------------
340      !
341      IF(lwp) THEN                  ! control print
342         WRITE(numout,*)
343         WRITE(numout,*) 'nemo_ctl: Control prints'
344         WRITE(numout,*) '~~~~~~~ '
345         WRITE(numout,*) '   Namelist namctl'
346         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
347         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
348         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
349         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
350         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
351         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
352         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
353         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
354         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
355      ENDIF
356      !
357      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
358      nictls    = nn_ictls
359      nictle    = nn_ictle
360      njctls    = nn_jctls
361      njctle    = nn_jctle
362      isplt     = nn_isplt
363      jsplt     = nn_jsplt
364
365
366      IF(lwp) THEN                  ! control print
367         WRITE(numout,*)
368         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
369         WRITE(numout,*) '~~~~~~~ '
370         WRITE(numout,*) '   Namelist namcfg'
371         WRITE(numout,*) '      read domain configuration files             ln_read_cfg      = ', ln_read_cfg
372         WRITE(numout,*) '         filename to be read                         cn_domcfg     = ', TRIM(cn_domcfg)
373         WRITE(numout,*) '      write  configuration definition files       ln_write_cfg     = ', ln_write_cfg
374         WRITE(numout,*) '         filename to be written                      cn_domcfg_out = ', TRIM(cn_domcfg_out)
375         WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr     = ', ln_use_jattr
376      ENDIF
377
378      !                             ! Parameter control
379      !
380      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
381         IF( lk_mpp .AND. jpnij > 1 ) THEN
382            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
383         ELSE
384            IF( isplt == 1 .AND. jsplt == 1  ) THEN
385               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
386                  &           ' - the print control will be done over the whole domain' )
387            ENDIF
388            ijsplt = isplt * jsplt            ! total number of processors ijsplt
389         ENDIF
390         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
391         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
392         !
393         !                              ! indices used for the SUM control
394         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
395            lsp_area = .FALSE.
396         ELSE                                             ! print control done over a specific  area
397            lsp_area = .TRUE.
398            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
399               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
400               nictls = 1
401            ENDIF
402            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
403               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
404               nictle = jpiglo
405            ENDIF
406            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
407               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
408               njctls = 1
409            ENDIF
410            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
411               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
412               njctle = jpjglo
413            ENDIF
414         ENDIF
415      ENDIF
416      !
417      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
418         &                                               'f2003 standard. '                              ,  &
419         &                                               'Compile with key_nosignedzero enabled' )
420      !
421   END SUBROUTINE nemo_ctl
422
423
424   SUBROUTINE nemo_closefile
425      !!----------------------------------------------------------------------
426      !!                     ***  ROUTINE nemo_closefile  ***
427      !!
428      !! ** Purpose :   Close the files
429      !!----------------------------------------------------------------------
430      !
431      IF ( lk_mpp ) CALL mppsync
432      !
433      CALL iom_close                                 ! close all input/output files managed by iom_*
434      !
435      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
436      IF( numnam_ref /= -1 )   CLOSE( numnam_ref )   ! oce reference namelist
437      IF( numnam_cfg /= -1 )   CLOSE( numnam_cfg )   ! oce configuration namelist
438      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
439      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
440
441      numout = 6                                     ! redefine numout in case it is used after this point...
442      !
443   END SUBROUTINE nemo_closefile
444
445
446   SUBROUTINE nemo_alloc
447      !!----------------------------------------------------------------------
448      !!                     ***  ROUTINE nemo_alloc  ***
449      !!
450      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
451      !!
452      !! ** Method  :
453      !!----------------------------------------------------------------------
454      USE diawri,       ONLY: dia_wri_alloc
455      USE dom_oce,      ONLY: dom_oce_alloc
456      USE zdf_oce,      ONLY: zdf_oce_alloc
457      USE trc_oce,      ONLY: trc_oce_alloc
458      !
459      INTEGER :: ierr
460      !!----------------------------------------------------------------------
461      !
462      ierr =        oce_alloc       ()          ! ocean
463      ierr = ierr + dia_wri_alloc   ()
464      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
465      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
466      !
467      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
468      !
469      IF( lk_mpp    )   CALL mpp_sum( ierr )
470      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
471      !
472   END SUBROUTINE nemo_alloc
473
474
475   SUBROUTINE nemo_partition( num_pes )
476      !!----------------------------------------------------------------------
477      !!                 ***  ROUTINE nemo_partition  ***
478      !!
479      !! ** Purpose :   
480      !!
481      !! ** Method  :
482      !!----------------------------------------------------------------------
483      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
484      !
485      INTEGER, PARAMETER :: nfactmax = 20
486      INTEGER :: nfact ! The no. of factors returned
487      INTEGER :: ierr  ! Error flag
488      INTEGER :: ji
489      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
490      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
491      !!----------------------------------------------------------------------
492
493      ierr = 0
494
495      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
496
497      IF( nfact <= 1 ) THEN
498         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
499         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
500         jpnj = 1
501         jpni = num_pes
502      ELSE
503         ! Search through factors for the pair that are closest in value
504         mindiff = 1000000
505         imin    = 1
506         DO ji = 1, nfact-1, 2
507            idiff = ABS( ifact(ji) - ifact(ji+1) )
508            IF( idiff < mindiff ) THEN
509               mindiff = idiff
510               imin = ji
511            ENDIF
512         END DO
513         jpnj = ifact(imin)
514         jpni = ifact(imin + 1)
515      ENDIF
516      !
517      jpnij = jpni*jpnj
518      !
519   END SUBROUTINE nemo_partition
520
521
522   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
523      !!----------------------------------------------------------------------
524      !!                     ***  ROUTINE factorise  ***
525      !!
526      !! ** Purpose :   return the prime factors of n.
527      !!                knfax factors are returned in array kfax which is of
528      !!                maximum dimension kmaxfax.
529      !! ** Method  :
530      !!----------------------------------------------------------------------
531      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
532      INTEGER                    , INTENT(  out) ::   kerr, knfax
533      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
534      !
535      INTEGER :: ifac, jl, inu
536      INTEGER, PARAMETER :: ntest = 14
537      INTEGER :: ilfax(ntest)
538      !
539      ! lfax contains the set of allowed factors.
540      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
541
542      ! Clear the error flag and initialise output vars
543      kerr = 0
544      kfax = 1
545      knfax = 0
546
547      ! Find the factors of n.
548      IF( kn == 1 )   GOTO 20
549
550      ! nu holds the unfactorised part of the number.
551      ! knfax holds the number of factors found.
552      ! l points to the allowed factor list.
553      ! ifac holds the current factor.
554
555      inu   = kn
556      knfax = 0
557
558      DO jl = ntest, 1, -1
559         !
560         ifac = ilfax(jl)
561         IF( ifac > inu )   CYCLE
562
563         ! Test whether the factor will divide.
564
565         IF( MOD(inu,ifac) == 0 ) THEN
566            !
567            knfax = knfax + 1            ! Add the factor to the list
568            IF( knfax > kmaxfax ) THEN
569               kerr = 6
570               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
571               return
572            ENDIF
573            kfax(knfax) = ifac
574            ! Store the other factor that goes with this one
575            knfax = knfax + 1
576            kfax(knfax) = inu / ifac
577            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
578         ENDIF
579         !
580      END DO
581
582   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
583      !
584   END SUBROUTINE factorise
585
586#if defined key_mpp_mpi
587   SUBROUTINE nemo_northcomms
588      !!======================================================================
589      !!                     ***  ROUTINE  nemo_northcomms  ***
590      !! nemo_northcomms    :  Setup for north fold exchanges with explicit
591      !!                       point-to-point messaging
592      !!=====================================================================
593      !!----------------------------------------------------------------------
594      !!
595      !! ** Purpose :   Initialization of the northern neighbours lists.
596      !!----------------------------------------------------------------------
597      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
598      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S.
599      !Mocavero, CMCC)
600      !!----------------------------------------------------------------------
601
602      INTEGER  ::   sxM, dxM, sxT, dxT, jn
603      INTEGER  ::   njmppmax
604
605      njmppmax = MAXVAL( njmppt )
606
607      !initializes the north-fold communication variables
608      isendto(:) = 0
609      nsndto = 0
610
611      !if I am a process in the north
612      IF ( njmpp == njmppmax ) THEN
613          !sxM is the first point (in the global domain) needed to compute the
614          !north-fold for the current process
615          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
616          !dxM is the last point (in the global domain) needed to compute the
617          !north-fold for the current process
618          dxM = jpiglo - nimppt(narea) + 2
619
620          !loop over the other north-fold processes to find the processes
621          !managing the points belonging to the sxT-dxT range
622
623          DO jn = 1, jpni
624                !sxT is the first point (in the global domain) of the jn
625                !process
626                sxT = nfiimpp(jn, jpnj)
627                !dxT is the last point (in the global domain) of the jn
628                !process
629                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
630                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
631                   nsndto = nsndto + 1
632                     isendto(nsndto) = jn
633                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
634                   nsndto = nsndto + 1
635                     isendto(nsndto) = jn
636                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
637                   nsndto = nsndto + 1
638                     isendto(nsndto) = jn
639                END IF
640          END DO
641          nfsloop = 1
642          nfeloop = nlci
643          DO jn = 2,jpni-1
644           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
645              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
646                 nfsloop = nldi
647              ENDIF
648              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
649                 nfeloop = nlei
650              ENDIF
651           ENDIF
652        END DO
653
654      ENDIF
655      l_north_nogather = .TRUE.
656   END SUBROUTINE nemo_northcomms
657#else
658   SUBROUTINE nemo_northcomms      ! Dummy routine
659      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
660   END SUBROUTINE nemo_northcomms
661#endif
662
663   SUBROUTINE istate_init
664      !!----------------------------------------------------------------------
665      !!                   ***  ROUTINE istate_init  ***
666      !!
667      !! ** Purpose :   Initialization to zero of the dynamics and tracers.
668      !!----------------------------------------------------------------------
669      !
670      !     now fields         !     after fields      !
671      un   (:,:,:)   = 0._wp   ;   ua(:,:,:) = 0._wp   !
672      vn   (:,:,:)   = 0._wp   ;   va(:,:,:) = 0._wp   !
673      wn   (:,:,:)   = 0._wp   !                       !
674      hdivn(:,:,:)   = 0._wp   !                       !
675      tsn  (:,:,:,:) = 0._wp   !                       !
676      !
677      rhd  (:,:,:) = 0.e0
678      rhop (:,:,:) = 0.e0
679      rn2  (:,:,:) = 0.e0
680      !
681   END SUBROUTINE istate_init
682
683   SUBROUTINE stp_ctl( kt, kindic )
684      !!----------------------------------------------------------------------
685      !!                    ***  ROUTINE stp_ctl  ***
686      !!
687      !! ** Purpose :   Control the run
688      !!
689      !! ** Method  : - Save the time step in numstp
690      !!
691      !! ** Actions :   'time.step' file containing the last ocean time-step
692      !!----------------------------------------------------------------------
693      INTEGER, INTENT(in   ) ::   kt      ! ocean time-step index
694      INTEGER, INTENT(inout) ::   kindic  ! indicator of solver convergence
695      !!----------------------------------------------------------------------
696      !
697      IF( kt == nit000 .AND. lwp ) THEN
698         WRITE(numout,*)
699         WRITE(numout,*) 'stp_ctl : time-stepping control'
700         WRITE(numout,*) '~~~~~~~'
701         ! open time.step file
702         CALL ctl_opn( numstp, 'time.step', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, narea )
703      ENDIF
704      !
705      IF(lwp) WRITE ( numstp, '(1x, i8)' )   kt      !* save the current time step in numstp
706      IF(lwp) REWIND( numstp )                       ! --------------------------
707      !
708   END SUBROUTINE stp_ctl
709   !!======================================================================
710END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.