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/2013/dev_r3853_CNRS9_ConfSetting/NEMOGCM/NEMO/SAS_SRC – NEMO

source: branches/2013/dev_r3853_CNRS9_ConfSetting/NEMOGCM/NEMO/SAS_SRC/nemogcm.F90 @ 3973

Last change on this file since 3973 was 3973, checked in by clevy, 11 years ago

Configuration setting/Step3, see ticket:#1074

File size: 33.2 KB
Line 
1MODULE nemogcm
2   !!======================================================================
3   !!                       ***  MODULE nemogcm   ***
4   !! Ocean system   : NEMO GCM (ocean dynamics, on-line tracers, biochemistry and sea-ice)
5   !!======================================================================
6   !! History :  OPA  ! 1990-10  (C. Levy, G. Madec)  Original code
7   !!            7.0  ! 1991-11  (M. Imbard, C. Levy, G. Madec)
8   !!            7.1  ! 1993-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
9   !!                             P. Delecluse, C. Perigaud, G. Caniaux, B. Colot, C. Maes) release 7.1
10   !!             -   ! 1992-06  (L.Terray)  coupling implementation
11   !!             -   ! 1993-11  (M.A. Filiberti) IGLOO sea-ice
12   !!            8.0  ! 1996-03  (M. Imbard, C. Levy, G. Madec, O. Marti, M. Guyon, A. Lazar,
13   !!                             P. Delecluse, L.Terray, M.A. Filiberti, J. Vialar, A.M. Treguier, M. Levy) release 8.0
14   !!            8.1  ! 1997-06  (M. Imbard, G. Madec)
15   !!            8.2  ! 1999-11  (M. Imbard, H. Goosse)  LIM sea-ice model
16   !!                 ! 1999-12  (V. Thierry, A-M. Treguier, M. Imbard, M-A. Foujols)  OPEN-MP
17   !!                 ! 2000-07  (J-M Molines, M. Imbard)  Open Boundary Conditions  (CLIPPER)
18   !!   NEMO     1.0  ! 2002-08  (G. Madec)  F90: Free form and modules
19   !!             -   ! 2004-06  (R. Redler, NEC CCRLE, Germany) add OASIS[3/4] coupled interfaces
20   !!             -   ! 2004-08  (C. Talandier) New trends organization
21   !!             -   ! 2005-06  (C. Ethe) Add the 1D configuration possibility
22   !!             -   ! 2005-11  (V. Garnier) Surface pressure gradient organization
23   !!             -   ! 2006-03  (L. Debreu, C. Mazauric)  Agrif implementation
24   !!             -   ! 2006-04  (G. Madec, R. Benshila)  Step reorganization
25   !!             -   ! 2007-07  (J. Chanut, A. Sellar) Unstructured open boundaries (BDY)
26   !!            3.2  ! 2009-08  (S. Masson)  open/write in the listing file in mpp
27   !!            3.3  ! 2010-05  (K. Mogensen, A. Weaver, M. Martin, D. Lea) Assimilation interface
28   !!             -   ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
29   !!            3.3.1! 2011-01  (A. R. Porter, STFC Daresbury) dynamical allocation
30   !!            3.4  ! 2011-11  (C. Harris) decomposition changes for running with CICE
31   !!----------------------------------------------------------------------
32
33   !!----------------------------------------------------------------------
34   !!   nemo_gcm       : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice
35   !!   nemo_init      : initialization of the NEMO system
36   !!   nemo_ctl       : initialisation of the contol print
37   !!   nemo_closefile : close remaining open files
38   !!   nemo_alloc     : dynamical allocation
39   !!   nemo_partition : calculate MPP domain decomposition
40   !!   factorise      : calculate the factors of the no. of MPI processes
41   !!----------------------------------------------------------------------
42   USE step_oce        ! module used in the ocean time stepping module
43   USE sbc_oce         ! surface boundary condition: ocean
44   USE cla             ! cross land advection               (tra_cla routine)
45   USE domcfg          ! domain configuration               (dom_cfg routine)
46   USE daymod          ! calendar
47   USE mppini          ! shared/distributed memory setting (mpp_init routine)
48   USE domain          ! domain initialization             (dom_init routine)
49   USE phycst          ! physical constant                  (par_cst routine)
50   USE step            ! NEMO time-stepping                 (stp     routine)
51   USE lib_mpp         ! distributed memory computing
52#if defined key_iomput
53   USE xios
54#endif
55   USE sbcssm
56
57   IMPLICIT NONE
58   PRIVATE
59
60   PUBLIC   nemo_gcm    ! called by model.F90
61   PUBLIC   nemo_init   ! needed by AGRIF
62
63   CHARACTER(lc) ::   cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
64
65   !!----------------------------------------------------------------------
66   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
67   !! $Id: nemogcm.F90 3294 2012-01-28 16:44:18Z rblod $
68   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
69   !!----------------------------------------------------------------------
70CONTAINS
71
72   SUBROUTINE nemo_gcm
73      !!----------------------------------------------------------------------
74      !!                     ***  ROUTINE nemo_gcm  ***
75      !!
76      !! ** Purpose :   NEMO solves the primitive equations on an orthogonal
77      !!              curvilinear mesh on the sphere.
78      !!
79      !! ** Method  : - model general initialization
80      !!              - launch the time-stepping (stp routine)
81      !!              - finalize the run by closing files and communications
82      !!
83      !! References : Madec, Delecluse, Imbard, and Levy, 1997:  internal report, IPSL.
84      !!              Madec, 2008, internal report, IPSL.
85      !!----------------------------------------------------------------------
86      INTEGER ::   istp       ! time step index
87      !!----------------------------------------------------------------------
88      !
89#if defined key_agrif
90      CALL Agrif_Init_Grids()      ! AGRIF: set the meshes
91#endif
92
93      !                            !-----------------------!
94      CALL nemo_init               !==  Initialisations  ==!
95      !                            !-----------------------!
96#if defined key_agrif
97      CALL Agrif_Declare_Var       ! AGRIF: set the meshes
98#endif
99      ! check that all process are still there... If some process have an error,
100      ! they will never enter in step and other processes will wait until the end of the cpu time!
101      IF( lk_mpp )   CALL mpp_max( nstop )
102
103      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
104
105      !                            !-----------------------!
106      !                            !==   time stepping   ==!
107      !                            !-----------------------!
108      istp = nit000
109       
110      DO WHILE ( istp <= nitend .AND. nstop == 0 )
111#if defined key_agrif
112         CALL Agrif_Step( stp )           ! AGRIF: time stepping
113#else
114         CALL stp( istp )                 ! standard time stepping
115#endif
116         istp = istp + 1
117         IF( lk_mpp )   CALL mpp_max( nstop )
118      END DO
119      !                            !------------------------!
120      !                            !==  finalize the run  ==!
121      !                            !------------------------!
122      IF(lwp) WRITE(numout,cform_aaa)   ! Flag AAAAAAA
123      !
124      IF( nstop /= 0 .AND. lwp ) THEN   ! error print
125         WRITE(numout,cform_err)
126         WRITE(numout,*) nstop, ' error have been found' 
127      ENDIF
128      !
129#if defined key_agrif
130      CALL Agrif_ParentGrid_To_ChildGrid()
131      IF( nn_timing == 1 )   CALL timing_finalize
132      CALL Agrif_ChildGrid_To_ParentGrid()
133#endif
134      IF( nn_timing == 1 )   CALL timing_finalize
135      !
136      CALL nemo_closefile
137#if defined key_iomput
138      CALL xios_finalize                ! end mpp communications with xios
139#else
140      IF( lk_mpp )   CALL mppstop       ! end mpp communications
141#endif
142      !
143   END SUBROUTINE nemo_gcm
144
145
146   SUBROUTINE nemo_init
147      !!----------------------------------------------------------------------
148      !!                     ***  ROUTINE nemo_init  ***
149      !!
150      !! ** Purpose :   initialization of the NEMO GCM
151      !!----------------------------------------------------------------------
152      INTEGER ::   ji            ! dummy loop indices
153      INTEGER ::   ilocal_comm   ! local integer     
154      INTEGER ::   ios
155
156      CHARACTER(len=80), DIMENSION(16) ::   cltxt
157      !!
158      NAMELIST/namctl/ ln_ctl  , nn_print, nn_ictls, nn_ictle,   &
159         &             nn_isplt, nn_jsplt, nn_jctls, nn_jctle,   &
160         &             nn_bench, nn_timing
161      NAMELIST/namcfg/ cp_cfg, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, &
162         &             jpizoom, jpjzoom, jperio, jphgr_msh, &
163         &             ppglam0, ppgphi0, ppe1_deg, ppe2_deg, ppe1_m, ppe2_m, &
164         &             ppsur, ppa0, ppa1, ppkth, ppacr, ppdzmin, pphmax, ldbletanh, &
165         &             ppa2, ppkth2, ppacr2
166      !!----------------------------------------------------------------------
167      !
168      cltxt = ''      !
169      !                             ! Open reference namelist and configuration namelist files
170      CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
171      CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
172      CALL ctl_opn( numond, 'output.namelist.dyn', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. )
173      !
174      REWIND( numnam_ref )              ! Namelist namctl in reference namelist : Control prints & Benchmark
175      READ  ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 )
176901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', lwp )
177
178      REWIND( numnam_cfg )              ! Namelist namctl in confguration namelist : Control prints & Benchmark
179      READ  ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 )
180902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', lwp )
181      WRITE( numond, namctl )
182      !
183      REWIND( numnam_ref )              ! Namelist namcfg in reference namelist : Control prints & Benchmark
184      READ  ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 )
185903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', lwp )
186
187      REWIND( numnam_cfg )              ! Namelist namcfg in confguration namelist : Control prints & Benchmark
188      READ  ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 )
189904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', lwp )   
190      WRITE( numond, namcfg )
191      !                             !--------------------------------------------!
192      !                             !  set communicator & select the local node  !
193      !                             !--------------------------------------------!
194#if defined key_iomput
195      IF( Agrif_Root() ) THEN
196         CALL  xios_initialize( "nemo",return_comm=ilocal_comm )
197      ENDIF
198      narea = mynode ( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )  ! Nodes selection
199#else
200      ilocal_comm = 0
201      narea = mynode( cltxt, numnam_ref, numnam_cfg, numond , nstop, ilocal_comm )        ! Nodes selection (control print return in cltxt)
202#endif
203      narea = narea + 1                                     ! mynode return the rank of proc (0 --> jpnij -1 )
204
205      lwp = (narea == 1) .OR. ln_ctl                        ! control of all listing output print
206
207      ! If dimensions of processor grid weren't specified in the namelist file
208      ! then we calculate them here now that we have our communicator size
209      IF( (jpni < 1) .OR. (jpnj < 1) )THEN
210#if   defined key_mpp_mpi
211         IF( Agrif_Root() ) CALL nemo_partition(mppsize)
212#else
213         jpni  = 1
214         jpnj  = 1
215         jpnij = jpni*jpnj
216#endif
217      END IF
218
219      ! Calculate domain dimensions given calculated jpni and jpnj
220      ! This used to be done in par_oce.F90 when they were parameters rather
221      ! than variables
222      IF( Agrif_Root() ) THEN
223         jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci   ! first  dim.
224#if defined key_nemocice_decomp
225         jpj = ( jpjglo+1-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim.
226#else
227         jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj   ! second dim.
228#endif
229         jpk = jpkdta                                             ! third dim
230         jpim1 = jpi-1                                            ! inner domain indices
231         jpjm1 = jpj-1                                            !   "           "
232         jpkm1 = jpk-1                                            !   "           "
233         jpij  = jpi*jpj                                          !  jpi x j
234      ENDIF
235
236      IF(lwp) THEN                            ! open listing units
237         !
238         CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea )
239         !
240         WRITE(numout,*)
241         WRITE(numout,*) '   CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC'
242         WRITE(numout,*) '                       NEMO team'
243         WRITE(numout,*) '            Ocean General Circulation Model'
244         WRITE(numout,*) '                  version 3.4  (2011) '
245         WRITE(numout,*) '             StandAlone Surface version (SAS) '
246         WRITE(numout,*)
247         WRITE(numout,*)
248         DO ji = 1, SIZE(cltxt) 
249            IF( TRIM(cltxt(ji)) /= '' )   WRITE(numout,*) cltxt(ji)      ! control print of mynode
250         END DO
251         WRITE(numout,cform_aaa)                                         ! Flag AAAAAAA
252         !
253      ENDIF
254
255      ! Now we know the dimensions of the grid and numout has been set we can
256      ! allocate arrays
257      CALL nemo_alloc()
258
259      !                             !-------------------------------!
260      !                             !  NEMO general initialization  !
261      !                             !-------------------------------!
262
263      CALL nemo_ctl                          ! Control prints & Benchmark
264
265      !                                      ! Domain decomposition
266      IF( jpni*jpnj == jpnij ) THEN   ;   CALL mpp_init      ! standard cutting out
267      ELSE                            ;   CALL mpp_init2     ! eliminate land processors
268      ENDIF
269      !
270      IF( nn_timing == 1 )  CALL timing_init
271      !
272      !                                     ! General initialization
273                            CALL phy_cst    ! Physical constants
274                            CALL eos_init   ! Equation of state
275                            CALL dom_cfg    ! Domain configuration
276                            CALL dom_init   ! Domain
277
278      IF( ln_nnogather )    CALL nemo_northcomms   ! Initialise the northfold neighbour lists (must be done after the masks are defined)
279
280      IF( ln_ctl        )   CALL prt_ctl_init   ! Print control
281                            CALL flush(numout)
282
283                            CALL day_init   ! model calendar (using both namelist and restart infos)
284
285                            CALL sbc_init   ! Forcings : surface module
286     
287      IF(lwp) WRITE(numout,*) 'Euler time step switch is ', neuler
288      !
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      ENDIF
316      !
317      nprint    = nn_print          ! convert DOCTOR namelist names into OLD names
318      nictls    = nn_ictls
319      nictle    = nn_ictle
320      njctls    = nn_jctls
321      njctle    = nn_jctle
322      isplt     = nn_isplt
323      jsplt     = nn_jsplt
324      nbench    = nn_bench
325
326      IF(lwp) THEN                  ! control print
327         WRITE(numout,*)
328         WRITE(numout,*) 'namcfg  : configuration initialization through namelist read'
329         WRITE(numout,*) '~~~~~~~ '
330         WRITE(numout,*) '   Namelist namcfg'
331         WRITE(numout,*) '      configuration name              cp_cfg      = ', TRIM(cp_cfg)
332         WRITE(numout,*) '      configuration resolution        jp_cfg      = ', jp_cfg
333         WRITE(numout,*) '      1st lateral dimension ( >= jpi ) jpidta     = ', jpidta
334         WRITE(numout,*) '      2nd    "         "    ( >= jpj ) jpjdta     = ', jpjdta
335         WRITE(numout,*) '      3nd    "         "               jpkdta     = ', jpkdta
336         WRITE(numout,*) '      1st dimension of global domain in i jpiglo  = ', jpiglo
337         WRITE(numout,*) '      2nd    -                  -    in j jpjglo  = ', jpjglo
338         WRITE(numout,*) '      left bottom i index of the zoom (in data domain) jpizoom = ', jpizoom
339         WRITE(numout,*) '      left bottom j index of the zoom (in data domain) jpizoom = ', jpjzoom
340         WRITE(numout,*) '      lateral cond. type (between 0 and 6) jperio = ', jperio   
341         WRITE(numout,*) '      type of horizontal mesh jphgr_msh           = ', jphgr_msh
342         WRITE(numout,*) '      longitude of first raw and column T-point ppglam0 = ', ppglam0
343         WRITE(numout,*) '      latitude  of first raw and column T-point ppgphi0 = ', ppgphi0
344         WRITE(numout,*) '      zonal      grid-spacing (degrees) ppe1_deg        = ', ppe1_deg
345         WRITE(numout,*) '      meridional grid-spacing (degrees) ppe2_deg        = ', ppe2_deg
346         WRITE(numout,*) '      zonal      grid-spacing (degrees) ppe1_m          = ', ppe1_m
347         WRITE(numout,*) '      meridional grid-spacing (degrees) ppe2_m          = ', ppe2_m
348         WRITE(numout,*) '      ORCA r4, r2 and r05 coefficients  ppsur           = ', ppsur
349         WRITE(numout,*) '                                        ppa0            = ', ppa0
350         WRITE(numout,*) '                                        ppa1            = ', ppa1
351         WRITE(numout,*) '                                        ppkth           = ', ppkth
352         WRITE(numout,*) '                                        ppacr           = ', ppacr
353         WRITE(numout,*) '      Minimum vertical spacing ppdzmin                  = ', ppdzmin
354         WRITE(numout,*) '      Maximum depth pphmax                              = ', pphmax
355         WRITE(numout,*) '      Use double tanf function for vertical coordinates ldbletanh = ', ldbletanh
356         WRITE(numout,*) '      Double tanh function parameters ppa2              = ', ppa2
357         WRITE(numout,*) '                                      ppkth2            = ', ppkth2
358         WRITE(numout,*) '                                      ppacr2            = ', ppacr2
359      ENDIF
360      !                             ! Parameter control
361      !
362      IF( ln_ctl ) THEN                 ! sub-domain area indices for the control prints
363         IF( lk_mpp .AND. jpnij > 1 ) THEN
364            isplt = jpni   ;   jsplt = jpnj   ;   ijsplt = jpni*jpnj   ! the domain is forced to the real split domain
365         ELSE
366            IF( isplt == 1 .AND. jsplt == 1  ) THEN
367               CALL ctl_warn( ' - isplt & jsplt are equal to 1',   &
368                  &           ' - the print control will be done over the whole domain' )
369            ENDIF
370            ijsplt = isplt * jsplt            ! total number of processors ijsplt
371         ENDIF
372         IF(lwp) WRITE(numout,*)'          - The total number of processors over which the'
373         IF(lwp) WRITE(numout,*)'            print control will be done is ijsplt : ', ijsplt
374         !
375         !                              ! indices used for the SUM control
376         IF( nictls+nictle+njctls+njctle == 0 )   THEN    ! print control done over the default area
377            lsp_area = .FALSE.                       
378         ELSE                                             ! print control done over a specific  area
379            lsp_area = .TRUE.
380            IF( nictls < 1 .OR. nictls > jpiglo )   THEN
381               CALL ctl_warn( '          - nictls must be 1<=nictls>=jpiglo, it is forced to 1' )
382               nictls = 1
383            ENDIF
384            IF( nictle < 1 .OR. nictle > jpiglo )   THEN
385               CALL ctl_warn( '          - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' )
386               nictle = jpiglo
387            ENDIF
388            IF( njctls < 1 .OR. njctls > jpjglo )   THEN
389               CALL ctl_warn( '          - njctls must be 1<=njctls>=jpjglo, it is forced to 1' )
390               njctls = 1
391            ENDIF
392            IF( njctle < 1 .OR. njctle > jpjglo )   THEN
393               CALL ctl_warn( '          - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' )
394               njctle = jpjglo
395            ENDIF
396         ENDIF
397      ENDIF
398      !
399      IF( nbench == 1 ) THEN              ! Benchmark
400         SELECT CASE ( cp_cfg )
401         CASE ( 'gyre' )   ;   CALL ctl_warn( ' The Benchmark is activated ' )
402         CASE DEFAULT      ;   CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:',   &
403            &                                 ' cp_cfg="gyre" in namelist &namcfg or set nbench = 0' )
404         END SELECT
405      ENDIF
406      !
407   END SUBROUTINE nemo_ctl
408
409
410   SUBROUTINE nemo_closefile
411      !!----------------------------------------------------------------------
412      !!                     ***  ROUTINE nemo_closefile  ***
413      !!
414      !! ** Purpose :   Close the files
415      !!----------------------------------------------------------------------
416      !
417      IF( lk_mpp )   CALL mppsync
418      !
419      CALL iom_close                                 ! close all input/output files managed by iom_*
420      !
421      IF( numstp          /= -1 )   CLOSE( numstp      )   ! time-step file     
422      IF( numnam_ref      /= -1 )   CLOSE( numnam_ref      )   ! oce reference namelist
423      IF( numnam_cfg      /= -1 )   CLOSE( numnam_cfg      )   ! oce configuration namelist
424      IF( numond          /= -1 )   CLOSE( numond          )   ! oce output namelist
425      IF( numnam_ice_ref  /= -1 )   CLOSE( numnam_ice_ref  )   ! ice reference namelist
426      IF( numnam_ice_cfg  /= -1 )   CLOSE( numnam_ice_cfg  )   ! ice configuration namelist
427      IF( numoni          /= -1 )   CLOSE( numoni          )   ! ice output namelist
428      IF( numevo_ice      /= -1 )   CLOSE( numevo_ice  )   ! ice variables (temp. evolution)
429      IF( numout          /=  6 )   CLOSE( numout      )   ! standard model output file
430      !
431      numout = 6                                     ! redefine numout in case it is used after this point...
432      !
433   END SUBROUTINE nemo_closefile
434
435
436   SUBROUTINE nemo_alloc
437      !!----------------------------------------------------------------------
438      !!                     ***  ROUTINE nemo_alloc  ***
439      !!
440      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
441      !!
442      !! ** Method  :
443      !!----------------------------------------------------------------------
444      USE diawri    , ONLY: dia_wri_alloc
445      USE dom_oce   , ONLY: dom_oce_alloc
446      USE oce       , ONLY : sshn, sshb, snwice_mass, snwice_mass_b, snwice_fmass 
447      !
448      INTEGER :: ierr,ierr4
449      !!----------------------------------------------------------------------
450      !
451      ierr =        dia_wri_alloc   ()
452      ierr = ierr + dom_oce_alloc   ()          ! ocean domain
453      ierr = ierr + lib_mpp_alloc   (numout)    ! mpp exchanges
454      ALLOCATE( snwice_mass(jpi,jpj)  , snwice_mass_b(jpi,jpj),             &
455         &      snwice_fmass(jpi,jpj), STAT= ierr4 )
456      ierr = ierr + ierr4
457      !
458      IF( lk_mpp    )   CALL mpp_sum( ierr )
459      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' )
460      !
461   END SUBROUTINE nemo_alloc
462
463
464   SUBROUTINE nemo_partition( num_pes )
465      !!----------------------------------------------------------------------
466      !!                 ***  ROUTINE nemo_partition  ***
467      !!
468      !! ** Purpose :   
469      !!
470      !! ** Method  :
471      !!----------------------------------------------------------------------
472      INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have
473      !
474      INTEGER, PARAMETER :: nfactmax = 20
475      INTEGER :: nfact ! The no. of factors returned
476      INTEGER :: ierr  ! Error flag
477      INTEGER :: ji
478      INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value
479      INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors
480      !!----------------------------------------------------------------------
481
482      ierr = 0
483
484      CALL factorise( ifact, nfactmax, nfact, num_pes, ierr )
485
486      IF( nfact <= 1 ) THEN
487         WRITE (numout, *) 'WARNING: factorisation of number of PEs failed'
488         WRITE (numout, *) '       : using grid of ',num_pes,' x 1'
489         jpnj = 1
490         jpni = num_pes
491      ELSE
492         ! Search through factors for the pair that are closest in value
493         mindiff = 1000000
494         imin    = 1
495         DO ji = 1, nfact-1, 2
496            idiff = ABS( ifact(ji) - ifact(ji+1) )
497            IF( idiff < mindiff ) THEN
498               mindiff = idiff
499               imin = ji
500            ENDIF
501         END DO
502         jpnj = ifact(imin)
503         jpni = ifact(imin + 1)
504      ENDIF
505      !
506      jpnij = jpni*jpnj
507      !
508   END SUBROUTINE nemo_partition
509
510
511   SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr )
512      !!----------------------------------------------------------------------
513      !!                     ***  ROUTINE factorise  ***
514      !!
515      !! ** Purpose :   return the prime factors of n.
516      !!                knfax factors are returned in array kfax which is of
517      !!                maximum dimension kmaxfax.
518      !! ** Method  :
519      !!----------------------------------------------------------------------
520      INTEGER                    , INTENT(in   ) ::   kn, kmaxfax
521      INTEGER                    , INTENT(  out) ::   kerr, knfax
522      INTEGER, DIMENSION(kmaxfax), INTENT(  out) ::   kfax
523      !
524      INTEGER :: ifac, jl, inu
525      INTEGER, PARAMETER :: ntest = 14
526      INTEGER :: ilfax(ntest)
527
528      ! lfax contains the set of allowed factors.
529      data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256,  &
530         &                            128,   64,   32,   16,    8,   4,   2  /
531      !!----------------------------------------------------------------------
532
533      ! Clear the error flag and initialise output vars
534      kerr = 0
535      kfax = 1
536      knfax = 0
537
538      ! Find the factors of n.
539      IF( kn == 1 )   GOTO 20
540
541      ! nu holds the unfactorised part of the number.
542      ! knfax holds the number of factors found.
543      ! l points to the allowed factor list.
544      ! ifac holds the current factor.
545
546      inu   = kn
547      knfax = 0
548
549      DO jl = ntest, 1, -1
550         !
551         ifac = ilfax(jl)
552         IF( ifac > inu )   CYCLE
553
554         ! Test whether the factor will divide.
555
556         IF( MOD(inu,ifac) == 0 ) THEN
557            !
558            knfax = knfax + 1            ! Add the factor to the list
559            IF( knfax > kmaxfax ) THEN
560               kerr = 6
561               write (*,*) 'FACTOR: insufficient space in factor array ', knfax
562               return
563            ENDIF
564            kfax(knfax) = ifac
565            ! Store the other factor that goes with this one
566            knfax = knfax + 1
567            kfax(knfax) = inu / ifac
568            !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax)
569         ENDIF
570         !
571      END DO
572
573   20 CONTINUE      ! Label 20 is the exit point from the factor search loop.
574      !
575   END SUBROUTINE factorise
576
577#if defined key_mpp_mpi
578   SUBROUTINE nemo_northcomms
579      !!======================================================================
580      !!                     ***  ROUTINE  nemo_northcomms  ***
581      !! nemo_northcomms    :  Setup for north fold exchanges with explicit peer to peer messaging
582      !!=====================================================================
583      !!----------------------------------------------------------------------
584      !!
585      !! ** Purpose :   Initialization of the northern neighbours lists.
586      !!----------------------------------------------------------------------
587      !!    1.0  ! 2011-10  (A. C. Coward, NOCS & J. Donners, PRACE)
588      !!----------------------------------------------------------------------
589
590      INTEGER ::   ji, jj, jk, ij, jtyp    ! dummy loop indices
591      INTEGER ::   ijpj                    ! number of rows involved in north-fold exchange
592      INTEGER ::   northcomms_alloc        ! allocate return status
593      REAL(wp), ALLOCATABLE, DIMENSION ( :,: ) ::   znnbrs     ! workspace
594      LOGICAL,  ALLOCATABLE, DIMENSION ( : )   ::   lrankset   ! workspace
595
596      IF(lwp) WRITE(numout,*)
597      IF(lwp) WRITE(numout,*) 'nemo_northcomms : Initialization of the northern neighbours lists'
598      IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
599
600      !!----------------------------------------------------------------------
601      ALLOCATE( znnbrs(jpi,jpj), stat = northcomms_alloc )
602      ALLOCATE( lrankset(jpnij), stat = northcomms_alloc )
603      IF( northcomms_alloc /= 0 ) THEN
604         WRITE(numout,cform_war)
605         WRITE(numout,*) 'northcomms_alloc : failed to allocate arrays'
606         CALL ctl_stop( 'STOP', 'nemo_northcomms : unable to allocate temporary arrays' )
607      ENDIF
608      nsndto = 0
609      isendto = -1
610      ijpj   = 4
611      !
612      ! This routine has been called because ln_nnogather has been set true ( nammpp )
613      ! However, these first few exchanges have to use the mpi_allgather method to
614      ! establish the neighbour lists to use in subsequent peer to peer exchanges.
615      ! Consequently, set l_north_nogather to be false here and set it true only after
616      ! the lists have been established.
617      !
618      l_north_nogather = .FALSE.
619      !
620      ! Exchange and store ranks on northern rows
621
622      DO jtyp = 1,4
623
624         lrankset = .FALSE.
625         znnbrs = narea
626         SELECT CASE (jtyp)
627            CASE(1)
628               CALL lbc_lnk( znnbrs, 'T', 1. )      ! Type 1: T,W-points
629            CASE(2)
630               CALL lbc_lnk( znnbrs, 'U', 1. )      ! Type 2: U-point
631            CASE(3)
632               CALL lbc_lnk( znnbrs, 'V', 1. )      ! Type 3: V-point
633            CASE(4)
634               CALL lbc_lnk( znnbrs, 'F', 1. )      ! Type 4: F-point
635         END SELECT
636
637         IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
638            DO jj = nlcj-ijpj+1, nlcj
639               ij = jj - nlcj + ijpj
640               DO ji = 1,jpi
641                  IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
642               &     lrankset(INT(znnbrs(ji,jj))) = .true.
643               END DO
644            END DO
645
646            DO jj = 1,jpnij
647               IF ( lrankset(jj) ) THEN
648                  nsndto(jtyp) = nsndto(jtyp) + 1
649                  IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
650                     CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
651                  &                 ' jpmaxngh will need to be increased ')
652                  ENDIF
653                  isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
654               ENDIF
655            END DO
656         ENDIF
657
658      END DO
659
660      !
661      ! Type 5: I-point
662      !
663      ! ICE point exchanges may involve some averaging. The neighbours list is
664      ! built up using two exchanges to ensure that the whole stencil is covered.
665      ! lrankset should not be reset between these 'J' and 'K' point exchanges
666
667      jtyp = 5
668      lrankset = .FALSE.
669      znnbrs = narea 
670      CALL lbc_lnk( znnbrs, 'J', 1. ) ! first ice U-V point
671
672      IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN
673         DO jj = nlcj-ijpj+1, nlcj
674            ij = jj - nlcj + ijpj
675            DO ji = 1,jpi
676               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) &
677            &     lrankset(INT(znnbrs(ji,jj))) = .true.
678         END DO
679        END DO
680      ENDIF
681
682      znnbrs = narea 
683      CALL lbc_lnk( znnbrs, 'K', 1. ) ! second ice U-V point
684
685      IF ( njmppt(narea) .EQ. MAXVAL( njmppt )) THEN
686         DO jj = nlcj-ijpj+1, nlcj
687            ij = jj - nlcj + ijpj
688            DO ji = 1,jpi
689               IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND.  INT(znnbrs(ji,jj)) .NE. narea ) &
690            &       lrankset( INT(znnbrs(ji,jj))) = .true.
691            END DO
692         END DO
693
694         DO jj = 1,jpnij
695            IF ( lrankset(jj) ) THEN
696               nsndto(jtyp) = nsndto(jtyp) + 1
697               IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN
698                  CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', &
699               &                 ' jpmaxngh will need to be increased ')
700               ENDIF
701               isendto(nsndto(jtyp),jtyp) = jj-1   ! narea converted to MPI rank
702            ENDIF
703         END DO
704         !
705         ! For northern row areas, set l_north_nogather so that all subsequent exchanges
706         ! can use peer to peer communications at the north fold
707         !
708         l_north_nogather = .TRUE.
709         !
710      ENDIF
711      DEALLOCATE( znnbrs )
712      DEALLOCATE( lrankset )
713
714   END SUBROUTINE nemo_northcomms
715#else
716   SUBROUTINE nemo_northcomms      ! Dummy routine
717      WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?'
718   END SUBROUTINE nemo_northcomms
719#endif
720   !!======================================================================
721END MODULE nemogcm
Note: See TracBrowser for help on using the repository browser.