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

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

merge in dev_LOCEAN_2013, the 1st development branch dev_r3853_CNRS9_Confsetting, from its starting point ( r3853 ) on the trunk: see ticket #1169

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