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_r3987_UKMO4_OBS/NEMOGCM/NEMO/OOO_SRC – NEMO

source: branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/NEMO/OOO_SRC/nemogcm.F90 @ 4120

Last change on this file since 4120 was 4120, checked in by andrewryan, 10 years ago

Refactored offline_obs_oper to be nemo_gcm. Renamed ooomod.F90 to ooo_intp.F90 since it now contains the interpolation steps only. Renamed namelist to ooo.nml since it contains settings for the offline obs_oper only.

  • Property svn:keywords set to Id
File size: 28.8 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 domcfg          ! domain configuration               (dom_cfg routine)
44   USE mppini          ! shared/distributed memory setting (mpp_init routine)
45   USE domain          ! domain initialization             (dom_init routine)
46#if defined key_nemocice_decomp
47   USE ice_domain_size, only: nx_global, ny_global
48#endif
49   USE istate          ! initial state setting          (istate_init routine)
50   USE phycst          ! physical constant                  (par_cst routine)
51   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
52   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
53   USE step            ! NEMO time-stepping                 (stp     routine)
54   USE icbini          ! handle bergs, initialisation
55   USE icbstp          ! handle bergs, calving, themodynamics and transport
56#if defined key_oasis3
57   USE cpl_oasis3      ! OASIS3 coupling
58#elif defined key_oasis4
59   USE cpl_oasis4      ! OASIS4 coupling (not working)
60#endif
61   USE lib_mpp         ! distributed memory computing
62#if defined key_iomput
63   USE xios
64#endif
65   USE ooo_data        ! Offline obs_oper data
66   USE ooo_read        ! Offline obs_oper read routines
67   USE ooo_intp        ! Offline obs_oper interpolation
68
69   IMPLICIT NONE
70   PRIVATE
71
72   PUBLIC   nemo_gcm    ! called by nemo.f90
73   PUBLIC   nemo_init   ! needed by AGRIF
74   PUBLIC   nemo_alloc  ! needed by TAM
75
76   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
77
78   !!----------------------------------------------------------------------
79   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
80   !! $Id$
81   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
82   !!----------------------------------------------------------------------
83CONTAINS
84
85   SUBROUTINE nemo_gcm
86         !!----------------------------------------------------------------------
87         !!                    ***  SUBROUTINE offline_obs_oper ***
88         !!
89         !! ** Purpose : To use NEMO components to interpolate model fields
90         !!              to observation space.
91         !!
92         !! ** Method : 1. Initialise NEMO
93         !!             2. Initialise offline obs_oper
94         !!             3. Cycle through match ups
95         !!             4. Write results to file
96         !!
97         !!----------------------------------------------------------------------
98         !! Class 4 output stream switch
99         USE obs_fbm, ONLY: ln_cl4
100         !! Initialise NEMO
101         CALL nemo_init
102         !! Initialise Offline obs_oper data
103         CALL ooo_data_init( ln_cl4 )
104         !! Loop over various model counterparts
105         DO jimatch = 1, cl4_match_len
106            IF (jimatch .GT. 1) THEN
107               !! Initialise obs_oper
108               CALL dia_obs_init
109            END IF
110            !! Interpolate to observation space
111            CALL ooo_interp
112            !! Pipe to output files
113            CALL dia_obs_wri
114            !! Reset the obs_oper between
115            CALL dia_obs_dealloc
116         END DO
117         !! Safely stop MPI
118         IF(lk_mpp) CALL mppstop  ! end mpp communications
119   END SUBROUTINE nemo_gcm
120
121   SUBROUTINE nemo_init
122      !!----------------------------------------------------------------------
123      !!                     ***  ROUTINE nemo_init  ***
124      !!
125      !! ** Purpose :   initialization of the NEMO GCM
126      !!----------------------------------------------------------------------
127      INTEGER ::   ji            ! dummy loop indices
128      INTEGER ::   ilocal_comm   ! local integer
129      CHARACTER(len=80), DIMENSION(16) ::   cltxt
130      !!
131      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
132         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
133         &             nn_bench, nn_timing
134      !!----------------------------------------------------------------------
135      !
136      cltxt = ''
137      !
138      !                             ! open Namelist file
139      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
140      !
141      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
142      !
143      !                             !--------------------------------------------!
144      !                             !  set communicator & select the local node  !
145      !                             !--------------------------------------------!
146#if defined key_iomput
147      IF( Agrif_Root() ) THEN
148# if defined key_oasis3 || defined key_oasis4
149         CALL cpl_prism_init( ilocal_comm )      ! nemo local communicator given by oasis
150         CALL xios_initialize( "oceanx",local_comm=ilocal_comm )
151# else
152         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
153# endif
154      ENDIF
155      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection
156#else
157# if defined key_oasis3 || defined key_oasis4
158      IF( Agrif_Root() ) THEN
159         CALL cpl_prism_init( ilocal_comm )                 ! nemo local communicator given by oasis
160      ENDIF
161      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection (control print return in cltxt)
162# else
163      ilocal_comm = 0
164      narea = mynode( cltxt, numnam, nstop )                 ! Nodes selection (control print return in cltxt)
165# endif
166#endif
167      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
168
169      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
170
171      ! If dimensions of processor grid weren't specified in the namelist file
172      ! then we calculate them here now that we have our communicator size
173      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
174#if   defined key_mpp_mpi
175         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
176#else
177         jpni  = 1
178         jpnj  = 1
179         jpnij = jpni*jpnj
180#endif
181      END IF
182
183      ! Calculate domain dimensions given calculated jpni and jpnj
184      ! This used to be done in par_oce.F90 when they were parameters rather
185      ! than variables
186      IF( Agrif_Root() ) THEN
187#if defined key_nemocice_decomp
188         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first  dim.
189         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
190#else
191         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
192         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
193#endif
194         jpk = jpkdta                                             ! third dim
195         jpim1 = jpi-1                                            ! inner domain indices
196         jpjm1 = jpj-1                                            !   "           "
197         jpkm1 = jpk-1                                            !   "           "
198         jpij  = jpi*jpj                                          !  jpi x j
199      ENDIF
200
201      IF(lwp) THEN                            ! open listing units
202         !
203         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
204         !
205         WRITE(numout,*)
206         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
207         WRITE(numout,*) '                       NEMO team'
208         WRITE(numout,*) '            Ocean General Circulation Model'
209         WRITE(numout,*) '                  version 3.4  (2011) '
210         WRITE(numout,*)
211         WRITE(numout,*)
212         DO ji = 1, SIZE(cltxt)
213            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
214         END DO
215         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
216         !
217      ENDIF
218
219      ! Now we know the dimensions of the grid and numout has been set we can
220      ! allocate arrays
221      CALL nemo_alloc()
222
223      !                             !-------------------------------!
224      !                             !  NEMO general initialization  !
225      !                             !-------------------------------!
226
227      CALL nemo_ctl                          ! Control prints & Benchmark
228
229      !                                      ! Domain decomposition
230      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
231      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
232      ENDIF
233      !
234      IF( nn_timing == 1 )  CALL timing_init
235      !
236      !                                      ! General initialization
237                            CALL     phy_cst    ! Physical constants
238                            CALL     eos_init   ! Equation of state
239                            CALL     dom_cfg    ! Domain configuration
240                            CALL     dom_init   ! Domain
241
242      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
243
244      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
245
246                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
247
248      IF( lk_diaobs     ) THEN                  ! Observation & model comparison
249                            CALL dia_obs_init            ! Initialize observational data
250                            CALL dia_obs( nit000 - 1 )   ! Observation operator for restart
251      ENDIF
252   END SUBROUTINE nemo_init
253
254
255   SUBROUTINE nemo_ctl
256      !!----------------------------------------------------------------------
257      !!                     ***  ROUTINE nemo_ctl  ***
258      !!
259      !! ** Purpose :   control print setting
260      !!
261      !! ** Method  : - print namctl information and check some consistencies
262      !!----------------------------------------------------------------------
263      !
264      IF(lwp) THEN                  ! control print
265         WRITE(numout,*)
266         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
267         WRITE(numout,*) '~~~~~~~ '
268         WRITE(numout,*) '   Namelist namctl'
269         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
270         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
271         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
272         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
273         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
274         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
275         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
276         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
277         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
278         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
279      ENDIF
280      !
281      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
282      nictls    = nn_ictls
283      nictle    = nn_ictle
284      njctls    = nn_jctls
285      njctle    = nn_jctle
286      isplt     = nn_isplt
287      jsplt     = nn_jsplt
288      nbench    = nn_bench
289      !                             ! Parameter control
290      !
291      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
292         IF( lk_mpp .AND. jpnij > 1 ) THEN
293            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
294         ELSE
295            IF( isplt == 1 .AND. jsplt == 1  ) THEN
296               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
297                  &           ' - the print control will be done over the whole domain' )
298            ENDIF
299            ijsplt = isplt * jsplt            ! total number of processors ijsplt
300         ENDIF
301         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
302         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
303         !
304         !                              ! indices used for the SUM control
305         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
306            lsp_area = .FALSE.
307         ELSE                                             ! print control done over a specific  area
308            lsp_area = .TRUE.
309            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
310               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
311               nictls = 1
312            ENDIF
313            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
314               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
315               nictle = jpiglo
316            ENDIF
317            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
318               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
319               njctls = 1
320            ENDIF
321            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
322               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
323               njctle = jpjglo
324            ENDIF
325         ENDIF
326      ENDIF
327      !
328      IF( nbench == 1 ) THEN              ! Benchmark
329         SELECT CASE ( cp_cfg )
330         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
331         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
332            &                                 ' key_gyre must be used or set nbench = 0' )
333         END SELECT
334      ENDIF
335      !
336      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
337         &                                               'with the IOM Input/Output manager. '         ,   &
338         &                                               'Compile with key_iomput enabled' )
339      !
340      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
341         &                                               'f2003 standard. '                              ,  &
342         &                                               'Compile with key_nosignedzero enabled' )
343      !
344   END SUBROUTINE nemo_ctl
345
346
347   SUBROUTINE nemo_closefile
348      !!----------------------------------------------------------------------
349      !!                     ***  ROUTINE nemo_closefile  ***
350      !!
351      !! ** Purpose :   Close the files
352      !!----------------------------------------------------------------------
353      !
354      IF( lk_mpp )   CALL mppsync
355      !
356      CALL iom_close                                 ! close all input/output files managed by iom_*
357      !
358      IF( numstp      /= -1 )   CLOSE( numstp      )   ! time-step file
359      IF( numsol      /= -1 )   CLOSE( numsol      )   ! solver file
360      IF( numnam      /= -1 )   CLOSE( numnam      )   ! oce namelist
361      IF( numnam_ice  /= -1 )   CLOSE( numnam_ice  )   ! ice namelist
362      IF( numevo_ice  /= -1 )   CLOSE( numevo_ice  )   ! ice variables (temp. evolution)
363      IF( numout      /=  6 )   CLOSE( numout      )   ! standard model output file
364      IF( numdct_vol  /= -1 )   CLOSE( numdct_vol  )   ! volume transports
365      IF( numdct_heat /= -1 )   CLOSE( numdct_heat )   ! heat transports
366      IF( numdct_salt /= -1 )   CLOSE( numdct_salt )   ! salt transports
367
368      !
369      numout = 6                                     ! redefine numout in case it is used after this point...
370      !
371   END SUBROUTINE nemo_closefile
372
373
374   SUBROUTINE nemo_alloc
375      !!----------------------------------------------------------------------
376      !!                     ***  ROUTINE nemo_alloc  ***
377      !!
378      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
379      !!
380      !! ** Method  :
381      !!----------------------------------------------------------------------
382      USE diawri    , ONLY: dia_wri_alloc
383      USE dom_oce   , ONLY: dom_oce_alloc
384      !
385      INTEGER :: ierr
386      !!----------------------------------------------------------------------
387      !
388      ierr =        oce_alloc       ()          ! ocean
389      ierr = ierr + dia_wri_alloc   ()
390      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
391      !
392      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
393      !
394      IF( lk_mpp    )   CALL mpp_sum( ierr )
395      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
396      !
397   END SUBROUTINE nemo_alloc
398
399
400   SUBROUTINE nemo_partition( num_pes )
401      !!----------------------------------------------------------------------
402      !!                 ***  ROUTINE nemo_partition  ***
403      !!
404      !! ** Purpose :
405      !!
406      !! ** Method  :
407      !!----------------------------------------------------------------------
408      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
409      !
410      INTEGER, PARAMETER :: nfactmax = 20
411      INTEGER :: nfact ! The no. of factors returned
412      INTEGER :: ierr  ! Error flag
413      INTEGER :: ji
414      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
415      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
416      !!----------------------------------------------------------------------
417
418      ierr = 0
419
420      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
421
422      IF( nfact <= 1 ) THEN
423         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
424         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
425         jpnj = 1
426         jpni = num_pes
427      ELSE
428         ! Search through factors for the pair that are closest in value
429         mindiff = 1000000
430         imin    = 1
431         DO ji = 1, nfact-1, 2
432            idiff = ABS( ifact(ji) - ifact(ji+1) )
433            IF( idiff < mindiff ) THEN
434               mindiff = idiff
435               imin = ji
436            ENDIF
437         END DO
438         jpnj = ifact(imin)
439         jpni = ifact(imin + 1)
440      ENDIF
441      !
442      jpnij = jpni*jpnj
443      !
444   END SUBROUTINE nemo_partition
445
446
447   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
448      !!----------------------------------------------------------------------
449      !!                     ***  ROUTINE factorise  ***
450      !!
451      !! ** Purpose :   return the prime factors of n.
452      !!                knfax factors are returned in array kfax which is of
453      !!                maximum dimension kmaxfax.
454      !! ** Method  :
455      !!----------------------------------------------------------------------
456      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
457      INTEGER                    , INTENT(  out) ::   kerr, knfax
458      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
459      !
460      INTEGER :: ifac, jl, inu
461      INTEGER, PARAMETER :: ntest = 14
462      INTEGER :: ilfax(ntest)
463
464      ! lfax contains the set of allowed factors.
465      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
466         &                            128,   64,   32,   16,    8,   4,   2  /
467      !!----------------------------------------------------------------------
468
469      ! Clear the error flag and initialise output vars
470      kerr = 0
471      kfax = 1
472      knfax = 0
473
474      ! Find the factors of n.
475      IF( kn == 1 )   GOTO 20
476
477      ! nu holds the unfactorised part of the number.
478      ! knfax holds the number of factors found.
479      ! l points to the allowed factor list.
480      ! ifac holds the current factor.
481
482      inu   = kn
483      knfax = 0
484
485      DO jl = ntest, 1, -1
486         !
487         ifac = ilfax(jl)
488         IF( ifac > inu )   CYCLE
489
490         ! Test whether the factor will divide.
491
492         IF( MOD(inu,ifac) == 0 ) THEN
493            !
494            knfax = knfax + 1            ! Add the factor to the list
495            IF( knfax > kmaxfax ) THEN
496               kerr = 6
497               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
498               return
499            ENDIF
500            kfax(knfax) = ifac
501            ! Store the other factor that goes with this one
502            knfax = knfax + 1
503            kfax(knfax) = inu / ifac
504            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
505         ENDIF
506         !
507      END DO
508
509   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
510      !
511   END SUBROUTINE factorise
512
513#if defined key_mpp_mpi
514   SUBROUTINE nemo_northcomms
515      !!======================================================================
516      !!                     ***  ROUTINE  nemo_northcomms  ***
517      !! nemo_northcomms    :  Setup for north fold exchanges with explicit peer to peer messaging
518      !!=====================================================================
519      !!----------------------------------------------------------------------
520      !!
521      !! ** Purpose :   Initialization of the northern neighbours lists.
522      !!----------------------------------------------------------------------
523      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
524      !!----------------------------------------------------------------------
525
526      INTEGER ::   ji, jj, jk, ij, jtyp    ! dummy loop indices
527      INTEGER ::   ijpj                    ! number of rows involved in north-fold exchange
528      INTEGER ::   northcomms_alloc        ! allocate return status
529      REAL(wp), ALLOCATABLE, DIMENSION ( :,: ) ::   znnbrs     ! workspace
530      LOGICAL,  ALLOCATABLE, DIMENSION ( : )   ::   lrankset   ! workspace
531
532      IF(lwp) WRITE(numout,*)
533      IF(lwp) WRITE(numout,*) 'nemo_northcomms : Initialization of the northern neighbours lists'
534      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
535
536      !!----------------------------------------------------------------------
537      ALLOCATE( znnbrs(jpi,jpj), stat = northcomms_alloc )
538      ALLOCATE( lrankset(jpnij), stat = northcomms_alloc )
539      IF( northcomms_alloc /= 0 ) THEN
540         WRITE(numout,cform_war)
541         WRITE(numout,*) 'northcomms_alloc : failed to allocate arrays'
542         CALL ctl_stop( 'STOP', 'nemo_northcomms : unable to allocate temporary arrays' )
543      ENDIF
544      nsndto = 0
545      isendto = -1
546      ijpj   = 4
547      !
548      ! This routine has been called because ln_nnogather has been set true ( nammpp )
549      ! However, these first few exchanges have to use the mpi_allgather method to
550      ! establish the neighbour lists to use in subsequent peer to peer exchanges.
551      ! Consequently, set l_north_nogather to be false here and set it true only after
552      ! the lists have been established.
553      !
554      l_north_nogather = .FALSE.
555      !
556      ! Exchange and store ranks on northern rows
557
558      DO jtyp = 1,4
559
560         lrankset = .FALSE.
561         znnbrs = narea
562         SELECT CASE (jtyp)
563            CASE(1)
564               CALL lbc_lnk( znnbrs, 'T', 1. )      ! Type 1: T,W-points
565            CASE(2)
566               CALL lbc_lnk( znnbrs, 'U', 1. )      ! Type 2: U-point
567            CASE(3)
568               CALL lbc_lnk( znnbrs, 'V', 1. )      ! Type 3: V-point
569            CASE(4)
570               CALL lbc_lnk( znnbrs, 'F', 1. )      ! Type 4: F-point
571         END SELECT
572
573         IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
574            DO jj = nlcj-ijpj+1, nlcj
575               ij = jj - nlcj + ijpj
576               DO ji = 1,jpi
577                  IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
578               &     lrankset(INT(znnbrs(ji,jj))) = .true.
579               END DO
580            END DO
581
582            DO jj = 1,jpnij
583               IF ( lrankset(jj) ) THEN
584                  nsndto(jtyp) = nsndto(jtyp) + 1
585                  IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
586                     CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
587                  &                 ' jpmaxngh will need to be increased ')
588                  ENDIF
589                  isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
590               ENDIF
591            END DO
592         ENDIF
593
594      END DO
595
596      !
597      ! Type 5: I-point
598      !
599      ! ICE point exchanges may involve some averaging. The neighbours list is
600      ! built up using two exchanges to ensure that the whole stencil is covered.
601      ! lrankset should not be reset between these 'J' and 'K' point exchanges
602
603      jtyp = 5
604      lrankset = .FALSE.
605      znnbrs = narea
606      CALL lbc_lnk( znnbrs, 'J', 1. ) ! first ice U-V point
607
608      IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
609         DO jj = nlcj-ijpj+1, nlcj
610            ij = jj - nlcj + ijpj
611            DO ji = 1,jpi
612               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
613            &     lrankset(INT(znnbrs(ji,jj))) = .true.
614         END DO
615        END DO
616      ENDIF
617
618      znnbrs = narea
619      CALL lbc_lnk( znnbrs, 'K', 1. ) ! second ice U-V point
620
621      IF ( njmppt(narea) .EQ. MAXVAL( njmppt )) THEN
622         DO jj = nlcj-ijpj+1, nlcj
623            ij = jj - nlcj + ijpj
624            DO ji = 1,jpi
625               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND.  INT(znnbrs(ji,jj)) .NE. narea ) &
626            &       lrankset( INT(znnbrs(ji,jj))) = .true.
627            END DO
628         END DO
629
630         DO jj = 1,jpnij
631            IF ( lrankset(jj) ) THEN
632               nsndto(jtyp) = nsndto(jtyp) + 1
633               IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
634                  CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
635               &                 ' jpmaxngh will need to be increased ')
636               ENDIF
637               isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
638            ENDIF
639         END DO
640         !
641         ! For northern row areas, set l_north_nogather so that all subsequent exchanges
642         ! can use peer to peer communications at the north fold
643         !
644         l_north_nogather = .TRUE.
645         !
646      ENDIF
647      DEALLOCATE( znnbrs )
648      DEALLOCATE( lrankset )
649
650   END SUBROUTINE nemo_northcomms
651#else
652   SUBROUTINE nemo_northcomms      ! Dummy routine
653      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
654   END SUBROUTINE nemo_northcomms
655#endif
656   !!======================================================================
657END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.