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_MERGE_2012/NEMOGCM/NEMO/OFF_SRC – NEMO

source: branches/2012/dev_MERGE_2012/NEMOGCM/NEMO/OFF_SRC/nemogcm.F90 @ 3716

Last change on this file since 3716 was 3716, checked in by acc, 11 years ago

Branch dev_MERGE_2012. Updating of OFF_SRC/nemogcm.F90 to replace old io_server calls

File size: 28.0 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Off-line Ocean   : passive tracer evolution, dynamics read in files
5   !!======================================================================
6   !! History :  3.3  ! 2010-05  (C. Ethe)  Full reorganization of the off-line: phasing with the on-line
7   !!            4.0  ! 2011-01  (C. Ethe, A. R. Porter, STFC Daresbury) dynamical allocation
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   nemo_gcm        : off-line: solve ocean tracer only
12   !!   nemo_init       : initialization of the nemo model
13   !!   nemo_ctl        : initialisation of algorithm flag
14   !!   nemo_closefile  : close remaining files
15   !!----------------------------------------------------------------------
16   USE dom_oce         ! ocean space domain variables
17   USE oce             ! dynamics and tracers variables
18   USE c1d             ! 1D configuration
19   USE domcfg          ! domain configuration               (dom_cfg routine)
20   USE domain          ! domain initialization             (dom_init routine)
21   USE istate          ! initial state setting          (istate_init routine)
22   USE eosbn2          ! equation of state            (eos bn2 routine)
23   !              ! ocean physics
24   USE ldftra          ! lateral diffusivity setting    (ldf_tra_init routine)
25   USE ldfslp          ! slopes of neutral surfaces     (ldf_slp_init routine)
26   USE traqsr          ! solar radiation penetration    (tra_qsr_init routine)
27   USE trabbl          ! bottom boundary layer          (tra_bbl_init routine)
28   USE zdfini          ! vertical physics: initialization
29   USE sbcmod          ! surface boundary condition       (sbc_init     routine)
30   USE phycst          ! physical constant                  (par_cst routine)
31   USE dtadyn          ! Lecture and Interpolation of the dynamical fields
32   USE trcini          ! Initilization of the passive tracers
33   USE daymod          ! calendar                         (day     routine)
34   USE trcstp          ! passive tracer time-stepping      (trc_stp routine)
35   USE dtadyn          ! Lecture and interpolation of the dynamical fields
36   USE stpctl          ! time stepping control            (stp_ctl routine)
37   !              ! I/O & MPP
38   USE iom             ! I/O library
39   USE in_out_manager  ! I/O manager
40   USE mppini          ! shared/distributed memory setting (mpp_init routine)
41   USE lib_mpp         ! distributed memory computing
42#if defined key_iomput
43   USE xios
44#endif
45   USE prtctl          ! Print control                    (prt_ctl_init routine)
46   USE timing          ! Timing
47
48   IMPLICIT NONE
49   PRIVATE
50   
51   PUBLIC   nemo_gcm   ! called by nemo.F90
52
53   CHARACTER (len=64) ::   cform_aaa="( /, 'AAAAAAAA', / ) "   ! flag for output listing
54
55   !!----------------------------------------------------------------------
56   !! NEMO/OFF 3.3 , NEMO Consortium (2010)
57   !! $Id: nemogcm.F90 2528 2010-12-27 17:33:53Z rblod $
58   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
59   !!----------------------------------------------------------------------
60CONTAINS
61
62   SUBROUTINE nemo_gcm
63      !!----------------------------------------------------------------------
64      !!                     ***  ROUTINE nemo_gcm  ***
65      !!
66      !! ** Purpose :   nemo solves the primitive equations on an orthogonal
67      !!      curvilinear mesh on the sphere.
68      !!
69      !! ** Method  : - model general initialization
70      !!              - launch the time-stepping (dta_dyn and trc_stp)
71      !!              - finalize the run by closing files and communications
72      !!
73      !! References : Madec, Delecluse,Imbard, and Levy, 1997:  internal report, IPSL.
74      !!              Madec, 2008, internal report, IPSL.
75      !!----------------------------------------------------------------------
76      INTEGER :: istp, indic       ! time step index
77      !!----------------------------------------------------------------------
78
79      CALL nemo_init  ! Initializations
80
81      IF( lk_mpp )   CALL mpp_max( nstop )
82
83      ! check that all process are still there... If some process have an error,
84      ! they will never enter in step and other processes will wait until the end of the cpu time!
85      IF( lk_mpp )   CALL mpp_max( nstop )
86
87      !                            !-----------------------!
88      !                            !==   time stepping   ==!
89      !                            !-----------------------!
90      istp = nit000
91         !
92      DO WHILE ( istp <= nitend .AND. nstop == 0 )    ! time stepping
93         !
94         IF( istp /= nit000 )   CALL day      ( istp )         ! Calendar (day was already called at nit000 in day_init)
95                                CALL iom_setkt( istp )         ! say to iom that we are at time step kstp
96                                CALL dta_dyn  ( istp )         ! Interpolation of the dynamical fields
97                                CALL trc_stp  ( istp )         ! time-stepping
98                                CALL stp_ctl  ( istp, indic )  ! Time loop: control and print
99         istp = istp + 1
100         IF( lk_mpp )   CALL mpp_max( nstop )
101      END DO
102
103      !                            !------------------------!
104      !                            !==  finalize the run  ==!
105      !                            !------------------------!
106      IF(lwp) WRITE(numout,cform_aaa)                 ! Flag AAAAAAA
107
108      IF( nstop /= 0 .AND. lwp ) THEN                 ! error print
109         WRITE(numout,cform_err)
110         WRITE(numout,*) nstop, ' error have been found'
111      ENDIF
112      !
113      IF( nn_timing == 1 )   CALL timing_finalize
114      !
115      CALL nemo_closefile
116      !
117# if defined key_iomput
118         CALL xios_finalize             ! end mpp communications
119# else
120      IF( lk_mpp )   CALL mppstop       ! end mpp communications
121# endif
122      !
123   END SUBROUTINE nemo_gcm
124
125
126   SUBROUTINE nemo_init
127      !!----------------------------------------------------------------------
128      !!                     ***  ROUTINE nemo_init ***
129      !!
130      !! ** Purpose :   initialization of the nemo model in off-line mode
131      !!----------------------------------------------------------------------
132      INTEGER ::   ji            ! dummy loop indices
133      INTEGER ::   ilocal_comm   ! local integer
134      CHARACTER(len=80), DIMENSION(16) ::   cltxt
135      !!
136      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
137         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
138         &             nn_bench, nn_timing
139      !!----------------------------------------------------------------------
140      !
141      cltxt = ''
142      !
143      !                             ! open Namelist file
144      CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
145      !
146      READ( numnam, namctl )        ! Namelist namctl : Control prints & Benchmark
147      !
148      !                             !--------------------------------------------!
149      !                             !  set communicator & select the local node  !
150      !                             !--------------------------------------------!
151#if defined key_iomput
152         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
153      narea = mynode( cltxt, numnam, nstop, ilocal_comm )   ! Nodes selection
154#else
155      ilocal_comm = 0
156      narea = mynode( cltxt, numnam, nstop )                 ! Nodes selection (control print return in cltxt)
157#endif
158
159      narea = narea + 1                       ! mynode return the rank of proc (0 --> jpnij -1 )
160
161      lwp = (narea == 1) .OR. ln_ctl          ! control of all listing output print
162
163      ! If dimensions of processor grid weren't specified in the namelist file
164      ! then we calculate them here now that we have our communicator size
165      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
166#if   defined key_mpp_mpi
167         CALL nemo_partition(mppsize)
168#else
169         jpni = 1
170         jpnj = 1
171         jpnij = jpni*jpnj
172#endif
173      END IF
174
175      ! Calculate domain dimensions given calculated jpni and jpnj
176      ! This used to be done in par_oce.F90 when they were parameters rather
177      ! than variables
178      jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
179      jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
180      jpk = jpkdta                                             ! third dim
181      jpim1 = jpi-1                                            ! inner domain indices
182      jpjm1 = jpj-1                                            !   "           "
183      jpkm1 = jpk-1                                            !   "           "
184      jpij  = jpi*jpj                                          !  jpi x j
185
186
187      IF(lwp) THEN                            ! open listing units
188         !
189         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
190         !
191         WRITE(numout,*)
192         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
193         WRITE(numout,*) '                       NEMO team'
194         WRITE(numout,*) '            Ocean General Circulation Model'
195         WRITE(numout,*) '                  version 3.5  (2012) '
196         WRITE(numout,*)
197         WRITE(numout,*)
198         DO ji = 1, SIZE(cltxt) 
199            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
200         END DO
201         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
202         !
203      ENDIF
204
205      ! Now we know the dimensions of the grid and numout has been set we can
206      ! allocate arrays
207      CALL nemo_alloc()
208
209      !                             !--------------------------------!
210      !                             !  Model general initialization  !
211      !                             !--------------------------------!
212
213      CALL nemo_ctl                           ! Control prints & Benchmark
214
215      !                                      ! Domain decomposition
216      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
217      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
218      ENDIF
219      !
220      IF( nn_timing == 1 )  CALL timing_init
221      !
222
223      !                                      ! General initialization
224      IF( nn_timing == 1 )  CALL timing_start( 'nemo_init')
225      !
226                            CALL     phy_cst    ! Physical constants
227                            CALL     eos_init   ! Equation of state
228                            CALL     dom_cfg    ! Domain configuration
229                            CALL     dom_init   ! Domain
230                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
231
232      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
233
234      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
235
236      !                                     ! Ocean physics
237                            CALL     sbc_init   ! Forcings : surface module
238#if ! defined key_degrad
239                            CALL ldf_tra_init   ! Lateral ocean tracer physics
240#endif
241      IF( lk_ldfslp )       CALL ldf_slp_init   ! slope of lateral mixing
242
243      !                                     ! Active tracers
244                            CALL tra_qsr_init   ! penetrative solar radiation qsr
245      IF( lk_trabbl     )   CALL tra_bbl_init   ! advective (and/or diffusive) bottom boundary layer scheme
246
247      !                                     ! Passive tracers
248                            CALL     trc_init   ! Passive tracers initialization
249      !                                     ! Dynamics
250                            CALL dta_dyn_init   ! Initialization for the dynamics
251                            CALL     iom_init       ! iom_put initialization
252
253      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
254      !
255      IF( nn_timing == 1 )  CALL timing_stop( 'nemo_init')
256      !
257   END SUBROUTINE nemo_init
258
259
260   SUBROUTINE nemo_ctl
261      !!----------------------------------------------------------------------
262      !!                     ***  ROUTINE nemo_ctl  ***
263      !!
264      !! ** Purpose :   control print setting
265      !!
266      !! ** Method  : - print namctl information and check some consistencies
267      !!----------------------------------------------------------------------
268      !
269      IF(lwp) THEN                  ! Parameter print
270         WRITE(numout,*)
271         WRITE(numout,*) 'nemo_flg: Control prints & Benchmark'
272         WRITE(numout,*) '~~~~~~~ '
273         WRITE(numout,*) '   Namelist namctl'
274         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
275         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
276         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
277         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
278         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
279         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
280         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
281         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
282         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
283      ENDIF
284      !
285      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
286      nictls    = nn_ictls
287      nictle    = nn_ictle
288      njctls    = nn_jctls
289      njctle    = nn_jctle
290      isplt     = nn_isplt
291      jsplt     = nn_jsplt
292      nbench    = nn_bench
293      !                             ! Parameter control
294      !
295      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
296         IF( lk_mpp ) THEN
297            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real splitted domain
298         ELSE
299            IF( isplt == 1 .AND. jsplt == 1  ) THEN
300               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
301                  &           ' - the print control will be done over the whole domain' )
302            ENDIF
303            ijsplt = isplt * jsplt            ! total number of processors ijsplt
304         ENDIF
305         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
306         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
307         !
308         !                              ! indices used for the SUM control
309         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
310            lsp_area = .FALSE.
311         ELSE                                             ! print control done over a specific  area
312            lsp_area = .TRUE.
313            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
314               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
315               nictls = 1
316            ENDIF
317            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
318               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
319               nictle = jpiglo
320            ENDIF
321            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
322               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
323               njctls = 1
324            ENDIF
325            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
326               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
327               njctle = jpjglo
328            ENDIF
329         ENDIF
330      ENDIF
331      !
332      IF( nbench == 1 )   THEN            ! Benchmark
333         SELECT CASE ( cp_cfg )
334         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
335         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
336            &                                 ' key_gyre must be used or set nbench = 0' )
337         END SELECT
338      ENDIF
339      !
340      IF( lk_c1d .AND. .NOT.lk_iomput )   CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ',   &
341         &                                               'with the IOM Input/Output manager. '        ,   &
342         &                                               'Compile with key_iomput 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( numnam     /= -1 )   CLOSE( numnam     )   ! oce namelist
360      IF( numout     /=  6 )   CLOSE( numout     )   ! standard model output file
361      numout = 6                                     ! redefine numout in case it is used after this point...
362      !
363   END SUBROUTINE nemo_closefile
364
365
366   SUBROUTINE nemo_alloc
367      !!----------------------------------------------------------------------
368      !!                     ***  ROUTINE nemo_alloc  ***
369      !!
370      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
371      !!
372      !! ** Method  :
373      !!----------------------------------------------------------------------
374      USE diawri,       ONLY: dia_wri_alloc
375      USE dom_oce,      ONLY: dom_oce_alloc
376      USE zdf_oce,      ONLY: zdf_oce_alloc
377      USE ldftra_oce,   ONLY: ldftra_oce_alloc
378      USE trc_oce,      ONLY: trc_oce_alloc
379      !
380      INTEGER :: ierr
381      !!----------------------------------------------------------------------
382      !
383      ierr =        oce_alloc       ()          ! ocean
384      ierr = ierr + dia_wri_alloc   ()
385      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
386      ierr = ierr + ldftra_oce_alloc()          ! ocean lateral  physics : tracers
387      ierr = ierr + zdf_oce_alloc   ()          ! ocean vertical physics
388      !
389      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
390      ierr = ierr + trc_oce_alloc   ()          ! shared TRC / TRA arrays
391      !
392      IF( lk_mpp    )   CALL mpp_sum( ierr )
393      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc: unable to allocate standard ocean arrays' )
394      !
395   END SUBROUTINE nemo_alloc
396
397
398   SUBROUTINE nemo_partition( num_pes )
399      !!----------------------------------------------------------------------
400      !!                 ***  ROUTINE nemo_partition  ***
401      !!
402      !! ** Purpose :   
403      !!
404      !! ** Method  :
405      !!----------------------------------------------------------------------
406      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
407      !
408      INTEGER, PARAMETER :: nfactmax = 20
409      INTEGER :: nfact ! The no. of factors returned
410      INTEGER :: ierr  ! Error flag
411      INTEGER :: ji
412      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
413      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
414      !!----------------------------------------------------------------------
415
416      ierr = 0
417
418      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
419
420      IF( nfact <= 1 ) THEN
421         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
422         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
423         jpnj = 1
424         jpni = num_pes
425      ELSE
426         ! Search through factors for the pair that are closest in value
427         mindiff = 1000000
428         imin    = 1
429         DO ji = 1, nfact-1, 2
430            idiff = ABS( ifact(ji) - ifact(ji+1) )
431            IF( idiff < mindiff ) THEN
432               mindiff = idiff
433               imin = ji
434            ENDIF
435         END DO
436         jpnj = ifact(imin)
437         jpni = ifact(imin + 1)
438      ENDIF
439      !
440      jpnij = jpni*jpnj
441      !
442   END SUBROUTINE nemo_partition
443
444
445   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
446      !!----------------------------------------------------------------------
447      !!                     ***  ROUTINE factorise  ***
448      !!
449      !! ** Purpose :   return the prime factors of n.
450      !!                knfax factors are returned in array kfax which is of
451      !!                maximum dimension kmaxfax.
452      !! ** Method  :
453      !!----------------------------------------------------------------------
454      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
455      INTEGER                    , INTENT(  out) ::   kerr, knfax
456      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
457      !
458      INTEGER :: ifac, jl, inu
459      INTEGER, PARAMETER :: ntest = 14
460      INTEGER :: ilfax(ntest)
461      !
462      ! lfax contains the set of allowed factors.
463      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
464         &                            128,   64,   32,   16,    8,   4,   2  /
465      !!----------------------------------------------------------------------
466
467      ! Clear the error flag and initialise output vars
468      kerr = 0
469      kfax = 1
470      knfax = 0
471
472      ! Find the factors of n.
473      IF( kn == 1 )   GOTO 20
474
475      ! nu holds the unfactorised part of the number.
476      ! knfax holds the number of factors found.
477      ! l points to the allowed factor list.
478      ! ifac holds the current factor.
479
480      inu   = kn
481      knfax = 0
482
483      DO jl = ntest, 1, -1
484         !
485         ifac = ilfax(jl)
486         IF( ifac > inu )   CYCLE
487
488         ! Test whether the factor will divide.
489
490         IF( MOD(inu,ifac) == 0 ) THEN
491            !
492            knfax = knfax + 1            ! Add the factor to the list
493            IF( knfax > kmaxfax ) THEN
494               kerr = 6
495               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
496               return
497            ENDIF
498            kfax(knfax) = ifac
499            ! Store the other factor that goes with this one
500            knfax = knfax + 1
501            kfax(knfax) = inu / ifac
502            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
503         ENDIF
504         !
505      END DO
506
507   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
508      !
509   END SUBROUTINE factorise
510
511#if defined key_mpp_mpi
512   SUBROUTINE nemo_northcomms
513      !!======================================================================
514      !!                     ***  ROUTINE  nemo_northcomms  ***
515      !! nemo_northcomms    :  Setup for north fold exchanges with explicit peer to peer messaging
516      !!=====================================================================
517      !!----------------------------------------------------------------------
518      !!
519      !! ** Purpose :   Initialization of the northern neighbours lists.
520      !!----------------------------------------------------------------------
521      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
522      !!----------------------------------------------------------------------
523
524      INTEGER ::   ji, jj, jk, ij, jtyp    ! dummy loop indices
525      INTEGER ::   ijpj                    ! number of rows involved in north-fold exchange
526      INTEGER ::   northcomms_alloc        ! allocate return status
527      REAL(wp), ALLOCATABLE, DIMENSION ( :,: ) ::   znnbrs     ! workspace
528      LOGICAL,  ALLOCATABLE, DIMENSION ( : )   ::   lrankset   ! workspace
529
530      IF(lwp) WRITE(numout,*)
531      IF(lwp) WRITE(numout,*) 'nemo_northcomms : Initialization of the northern neighbours lists'
532      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
533
534      !!----------------------------------------------------------------------
535      ALLOCATE( znnbrs(jpi,jpj), stat = northcomms_alloc )
536      ALLOCATE( lrankset(jpnij), stat = northcomms_alloc )
537      IF( northcomms_alloc /= 0 ) THEN
538         WRITE(numout,cform_war)
539         WRITE(numout,*) 'northcomms_alloc : failed to allocate arrays'
540         CALL ctl_stop( 'STOP', 'nemo_northcomms : unable to allocate temporary arrays' )
541      ENDIF
542      nsndto = 0
543      isendto = -1
544      ijpj   = 4
545      !
546      ! This routine has been called because ln_nnogather has been set true ( nammpp )
547      ! However, these first few exchanges have to use the mpi_allgather method to
548      ! establish the neighbour lists to use in subsequent peer to peer exchanges.
549      ! Consequently, set l_north_nogather to be false here and set it true only after
550      ! the lists have been established.
551      !
552      l_north_nogather = .FALSE.
553      !
554      ! Exchange and store ranks on northern rows
555
556      DO jtyp = 1,4
557
558         lrankset = .FALSE.
559         znnbrs = narea
560         SELECT CASE (jtyp)
561            CASE(1)
562               CALL lbc_lnk( znnbrs, 'T', 1. )      ! Type 1: T,W-points
563            CASE(2)
564               CALL lbc_lnk( znnbrs, 'U', 1. )      ! Type 2: U-point
565            CASE(3)
566               CALL lbc_lnk( znnbrs, 'V', 1. )      ! Type 3: V-point
567            CASE(4)
568               CALL lbc_lnk( znnbrs, 'F', 1. )      ! Type 4: F-point
569         END SELECT
570
571         IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
572            DO jj = nlcj-ijpj+1, nlcj
573               ij = jj - nlcj + ijpj
574               DO ji = 1,jpi
575                  IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
576               &     lrankset(INT(znnbrs(ji,jj))) = .true.
577               END DO
578            END DO
579
580            DO jj = 1,jpnij
581               IF ( lrankset(jj) ) THEN
582                  nsndto(jtyp) = nsndto(jtyp) + 1
583                  IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
584                     CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
585                  &                 ' jpmaxngh will need to be increased ')
586                  ENDIF
587                  isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
588               ENDIF
589            END DO
590         ENDIF
591
592      END DO
593
594      !
595      ! Type 5: I-point
596      !
597      ! ICE point exchanges may involve some averaging. The neighbours list is
598      ! built up using two exchanges to ensure that the whole stencil is covered.
599      ! lrankset should not be reset between these 'J' and 'K' point exchanges
600
601      jtyp = 5
602      lrankset = .FALSE.
603      znnbrs = narea 
604      CALL lbc_lnk( znnbrs, 'J', 1. ) ! first ice U-V point
605
606      IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
607         DO jj = nlcj-ijpj+1, nlcj
608            ij = jj - nlcj + ijpj
609            DO ji = 1,jpi
610               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
611            &     lrankset(INT(znnbrs(ji,jj))) = .true.
612         END DO
613        END DO
614      ENDIF
615
616      znnbrs = narea 
617      CALL lbc_lnk( znnbrs, 'K', 1. ) ! second ice U-V point
618
619      IF ( njmppt(narea) .EQ. MAXVAL( njmppt )) THEN
620         DO jj = nlcj-ijpj+1, nlcj
621            ij = jj - nlcj + ijpj
622            DO ji = 1,jpi
623               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND.  INT(znnbrs(ji,jj)) .NE. narea ) &
624            &       lrankset( INT(znnbrs(ji,jj))) = .true.
625            END DO
626         END DO
627
628         DO jj = 1,jpnij
629            IF ( lrankset(jj) ) THEN
630               nsndto(jtyp) = nsndto(jtyp) + 1
631               IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
632                  CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
633               &                 ' jpmaxngh will need to be increased ')
634               ENDIF
635               isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
636            ENDIF
637         END DO
638         !
639         ! For northern row areas, set l_north_nogather so that all subsequent exchanges
640         ! can use peer to peer communications at the north fold
641         !
642         l_north_nogather = .TRUE.
643         !
644      ENDIF
645      DEALLOCATE( znnbrs )
646      DEALLOCATE( lrankset )
647
648   END SUBROUTINE nemo_northcomms
649#else
650   SUBROUTINE nemo_northcomms      ! Dummy routine
651      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
652   END SUBROUTINE nemo_northcomms
653#endif
654   !!======================================================================
655END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.