1 | MODULE 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 mppini ! shared/distributed memory setting (mpp_init routine) |
---|
47 | USE domain ! domain initialization (dom_init routine) |
---|
48 | #if defined key_nemocice_decomp |
---|
49 | USE ice_domain_size, only: nx_global, ny_global |
---|
50 | #endif |
---|
51 | USE tideini ! tidal components initialization (tide_ini routine) |
---|
52 | USE obcini ! open boundary cond. initialization (obc_ini routine) |
---|
53 | USE bdyini ! open boundary cond. initialization (bdy_init routine) |
---|
54 | USE bdydta ! open boundary cond. initialization (bdy_dta_init routine) |
---|
55 | USE bdytides ! open boundary cond. initialization (bdytide_init routine) |
---|
56 | USE istate ! initial state setting (istate_init routine) |
---|
57 | USE ldfdyn ! lateral viscosity setting (ldfdyn_init routine) |
---|
58 | USE ldftra ! lateral diffusivity setting (ldftra_init routine) |
---|
59 | USE zdfini ! vertical physics setting (zdf_init routine) |
---|
60 | USE phycst ! physical constant (par_cst routine) |
---|
61 | USE trdmod ! momentum/tracers trends (trd_mod_init routine) |
---|
62 | USE asminc ! assimilation increments |
---|
63 | USE asmbkg ! writing out state trajectory |
---|
64 | USE diaptr ! poleward transports (dia_ptr_init routine) |
---|
65 | USE diadct ! sections transports (dia_dct_init routine) |
---|
66 | USE diaobs ! Observation diagnostics (dia_obs_init routine) |
---|
67 | USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined) |
---|
68 | USE step ! NEMO time-stepping (stp routine) |
---|
69 | USE icbini ! handle bergs, initialisation |
---|
70 | USE icbstp ! handle bergs, calving, themodynamics and transport |
---|
71 | #if defined key_oasis3 |
---|
72 | USE cpl_oasis3 ! OASIS3 coupling |
---|
73 | #elif defined key_oasis4 |
---|
74 | USE cpl_oasis4 ! OASIS4 coupling (not working) |
---|
75 | #endif |
---|
76 | USE c1d ! 1D configuration |
---|
77 | USE step_c1d ! Time stepping loop for the 1D configuration |
---|
78 | #if defined key_top |
---|
79 | USE trcini ! passive tracer initialisation |
---|
80 | #endif |
---|
81 | USE lib_mpp ! distributed memory computing |
---|
82 | #if defined key_iomput |
---|
83 | USE xios |
---|
84 | #endif |
---|
85 | USE sbctide, ONLY: lk_tide |
---|
86 | |
---|
87 | IMPLICIT NONE |
---|
88 | PRIVATE |
---|
89 | |
---|
90 | PUBLIC nemo_gcm ! called by model.F90 |
---|
91 | PUBLIC nemo_init ! needed by AGRIF |
---|
92 | PUBLIC nemo_alloc ! needed by TAM |
---|
93 | |
---|
94 | CHARACTER(lc) :: cform_aaa="( /, 'AAAAAAAA', / ) " ! flag for output listing |
---|
95 | |
---|
96 | !!---------------------------------------------------------------------- |
---|
97 | !! NEMO/OPA 4.0 , NEMO Consortium (2011) |
---|
98 | !! $Id$ |
---|
99 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
100 | !!---------------------------------------------------------------------- |
---|
101 | CONTAINS |
---|
102 | |
---|
103 | |
---|
104 | SUBROUTINE nemo_init |
---|
105 | !!---------------------------------------------------------------------- |
---|
106 | !! *** ROUTINE nemo_init *** |
---|
107 | !! |
---|
108 | !! ** Purpose : initialization of the NEMO GCM |
---|
109 | !!---------------------------------------------------------------------- |
---|
110 | INTEGER :: ji ! dummy loop indices |
---|
111 | INTEGER :: ilocal_comm ! local integer |
---|
112 | CHARACTER(len=80), DIMENSION(16) :: cltxt |
---|
113 | !! |
---|
114 | NAMELIST/namctl/ ln_ctl , nn_print, nn_ictls, nn_ictle, & |
---|
115 | & nn_isplt, nn_jsplt, nn_jctls, nn_jctle, & |
---|
116 | & nn_bench, nn_timing |
---|
117 | !!---------------------------------------------------------------------- |
---|
118 | ! |
---|
119 | cltxt = '' |
---|
120 | ! |
---|
121 | ! ! open Namelist file |
---|
122 | CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. ) |
---|
123 | ! |
---|
124 | READ( numnam, namctl ) ! Namelist namctl : Control prints & Benchmark |
---|
125 | ! |
---|
126 | ! !--------------------------------------------! |
---|
127 | ! ! set communicator & select the local node ! |
---|
128 | ! !--------------------------------------------! |
---|
129 | #if defined key_iomput |
---|
130 | IF( Agrif_Root() ) THEN |
---|
131 | # if defined key_oasis3 || defined key_oasis4 |
---|
132 | CALL cpl_prism_init( ilocal_comm ) ! nemo local communicator given by oasis |
---|
133 | CALL xios_initialize( "oceanx",local_comm=ilocal_comm ) |
---|
134 | # else |
---|
135 | CALL xios_initialize( "nemo",return_comm=ilocal_comm ) |
---|
136 | # endif |
---|
137 | ENDIF |
---|
138 | narea = mynode( cltxt, numnam, nstop, ilocal_comm ) ! Nodes selection |
---|
139 | #else |
---|
140 | # if defined key_oasis3 || defined key_oasis4 |
---|
141 | IF( Agrif_Root() ) THEN |
---|
142 | CALL cpl_prism_init( ilocal_comm ) ! nemo local communicator given by oasis |
---|
143 | ENDIF |
---|
144 | narea = mynode( cltxt, numnam, nstop, ilocal_comm ) ! Nodes selection (control print return in cltxt) |
---|
145 | # else |
---|
146 | ilocal_comm = 0 |
---|
147 | narea = mynode( cltxt, numnam, nstop ) ! Nodes selection (control print return in cltxt) |
---|
148 | # endif |
---|
149 | #endif |
---|
150 | narea = narea + 1 ! mynode return the rank of proc (0 --> jpnij -1 ) |
---|
151 | |
---|
152 | lwp = (narea == 1) .OR. ln_ctl ! control of all listing output print |
---|
153 | |
---|
154 | ! If dimensions of processor grid weren't specified in the namelist file |
---|
155 | ! then we calculate them here now that we have our communicator size |
---|
156 | IF( (jpni < 1) .OR. (jpnj < 1) )THEN |
---|
157 | #if defined key_mpp_mpi |
---|
158 | IF( Agrif_Root() ) CALL nemo_partition(mppsize) |
---|
159 | #else |
---|
160 | jpni = 1 |
---|
161 | jpnj = 1 |
---|
162 | jpnij = jpni*jpnj |
---|
163 | #endif |
---|
164 | END IF |
---|
165 | |
---|
166 | ! Calculate domain dimensions given calculated jpni and jpnj |
---|
167 | ! This used to be done in par_oce.F90 when they were parameters rather |
---|
168 | ! than variables |
---|
169 | IF( Agrif_Root() ) THEN |
---|
170 | #if defined key_nemocice_decomp |
---|
171 | jpi = ( nx_global+2-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim. |
---|
172 | jpj = ( ny_global+2-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim. |
---|
173 | #else |
---|
174 | jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim. |
---|
175 | jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim. |
---|
176 | #endif |
---|
177 | jpk = jpkdta ! third dim |
---|
178 | jpim1 = jpi-1 ! inner domain indices |
---|
179 | jpjm1 = jpj-1 ! " " |
---|
180 | jpkm1 = jpk-1 ! " " |
---|
181 | jpij = jpi*jpj ! jpi x j |
---|
182 | ENDIF |
---|
183 | |
---|
184 | IF(lwp) THEN ! open listing units |
---|
185 | ! |
---|
186 | CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea ) |
---|
187 | ! |
---|
188 | WRITE(numout,*) |
---|
189 | WRITE(numout,*) ' CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC' |
---|
190 | WRITE(numout,*) ' NEMO team' |
---|
191 | WRITE(numout,*) ' Ocean General Circulation Model' |
---|
192 | WRITE(numout,*) ' version 3.4 (2011) ' |
---|
193 | WRITE(numout,*) |
---|
194 | WRITE(numout,*) |
---|
195 | DO ji = 1, SIZE(cltxt) |
---|
196 | IF( TRIM(cltxt(ji)) /= '' ) WRITE(numout,*) cltxt(ji) ! control print of mynode |
---|
197 | END DO |
---|
198 | WRITE(numout,cform_aaa) ! Flag AAAAAAA |
---|
199 | ! |
---|
200 | ENDIF |
---|
201 | |
---|
202 | ! Now we know the dimensions of the grid and numout has been set we can |
---|
203 | ! allocate arrays |
---|
204 | CALL nemo_alloc() |
---|
205 | |
---|
206 | ! !-------------------------------! |
---|
207 | ! ! NEMO general initialization ! |
---|
208 | ! !-------------------------------! |
---|
209 | |
---|
210 | CALL nemo_ctl ! Control prints & Benchmark |
---|
211 | |
---|
212 | ! ! Domain decomposition |
---|
213 | IF( jpni*jpnj == jpnij ) THEN ; CALL mpp_init ! standard cutting out |
---|
214 | ELSE ; CALL mpp_init2 ! eliminate land processors |
---|
215 | ENDIF |
---|
216 | ! |
---|
217 | IF( nn_timing == 1 ) CALL timing_init |
---|
218 | ! |
---|
219 | ! ! General initialization |
---|
220 | CALL phy_cst ! Physical constants |
---|
221 | CALL eos_init ! Equation of state |
---|
222 | CALL dom_cfg ! Domain configuration |
---|
223 | CALL dom_init ! Domain |
---|
224 | |
---|
225 | IF( ln_nnogather ) CALL nemo_northcomms ! Initialise the northfold neighbour lists (must be done after the masks are defined) |
---|
226 | |
---|
227 | IF( ln_ctl ) CALL prt_ctl_init ! Print control |
---|
228 | |
---|
229 | CALL istate_init ! ocean initial state (Dynamics and tracers) |
---|
230 | |
---|
231 | IF( lk_diaobs ) THEN ! Observation & model comparison |
---|
232 | CALL dia_obs_init ! Initialize observational data |
---|
233 | CALL dia_obs( nit000 - 1 ) ! Observation operator for restart |
---|
234 | ENDIF |
---|
235 | END SUBROUTINE nemo_init |
---|
236 | |
---|
237 | |
---|
238 | SUBROUTINE nemo_ctl |
---|
239 | !!---------------------------------------------------------------------- |
---|
240 | !! *** ROUTINE nemo_ctl *** |
---|
241 | !! |
---|
242 | !! ** Purpose : control print setting |
---|
243 | !! |
---|
244 | !! ** Method : - print namctl information and check some consistencies |
---|
245 | !!---------------------------------------------------------------------- |
---|
246 | ! |
---|
247 | IF(lwp) THEN ! control print |
---|
248 | WRITE(numout,*) |
---|
249 | WRITE(numout,*) 'nemo_ctl: Control prints & Benchmark' |
---|
250 | WRITE(numout,*) '~~~~~~~ ' |
---|
251 | WRITE(numout,*) ' Namelist namctl' |
---|
252 | WRITE(numout,*) ' run control (for debugging) ln_ctl = ', ln_ctl |
---|
253 | WRITE(numout,*) ' level of print nn_print = ', nn_print |
---|
254 | WRITE(numout,*) ' Start i indice for SUM control nn_ictls = ', nn_ictls |
---|
255 | WRITE(numout,*) ' End i indice for SUM control nn_ictle = ', nn_ictle |
---|
256 | WRITE(numout,*) ' Start j indice for SUM control nn_jctls = ', nn_jctls |
---|
257 | WRITE(numout,*) ' End j indice for SUM control nn_jctle = ', nn_jctle |
---|
258 | WRITE(numout,*) ' number of proc. following i nn_isplt = ', nn_isplt |
---|
259 | WRITE(numout,*) ' number of proc. following j nn_jsplt = ', nn_jsplt |
---|
260 | WRITE(numout,*) ' benchmark parameter (0/1) nn_bench = ', nn_bench |
---|
261 | WRITE(numout,*) ' timing activated (0/1) nn_timing = ', nn_timing |
---|
262 | ENDIF |
---|
263 | ! |
---|
264 | nprint = nn_print ! convert DOCTOR namelist names into OLD names |
---|
265 | nictls = nn_ictls |
---|
266 | nictle = nn_ictle |
---|
267 | njctls = nn_jctls |
---|
268 | njctle = nn_jctle |
---|
269 | isplt = nn_isplt |
---|
270 | jsplt = nn_jsplt |
---|
271 | nbench = nn_bench |
---|
272 | ! ! Parameter control |
---|
273 | ! |
---|
274 | IF( ln_ctl ) THEN ! sub-domain area indices for the control prints |
---|
275 | IF( lk_mpp .AND. jpnij > 1 ) THEN |
---|
276 | isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj ! the domain is forced to the real split domain |
---|
277 | ELSE |
---|
278 | IF( isplt == 1 .AND. jsplt == 1 ) THEN |
---|
279 | CALL ctl_warn( ' - isplt & jsplt are equal to 1', & |
---|
280 | & ' - the print control will be done over the whole domain' ) |
---|
281 | ENDIF |
---|
282 | ijsplt = isplt * jsplt ! total number of processors ijsplt |
---|
283 | ENDIF |
---|
284 | IF(lwp) WRITE(numout,*)' - The total number of processors over which the' |
---|
285 | IF(lwp) WRITE(numout,*)' print control will be done is ijsplt : ', ijsplt |
---|
286 | ! |
---|
287 | ! ! indices used for the SUM control |
---|
288 | IF( nictls+nictle+njctls+njctle == 0 ) THEN ! print control done over the default area |
---|
289 | lsp_area = .FALSE. |
---|
290 | ELSE ! print control done over a specific area |
---|
291 | lsp_area = .TRUE. |
---|
292 | IF( nictls < 1 .OR. nictls > jpiglo ) THEN |
---|
293 | CALL ctl_warn( ' - nictls must be 1<=nictls>=jpiglo, it is forced to 1' ) |
---|
294 | nictls = 1 |
---|
295 | ENDIF |
---|
296 | IF( nictle < 1 .OR. nictle > jpiglo ) THEN |
---|
297 | CALL ctl_warn( ' - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' ) |
---|
298 | nictle = jpiglo |
---|
299 | ENDIF |
---|
300 | IF( njctls < 1 .OR. njctls > jpjglo ) THEN |
---|
301 | CALL ctl_warn( ' - njctls must be 1<=njctls>=jpjglo, it is forced to 1' ) |
---|
302 | njctls = 1 |
---|
303 | ENDIF |
---|
304 | IF( njctle < 1 .OR. njctle > jpjglo ) THEN |
---|
305 | CALL ctl_warn( ' - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' ) |
---|
306 | njctle = jpjglo |
---|
307 | ENDIF |
---|
308 | ENDIF |
---|
309 | ENDIF |
---|
310 | ! |
---|
311 | IF( nbench == 1 ) THEN ! Benchmark |
---|
312 | SELECT CASE ( cp_cfg ) |
---|
313 | CASE ( 'gyre' ) ; CALL ctl_warn( ' The Benchmark is activated ' ) |
---|
314 | CASE DEFAULT ; CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:', & |
---|
315 | & ' key_gyre must be used or set nbench = 0' ) |
---|
316 | END SELECT |
---|
317 | ENDIF |
---|
318 | ! |
---|
319 | IF( lk_c1d .AND. .NOT.lk_iomput ) CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ', & |
---|
320 | & 'with the IOM Input/Output manager. ' , & |
---|
321 | & 'Compile with key_iomput enabled' ) |
---|
322 | ! |
---|
323 | IF( 1_wp /= SIGN(1._wp,-0._wp) ) CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ', & |
---|
324 | & 'f2003 standard. ' , & |
---|
325 | & 'Compile with key_nosignedzero enabled' ) |
---|
326 | ! |
---|
327 | END SUBROUTINE nemo_ctl |
---|
328 | |
---|
329 | |
---|
330 | SUBROUTINE nemo_closefile |
---|
331 | !!---------------------------------------------------------------------- |
---|
332 | !! *** ROUTINE nemo_closefile *** |
---|
333 | !! |
---|
334 | !! ** Purpose : Close the files |
---|
335 | !!---------------------------------------------------------------------- |
---|
336 | ! |
---|
337 | IF( lk_mpp ) CALL mppsync |
---|
338 | ! |
---|
339 | CALL iom_close ! close all input/output files managed by iom_* |
---|
340 | ! |
---|
341 | IF( numstp /= -1 ) CLOSE( numstp ) ! time-step file |
---|
342 | IF( numsol /= -1 ) CLOSE( numsol ) ! solver file |
---|
343 | IF( numnam /= -1 ) CLOSE( numnam ) ! oce namelist |
---|
344 | IF( numnam_ice /= -1 ) CLOSE( numnam_ice ) ! ice namelist |
---|
345 | IF( numevo_ice /= -1 ) CLOSE( numevo_ice ) ! ice variables (temp. evolution) |
---|
346 | IF( numout /= 6 ) CLOSE( numout ) ! standard model output file |
---|
347 | IF( numdct_vol /= -1 ) CLOSE( numdct_vol ) ! volume transports |
---|
348 | IF( numdct_heat /= -1 ) CLOSE( numdct_heat ) ! heat transports |
---|
349 | IF( numdct_salt /= -1 ) CLOSE( numdct_salt ) ! salt transports |
---|
350 | |
---|
351 | ! |
---|
352 | numout = 6 ! redefine numout in case it is used after this point... |
---|
353 | ! |
---|
354 | END SUBROUTINE nemo_closefile |
---|
355 | |
---|
356 | |
---|
357 | SUBROUTINE nemo_alloc |
---|
358 | !!---------------------------------------------------------------------- |
---|
359 | !! *** ROUTINE nemo_alloc *** |
---|
360 | !! |
---|
361 | !! ** Purpose : Allocate all the dynamic arrays of the OPA modules |
---|
362 | !! |
---|
363 | !! ** Method : |
---|
364 | !!---------------------------------------------------------------------- |
---|
365 | USE diawri , ONLY: dia_wri_alloc |
---|
366 | USE dom_oce , ONLY: dom_oce_alloc |
---|
367 | USE ldfdyn_oce, ONLY: ldfdyn_oce_alloc |
---|
368 | USE ldftra_oce, ONLY: ldftra_oce_alloc |
---|
369 | USE trc_oce , ONLY: trc_oce_alloc |
---|
370 | #if defined key_diadct |
---|
371 | USE diadct , ONLY: diadct_alloc |
---|
372 | #endif |
---|
373 | ! |
---|
374 | INTEGER :: ierr |
---|
375 | !!---------------------------------------------------------------------- |
---|
376 | ! |
---|
377 | ierr = oce_alloc () ! ocean |
---|
378 | ierr = ierr + dia_wri_alloc () |
---|
379 | ierr = ierr + dom_oce_alloc () ! ocean domain |
---|
380 | ierr = ierr + ldfdyn_oce_alloc() ! ocean lateral physics : dynamics |
---|
381 | ierr = ierr + ldftra_oce_alloc() ! ocean lateral physics : tracers |
---|
382 | ierr = ierr + zdf_oce_alloc () ! ocean vertical physics |
---|
383 | ! |
---|
384 | ierr = ierr + lib_mpp_alloc (numout) ! mpp exchanges |
---|
385 | ierr = ierr + trc_oce_alloc () ! shared TRC / TRA arrays |
---|
386 | ! |
---|
387 | #if defined key_diadct |
---|
388 | ierr = ierr + diadct_alloc () ! |
---|
389 | #endif |
---|
390 | ! |
---|
391 | IF( lk_mpp ) CALL mpp_sum( ierr ) |
---|
392 | IF( ierr /= 0 ) CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' ) |
---|
393 | ! |
---|
394 | END SUBROUTINE nemo_alloc |
---|
395 | |
---|
396 | |
---|
397 | SUBROUTINE nemo_partition( num_pes ) |
---|
398 | !!---------------------------------------------------------------------- |
---|
399 | !! *** ROUTINE nemo_partition *** |
---|
400 | !! |
---|
401 | !! ** Purpose : |
---|
402 | !! |
---|
403 | !! ** Method : |
---|
404 | !!---------------------------------------------------------------------- |
---|
405 | INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have |
---|
406 | ! |
---|
407 | INTEGER, PARAMETER :: nfactmax = 20 |
---|
408 | INTEGER :: nfact ! The no. of factors returned |
---|
409 | INTEGER :: ierr ! Error flag |
---|
410 | INTEGER :: ji |
---|
411 | INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value |
---|
412 | INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors |
---|
413 | !!---------------------------------------------------------------------- |
---|
414 | |
---|
415 | ierr = 0 |
---|
416 | |
---|
417 | CALL factorise( ifact, nfactmax, nfact, num_pes, ierr ) |
---|
418 | |
---|
419 | IF( nfact <= 1 ) THEN |
---|
420 | WRITE (numout, *) 'WARNING: factorisation of number of PEs failed' |
---|
421 | WRITE (numout, *) ' : using grid of ',num_pes,' x 1' |
---|
422 | jpnj = 1 |
---|
423 | jpni = num_pes |
---|
424 | ELSE |
---|
425 | ! Search through factors for the pair that are closest in value |
---|
426 | mindiff = 1000000 |
---|
427 | imin = 1 |
---|
428 | DO ji = 1, nfact-1, 2 |
---|
429 | idiff = ABS( ifact(ji) - ifact(ji+1) ) |
---|
430 | IF( idiff < mindiff ) THEN |
---|
431 | mindiff = idiff |
---|
432 | imin = ji |
---|
433 | ENDIF |
---|
434 | END DO |
---|
435 | jpnj = ifact(imin) |
---|
436 | jpni = ifact(imin + 1) |
---|
437 | ENDIF |
---|
438 | ! |
---|
439 | jpnij = jpni*jpnj |
---|
440 | ! |
---|
441 | END SUBROUTINE nemo_partition |
---|
442 | |
---|
443 | |
---|
444 | SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr ) |
---|
445 | !!---------------------------------------------------------------------- |
---|
446 | !! *** ROUTINE factorise *** |
---|
447 | !! |
---|
448 | !! ** Purpose : return the prime factors of n. |
---|
449 | !! knfax factors are returned in array kfax which is of |
---|
450 | !! maximum dimension kmaxfax. |
---|
451 | !! ** Method : |
---|
452 | !!---------------------------------------------------------------------- |
---|
453 | INTEGER , INTENT(in ) :: kn, kmaxfax |
---|
454 | INTEGER , INTENT( out) :: kerr, knfax |
---|
455 | INTEGER, DIMENSION(kmaxfax), INTENT( out) :: kfax |
---|
456 | ! |
---|
457 | INTEGER :: ifac, jl, inu |
---|
458 | INTEGER, PARAMETER :: ntest = 14 |
---|
459 | INTEGER :: ilfax(ntest) |
---|
460 | |
---|
461 | ! lfax contains the set of allowed factors. |
---|
462 | data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256, & |
---|
463 | & 128, 64, 32, 16, 8, 4, 2 / |
---|
464 | !!---------------------------------------------------------------------- |
---|
465 | |
---|
466 | ! Clear the error flag and initialise output vars |
---|
467 | kerr = 0 |
---|
468 | kfax = 1 |
---|
469 | knfax = 0 |
---|
470 | |
---|
471 | ! Find the factors of n. |
---|
472 | IF( kn == 1 ) GOTO 20 |
---|
473 | |
---|
474 | ! nu holds the unfactorised part of the number. |
---|
475 | ! knfax holds the number of factors found. |
---|
476 | ! l points to the allowed factor list. |
---|
477 | ! ifac holds the current factor. |
---|
478 | |
---|
479 | inu = kn |
---|
480 | knfax = 0 |
---|
481 | |
---|
482 | DO jl = ntest, 1, -1 |
---|
483 | ! |
---|
484 | ifac = ilfax(jl) |
---|
485 | IF( ifac > inu ) CYCLE |
---|
486 | |
---|
487 | ! Test whether the factor will divide. |
---|
488 | |
---|
489 | IF( MOD(inu,ifac) == 0 ) THEN |
---|
490 | ! |
---|
491 | knfax = knfax + 1 ! Add the factor to the list |
---|
492 | IF( knfax > kmaxfax ) THEN |
---|
493 | kerr = 6 |
---|
494 | write (*,*) 'FACTOR: insufficient space in factor array ', knfax |
---|
495 | return |
---|
496 | ENDIF |
---|
497 | kfax(knfax) = ifac |
---|
498 | ! Store the other factor that goes with this one |
---|
499 | knfax = knfax + 1 |
---|
500 | kfax(knfax) = inu / ifac |
---|
501 | !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax) |
---|
502 | ENDIF |
---|
503 | ! |
---|
504 | END DO |
---|
505 | |
---|
506 | 20 CONTINUE ! Label 20 is the exit point from the factor search loop. |
---|
507 | ! |
---|
508 | END SUBROUTINE factorise |
---|
509 | |
---|
510 | #if defined key_mpp_mpi |
---|
511 | SUBROUTINE nemo_northcomms |
---|
512 | !!====================================================================== |
---|
513 | !! *** ROUTINE nemo_northcomms *** |
---|
514 | !! nemo_northcomms : Setup for north fold exchanges with explicit peer to peer messaging |
---|
515 | !!===================================================================== |
---|
516 | !!---------------------------------------------------------------------- |
---|
517 | !! |
---|
518 | !! ** Purpose : Initialization of the northern neighbours lists. |
---|
519 | !!---------------------------------------------------------------------- |
---|
520 | !! 1.0 ! 2011-10 (A. C. Coward, NOCS & J. Donners, PRACE) |
---|
521 | !!---------------------------------------------------------------------- |
---|
522 | |
---|
523 | INTEGER :: ji, jj, jk, ij, jtyp ! dummy loop indices |
---|
524 | INTEGER :: ijpj ! number of rows involved in north-fold exchange |
---|
525 | INTEGER :: northcomms_alloc ! allocate return status |
---|
526 | REAL(wp), ALLOCATABLE, DIMENSION ( :,: ) :: znnbrs ! workspace |
---|
527 | LOGICAL, ALLOCATABLE, DIMENSION ( : ) :: lrankset ! workspace |
---|
528 | |
---|
529 | IF(lwp) WRITE(numout,*) |
---|
530 | IF(lwp) WRITE(numout,*) 'nemo_northcomms : Initialization of the northern neighbours lists' |
---|
531 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~' |
---|
532 | |
---|
533 | !!---------------------------------------------------------------------- |
---|
534 | ALLOCATE( znnbrs(jpi,jpj), stat = northcomms_alloc ) |
---|
535 | ALLOCATE( lrankset(jpnij), stat = northcomms_alloc ) |
---|
536 | IF( northcomms_alloc /= 0 ) THEN |
---|
537 | WRITE(numout,cform_war) |
---|
538 | WRITE(numout,*) 'northcomms_alloc : failed to allocate arrays' |
---|
539 | CALL ctl_stop( 'STOP', 'nemo_northcomms : unable to allocate temporary arrays' ) |
---|
540 | ENDIF |
---|
541 | nsndto = 0 |
---|
542 | isendto = -1 |
---|
543 | ijpj = 4 |
---|
544 | ! |
---|
545 | ! This routine has been called because ln_nnogather has been set true ( nammpp ) |
---|
546 | ! However, these first few exchanges have to use the mpi_allgather method to |
---|
547 | ! establish the neighbour lists to use in subsequent peer to peer exchanges. |
---|
548 | ! Consequently, set l_north_nogather to be false here and set it true only after |
---|
549 | ! the lists have been established. |
---|
550 | ! |
---|
551 | l_north_nogather = .FALSE. |
---|
552 | ! |
---|
553 | ! Exchange and store ranks on northern rows |
---|
554 | |
---|
555 | DO jtyp = 1,4 |
---|
556 | |
---|
557 | lrankset = .FALSE. |
---|
558 | znnbrs = narea |
---|
559 | SELECT CASE (jtyp) |
---|
560 | CASE(1) |
---|
561 | CALL lbc_lnk( znnbrs, 'T', 1. ) ! Type 1: T,W-points |
---|
562 | CASE(2) |
---|
563 | CALL lbc_lnk( znnbrs, 'U', 1. ) ! Type 2: U-point |
---|
564 | CASE(3) |
---|
565 | CALL lbc_lnk( znnbrs, 'V', 1. ) ! Type 3: V-point |
---|
566 | CASE(4) |
---|
567 | CALL lbc_lnk( znnbrs, 'F', 1. ) ! Type 4: F-point |
---|
568 | END SELECT |
---|
569 | |
---|
570 | IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN |
---|
571 | DO jj = nlcj-ijpj+1, nlcj |
---|
572 | ij = jj - nlcj + ijpj |
---|
573 | DO ji = 1,jpi |
---|
574 | IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) & |
---|
575 | & lrankset(INT(znnbrs(ji,jj))) = .true. |
---|
576 | END DO |
---|
577 | END DO |
---|
578 | |
---|
579 | DO jj = 1,jpnij |
---|
580 | IF ( lrankset(jj) ) THEN |
---|
581 | nsndto(jtyp) = nsndto(jtyp) + 1 |
---|
582 | IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN |
---|
583 | CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', & |
---|
584 | & ' jpmaxngh will need to be increased ') |
---|
585 | ENDIF |
---|
586 | isendto(nsndto(jtyp),jtyp) = jj-1 ! narea converted to MPI rank |
---|
587 | ENDIF |
---|
588 | END DO |
---|
589 | ENDIF |
---|
590 | |
---|
591 | END DO |
---|
592 | |
---|
593 | ! |
---|
594 | ! Type 5: I-point |
---|
595 | ! |
---|
596 | ! ICE point exchanges may involve some averaging. The neighbours list is |
---|
597 | ! built up using two exchanges to ensure that the whole stencil is covered. |
---|
598 | ! lrankset should not be reset between these 'J' and 'K' point exchanges |
---|
599 | |
---|
600 | jtyp = 5 |
---|
601 | lrankset = .FALSE. |
---|
602 | znnbrs = narea |
---|
603 | CALL lbc_lnk( znnbrs, 'J', 1. ) ! first ice U-V point |
---|
604 | |
---|
605 | IF ( njmppt(narea) .EQ. MAXVAL( njmppt ) ) THEN |
---|
606 | DO jj = nlcj-ijpj+1, nlcj |
---|
607 | ij = jj - nlcj + ijpj |
---|
608 | DO ji = 1,jpi |
---|
609 | IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) & |
---|
610 | & lrankset(INT(znnbrs(ji,jj))) = .true. |
---|
611 | END DO |
---|
612 | END DO |
---|
613 | ENDIF |
---|
614 | |
---|
615 | znnbrs = narea |
---|
616 | CALL lbc_lnk( znnbrs, 'K', 1. ) ! second ice U-V point |
---|
617 | |
---|
618 | IF ( njmppt(narea) .EQ. MAXVAL( njmppt )) THEN |
---|
619 | DO jj = nlcj-ijpj+1, nlcj |
---|
620 | ij = jj - nlcj + ijpj |
---|
621 | DO ji = 1,jpi |
---|
622 | IF ( INT(znnbrs(ji,jj)) .NE. 0 .AND. INT(znnbrs(ji,jj)) .NE. narea ) & |
---|
623 | & lrankset( INT(znnbrs(ji,jj))) = .true. |
---|
624 | END DO |
---|
625 | END DO |
---|
626 | |
---|
627 | DO jj = 1,jpnij |
---|
628 | IF ( lrankset(jj) ) THEN |
---|
629 | nsndto(jtyp) = nsndto(jtyp) + 1 |
---|
630 | IF ( nsndto(jtyp) .GT. jpmaxngh ) THEN |
---|
631 | CALL ctl_stop( ' Too many neighbours in nemo_northcomms ', & |
---|
632 | & ' jpmaxngh will need to be increased ') |
---|
633 | ENDIF |
---|
634 | isendto(nsndto(jtyp),jtyp) = jj-1 ! narea converted to MPI rank |
---|
635 | ENDIF |
---|
636 | END DO |
---|
637 | ! |
---|
638 | ! For northern row areas, set l_north_nogather so that all subsequent exchanges |
---|
639 | ! can use peer to peer communications at the north fold |
---|
640 | ! |
---|
641 | l_north_nogather = .TRUE. |
---|
642 | ! |
---|
643 | ENDIF |
---|
644 | DEALLOCATE( znnbrs ) |
---|
645 | DEALLOCATE( lrankset ) |
---|
646 | |
---|
647 | END SUBROUTINE nemo_northcomms |
---|
648 | #else |
---|
649 | SUBROUTINE nemo_northcomms ! Dummy routine |
---|
650 | WRITE(*,*) 'nemo_northcomms: You should not have seen this print! error?' |
---|
651 | END SUBROUTINE nemo_northcomms |
---|
652 | #endif |
---|
653 | !!====================================================================== |
---|
654 | END MODULE nemogcm |
---|