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

source: branches/2012/dev_r3322_NOCS09_SAS/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 3331

Last change on this file since 3331 was 3331, checked in by sga, 12 years ago

NEMO 2012 development branch dev_r3322_NOCS09_SAS
Code changes made for compilation and running of StandAlone? Surface scheme (tinkering still required)

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