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_merge_2017/NEMOGCM/NEMO/SAO_SRC – NEMO

source: branches/2017/dev_merge_2017/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90 @ 9250

Last change on this file since 9250 was 9169, checked in by gm, 6 years ago

dev_merge_2017: all SRC: finalize the removal of useless warning when reading namelist_cfg + remove all nn_closea + nn_msh replaced by a logical

  • Property svn:keywords set to Id
File size: 28.6 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
5   !!======================================================================
6   !! History :  3.6  ! 2015-12  (A. Ryan) Original code   (from OPA_SRC/)
7   !!            4.0  ! 2016-11  (G. Madec, S. Flavoni)  domain configuration / user defined interface
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   nemo_gcm      : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
12   !!   nemo_init     : initialization of the NEMO system
13   !!   nemo_ctl      : initialisation of the contol print
14   !!   nemo_closefile: close remaining open files
15   !!   nemo_alloc    : dynamical allocation
16   !!   nemo_partition: calculate MPP domain decomposition
17   !!   factorise     : calculate the factors of the no. of MPI processes
18   !!----------------------------------------------------------------------
19   USE step_oce       ! module used in the ocean time stepping module (step.F90)
20   USE domain         ! domain initialization   (dom_init & dom_cfg routines)
21   USE istate         ! initial state setting          (istate_init routine)
22   USE phycst         ! physical constant                  (par_cst routine)
23   USE step           ! NEMO time-stepping                 (stp     routine)
24   USE cpl_oasis3     ! OASIS3 coupling
25   USE diaobs         ! Observation diagnostics       (dia_obs_init routine)
26#if defined key_nemocice_decomp
27   USE ice_domain_size, only: nx_global, ny_global
28#endif
29   !           ! Stand Alone Observation operator modules
30   USE sao_data
31   USE sao_intp
32   !
33   USE lib_mpp        ! distributed memory computing
34   USE mppini         ! shared/distributed memory setting (mpp_init routine)
35   USE lbcnfd  , ONLY : isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
36   USE lib_fortran    ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
37#if defined key_iomput
38   USE xios           ! xIOserver
39#endif
40
41   IMPLICIT NONE
42   PRIVATE
43
44   PUBLIC   nemo_gcm    ! called by model.F90
45   PUBLIC   nemo_init   ! needed by AGRIF
46   PUBLIC   nemo_alloc  ! needed by TAM
47
48   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
49
50   !!----------------------------------------------------------------------
51   !! NEMO/OPA 4.0 , NEMO Consortium (2016)
52   !! $Id$
53   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
54   !!----------------------------------------------------------------------
55CONTAINS
56
57   SUBROUTINE nemo_gcm
58         !!----------------------------------------------------------------------
59         !!                    ***  SUBROUTINE offline_obs_oper ***
60         !!
61         !! ** Purpose : To use NEMO components to interpolate model fields
62         !!              to observation space.
63         !!
64         !! ** Method : 1. Initialise NEMO
65         !!             2. Initialise offline obs_oper
66         !!             3. Cycle through match ups
67         !!             4. Write results to file
68         !!----------------------------------------------------------------------
69         !
70         CALL nemo_init       ! Initialise NEMO
71         !
72         CALL sao_data_init   ! Initialise Stand Alone Observation operator data
73         !
74         CALL dia_obs_init    ! Initialise obs_operator
75         !
76         CALL sao_interp      ! Interpolate to observation space
77         !
78         CALL dia_obs_wri     ! Pipe to output files
79         !
80         CALL dia_obs_dealloc ! Reset the obs_oper between
81         !
82         IF(lk_mpp)   CALL mppstop  ! Safely stop MPI (end mpp communications)
83         !
84   END SUBROUTINE nemo_gcm
85
86
87   SUBROUTINE nemo_init
88      !!----------------------------------------------------------------------
89      !!                     ***  ROUTINE nemo_init  ***
90      !!
91      !! ** Purpose :   initialization of the NEMO GCM
92      !!----------------------------------------------------------------------
93      INTEGER ::   ji                 ! dummy loop indices
94      INTEGER ::   ios, ilocal_comm   ! local integer
95      INTEGER  ::   iiarea, ijarea     ! local integers
96      INTEGER  ::   iirest, ijrest     ! local integers
97      CHARACTER(len=120), DIMENSION(30) ::   cltxt, cltxt2, clnam
98      !
99      NAMELIST/namctl/ ln_ctl   , nn_print, nn_ictls, nn_ictle,   &
100         &             nn_isplt , nn_jsplt, nn_jctls, nn_jctle,   &
101         &             ln_timing, ln_diacfl
102      NAMELIST/namcfg/ ln_read_cfg, cn_domcfg, ln_write_cfg, cn_domcfg_out, ln_use_jattr
103      !!----------------------------------------------------------------------
104      !
105      cltxt  = ''
106      cltxt2 = ''
107      clnam  = '' 
108      cxios_context = 'nemo'
109      !
110      !                             ! Open reference namelist and configuration namelist files
111      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
112      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
113      !
114      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints
115      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
116901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
117      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist
118      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
119902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
120      !
121      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints
122      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
123903   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
124      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
125      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
126904   IF( ios >  0 )   CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
127
128      !                             !--------------------------!
129      !                             !  Set global domain size  !   (control print return in cltxt2)
130      !                             !--------------------------!
131      IF( ln_read_cfg ) THEN              ! Read sizes in domain configuration file
132         CALL domain_cfg ( cltxt2,        cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
133         !
134      ELSE                                ! user-defined namelist
135         CALL usr_def_nam( cltxt2, clnam, cn_cfg, nn_cfg, jpiglo, jpjglo, jpkglo, jperio )
136      ENDIF
137      !
138      jpk = jpkglo
139      !
140#if defined key_agrif
141      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
142         jpiglo  = nbcellsx + 2 + 2*nbghostcells
143         jpjglo  = nbcellsy + 2 + 2*nbghostcells
144         jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
145         jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
146         nperio  = 0
147         jperio  = 0
148         ln_use_jattr = .false.
149      ENDIF
150#endif
151      !
152      !                             !--------------------------------------------!
153      !                             !  set communicator & select the local node  !
154      !                             !  NB: mynode also opens output.namelist.dyn !
155      !                             !      on unit number numond on first proc   !
156      !                             !--------------------------------------------!
157#if defined key_iomput
158      IF( Agrif_Root() ) THEN
159         IF( lk_oasis ) THEN
160            CALL cpl_init( "oceanx", ilocal_comm )                     ! nemo local communicator given by oasis
161            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
162         ELSE
163            CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
164         ENDIF
165      ENDIF
166      ! Nodes selection (control print return in cltxt)
167      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
168#else
169      IF( lk_oasis ) THEN
170         IF( Agrif_Root() ) THEN
171            CALL cpl_init( "oceanx", ilocal_comm )                      ! nemo local communicator given by oasis
172         ENDIF
173         ! Nodes selection (control print return in cltxt)
174         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
175      ELSE
176         ilocal_comm = 0
177         ! Nodes selection (control print return in cltxt)
178         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
179      ENDIF
180#endif
181
182      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
183
184      lwm = (narea == 1)                                    ! control of output namelists
185      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
186
187      IF(lwm) THEN
188         ! write merged namelists from earlier to output namelist now that the
189         ! file has been opened in call to mynode. nammpp has already been
190         ! written in mynode (if lk_mpp_mpi)
191         WRITE( numond, namctl )
192         WRITE( numond, namcfg )
193         IF( .NOT.ln_read_cfg ) THEN
194            DO ji = 1, SIZE(clnam)
195               IF( TRIM(clnam(ji)) /= '' )   WRITE(numond, * ) clnam(ji)     ! namusr_def print
196            END DO
197         ENDIF
198      ENDIF
199
200      ! If dimensions of processor grid weren't specified in the namelist file
201      ! then we calculate them here now that we have our communicator size
202      IF( jpni < 1 .OR. jpnj < 1 ) THEN
203#if   defined key_mpp_mpi
204         IF( Agrif_Root() )   CALL nemo_partition( mppsize )
205#else
206         jpni  = 1
207         jpnj  = 1
208         jpnij = jpni*jpnj
209#endif
210      ENDIF
211      !
212#if defined key_agrif
213      IF( .NOT. Agrif_Root() ) THEN       ! AGRIF children: specific setting (cf. agrif_user.F90)
214         jpiglo  = nbcellsx + 2 + 2*nbghostcells
215         jpjglo  = nbcellsy + 2 + 2*nbghostcells
216         jpi     = ( jpiglo-2*nn_hls + (jpni-1+0) ) / jpni + 2*nn_hls
217         jpj     = ( jpjglo-2*nn_hls + (jpnj-1+0) ) / jpnj + 2*nn_hls
218         jpimax  = jpi
219         jpjmax  = jpj
220         nperio  = 0
221         jperio  = 0
222         ln_use_jattr = .false.
223      ENDIF
224#endif
225
226      IF( Agrif_Root() ) THEN       ! AGRIF mother: specific setting from jpni and jpnj
227         iiarea = 1 + MOD( narea - 1 , jpni )
228         ijarea = 1 + ( narea - 1 ) / jpni
229         iirest = 1 + MOD( jpiglo - 2*nn_hls - 1 , jpni )
230         ijrest = 1 + MOD( jpjglo - 2*nn_hls - 1 , jpnj )
231#if defined key_nemocice_decomp
232         jpi = ( nx_global+2-2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
233         jpj = ( ny_global+2-2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
234         jpimax  = jpi
235         jpjmax  = jpj
236         IF( iiarea == jpni ) jpi = jpiglo - (jpni - 1) * (jpi - 2*nn_hls)
237         IF( ijarea == jpnj ) jpj = jpjglo - (jpnj - 1) * (jpj - 2*nn_hls)
238#else
239         jpi = ( jpiglo     -2*nn_hls + (jpni-1) ) / jpni + 2*nn_hls    ! first  dim.
240         jpj = ( jpjglo     -2*nn_hls + (jpnj-1) ) / jpnj + 2*nn_hls    ! second dim.
241         jpimax  = jpi
242         jpjmax  = jpj
243         IF( iiarea > iirest ) jpi = jpi - 1
244         IF( ijarea > ijrest ) jpj = jpj - 1
245#endif
246      ENDIF
247
248      jpk = jpkglo                                             ! third dim
249
250#if defined key_agrif
251      ! simple trick to use same vertical grid as parent but different number of levels:
252      ! Save maximum number of levels in jpkglo, then define all vertical grids with this number.
253      ! Suppress once vertical online interpolation is ok
254      IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo )
255#endif
256      jpim1 = jpi-1                                            ! inner domain indices
257      jpjm1 = jpj-1                                            !   "           "
258      jpkm1 = MAX( 1, jpk-1 )                                  !   "           "
259      jpij  = jpi*jpj                                          !  jpi x j
260
261      IF(lwp) THEN                            ! open listing units
262         !
263         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
264         !
265         WRITE(numout,*)
266         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
267         WRITE(numout,*) '                       NEMO team'
268         WRITE(numout,*) '            Stand Alone Observation operator'
269         WRITE(numout,*) '                NEMO version 3.7  (2015) '
270         WRITE(numout,*)
271         WRITE(numout,*)
272         DO ji = 1, SIZE(cltxt)
273            IF( TRIM(cltxt (ji)) /= '' )   WRITE(numout,*) cltxt(ji)    ! control print of mynode
274         END DO
275         WRITE(numout,*)
276         WRITE(numout,*)
277         DO ji = 1, SIZE(cltxt2)
278            IF( TRIM(cltxt2(ji)) /= '' )   WRITE(numout,*) cltxt2(ji)   ! control print of domain size
279         END DO
280         !
281         WRITE(numout,cform_aaa)                                        ! Flag AAAAAAA
282         !
283      ENDIF
284
285      ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays
286      CALL nemo_alloc()
287
288      !                             !-------------------------------!
289      !                             !  NEMO general initialization  !
290      !                             !-------------------------------!
291
292      CALL nemo_ctl                             ! Control prints & Benchmark
293
294      !                                      ! Domain decomposition
295      CALL mpp_init
296      !
297      IF( ln_timing    )   CALL timing_init     ! timing by routine
298      !
299      !                                         ! General initialization
300                           CALL phy_cst            ! Physical constants
301                           CALL eos_init           ! Equation of state
302                           CALL dom_init           ! Domain
303
304      IF( ln_nnogather )   CALL nemo_northcomms ! Initialise the northfold neighbour lists (must be done after the masks are defined)
305
306      IF( ln_ctl       )   CALL prt_ctl_init    ! Print control
307
308                           CALL istate_init     ! ocean initial state (Dynamics and tracers)
309   END SUBROUTINE nemo_init
310
311
312   SUBROUTINE nemo_ctl
313      !!----------------------------------------------------------------------
314      !!                     ***  ROUTINE nemo_ctl  ***
315      !!
316      !! ** Purpose :   control print setting
317      !!
318      !! ** Method  : - print namctl information and check some consistencies
319      !!----------------------------------------------------------------------
320      !
321      IF(lwp) THEN                  ! control print
322         WRITE(numout,*)
323         WRITE(numout,*) 'nemo_ctl: Control prints'
324         WRITE(numout,*) '~~~~~~~ '
325         WRITE(numout,*) '   Namelist namctl'
326         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
327         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
328         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
329         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
330         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
331         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
332         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
333         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
334         WRITE(numout,*) '      timing by routine               ln_timing  = ', ln_timing
335         WRITE(numout,*) '      CFL diagnostics                 ln_diacfl  = ', ln_diacfl
336      ENDIF
337      !
338      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
339      nictls    = nn_ictls
340      nictle    = nn_ictle
341      njctls    = nn_jctls
342      njctle    = nn_jctle
343      isplt     = nn_isplt
344      jsplt     = nn_jsplt
345
346      IF(lwp) THEN                  ! control print
347         WRITE(numout,*)
348         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
349         WRITE(numout,*) '~~~~~~~ '
350         WRITE(numout,*) '   Namelist namcfg'
351         WRITE(numout,*) '      read domain configuration file                ln_read_cfg      = ', ln_read_cfg
352         WRITE(numout,*) '         filename to be read                           cn_domcfg     = ', TRIM(cn_domcfg)
353         WRITE(numout,*) '      write configuration definition file           ln_write_cfg     = ', ln_write_cfg
354         WRITE(numout,*) '         filename to be written                        cn_domcfg_out = ', TRIM(cn_domcfg_out)
355         WRITE(numout,*) '      use file attribute if exists as i/p j-start   ln_use_jattr     = ', ln_use_jattr
356      ENDIF
357      !                             ! Parameter control
358      !
359      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
360         IF( lk_mpp .AND. jpnij > 1 ) THEN
361            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
362         ELSE
363            IF( isplt == 1 .AND. jsplt == 1  ) THEN
364               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
365                  &           ' - the print control will be done over the whole domain' )
366            ENDIF
367            ijsplt = isplt * jsplt            ! total number of processors ijsplt
368         ENDIF
369         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
370         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
371         !
372         !                              ! indices used for the SUM control
373         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
374            lsp_area = .FALSE.
375         ELSE                                             ! print control done over a specific  area
376            lsp_area = .TRUE.
377            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
378               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
379               nictls = 1
380            ENDIF
381            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
382               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
383               nictle = jpiglo
384            ENDIF
385            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
386               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
387               njctls = 1
388            ENDIF
389            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
390               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
391               njctle = jpjglo
392            ENDIF
393         ENDIF
394      ENDIF
395      !
396      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
397         &                                               'f2003 standard. '                              ,  &
398         &                                               'Compile with key_nosignedzero enabled' )
399      !
400   END SUBROUTINE nemo_ctl
401
402
403   SUBROUTINE nemo_closefile
404      !!----------------------------------------------------------------------
405      !!                     ***  ROUTINE nemo_closefile  ***
406      !!
407      !! ** Purpose :   Close the files
408      !!----------------------------------------------------------------------
409      !
410      IF( lk_mpp )   CALL mppsync
411      !
412      CALL iom_close                                 ! close all input/output files managed by iom_*
413      !
414      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
415      IF( numrun          /= -1 )   CLOSE( numrun          )   ! run statistics 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( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
419      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
420      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
421      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
422      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
423      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
424      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
425      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
426      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
427      !
428      numout = 6                                     ! redefine numout in case it is used after this point...
429      !
430   END SUBROUTINE nemo_closefile
431
432
433   SUBROUTINE nemo_alloc
434      !!----------------------------------------------------------------------
435      !!                     ***  ROUTINE nemo_alloc  ***
436      !!
437      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
438      !!
439      !! ** Method  :
440      !!----------------------------------------------------------------------
441      USE diawri    , ONLY: dia_wri_alloc
442      USE dom_oce   , ONLY: dom_oce_alloc
443      !
444      INTEGER :: ierr
445      !!----------------------------------------------------------------------
446      !
447      ierr =        oce_alloc       ()          ! ocean
448      ierr = ierr + dia_wri_alloc   ()
449      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
450      !
451      IF( lk_mpp    )   CALL mpp_sum( ierr )
452      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
453      !
454   END SUBROUTINE nemo_alloc
455
456
457   SUBROUTINE nemo_partition( num_pes )
458      !!----------------------------------------------------------------------
459      !!                 ***  ROUTINE nemo_partition  ***
460      !!
461      !! ** Purpose :
462      !!
463      !! ** Method  :
464      !!----------------------------------------------------------------------
465      INTEGER, INTENT(in) ::   num_pes   ! The number of MPI processes we have
466      !
467      INTEGER, PARAMETER :: nfactmax = 20
468      INTEGER :: nfact ! The no. of factors returned
469      INTEGER :: ierr  ! Error flag
470      INTEGER :: ji
471      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
472      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
473      !!----------------------------------------------------------------------
474      !
475      ierr = 0
476      !
477      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
478      !
479      IF( nfact <= 1 ) THEN
480         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
481         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
482         jpnj = 1
483         jpni = num_pes
484      ELSE
485         ! Search through factors for the pair that are closest in value
486         mindiff = 1000000
487         imin    = 1
488         DO ji = 1, nfact-1, 2
489            idiff = ABS( ifact(ji) - ifact(ji+1) )
490            IF( idiff < mindiff ) THEN
491               mindiff = idiff
492               imin = ji
493            ENDIF
494         END DO
495         jpnj = ifact(imin)
496         jpni = ifact(imin + 1)
497      ENDIF
498      !
499      jpnij = jpni*jpnj
500      !
501   END SUBROUTINE nemo_partition
502
503
504   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
505      !!----------------------------------------------------------------------
506      !!                     ***  ROUTINE factorise  ***
507      !!
508      !! ** Purpose :   return the prime factors of n.
509      !!                knfax factors are returned in array kfax which is of
510      !!                maximum dimension kmaxfax.
511      !! ** Method  :
512      !!----------------------------------------------------------------------
513      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
514      INTEGER                    , INTENT(  out) ::   kerr, knfax
515      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
516      !
517      INTEGER :: ifac, jl, inu
518      INTEGER, PARAMETER :: ntest = 14
519      INTEGER, DIMENSION(ntest) ::   ilfax
520      !!----------------------------------------------------------------------
521      !
522      ! lfax contains the set of allowed factors.
523      ilfax(:) = (/(2**jl,jl=ntest,1,-1)/)
524      !
525      ! Clear the error flag and initialise output vars
526      kerr  = 0
527      kfax  = 1
528      knfax = 0
529      !
530      ! Find the factors of n.
531      IF( kn .NE. 1 ) THEN
532
533         ! nu holds the unfactorised part of the number.
534         ! knfax holds the number of factors found.
535         ! l points to the allowed factor list.
536         ! ifac holds the current factor.
537         !
538         inu   = kn
539         knfax = 0
540         !
541         DO jl = ntest, 1, -1
542            !
543            ifac = ilfax(jl)
544            IF( ifac > inu )   CYCLE
545   
546            ! Test whether the factor will divide.
547   
548            IF( MOD(inu,ifac) == 0 ) THEN
549               !
550               knfax = knfax + 1            ! Add the factor to the list
551               IF( knfax > kmaxfax ) THEN
552                  kerr = 6
553                  write (*,*) 'FACTOR: insufficient space in factor array ', knfax
554                  return
555               ENDIF
556               kfax(knfax) = ifac
557               ! Store the other factor that goes with this one
558               knfax = knfax + 1
559               kfax(knfax) = inu / ifac
560               !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
561            ENDIF
562            !
563         END DO
564         !
565      ENDIF
566      !
567   END SUBROUTINE factorise
568
569#if defined key_mpp_mpi
570
571   SUBROUTINE nemo_northcomms
572      !!----------------------------------------------------------------------
573      !!                     ***  ROUTINE  nemo_northcomms  ***
574      !! ** Purpose :   Setup for north fold exchanges with explicit
575      !!                point-to-point messaging
576      !!
577      !! ** Method :   Initialization of the northern neighbours lists.
578      !!----------------------------------------------------------------------
579      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
580      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
581      !!----------------------------------------------------------------------
582      INTEGER  ::   sxM, dxM, sxT, dxT, jn
583      INTEGER  ::   njmppmax
584      !!----------------------------------------------------------------------
585      !
586      njmppmax = MAXVAL( njmppt )
587      !
588      !initializes the north-fold communication variables
589      isendto(:) = 0
590      nsndto     = 0
591      !
592      !if I am a process in the north
593      IF ( njmpp == njmppmax ) THEN
594          !sxM is the first point (in the global domain) needed to compute the
595          !north-fold for the current process
596          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
597          !dxM is the last point (in the global domain) needed to compute the
598          !north-fold for the current process
599          dxM = jpiglo - nimppt(narea) + 2
600
601          !loop over the other north-fold processes to find the processes
602          !managing the points belonging to the sxT-dxT range
603 
604          DO jn = 1, jpni
605                !sxT is the first point (in the global domain) of the jn
606                !process
607                sxT = nfiimpp(jn, jpnj)
608                !dxT is the last point (in the global domain) of the jn
609                !process
610                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
611                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
612                   nsndto = nsndto + 1
613                   isendto(nsndto) = jn
614                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
615                   nsndto = nsndto + 1
616                   isendto(nsndto) = jn
617                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
618                   nsndto = nsndto + 1
619                   isendto(nsndto) = jn
620                ENDIF
621          END DO
622          nfsloop = 1
623          nfeloop = nlci
624          DO jn = 2,jpni-1
625           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
626              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
627                 nfsloop = nldi
628              ENDIF
629              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
630                 nfeloop = nlei
631              ENDIF
632           ENDIF
633        END DO
634
635      ENDIF
636      l_north_nogather = .TRUE.
637   END SUBROUTINE nemo_northcomms
638
639#else
640   SUBROUTINE nemo_northcomms      ! Dummy routine
641      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
642   END SUBROUTINE nemo_northcomms
643#endif
644
645   !!======================================================================
646END MODULE nemogcm
647
Note: See TracBrowser for help on using the repository browser.