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

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

changed standard print statement to indicate use of stand alone operator executable in ocean.output

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