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

Last change on this file since 4116 was 4116, checked in by andrewryan, 11 years ago

Refactored OOO_SRC nemogcm module to reduce memory overheads.

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