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/2015/dev_merge_2015/NEMOGCM/NEMO/SAO_SRC – NEMO

source: branches/2015/dev_merge_2015/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90 @ 6069

Last change on this file since 6069 was 5600, checked in by andrewryan, 9 years ago

merged in latest version of trunk alongside changes to SAO_SRC to be compatible with latest OBS

  • Property svn:keywords set to Id
File size: 29.6 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   !!                 ! 2012-05  (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening
32   !!----------------------------------------------------------------------
33
34   !!----------------------------------------------------------------------
35   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
36   !!   nemo_init      : initialization of the NEMO system
37   !!   nemo_ctl       : initialisation of the contol print
38   !!   nemo_closefile : close remaining open files
39   !!   nemo_alloc     : dynamical allocation
40   !!   nemo_partition : calculate MPP domain decomposition
41   !!   factorise      : calculate the factors of the no. of MPI processes
42   !!----------------------------------------------------------------------
43   USE step_oce        ! module used in the ocean time stepping module
44   USE domcfg          ! domain configuration               (dom_cfg routine)
45   USE mppini          ! shared/distributed memory setting (mpp_init routine)
46   USE domain          ! domain initialization             (dom_init routine)
47#if defined key_nemocice_decomp
48   USE ice_domain_size, only: nx_global, ny_global
49#endif
50   USE istate          ! initial state setting          (istate_init routine)
51   USE phycst          ! physical constant                  (par_cst routine)
52   USE diaobs          ! Observation diagnostics       (dia_obs_init routine)
53   USE lib_fortran     ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined)
54   USE step            ! NEMO time-stepping                 (stp     routine)
55   USE cpl_oasis3      ! OASIS3 coupling
56   USE lib_mpp         ! distributed memory computing
57#if defined key_iomput
58   USE xios
59#endif
60   USE lbcnfd, ONLY: isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges
61
62   ! Stand Alone Observation operator modules
63   USE sao_data
64   USE sao_intp
65
66   IMPLICIT NONE
67   PRIVATE
68
69   PUBLIC   nemo_gcm    ! called by model.F90
70   PUBLIC   nemo_init   ! needed by AGRIF
71   PUBLIC   nemo_alloc  ! needed by TAM
72
73   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
74
75   !!----------------------------------------------------------------------
76   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
77   !! $Id$
78   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
79   !!----------------------------------------------------------------------
80CONTAINS
81
82   SUBROUTINE nemo_gcm
83         !!----------------------------------------------------------------------
84         !!                    ***  SUBROUTINE offline_obs_oper ***
85         !!
86         !! ** Purpose : To use NEMO components to interpolate model fields
87         !!              to observation space.
88         !!
89         !! ** Method : 1. Initialise NEMO
90         !!             2. Initialise offline obs_oper
91         !!             3. Cycle through match ups
92         !!             4. Write results to file
93         !!
94         !!----------------------------------------------------------------------
95         !! Initialise NEMO
96         CALL nemo_init
97         !! Initialise Stand Alone Observation operator data
98         CALL sao_data_init
99         !! Initialise obs_oper
100         CALL dia_obs_init
101         !! Interpolate to observation space
102         CALL sao_interp
103         !! Pipe to output files
104         CALL dia_obs_wri
105         !! Reset the obs_oper between
106         CALL dia_obs_dealloc
107         !! Safely stop MPI
108         IF(lk_mpp) CALL mppstop  ! end mpp communications
109   END SUBROUTINE nemo_gcm
110
111
112   SUBROUTINE nemo_init
113      !!----------------------------------------------------------------------
114      !!                     ***  ROUTINE nemo_init  ***
115      !!
116      !! ** Purpose :   initialization of the NEMO GCM
117      !!----------------------------------------------------------------------
118      INTEGER ::   ji            ! dummy loop indices
119      INTEGER ::   ilocal_comm   ! local integer
120      INTEGER ::   ios
121      CHARACTER(len=80), DIMENSION(16) ::   cltxt
122      !
123      NAMELIST/namctl/ ln_ctl, nn_print, nn_ictls, nn_ictle,   &
124         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
125         &             nn_bench, nn_timing
126      NAMELIST/namcfg/ cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
127         &             jpizoom, jpjzoom, jperio, ln_use_jattr
128      !!----------------------------------------------------------------------
129      !
130      cltxt = ''
131      cxios_context = 'nemo'
132      !
133      !                             ! Open reference namelist and configuration namelist files
134      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
135      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
136      !
137      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
138      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
139901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. )
140
141      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
142      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
143902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. )
144
145      !
146      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
147      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
148903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. )
149
150      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
151      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
152904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. )   
153
154! Force values for AGRIF zoom (cf. agrif_user.F90)
155#if defined key_agrif
156   IF( .NOT. Agrif_Root() ) THEN
157      jpiglo  = nbcellsx + 2 + 2*nbghostcells
158      jpjglo  = nbcellsy + 2 + 2*nbghostcells
159      jpi     = ( jpiglo-2*jpreci + (jpni-1+0) ) / jpni + 2*jpreci
160      jpj     = ( jpjglo-2*jprecj + (jpnj-1+0) ) / jpnj + 2*jprecj
161      jpidta  = jpiglo
162      jpjdta  = jpjglo
163      jpizoom = 1
164      jpjzoom = 1
165      nperio  = 0
166      jperio  = 0
167      ln_use_jattr = .false.
168   ENDIF
169#endif
170      !
171      !                             !--------------------------------------------!
172      !                             !  set communicator & select the local node  !
173      !                             !  NB: mynode also opens output.namelist.dyn !
174      !                             !      on unit number numond on first proc   !
175      !                             !--------------------------------------------!
176#if defined key_iomput
177      IF( Agrif_Root() ) THEN
178         IF( lk_oasis ) THEN
179            CALL cpl_init( "oceanx", ilocal_comm )                     ! nemo local communicator given by oasis
180            CALL xios_initialize( "not used",local_comm=ilocal_comm )    ! send nemo communicator to xios
181         ELSE
182            CALL  xios_initialize( "for_xios_mpi_id",return_comm=ilocal_comm )    ! nemo local communicator given by xios
183         ENDIF
184      ENDIF
185      ! Nodes selection (control print return in cltxt)
186      narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
187#else
188      IF( lk_oasis ) THEN
189         IF( Agrif_Root() ) THEN
190            CALL cpl_init( "oceanx", ilocal_comm )                      ! nemo local communicator given by oasis
191         ENDIF
192         ! Nodes selection (control print return in cltxt)
193         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )
194      ELSE
195         ilocal_comm = 0
196         ! Nodes selection (control print return in cltxt)
197         narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop )
198      ENDIF
199#endif
200      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
201
202      lwm = (narea == 1)                                    ! control of output namelists
203      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
204
205      IF(lwm) THEN
206         ! write merged namelists from earlier to output namelist now that the
207         ! file has been opened in call to mynode. nammpp has already been
208         ! written in mynode (if lk_mpp_mpi)
209         WRITE( numond, namctl )
210         WRITE( numond, namcfg )
211      ENDIF
212
213      ! If dimensions of processor grid weren't specified in the namelist file
214      ! then we calculate them here now that we have our communicator size
215      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
216#if   defined key_mpp_mpi
217         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
218#else
219         jpni  = 1
220         jpnj  = 1
221         jpnij = jpni*jpnj
222#endif
223      END IF
224
225      ! Calculate domain dimensions given calculated jpni and jpnj
226      ! This used to be done in par_oce.F90 when they were parameters rather
227      ! than variables
228      IF( Agrif_Root() ) THEN
229#if defined key_nemocice_decomp
230         jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first  dim.
231         jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
232#else
233         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
234         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
235#endif
236      ENDIF
237         jpk = jpkdta                                             ! third dim
238         jpim1 = jpi-1                                            ! inner domain indices
239         jpjm1 = jpj-1                                            !   "           "
240         jpkm1 = jpk-1                                            !   "           "
241         jpij  = jpi*jpj                                          !  jpi x j
242
243      IF(lwp) THEN                            ! open listing units
244         !
245         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
246         !
247         WRITE(numout,*)
248         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
249         WRITE(numout,*) '                       NEMO team'
250         WRITE(numout,*) '            Stand Alone Observation operator'
251         WRITE(numout,*) '                  version 1.0  (2015) '
252         WRITE(numout,*)
253         WRITE(numout,*)
254         DO ji = 1, SIZE(cltxt)
255            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
256         END DO
257         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
258         !
259      ENDIF
260
261      ! Now we know the dimensions of the grid and numout has been set we can
262      ! allocate arrays
263      CALL nemo_alloc()
264
265      !                             !-------------------------------!
266      !                             !  NEMO general initialization  !
267      !                             !-------------------------------!
268
269      CALL nemo_ctl                          ! Control prints & Benchmark
270
271      !                                      ! Domain decomposition
272      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
273      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
274      ENDIF
275      !
276      IF( nn_timing == 1 )  CALL timing_init
277      !
278      !                                      ! General initialization
279                            CALL     phy_cst    ! Physical constants
280                            CALL     eos_init   ! Equation of state
281                            CALL     dom_cfg    ! Domain configuration
282                            CALL     dom_init   ! Domain
283
284      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
285
286      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
287
288                            CALL  istate_init   ! ocean initial state (Dynamics and tracers)
289   END SUBROUTINE nemo_init
290
291
292   SUBROUTINE nemo_ctl
293      !!----------------------------------------------------------------------
294      !!                     ***  ROUTINE nemo_ctl  ***
295      !!
296      !! ** Purpose :   control print setting
297      !!
298      !! ** Method  : - print namctl information and check some consistencies
299      !!----------------------------------------------------------------------
300      !
301      IF(lwp) THEN                  ! control print
302         WRITE(numout,*)
303         WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark'
304         WRITE(numout,*) '~~~~~~~ '
305         WRITE(numout,*) '   Namelist namctl'
306         WRITE(numout,*) '      run control (for debugging)     ln_ctl     = ', ln_ctl
307         WRITE(numout,*) '      level of print                  nn_print   = ', nn_print
308         WRITE(numout,*) '      Start i indice for SUM control  nn_ictls   = ', nn_ictls
309         WRITE(numout,*) '      End i indice for SUM control    nn_ictle   = ', nn_ictle
310         WRITE(numout,*) '      Start j indice for SUM control  nn_jctls   = ', nn_jctls
311         WRITE(numout,*) '      End j indice for SUM control    nn_jctle   = ', nn_jctle
312         WRITE(numout,*) '      number of proc. following i     nn_isplt   = ', nn_isplt
313         WRITE(numout,*) '      number of proc. following j     nn_jsplt   = ', nn_jsplt
314         WRITE(numout,*) '      benchmark parameter (0/1)       nn_bench   = ', nn_bench
315         WRITE(numout,*) '      timing activated    (0/1)       nn_timing  = ', nn_timing
316      ENDIF
317      !
318      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
319      nictls    = nn_ictls
320      nictle    = nn_ictle
321      njctls    = nn_jctls
322      njctle    = nn_jctle
323      isplt     = nn_isplt
324      jsplt     = nn_jsplt
325      nbench    = nn_bench
326
327      IF(lwp) THEN                  ! control print
328         WRITE(numout,*)
329         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
330         WRITE(numout,*) '~~~~~~~ '
331         WRITE(numout,*) '   Namelist namcfg'
332         WRITE(numout,*) '      configuration name              cp_cfg      = ', TRIM(cp_cfg)
333         WRITE(numout,*) '      configuration zoom name         cp_cfz      = ', TRIM(cp_cfz)
334         WRITE(numout,*) '      configuration resolution        jp_cfg      = ', jp_cfg
335         WRITE(numout,*) '      1st lateral dimension ( >= jpi ) jpidta     = ', jpidta
336         WRITE(numout,*) '      2nd    "         "    ( >= jpj ) jpjdta     = ', jpjdta
337         WRITE(numout,*) '      3nd    "         "               jpkdta     = ', jpkdta
338         WRITE(numout,*) '      1st dimension of global domain in i jpiglo  = ', jpiglo
339         WRITE(numout,*) '      2nd    -                  -    in j jpjglo  = ', jpjglo
340         WRITE(numout,*) '      left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
341         WRITE(numout,*) '      left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
342         WRITE(numout,*) '      lateral cond. type (between 0 and 6) jperio = ', jperio   
343         WRITE(numout,*) '      use file attribute if exists as i/p j-start ln_use_jattr = ', ln_use_jattr
344      ENDIF
345      !                             ! Parameter control
346      !
347      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
348         IF( lk_mpp .AND. jpnij > 1 ) THEN
349            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
350         ELSE
351            IF( isplt == 1 .AND. jsplt == 1  ) THEN
352               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
353                  &           ' - the print control will be done over the whole domain' )
354            ENDIF
355            ijsplt = isplt * jsplt            ! total number of processors ijsplt
356         ENDIF
357         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
358         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
359         !
360         !                              ! indices used for the SUM control
361         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
362            lsp_area = .FALSE.
363         ELSE                                             ! print control done over a specific  area
364            lsp_area = .TRUE.
365            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
366               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
367               nictls = 1
368            ENDIF
369            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
370               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
371               nictle = jpiglo
372            ENDIF
373            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
374               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
375               njctls = 1
376            ENDIF
377            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
378               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
379               njctle = jpjglo
380            ENDIF
381         ENDIF
382      ENDIF
383      !
384      IF( nbench == 1 ) THEN              ! Benchmark
385         SELECT CASE ( cp_cfg )
386         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
387         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
388            &                                 ' cp_cfg = "gyre" in namelist &namcfg or set nbench = 0' )
389         END SELECT
390      ENDIF
391      !
392      IF( 1_wp /= SIGN(1._wp,-0._wp)  )   CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ',  &
393         &                                               'f2003 standard. '                              ,  &
394         &                                               'Compile with key_nosignedzero enabled' )
395      !
396   END SUBROUTINE nemo_ctl
397
398
399   SUBROUTINE nemo_closefile
400      !!----------------------------------------------------------------------
401      !!                     ***  ROUTINE nemo_closefile  ***
402      !!
403      !! ** Purpose :   Close the files
404      !!----------------------------------------------------------------------
405      !
406      IF( lk_mpp )   CALL mppsync
407      !
408      CALL iom_close                                 ! close all input/output files managed by iom_*
409      !
410      IF( numstp          /= -1 )   CLOSE( numstp          )   ! time-step file
411      IF( numsol          /= -1 )   CLOSE( numsol          )   ! solver file
412      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
413      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
414      IF( lwm.AND.numond  /= -1 )   CLOSE( numond          )   ! oce output namelist
415      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
416      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
417      IF( lwm.AND.numoni  /= -1 )   CLOSE( numoni          )   ! ice output namelist
418      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice      )   ! ice variables (temp. evolution)
419      IF( numout          /=  6 )   CLOSE( numout          )   ! standard model output file
420      IF( numdct_vol      /= -1 )   CLOSE( numdct_vol      )   ! volume transports
421      IF( numdct_heat     /= -1 )   CLOSE( numdct_heat     )   ! heat transports
422      IF( numdct_salt     /= -1 )   CLOSE( numdct_salt     )   ! salt transports
423
424      !
425      numout = 6                                     ! redefine numout in case it is used after this point...
426      !
427   END SUBROUTINE nemo_closefile
428
429
430   SUBROUTINE nemo_alloc
431      !!----------------------------------------------------------------------
432      !!                     ***  ROUTINE nemo_alloc  ***
433      !!
434      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
435      !!
436      !! ** Method  :
437      !!----------------------------------------------------------------------
438      USE diawri    , ONLY: dia_wri_alloc
439      USE dom_oce   , ONLY: dom_oce_alloc
440      !
441      INTEGER :: ierr
442      !!----------------------------------------------------------------------
443      !
444      ierr =        oce_alloc       ()          ! ocean
445      ierr = ierr + dia_wri_alloc   ()
446      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
447      !
448      IF( lk_mpp    )   CALL mpp_sum( ierr )
449      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
450      !
451   END SUBROUTINE nemo_alloc
452
453
454   SUBROUTINE nemo_partition( num_pes )
455      !!----------------------------------------------------------------------
456      !!                 ***  ROUTINE nemo_partition  ***
457      !!
458      !! ** Purpose :
459      !!
460      !! ** Method  :
461      !!----------------------------------------------------------------------
462      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
463      !
464      INTEGER, PARAMETER :: nfactmax = 20
465      INTEGER :: nfact ! The no. of factors returned
466      INTEGER :: ierr  ! Error flag
467      INTEGER :: ji
468      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
469      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
470      !!----------------------------------------------------------------------
471      !
472      ierr = 0
473      !
474      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
475      !
476      IF( nfact <= 1 ) THEN
477         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
478         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
479         jpnj = 1
480         jpni = num_pes
481      ELSE
482         ! Search through factors for the pair that are closest in value
483         mindiff = 1000000
484         imin    = 1
485         DO ji = 1, nfact-1, 2
486            idiff = ABS( ifact(ji) - ifact(ji+1) )
487            IF( idiff < mindiff ) THEN
488               mindiff = idiff
489               imin = ji
490            ENDIF
491         END DO
492         jpnj = ifact(imin)
493         jpni = ifact(imin + 1)
494      ENDIF
495      !
496      jpnij = jpni*jpnj
497      !
498   END SUBROUTINE nemo_partition
499
500
501   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
502      !!----------------------------------------------------------------------
503      !!                     ***  ROUTINE factorise  ***
504      !!
505      !! ** Purpose :   return the prime factors of n.
506      !!                knfax factors are returned in array kfax which is of
507      !!                maximum dimension kmaxfax.
508      !! ** Method  :
509      !!----------------------------------------------------------------------
510      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
511      INTEGER                    , INTENT(  out) ::   kerr, knfax
512      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
513      !
514      INTEGER :: ifac, jl, inu
515      INTEGER, PARAMETER :: ntest = 14
516      INTEGER :: ilfax(ntest)
517      !
518      ! lfax contains the set of allowed factors.
519      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
520         &                            128,   64,   32,   16,    8,   4,   2  /
521      !!----------------------------------------------------------------------
522
523      ! Clear the error flag and initialise output vars
524      kerr = 0
525      kfax = 1
526      knfax = 0
527
528      ! Find the factors of n.
529      IF( kn == 1 )   GOTO 20
530
531      ! nu holds the unfactorised part of the number.
532      ! knfax holds the number of factors found.
533      ! l points to the allowed factor list.
534      ! ifac holds the current factor.
535
536      inu   = kn
537      knfax = 0
538
539      DO jl = ntest, 1, -1
540         !
541         ifac = ilfax(jl)
542         IF( ifac > inu )   CYCLE
543
544         ! Test whether the factor will divide.
545
546         IF( MOD(inu,ifac) == 0 ) THEN
547            !
548            knfax = knfax + 1            ! Add the factor to the list
549            IF( knfax > kmaxfax ) THEN
550               kerr = 6
551               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
552               return
553            ENDIF
554            kfax(knfax) = ifac
555            ! Store the other factor that goes with this one
556            knfax = knfax + 1
557            kfax(knfax) = inu / ifac
558            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
559         ENDIF
560         !
561      END DO
562
563   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
564      !
565   END SUBROUTINE factorise
566
567#if defined key_mpp_mpi
568
569   SUBROUTINE nemo_northcomms
570      !!======================================================================
571      !!                     ***  ROUTINE  nemo_northcomms  ***
572      !! nemo_northcomms    :  Setup for north fold exchanges with explicit
573      !!                       point-to-point messaging
574      !!=====================================================================
575      !!----------------------------------------------------------------------
576      !!
577      !! ** Purpose :   Initialization of the northern neighbours lists.
578      !!----------------------------------------------------------------------
579      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
580      !!    2.0  ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC)
581      !!----------------------------------------------------------------------
582
583      INTEGER  ::   sxM, dxM, sxT, dxT, jn
584      INTEGER  ::   njmppmax
585
586      njmppmax = MAXVAL( njmppt )
587   
588      !initializes the north-fold communication variables
589      isendto(:) = 0
590      nsndto = 0
591
592      !if I am a process in the north
593      IF ( njmpp == njmppmax ) THEN
594          !sxM is the first point (in the global domain) needed to compute the
595          !north-fold for the current process
596          sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1
597          !dxM is the last point (in the global domain) needed to compute the
598          !north-fold for the current process
599          dxM = jpiglo - nimppt(narea) + 2
600
601          !loop over the other north-fold processes to find the processes
602          !managing the points belonging to the sxT-dxT range
603 
604          DO jn = 1, jpni
605                !sxT is the first point (in the global domain) of the jn
606                !process
607                sxT = nfiimpp(jn, jpnj)
608                !dxT is the last point (in the global domain) of the jn
609                !process
610                dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1
611                IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN
612                   nsndto = nsndto + 1
613                     isendto(nsndto) = jn
614                ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN
615                   nsndto = nsndto + 1
616                     isendto(nsndto) = jn
617                ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN
618                   nsndto = nsndto + 1
619                     isendto(nsndto) = jn
620                END IF
621          END DO
622          nfsloop = 1
623          nfeloop = nlci
624          DO jn = 2,jpni-1
625           IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN
626              IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN
627                 nfsloop = nldi
628              ENDIF
629              IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN
630                 nfeloop = nlei
631              ENDIF
632           ENDIF
633        END DO
634
635      ENDIF
636      l_north_nogather = .TRUE.
637   END SUBROUTINE nemo_northcomms
638#else
639   SUBROUTINE nemo_northcomms      ! Dummy routine
640      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
641   END SUBROUTINE nemo_northcomms
642#endif
643
644   !!======================================================================
645END MODULE nemogcm
646
647
Note: See TracBrowser for help on using the repository browser.