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

source: branches/2013/dev_LOCEAN_2013/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 @ 4152

Last change on this file since 4152 was 4152, checked in by cetlod, 10 years ago

merge in dev_LOCEAN_2013 the 2nd development branch dev_r3940_CNRS4_IOCRS, see ticket #1169

File size: 31.6 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 xios
44#endif
45   USE prtctl          ! Print control                    (prt_ctl_init routine)
46   USE timing          ! Timing
47   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
48
49   USE trc
50   USE trcnam
51   USE trcrst
52
53   IMPLICIT NONE
54   PRIVATE
55   
56   PUBLIC   nemo_gcm   ! called by nemo.F90
57
58   CHARACTER (len=64) ::   cform_aaa="( /, 'AAAAAAAA', / ) "   ! flag for output listing
59
60   !!----------------------------------------------------------------------
61   !! NEMO/OFF 3.3 , NEMO Consortium (2010)
62   !! $Id: nemogcm.F90 2528 2010-12-27 17:33:53Z rblod $
63   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
64   !!----------------------------------------------------------------------
65CONTAINS
66
67   SUBROUTINE nemo_gcm
68      !!----------------------------------------------------------------------
69      !!                     ***  ROUTINE nemo_gcm  ***
70      !!
71      !! ** Purpose :   nemo solves the primitive equations on an orthogonal
72      !!      curvilinear mesh on the sphere.
73      !!
74      !! ** Method  : - model general initialization
75      !!              - launch the time-stepping (dta_dyn and trc_stp)
76      !!              - finalize the run by closing files and communications
77      !!
78      !! References : Madec, Delecluse,Imbard, and Levy, 1997:  internal report, IPSL.
79      !!              Madec, 2008, internal report, IPSL.
80      !!----------------------------------------------------------------------
81      INTEGER :: istp, indic       ! time step index
82      !!----------------------------------------------------------------------
83
84      CALL nemo_init  ! Initializations
85
86      ! check that all process are still there... If some process have an error,
87      ! they will never enter in step and other processes will wait until the end of the cpu time!
88      IF( lk_mpp )   CALL mpp_max( nstop )
89
90      !                            !-----------------------!
91      !                            !==   time stepping   ==!
92      !                            !-----------------------!
93      istp = nit000
94      !
95      CALL iom_init( "nemo" )            ! iom_put initialization (must be done after nemo_init for AGRIF+XIOS+OASIS)
96      !
97      DO WHILE ( istp <= nitend .AND. nstop == 0 )    ! time stepping
98         !
99         IF( istp /= nit000 )   CALL day      ( istp )         ! Calendar (day was already called at nit000 in day_init)
100                                CALL iom_setkt( istp - nit000 + 1, "nemo" )   ! say to iom that we are at time step kstp
101                                CALL dta_dyn  ( istp )         ! Interpolation of the dynamical fields
102                                CALL trc_stp  ( istp )         ! time-stepping
103                                CALL stp_ctl  ( istp, indic )  ! Time loop: control and print
104         istp = istp + 1
105         IF( lk_mpp )   CALL mpp_max( nstop )
106      END DO
107#if defined key_iomput
108      CALL xios_context_finalize() ! needed for XIOS+AGRIF
109#endif
110
111      !                            !------------------------!
112      !                            !==  finalize the run  ==!
113      !                            !------------------------!
114      IF(lwp) WRITE(numout,cform_aaa)                 ! Flag AAAAAAA
115
116      IF( nstop /= 0 .AND. lwp ) THEN                 ! error print
117         WRITE(numout,cform_err)
118         WRITE(numout,*) nstop, ' error have been found'
119      ENDIF
120      !
121      IF( nn_timing == 1 )   CALL timing_finalize
122      !
123      CALL nemo_closefile
124      !
125# if defined key_iomput
126      CALL xios_finalize             ! end mpp communications
127# else
128      IF( lk_mpp )   CALL mppstop       ! end mpp communications
129# endif
130      !
131   END SUBROUTINE nemo_gcm
132
133
134   SUBROUTINE nemo_init
135      !!----------------------------------------------------------------------
136      !!                     ***  ROUTINE nemo_init ***
137      !!
138      !! ** Purpose :   initialization of the nemo model in off-line mode
139      !!----------------------------------------------------------------------
140      INTEGER ::   ji            ! dummy loop indices
141      INTEGER ::   ilocal_comm   ! local integer
142      INTEGER ::   ios
143      CHARACTER(len=80), DIMENSION(16) ::   cltxt
144      !!
145      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
146         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
147         &             nn_bench, nn_timing
148      NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
149         &             jpizoom, jpjzoom, jperio
150      !!----------------------------------------------------------------------
151      !
152      cltxt = ''
153      !
154      !                             ! Open reference namelist and configuration namelist files
155      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
156      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
157      CALL ctl_opn( numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
158      !
159      !
160      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
161      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
162901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', lwp )
163
164      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
165      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
166902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', lwp )
167      WRITE( numond, namctl )
168      !
169      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
170      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
171903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', lwp )
172
173      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
174      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
175904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', lwp )   
176      WRITE( numond, namcfg )
177      !                             !--------------------------------------------!
178      !                             !  set communicator & select the local node  !
179      !                             !--------------------------------------------!
180#if defined key_iomput
181         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
182      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )   ! Nodes selection
183#else
184      ilocal_comm = 0
185      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop )                ! Nodes selection (control print return in cltxt)
186#endif
187
188      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
189
190      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
191
192      ! If dimensions of processor grid weren't specified in the namelist file
193      ! then we calculate them here now that we have our communicator size
194      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
195#if   defined key_mpp_mpi
196         CALL nemo_partition(mppsize)
197#else
198         jpni = 1
199         jpnj = 1
200         jpnij = jpni*jpnj
201#endif
202      END IF
203
204      ! Calculate domain dimensions given calculated jpni and jpnj
205      ! This used to be done in par_oce.F90 when they were parameters rather
206      ! than variables
207      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
208      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
209      jpk = jpkdta                                             ! third dim
210      jpim1 = jpi-1                                            ! inner domain indices
211      jpjm1 = jpj-1                                            !   "           "
212      jpkm1 = jpk-1                                            !   "           "
213      jpij  = jpi*jpj                                          !  jpi x j
214
215
216      IF(lwp) THEN                            ! open listing units
217         !
218         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
219         !
220         WRITE(numout,*)
221         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
222         WRITE(numout,*) '                       NEMO team'
223         WRITE(numout,*) '            Ocean General Circulation Model'
224         WRITE(numout,*) '                  version 3.5  (2012) '
225         WRITE(numout,*)
226         WRITE(numout,*)
227         DO ji = 1, SIZE(cltxt) 
228            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
229         END DO
230         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
231         !
232      ENDIF
233
234      ! Now we know the dimensions of the grid and numout has been set we can
235      ! allocate arrays
236      CALL nemo_alloc()
237
238      !                             !--------------------------------!
239      !                             !  Model general initialization  !
240      !                             !--------------------------------!
241
242      CALL nemo_ctl                           ! Control prints & Benchmark
243
244      !                                      ! Domain decomposition
245      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
246      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
247      ENDIF
248      !
249      IF( nn_timing == 1 )  CALL timing_init
250      !
251
252      !                                      ! General initialization
253      IF( nn_timing == 1 )  CALL timing_start( 'nemo_init')
254      !
255                            CALL     phy_cst    ! Physical constants
256                            CALL     eos_init   ! Equation of state
257                            CALL     dom_cfg    ! Domain configuration
258                            CALL     dom_init   ! Domain
259                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
260
261      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
262
263      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
264
265      !                                     ! Ocean physics
266                            CALL     sbc_init   ! Forcings : surface module
267#if ! defined key_degrad
268                            CALL ldf_tra_init   ! Lateral ocean tracer physics
269#endif
270      IF( lk_ldfslp )       CALL ldf_slp_init   ! slope of lateral mixing
271
272      !                                     ! Active tracers
273                            CALL tra_qsr_init   ! penetrative solar radiation qsr
274      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
275
276                            CALL trc_nam_run  ! Needed to get restart parameters for passive tracers
277      IF( ln_rsttr ) THEN
278        neuler = 1   ! Set time-step indicator at nit000 (leap-frog)
279        CALL trc_rst_cal( nit000, 'READ' )   ! calendar
280      ELSE
281        neuler = 0                  ! Set time-step indicator at nit000 (euler)
282        CALL day_init               ! set calendar
283      ENDIF
284      !                                     ! Dynamics
285                            CALL dta_dyn_init   ! Initialization for the dynamics
286
287      !                                     ! Passive tracers
288                            CALL     trc_init   ! Passive tracers initialization
289
290      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
291      !
292      IF( nn_timing == 1 )  CALL timing_stop( 'nemo_init')
293      !
294   END SUBROUTINE nemo_init
295
296
297   SUBROUTINE nemo_ctl
298      !!----------------------------------------------------------------------
299      !!                     ***  ROUTINE nemo_ctl  ***
300      !!
301      !! ** Purpose :   control print setting
302      !!
303      !! ** Method  : - print namctl information and check some consistencies
304      !!----------------------------------------------------------------------
305      !
306      IF(lwp) THEN                  ! Parameter print
307         WRITE(numout,*)
308         WRITE(numout,*) 'nemo_flg: Control prints & Benchmark'
309         WRITE(numout,*) '~~~~~~~ '
310         WRITE(numout,*) '   Namelist namctl'
311         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
312         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
313         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
314         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
315         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
316         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
317         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
318         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
319         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
320      ENDIF
321      !
322      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
323      nictls    = nn_ictls
324      nictle    = nn_ictle
325      njctls    = nn_jctls
326      njctle    = nn_jctle
327      isplt     = nn_isplt
328      jsplt     = nn_jsplt
329      nbench    = nn_bench
330     IF(lwp) THEN                  ! control print
331         WRITE(numout,*)
332         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
333         WRITE(numout,*) '~~~~~~~ '
334         WRITE(numout,*) '   Namelist namcfg'
335         WRITE(numout,*) '      configuration name              cp_cfg      = ', TRIM(cp_cfg)
336         WRITE(numout,*) '      configuration resolution        jp_cfg      = ', jp_cfg
337         WRITE(numout,*) '      1st lateral dimension ( >= jpi ) jpidta     = ', jpidta
338         WRITE(numout,*) '      2nd    "         "    ( >= jpj ) jpjdta     = ', jpjdta
339         WRITE(numout,*) '      3nd    "         "               jpkdta     = ', jpkdta
340         WRITE(numout,*) '      1st dimension of global domain in i jpiglo  = ', jpiglo
341         WRITE(numout,*) '      2nd    -                  -    in j jpjglo  = ', jpjglo
342         WRITE(numout,*) '      left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
343         WRITE(numout,*) '      left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
344         WRITE(numout,*) '      lateral cond. type (between 0 and 6) jperio = ', jperio   
345      ENDIF
346      !                             ! Parameter control
347      !
348      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
349         IF( lk_mpp ) THEN
350            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real splitted domain
351         ELSE
352            IF( isplt == 1 .AND. jsplt == 1  ) THEN
353               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
354                  &           ' - the print control will be done over the whole domain' )
355            ENDIF
356            ijsplt = isplt * jsplt            ! total number of processors ijsplt
357         ENDIF
358         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
359         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
360         !
361         !                              ! indices used for the SUM control
362         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
363            lsp_area = .FALSE.
364         ELSE                                             ! print control done over a specific  area
365            lsp_area = .TRUE.
366            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
367               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
368               nictls = 1
369            ENDIF
370            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
371               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
372               nictle = jpiglo
373            ENDIF
374            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
375               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
376               njctls = 1
377            ENDIF
378            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
379               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
380               njctle = jpjglo
381            ENDIF
382         ENDIF
383      ENDIF
384      !
385      IF( nbench == 1 )   THEN            ! Benchmark
386         SELECT CASE ( cp_cfg )
387         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
388         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
389            &                                 ' cp_cfg="gyre" in namelsit &namcfg or set nbench = 0' )
390         END SELECT
391      ENDIF
392      !
393      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
394         &                                               'with the IOM Input/Output manager. '        ,   &
395         &                                               'Compile with key_iomput enabled' )
396      !
397      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
398         &                                               'f2003 standard. '                              ,  &
399         &                                               'Compile with key_nosignedzero enabled' )
400      !
401   END SUBROUTINE nemo_ctl
402
403
404   SUBROUTINE nemo_closefile
405      !!----------------------------------------------------------------------
406      !!                     ***  ROUTINE nemo_closefile  ***
407      !!
408      !! ** Purpose :   Close the files
409      !!----------------------------------------------------------------------
410      !
411      IF ( lk_mpp ) CALL mppsync
412      !
413      CALL iom_close                                 ! close all input/output files managed by iom_*
414      !
415      IF( numstp     /= -1 )   CLOSE( numstp     )   ! time-step file
416      IF( numnam_ref /= -1 )   CLOSE( numnam_ref )   ! oce reference namelist
417      IF( numnam_cfg /= -1 )   CLOSE( numnam_cfg )   ! oce configuration namelist
418      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
419      numout = 6                                     ! redefine numout in case it is used after this point...
420      !
421   END SUBROUTINE nemo_closefile
422
423
424   SUBROUTINE nemo_alloc
425      !!----------------------------------------------------------------------
426      !!                     ***  ROUTINE nemo_alloc  ***
427      !!
428      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
429      !!
430      !! ** Method  :
431      !!----------------------------------------------------------------------
432      USE diawri,       ONLY: dia_wri_alloc
433      USE dom_oce,      ONLY: dom_oce_alloc
434      USE zdf_oce,      ONLY: zdf_oce_alloc
435      USE ldftra_oce,   ONLY: ldftra_oce_alloc
436      USE trc_oce,      ONLY: trc_oce_alloc
437      !
438      INTEGER :: ierr
439      !!----------------------------------------------------------------------
440      !
441      ierr =        oce_alloc       ()          ! ocean
442      ierr = ierr + dia_wri_alloc   ()
443      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
444      ierr = ierr + ldftra_oce_alloc()          ! ocean lateral  physics : tracers
445      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
446      !
447      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
448      !
449      IF( lk_mpp    )   CALL mpp_sum( ierr )
450      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
451      !
452   END SUBROUTINE nemo_alloc
453
454
455   SUBROUTINE nemo_partition( num_pes )
456      !!----------------------------------------------------------------------
457      !!                 ***  ROUTINE nemo_partition  ***
458      !!
459      !! ** Purpose :   
460      !!
461      !! ** Method  :
462      !!----------------------------------------------------------------------
463      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
464      !
465      INTEGER, PARAMETER :: nfactmax = 20
466      INTEGER :: nfact ! The no. of factors returned
467      INTEGER :: ierr  ! Error flag
468      INTEGER :: ji
469      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
470      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
471      !!----------------------------------------------------------------------
472
473      ierr = 0
474
475      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
476
477      IF( nfact <= 1 ) THEN
478         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
479         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
480         jpnj = 1
481         jpni = num_pes
482      ELSE
483         ! Search through factors for the pair that are closest in value
484         mindiff = 1000000
485         imin    = 1
486         DO ji = 1, nfact-1, 2
487            idiff = ABS( ifact(ji) - ifact(ji+1) )
488            IF( idiff < mindiff ) THEN
489               mindiff = idiff
490               imin = ji
491            ENDIF
492         END DO
493         jpnj = ifact(imin)
494         jpni = ifact(imin + 1)
495      ENDIF
496      !
497      jpnij = jpni*jpnj
498      !
499   END SUBROUTINE nemo_partition
500
501
502   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
503      !!----------------------------------------------------------------------
504      !!                     ***  ROUTINE factorise  ***
505      !!
506      !! ** Purpose :   return the prime factors of n.
507      !!                knfax factors are returned in array kfax which is of
508      !!                maximum dimension kmaxfax.
509      !! ** Method  :
510      !!----------------------------------------------------------------------
511      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
512      INTEGER                    , INTENT(  out) ::   kerr, knfax
513      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
514      !
515      INTEGER :: ifac, jl, inu
516      INTEGER, PARAMETER :: ntest = 14
517      INTEGER :: ilfax(ntest)
518      !
519      ! lfax contains the set of allowed factors.
520      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
521         &                            128,   64,   32,   16,    8,   4,   2  /
522      !!----------------------------------------------------------------------
523
524      ! Clear the error flag and initialise output vars
525      kerr = 0
526      kfax = 1
527      knfax = 0
528
529      ! Find the factors of n.
530      IF( kn == 1 )   GOTO 20
531
532      ! nu holds the unfactorised part of the number.
533      ! knfax holds the number of factors found.
534      ! l points to the allowed factor list.
535      ! ifac holds the current factor.
536
537      inu   = kn
538      knfax = 0
539
540      DO jl = ntest, 1, -1
541         !
542         ifac = ilfax(jl)
543         IF( ifac > inu )   CYCLE
544
545         ! Test whether the factor will divide.
546
547         IF( MOD(inu,ifac) == 0 ) THEN
548            !
549            knfax = knfax + 1            ! Add the factor to the list
550            IF( knfax > kmaxfax ) THEN
551               kerr = 6
552               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
553               return
554            ENDIF
555            kfax(knfax) = ifac
556            ! Store the other factor that goes with this one
557            knfax = knfax + 1
558            kfax(knfax) = inu / ifac
559            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
560         ENDIF
561         !
562      END DO
563
564   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
565      !
566   END SUBROUTINE factorise
567
568#if defined key_mpp_mpi
569   SUBROUTINE nemo_northcomms
570      !!======================================================================
571      !!                     ***  ROUTINE  nemo_northcomms  ***
572      !! nemo_northcomms    :  Setup for north fold exchanges with explicit peer to peer messaging
573      !!=====================================================================
574      !!----------------------------------------------------------------------
575      !!
576      !! ** Purpose :   Initialization of the northern neighbours lists.
577      !!----------------------------------------------------------------------
578      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
579      !!----------------------------------------------------------------------
580
581      INTEGER ::   ji, jj, jk, ij, jtyp    ! dummy loop indices
582      INTEGER ::   ijpj                    ! number of rows involved in north-fold exchange
583      INTEGER ::   northcomms_alloc        ! allocate return status
584      REAL(wp), ALLOCATABLE, DIMENSION ( :,: ) ::   znnbrs     ! workspace
585      LOGICAL,  ALLOCATABLE, DIMENSION ( : )   ::   lrankset   ! workspace
586
587      IF(lwp) WRITE(numout,*)
588      IF(lwp) WRITE(numout,*) 'nemo_northcomms : Initialization of the northern neighbours lists'
589      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
590
591      !!----------------------------------------------------------------------
592      ALLOCATE( znnbrs(jpi,jpj), stat = northcomms_alloc )
593      ALLOCATE( lrankset(jpnij), stat = northcomms_alloc )
594      IF( northcomms_alloc /= 0 ) THEN
595         WRITE(numout,cform_war)
596         WRITE(numout,*) 'northcomms_alloc : failed to allocate arrays'
597         CALL ctl_stop( 'STOP', 'nemo_northcomms : unable to allocate temporary arrays' )
598      ENDIF
599      nsndto = 0
600      isendto = -1
601      ijpj   = 4
602      !
603      ! This routine has been called because ln_nnogather has been set true ( nammpp )
604      ! However, these first few exchanges have to use the mpi_allgather method to
605      ! establish the neighbour lists to use in subsequent peer to peer exchanges.
606      ! Consequently, set l_north_nogather to be false here and set it true only after
607      ! the lists have been established.
608      !
609      l_north_nogather = .FALSE.
610      !
611      ! Exchange and store ranks on northern rows
612
613      DO jtyp = 1,4
614
615         lrankset = .FALSE.
616         znnbrs = narea
617         SELECT CASE (jtyp)
618            CASE(1)
619               CALL lbc_lnk( znnbrs, 'T', 1. )      ! Type 1: T,W-points
620            CASE(2)
621               CALL lbc_lnk( znnbrs, 'U', 1. )      ! Type 2: U-point
622            CASE(3)
623               CALL lbc_lnk( znnbrs, 'V', 1. )      ! Type 3: V-point
624            CASE(4)
625               CALL lbc_lnk( znnbrs, 'F', 1. )      ! Type 4: F-point
626         END SELECT
627
628         IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
629            DO jj = nlcj-ijpj+1, nlcj
630               ij = jj - nlcj + ijpj
631               DO ji = 1,jpi
632                  IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
633               &     lrankset(INT(znnbrs(ji,jj))) = .true.
634               END DO
635            END DO
636
637            DO jj = 1,jpnij
638               IF ( lrankset(jj) ) THEN
639                  nsndto(jtyp) = nsndto(jtyp) + 1
640                  IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
641                     CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
642                  &                 ' jpmaxngh will need to be increased ')
643                  ENDIF
644                  isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
645               ENDIF
646            END DO
647         ENDIF
648
649      END DO
650
651      !
652      ! Type 5: I-point
653      !
654      ! ICE point exchanges may involve some averaging. The neighbours list is
655      ! built up using two exchanges to ensure that the whole stencil is covered.
656      ! lrankset should not be reset between these 'J' and 'K' point exchanges
657
658      jtyp = 5
659      lrankset = .FALSE.
660      znnbrs = narea 
661      CALL lbc_lnk( znnbrs, 'J', 1. ) ! first ice U-V point
662
663      IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
664         DO jj = nlcj-ijpj+1, nlcj
665            ij = jj - nlcj + ijpj
666            DO ji = 1,jpi
667               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
668            &     lrankset(INT(znnbrs(ji,jj))) = .true.
669         END DO
670        END DO
671      ENDIF
672
673      znnbrs = narea 
674      CALL lbc_lnk( znnbrs, 'K', 1. ) ! second ice U-V point
675
676      IF ( njmppt(narea) .EQ. MAXVAL( njmppt )) THEN
677         DO jj = nlcj-ijpj+1, nlcj
678            ij = jj - nlcj + ijpj
679            DO ji = 1,jpi
680               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND.  INT(znnbrs(ji,jj)) .NE. narea ) &
681            &       lrankset( INT(znnbrs(ji,jj))) = .true.
682            END DO
683         END DO
684
685         DO jj = 1,jpnij
686            IF ( lrankset(jj) ) THEN
687               nsndto(jtyp) = nsndto(jtyp) + 1
688               IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
689                  CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
690               &                 ' jpmaxngh will need to be increased ')
691               ENDIF
692               isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
693            ENDIF
694         END DO
695         !
696         ! For northern row areas, set l_north_nogather so that all subsequent exchanges
697         ! can use peer to peer communications at the north fold
698         !
699         l_north_nogather = .TRUE.
700         !
701      ENDIF
702      DEALLOCATE( znnbrs )
703      DEALLOCATE( lrankset )
704
705   END SUBROUTINE nemo_northcomms
706#else
707   SUBROUTINE nemo_northcomms      ! Dummy routine
708      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
709   END SUBROUTINE nemo_northcomms
710#endif
711   !!======================================================================
712END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.