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

source: branches/2017/dev_r7881_ENHANCE09_RK3/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 @ 8215

Last change on this file since 8215 was 8215, checked in by gm, 7 years ago

#1911 (ENHANCE-09): PART 0 - phasing with branch dev_r7832_HPC09_ZDF revision 8214

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