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/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/SAO_SRC – NEMO

source: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/SAO_SRC/nemogcm.F90 @ 4847

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

moved ooo_intp.F90 to sao_intp.F90 along with renaming its internal subroutines appropriately

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