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_r3853_CNRS9_ConfSetting/NEMOGCM/NEMO/SAS_SRC – NEMO

source: branches/2013/dev_r3853_CNRS9_ConfSetting/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 3954

Last change on this file since 3954 was 3954, checked in by clevy, 11 years ago

Configuration setting/Step2, additions, see ticket:#1074

File size: 29.5 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 :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
7   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
8   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
9   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
10   !!             -   ! 1992-06  (L.Terray)  coupling implementation
11   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
12   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
13   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
14   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
15   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
16   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
17   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
18   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
19   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
20   !!             -   ! 2004-08  (C. Talandier) New trends organization
21   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
22   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
23   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
24   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
25   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
26   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
27   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
28   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
29   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
30   !!            3.4  ! 2011-11  (C. Harris) decomposition changes for running with CICE
31   !!----------------------------------------------------------------------
32
33   !!----------------------------------------------------------------------
34   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
35   !!   nemo_init      : initialization of the NEMO system
36   !!   nemo_ctl       : initialisation of the contol print
37   !!   nemo_closefile : close remaining open files
38   !!   nemo_alloc     : dynamical allocation
39   !!   nemo_partition : calculate MPP domain decomposition
40   !!   factorise      : calculate the factors of the no. of MPI processes
41   !!----------------------------------------------------------------------
42   USE step_oce        ! module used in the ocean time stepping module
43   USE sbc_oce         ! surface boundary condition: ocean
44   USE cla             ! cross land advection               (tra_cla routine)
45   USE domcfg          ! domain configuration               (dom_cfg routine)
46   USE daymod          ! calendar
47   USE mppini          ! shared/distributed memory setting (mpp_init routine)
48   USE domain          ! domain initialization             (dom_init routine)
49   USE phycst          ! physical constant                  (par_cst routine)
50   USE step            ! NEMO time-stepping                 (stp     routine)
51   USE lib_mpp         ! distributed memory computing
52#if defined key_iomput
53   USE xios
54#endif
55   USE sbcssm
56
57   IMPLICIT NONE
58   PRIVATE
59
60   PUBLIC   nemo_gcm    ! called by model.F90
61   PUBLIC   nemo_init   ! needed by AGRIF
62
63   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
64
65   !!----------------------------------------------------------------------
66   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
67   !! $Id: nemogcm.F90 3294 2012-01-28 16:44:18Z rblod $
68   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
69   !!----------------------------------------------------------------------
70CONTAINS
71
72   SUBROUTINE nemo_gcm
73      !!----------------------------------------------------------------------
74      !!                     ***  ROUTINE nemo_gcm  ***
75      !!
76      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
77      !!              curvilinear mesh on the sphere.
78      !!
79      !! ** Method  : - model general initialization
80      !!              - launch the time-stepping (stp routine)
81      !!              - finalize the run by closing files and communications
82      !!
83      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
84      !!              Madec, 2008, internal report, IPSL.
85      !!----------------------------------------------------------------------
86      INTEGER ::   istp       ! time step index
87      !!----------------------------------------------------------------------
88      !
89#if defined key_agrif
90      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
91#endif
92
93      !                            !-----------------------!
94      CALL nemo_init               !==  Initialisations  ==!
95      !                            !-----------------------!
96#if defined key_agrif
97      CALL Agrif_Declare_Var       ! AGRIF: set the meshes
98#endif
99      ! check that all process are still there... If some process have an error,
100      ! they will never enter in step and other processes will wait until the end of the cpu time!
101      IF( lk_mpp )   CALL mpp_max( nstop )
102
103      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
104
105      !                            !-----------------------!
106      !                            !==   time stepping   ==!
107      !                            !-----------------------!
108      istp = nit000
109       
110      DO WHILE ( istp <= nitend .AND. nstop == 0 )
111#if defined key_agrif
112         CALL Agrif_Step( stp )           ! AGRIF: time stepping
113#else
114         CALL stp( istp )                 ! standard time stepping
115#endif
116         istp = istp + 1
117         IF( lk_mpp )   CALL mpp_max( nstop )
118      END DO
119      !                            !------------------------!
120      !                            !==  finalize the run  ==!
121      !                            !------------------------!
122      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
123      !
124      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
125         WRITE(numout,cform_err)
126         WRITE(numout,*) nstop, ' error have been found' 
127      ENDIF
128      !
129#if defined key_agrif
130      CALL Agrif_ParentGrid_To_ChildGrid()
131      IF( nn_timing == 1 )   CALL timing_finalize
132      CALL Agrif_ChildGrid_To_ParentGrid()
133#endif
134      IF( nn_timing == 1 )   CALL timing_finalize
135      !
136      CALL nemo_closefile
137#if defined key_iomput
138      CALL xios_finalize                ! end mpp communications with xios
139#else
140      IF( lk_mpp )   CALL mppstop       ! end mpp communications
141#endif
142      !
143   END SUBROUTINE nemo_gcm
144
145
146   SUBROUTINE nemo_init
147      !!----------------------------------------------------------------------
148      !!                     ***  ROUTINE nemo_init  ***
149      !!
150      !! ** Purpose :   initialization of the NEMO GCM
151      !!----------------------------------------------------------------------
152      INTEGER ::   ji            ! dummy loop indices
153      INTEGER ::   ilocal_comm   ! local integer     
154      INTEGER ::   ios
155
156      CHARACTER(len=80), DIMENSION(16) ::   cltxt
157      !!
158      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
159         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
160         &             nn_bench, nn_timing
161      !!----------------------------------------------------------------------
162      !
163      cltxt = ''      !
164      !                             ! Open reference namelist and configuration namelist files
165      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
166      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
167      CALL ctl_opn( numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
168      !
169      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
170      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
171901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', lwp )
172
173      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
174      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
175902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', lwp )
176      WRITE( numond, namctl )
177      !
178      !                             !--------------------------------------------!
179      !                             !  set communicator & select the local node  !
180      !                             !--------------------------------------------!
181#if defined key_iomput
182      IF( Agrif_Root() ) THEN
183         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
184      ENDIF
185      narea = mynode ( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )  ! Nodes selection
186#else
187      ilocal_comm = 0
188      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )        ! Nodes selection (control print return in cltxt)
189#endif
190      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
191
192      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
193
194      ! If dimensions of processor grid weren't specified in the namelist file
195      ! then we calculate them here now that we have our communicator size
196      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
197#if   defined key_mpp_mpi
198         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
199#else
200         jpni  = 1
201         jpnj  = 1
202         jpnij = jpni*jpnj
203#endif
204      END IF
205
206      ! Calculate domain dimensions given calculated jpni and jpnj
207      ! This used to be done in par_oce.F90 when they were parameters rather
208      ! than variables
209      IF( Agrif_Root() ) THEN
210         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
211#if defined key_nemocice_decomp
212         jpj = ( jpjglo+1-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
213#else
214         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
215#endif
216         jpk = jpkdta                                             ! third dim
217         jpim1 = jpi-1                                            ! inner domain indices
218         jpjm1 = jpj-1                                            !   "           "
219         jpkm1 = jpk-1                                            !   "           "
220         jpij  = jpi*jpj                                          !  jpi x j
221      ENDIF
222
223      IF(lwp) THEN                            ! open listing units
224         !
225         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
226         !
227         WRITE(numout,*)
228         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
229         WRITE(numout,*) '                       NEMO team'
230         WRITE(numout,*) '            Ocean General Circulation Model'
231         WRITE(numout,*) '                  version 3.4  (2011) '
232         WRITE(numout,*) '             StandAlone Surface version (SAS) '
233         WRITE(numout,*)
234         WRITE(numout,*)
235         DO ji = 1, SIZE(cltxt) 
236            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
237         END DO
238         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
239         !
240      ENDIF
241
242      ! Now we know the dimensions of the grid and numout has been set we can
243      ! allocate arrays
244      CALL nemo_alloc()
245
246      !                             !-------------------------------!
247      !                             !  NEMO general initialization  !
248      !                             !-------------------------------!
249
250      CALL nemo_ctl                          ! Control prints & Benchmark
251
252      !                                      ! Domain decomposition
253      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
254      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
255      ENDIF
256      !
257      IF( nn_timing == 1 )  CALL timing_init
258      !
259      !                                     ! General initialization
260                            CALL phy_cst    ! Physical constants
261                            CALL eos_init   ! Equation of state
262                            CALL dom_cfg    ! Domain configuration
263                            CALL dom_init   ! Domain
264
265      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
266
267      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
268                            CALL flush(numout)
269
270                            CALL day_init   ! model calendar (using both namelist and restart infos)
271
272                            CALL sbc_init   ! Forcings : surface module
273     
274      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
275      !
276   END SUBROUTINE nemo_init
277
278
279   SUBROUTINE nemo_ctl
280      !!----------------------------------------------------------------------
281      !!                     ***  ROUTINE nemo_ctl  ***
282      !!
283      !! ** Purpose :   control print setting
284      !!
285      !! ** Method  : - print namctl information and check some consistencies
286      !!----------------------------------------------------------------------
287      !
288      IF(lwp) THEN                  ! control print
289         WRITE(numout,*)
290         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
291         WRITE(numout,*) '~~~~~~~ '
292         WRITE(numout,*) '   Namelist namctl'
293         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
294         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
295         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
296         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
297         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
298         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
299         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
300         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
301         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
302      ENDIF
303      !
304      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
305      nictls    = nn_ictls
306      nictle    = nn_ictle
307      njctls    = nn_jctls
308      njctle    = nn_jctle
309      isplt     = nn_isplt
310      jsplt     = nn_jsplt
311      nbench    = nn_bench
312      !                             ! Parameter control
313      !
314      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
315         IF( lk_mpp .AND. jpnij > 1 ) THEN
316            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
317         ELSE
318            IF( isplt == 1 .AND. jsplt == 1  ) THEN
319               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
320                  &           ' - the print control will be done over the whole domain' )
321            ENDIF
322            ijsplt = isplt * jsplt            ! total number of processors ijsplt
323         ENDIF
324         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
325         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
326         !
327         !                              ! indices used for the SUM control
328         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
329            lsp_area = .FALSE.                       
330         ELSE                                             ! print control done over a specific  area
331            lsp_area = .TRUE.
332            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
333               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
334               nictls = 1
335            ENDIF
336            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
337               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
338               nictle = jpiglo
339            ENDIF
340            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
341               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
342               njctls = 1
343            ENDIF
344            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
345               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
346               njctle = jpjglo
347            ENDIF
348         ENDIF
349      ENDIF
350      !
351      IF( nbench == 1 ) THEN              ! Benchmark
352         SELECT CASE ( cp_cfg )
353         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
354         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
355            &                                 ' key_gyre must be used or set nbench = 0' )
356         END SELECT
357      ENDIF
358      !
359   END SUBROUTINE nemo_ctl
360
361
362   SUBROUTINE nemo_closefile
363      !!----------------------------------------------------------------------
364      !!                     ***  ROUTINE nemo_closefile  ***
365      !!
366      !! ** Purpose :   Close the files
367      !!----------------------------------------------------------------------
368      !
369      IF( lk_mpp )   CALL mppsync
370      !
371      CALL iom_close                                 ! close all input/output files managed by iom_*
372      !
373      IF( numstp          /= -1 )   CLOSE( numstp      )   ! time-step file     
374      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
375      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
376      IF( numond          /= -1 )   CLOSE( numond          )   ! oce output namelist
377      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
378      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
379      IF( numoni          /= -1 )   CLOSE( numoni          )   ! ice output namelist
380      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice  )   ! ice variables (temp. evolution)
381      IF( numout          /=  6 )   CLOSE( numout      )   ! standard model output file
382      !
383      numout = 6                                     ! redefine numout in case it is used after this point...
384      !
385   END SUBROUTINE nemo_closefile
386
387
388   SUBROUTINE nemo_alloc
389      !!----------------------------------------------------------------------
390      !!                     ***  ROUTINE nemo_alloc  ***
391      !!
392      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
393      !!
394      !! ** Method  :
395      !!----------------------------------------------------------------------
396      USE diawri    , ONLY: dia_wri_alloc
397      USE dom_oce   , ONLY: dom_oce_alloc
398      USE oce       , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass 
399      !
400      INTEGER :: ierr,ierr4
401      !!----------------------------------------------------------------------
402      !
403      ierr =        dia_wri_alloc   ()
404      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
405      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
406      ALLOCATE( snwice_mass(jpi,jpj)  , snwice_mass_b(jpi,jpj),             &
407         &      snwice_fmass(jpi,jpj), STAT= ierr4 )
408      ierr = ierr + ierr4
409      !
410      IF( lk_mpp    )   CALL mpp_sum( ierr )
411      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
412      !
413   END SUBROUTINE nemo_alloc
414
415
416   SUBROUTINE nemo_partition( num_pes )
417      !!----------------------------------------------------------------------
418      !!                 ***  ROUTINE nemo_partition  ***
419      !!
420      !! ** Purpose :   
421      !!
422      !! ** Method  :
423      !!----------------------------------------------------------------------
424      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
425      !
426      INTEGER, PARAMETER :: nfactmax = 20
427      INTEGER :: nfact ! The no. of factors returned
428      INTEGER :: ierr  ! Error flag
429      INTEGER :: ji
430      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
431      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
432      !!----------------------------------------------------------------------
433
434      ierr = 0
435
436      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
437
438      IF( nfact <= 1 ) THEN
439         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
440         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
441         jpnj = 1
442         jpni = num_pes
443      ELSE
444         ! Search through factors for the pair that are closest in value
445         mindiff = 1000000
446         imin    = 1
447         DO ji = 1, nfact-1, 2
448            idiff = ABS( ifact(ji) - ifact(ji+1) )
449            IF( idiff < mindiff ) THEN
450               mindiff = idiff
451               imin = ji
452            ENDIF
453         END DO
454         jpnj = ifact(imin)
455         jpni = ifact(imin + 1)
456      ENDIF
457      !
458      jpnij = jpni*jpnj
459      !
460   END SUBROUTINE nemo_partition
461
462
463   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
464      !!----------------------------------------------------------------------
465      !!                     ***  ROUTINE factorise  ***
466      !!
467      !! ** Purpose :   return the prime factors of n.
468      !!                knfax factors are returned in array kfax which is of
469      !!                maximum dimension kmaxfax.
470      !! ** Method  :
471      !!----------------------------------------------------------------------
472      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
473      INTEGER                    , INTENT(  out) ::   kerr, knfax
474      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
475      !
476      INTEGER :: ifac, jl, inu
477      INTEGER, PARAMETER :: ntest = 14
478      INTEGER :: ilfax(ntest)
479
480      ! lfax contains the set of allowed factors.
481      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
482         &                            128,   64,   32,   16,    8,   4,   2  /
483      !!----------------------------------------------------------------------
484
485      ! Clear the error flag and initialise output vars
486      kerr = 0
487      kfax = 1
488      knfax = 0
489
490      ! Find the factors of n.
491      IF( kn == 1 )   GOTO 20
492
493      ! nu holds the unfactorised part of the number.
494      ! knfax holds the number of factors found.
495      ! l points to the allowed factor list.
496      ! ifac holds the current factor.
497
498      inu   = kn
499      knfax = 0
500
501      DO jl = ntest, 1, -1
502         !
503         ifac = ilfax(jl)
504         IF( ifac > inu )   CYCLE
505
506         ! Test whether the factor will divide.
507
508         IF( MOD(inu,ifac) == 0 ) THEN
509            !
510            knfax = knfax + 1            ! Add the factor to the list
511            IF( knfax > kmaxfax ) THEN
512               kerr = 6
513               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
514               return
515            ENDIF
516            kfax(knfax) = ifac
517            ! Store the other factor that goes with this one
518            knfax = knfax + 1
519            kfax(knfax) = inu / ifac
520            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
521         ENDIF
522         !
523      END DO
524
525   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
526      !
527   END SUBROUTINE factorise
528
529#if defined key_mpp_mpi
530   SUBROUTINE nemo_northcomms
531      !!======================================================================
532      !!                     ***  ROUTINE  nemo_northcomms  ***
533      !! nemo_northcomms    :  Setup for north fold exchanges with explicit peer to peer messaging
534      !!=====================================================================
535      !!----------------------------------------------------------------------
536      !!
537      !! ** Purpose :   Initialization of the northern neighbours lists.
538      !!----------------------------------------------------------------------
539      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
540      !!----------------------------------------------------------------------
541
542      INTEGER ::   ji, jj, jk, ij, jtyp    ! dummy loop indices
543      INTEGER ::   ijpj                    ! number of rows involved in north-fold exchange
544      INTEGER ::   northcomms_alloc        ! allocate return status
545      REAL(wp), ALLOCATABLE, DIMENSION ( :,: ) ::   znnbrs     ! workspace
546      LOGICAL,  ALLOCATABLE, DIMENSION ( : )   ::   lrankset   ! workspace
547
548      IF(lwp) WRITE(numout,*)
549      IF(lwp) WRITE(numout,*) 'nemo_northcomms : Initialization of the northern neighbours lists'
550      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
551
552      !!----------------------------------------------------------------------
553      ALLOCATE( znnbrs(jpi,jpj), stat = northcomms_alloc )
554      ALLOCATE( lrankset(jpnij), stat = northcomms_alloc )
555      IF( northcomms_alloc /= 0 ) THEN
556         WRITE(numout,cform_war)
557         WRITE(numout,*) 'northcomms_alloc : failed to allocate arrays'
558         CALL ctl_stop( 'STOP', 'nemo_northcomms : unable to allocate temporary arrays' )
559      ENDIF
560      nsndto = 0
561      isendto = -1
562      ijpj   = 4
563      !
564      ! This routine has been called because ln_nnogather has been set true ( nammpp )
565      ! However, these first few exchanges have to use the mpi_allgather method to
566      ! establish the neighbour lists to use in subsequent peer to peer exchanges.
567      ! Consequently, set l_north_nogather to be false here and set it true only after
568      ! the lists have been established.
569      !
570      l_north_nogather = .FALSE.
571      !
572      ! Exchange and store ranks on northern rows
573
574      DO jtyp = 1,4
575
576         lrankset = .FALSE.
577         znnbrs = narea
578         SELECT CASE (jtyp)
579            CASE(1)
580               CALL lbc_lnk( znnbrs, 'T', 1. )      ! Type 1: T,W-points
581            CASE(2)
582               CALL lbc_lnk( znnbrs, 'U', 1. )      ! Type 2: U-point
583            CASE(3)
584               CALL lbc_lnk( znnbrs, 'V', 1. )      ! Type 3: V-point
585            CASE(4)
586               CALL lbc_lnk( znnbrs, 'F', 1. )      ! Type 4: F-point
587         END SELECT
588
589         IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
590            DO jj = nlcj-ijpj+1, nlcj
591               ij = jj - nlcj + ijpj
592               DO ji = 1,jpi
593                  IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
594               &     lrankset(INT(znnbrs(ji,jj))) = .true.
595               END DO
596            END DO
597
598            DO jj = 1,jpnij
599               IF ( lrankset(jj) ) THEN
600                  nsndto(jtyp) = nsndto(jtyp) + 1
601                  IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
602                     CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
603                  &                 ' jpmaxngh will need to be increased ')
604                  ENDIF
605                  isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
606               ENDIF
607            END DO
608         ENDIF
609
610      END DO
611
612      !
613      ! Type 5: I-point
614      !
615      ! ICE point exchanges may involve some averaging. The neighbours list is
616      ! built up using two exchanges to ensure that the whole stencil is covered.
617      ! lrankset should not be reset between these 'J' and 'K' point exchanges
618
619      jtyp = 5
620      lrankset = .FALSE.
621      znnbrs = narea 
622      CALL lbc_lnk( znnbrs, 'J', 1. ) ! first ice U-V point
623
624      IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
625         DO jj = nlcj-ijpj+1, nlcj
626            ij = jj - nlcj + ijpj
627            DO ji = 1,jpi
628               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
629            &     lrankset(INT(znnbrs(ji,jj))) = .true.
630         END DO
631        END DO
632      ENDIF
633
634      znnbrs = narea 
635      CALL lbc_lnk( znnbrs, 'K', 1. ) ! second ice U-V point
636
637      IF ( njmppt(narea) .EQ. MAXVAL( njmppt )) THEN
638         DO jj = nlcj-ijpj+1, nlcj
639            ij = jj - nlcj + ijpj
640            DO ji = 1,jpi
641               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND.  INT(znnbrs(ji,jj)) .NE. narea ) &
642            &       lrankset( INT(znnbrs(ji,jj))) = .true.
643            END DO
644         END DO
645
646         DO jj = 1,jpnij
647            IF ( lrankset(jj) ) THEN
648               nsndto(jtyp) = nsndto(jtyp) + 1
649               IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
650                  CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
651               &                 ' jpmaxngh will need to be increased ')
652               ENDIF
653               isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
654            ENDIF
655         END DO
656         !
657         ! For northern row areas, set l_north_nogather so that all subsequent exchanges
658         ! can use peer to peer communications at the north fold
659         !
660         l_north_nogather = .TRUE.
661         !
662      ENDIF
663      DEALLOCATE( znnbrs )
664      DEALLOCATE( lrankset )
665
666   END SUBROUTINE nemo_northcomms
667#else
668   SUBROUTINE nemo_northcomms      ! Dummy routine
669      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
670   END SUBROUTINE nemo_northcomms
671#endif
672   !!======================================================================
673END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.