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-10 (A. C. Coward, NOCS & J. Donners, PRACE) add nemo_northcomms |
---|
31 | !! - ! 2011-11 (C. Harris) decomposition changes for running with CICE |
---|
32 | !! 3.6 ! 2012-05 (C. Calone, J. Simeon, G. Madec, C. Ethe) Add grid coarsening |
---|
33 | !! - ! 2013-06 (I. Epicoco, S. Mocavero, CMCC) nemo_northcomms: setup avoiding MPI communication |
---|
34 | !! - ! 2014-12 (G. Madec) remove KPP scheme and cross-land advection (cla) |
---|
35 | !!---------------------------------------------------------------------- |
---|
36 | |
---|
37 | !!---------------------------------------------------------------------- |
---|
38 | !! nemo_gcm : solve ocean dynamics, tracer, biogeochemistry and/or sea-ice |
---|
39 | !! nemo_init : initialization of the NEMO system |
---|
40 | !! nemo_ctl : initialisation of the contol print |
---|
41 | !! nemo_closefile: close remaining open files |
---|
42 | !! nemo_alloc : dynamical allocation |
---|
43 | !! nemo_partition: calculate MPP domain decomposition |
---|
44 | !! factorise : calculate the factors of the no. of MPI processes |
---|
45 | !!---------------------------------------------------------------------- |
---|
46 | USE dom_oce ! ocean space and time domain variables |
---|
47 | USE in_out_manager ! I/O manager |
---|
48 | USE iom ! |
---|
49 | USE domcfg ! domain configuration (dom_cfg routine) |
---|
50 | USE mppini ! shared/distributed memory setting (mpp_init routine) |
---|
51 | USE domain ! domain initialization (dom_init routine) |
---|
52 | USE phycst ! physical constant (par_cst routine) |
---|
53 | USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined) |
---|
54 | USE lib_mpp ! distributed memory computing |
---|
55 | |
---|
56 | USE lbcnfd , ONLY : isendto, nsndto, nfsloop, nfeloop ! Setup of north fold exchanges |
---|
57 | |
---|
58 | IMPLICIT NONE |
---|
59 | PRIVATE |
---|
60 | |
---|
61 | PUBLIC nemo_gcm ! called by model.F90 |
---|
62 | PUBLIC nemo_init ! needed by AGRIF |
---|
63 | PUBLIC nemo_alloc ! needed by TAM |
---|
64 | |
---|
65 | CHARACTER(lc) :: cform_aaa="( /, 'AAAAAAAA', / ) " ! flag for output listing |
---|
66 | |
---|
67 | #if defined key_agrif |
---|
68 | external agrif_boundary_connections, agrif_update_all, agrif_recompute_scalefactors |
---|
69 | #endif |
---|
70 | |
---|
71 | !!---------------------------------------------------------------------- |
---|
72 | !! NEMO/OPA 3.7 , NEMO Consortium (2015) |
---|
73 | !! $Id: nemogcm.F90 6152 2015-12-21 22:33:57Z acc $ |
---|
74 | !! Software governed by the CeCILL licence (./LICENSE) |
---|
75 | !!---------------------------------------------------------------------- |
---|
76 | CONTAINS |
---|
77 | |
---|
78 | SUBROUTINE nemo_gcm |
---|
79 | !!---------------------------------------------------------------------- |
---|
80 | !! *** ROUTINE nemo_gcm *** |
---|
81 | !! |
---|
82 | !! ** Purpose : NEMO solves the primitive equations on an orthogonal |
---|
83 | !! curvilinear mesh on the sphere. |
---|
84 | !! |
---|
85 | !! ** Method : - model general initialization |
---|
86 | !! - launch the time-stepping (stp routine) |
---|
87 | !! - finalize the run by closing files and communications |
---|
88 | !! |
---|
89 | !! References : Madec, Delecluse, Imbard, and Levy, 1997: internal report, IPSL. |
---|
90 | !! Madec, 2008, internal report, IPSL. |
---|
91 | !!---------------------------------------------------------------------- |
---|
92 | INTEGER :: istp ! time step index |
---|
93 | !!---------------------------------------------------------------------- |
---|
94 | ! |
---|
95 | #if defined key_agrif |
---|
96 | CALL Agrif_Init_Grids() ! AGRIF: set the meshes |
---|
97 | #endif |
---|
98 | ! !-----------------------! |
---|
99 | CALL nemo_init !== Initialisations ==! |
---|
100 | ! !-----------------------! |
---|
101 | |
---|
102 | #if defined key_agrif |
---|
103 | CALL Agrif_Regrid() |
---|
104 | |
---|
105 | CALL Agrif_Step_Child(agrif_boundary_connections) |
---|
106 | |
---|
107 | CALL Agrif_Step_Child_adj(agrif_update_all) |
---|
108 | |
---|
109 | CALL Agrif_Step_Child(agrif_recompute_scalefactors) |
---|
110 | |
---|
111 | CALL Agrif_Step_Child(cfg_write) |
---|
112 | #endif |
---|
113 | |
---|
114 | ! check that all process are still there... If some process have an error, |
---|
115 | ! they will never enter in step and other processes will wait until the end of the cpu time! |
---|
116 | IF( lk_mpp ) CALL mpp_max( 'nemogcm',nstop ) |
---|
117 | |
---|
118 | IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA |
---|
119 | |
---|
120 | ! !-----------------------! |
---|
121 | ! !== finalize the run ==! |
---|
122 | ! !------------------------! |
---|
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 | ! |
---|
130 | CALL nemo_closefile |
---|
131 | ! |
---|
132 | ! |
---|
133 | END SUBROUTINE nemo_gcm |
---|
134 | |
---|
135 | |
---|
136 | SUBROUTINE nemo_init |
---|
137 | !!---------------------------------------------------------------------- |
---|
138 | !! *** ROUTINE nemo_init *** |
---|
139 | !! |
---|
140 | !! ** Purpose : initialization of the NEMO GCM |
---|
141 | !!---------------------------------------------------------------------- |
---|
142 | INTEGER :: ji ! dummy loop indices |
---|
143 | INTEGER :: ios, ilocal_comm ! local integers |
---|
144 | CHARACTER(len=120), DIMENSION(60) :: cltxt, cltxt2, clnam |
---|
145 | !! |
---|
146 | NAMELIST/namctl/ ln_ctl , sn_cfctl, nn_print, nn_ictls, nn_ictle, & |
---|
147 | & nn_isplt , nn_jsplt, nn_jctls, nn_jctle, & |
---|
148 | & ln_timing, ln_diacfl |
---|
149 | NAMELIST/namcfg/ ln_e3_dep, & |
---|
150 | & cp_cfg, cp_cfz, jp_cfg, jpidta, jpjdta, jpkdta, jpiglo, jpjglo, & |
---|
151 | & jperio, ln_use_jattr, ln_domclo |
---|
152 | !!---------------------------------------------------------------------- |
---|
153 | ! |
---|
154 | cltxt = '' |
---|
155 | ! |
---|
156 | ! ! Open reference namelist and configuration namelist files |
---|
157 | CALL ctl_opn( numnam_ref, 'namelist_ref', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. ) |
---|
158 | CALL ctl_opn( numnam_cfg, 'namelist_cfg', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. ) |
---|
159 | ! |
---|
160 | REWIND( numnam_ref ) ! Namelist namctl in reference namelist |
---|
161 | READ ( numnam_ref, namctl, IOSTAT = ios, ERR = 901 ) |
---|
162 | 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namctl in reference namelist', .TRUE. ) |
---|
163 | REWIND( numnam_cfg ) ! Namelist namctl in confguration namelist |
---|
164 | READ ( numnam_cfg, namctl, IOSTAT = ios, ERR = 902 ) |
---|
165 | 902 IF( ios > 0 ) CALL ctl_nam ( ios , 'namctl in configuration namelist', .TRUE. ) |
---|
166 | ! |
---|
167 | REWIND( numnam_ref ) ! Namelist namcfg in reference namelist |
---|
168 | READ ( numnam_ref, namcfg, IOSTAT = ios, ERR = 903 ) |
---|
169 | 903 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namcfg in reference namelist', .TRUE. ) |
---|
170 | REWIND( numnam_cfg ) ! Namelist namcfg in confguration namelist |
---|
171 | READ ( numnam_cfg, namcfg, IOSTAT = ios, ERR = 904 ) |
---|
172 | 904 IF( ios > 0 ) CALL ctl_nam ( ios , 'namcfg in configuration namelist', .TRUE. ) |
---|
173 | |
---|
174 | ! Force values for AGRIF zoom (cf. agrif_user.F90) |
---|
175 | ! |
---|
176 | ! !--------------------------------------------! |
---|
177 | ! ! set communicator & select the local node ! |
---|
178 | ! ! NB: mynode also opens output.namelist.dyn ! |
---|
179 | ! ! on unit number numond on first proc ! |
---|
180 | ! !--------------------------------------------! |
---|
181 | ! Nodes selection (control print return in cltxt) |
---|
182 | narea = mynode( cltxt, 'output.namelist.dyn', numnam_ref, numnam_cfg, numond , nstop ) |
---|
183 | narea = narea + 1 ! mynode return the rank of proc (0 --> jpnij -1 ) |
---|
184 | |
---|
185 | lwm = (narea == 1) ! control of output namelists |
---|
186 | lwp = (narea == 1) .OR. ln_ctl ! control of all listing output print |
---|
187 | |
---|
188 | IF(lwm) THEN |
---|
189 | ! write merged namelists from earlier to output namelist now that the |
---|
190 | ! file has been opened in call to mynode. nammpp has already been |
---|
191 | ! written in mynode (if lk_mpp_mpi) |
---|
192 | WRITE( numond, namctl ) |
---|
193 | WRITE( numond, namcfg ) |
---|
194 | ENDIF |
---|
195 | |
---|
196 | IF(lwp) THEN ! open listing units |
---|
197 | ! |
---|
198 | CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea ) |
---|
199 | ! |
---|
200 | WRITE(numout,*) |
---|
201 | WRITE(numout,*) ' CNRS - NERC - Met OFFICE - MERCATOR-ocean - INGV - CMCC' |
---|
202 | WRITE(numout,*) ' NEMO team' |
---|
203 | WRITE(numout,*) ' Ocean General Circulation Model' |
---|
204 | WRITE(numout,*) ' NEMO version 4.0 (2019) ' |
---|
205 | WRITE(numout,*) |
---|
206 | WRITE(numout,*) " ._ ._ ._ ._ ._ " |
---|
207 | WRITE(numout,*) " _.-._)`\_.-._)`\_.-._)`\_.-._)`\_.-._)`\_ " |
---|
208 | WRITE(numout,*) |
---|
209 | WRITE(numout,*) " o _, _, " |
---|
210 | WRITE(numout,*) " o .' ( .-' / " |
---|
211 | WRITE(numout,*) " o _/..._'. .' / " |
---|
212 | WRITE(numout,*) " ( o .-'` ` '-./ _.' " |
---|
213 | WRITE(numout,*) " ) ( o) ;= <_ ( " |
---|
214 | WRITE(numout,*) " ( '-.,\\__ __.-;`\ '. ) " |
---|
215 | WRITE(numout,*) " ) ) \) |`\ \) '. \ ( ( " |
---|
216 | WRITE(numout,*) " ( ( \_/ '-._\ ) ) " |
---|
217 | WRITE(numout,*) " ) ) ` ( ( " |
---|
218 | WRITE(numout,*) " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ " |
---|
219 | WRITE(numout,*) |
---|
220 | |
---|
221 | DO ji = 1, SIZE(cltxt) |
---|
222 | IF( TRIM(cltxt (ji)) /= '' ) WRITE(numout,*) TRIM(cltxt(ji)) ! control print of mynode |
---|
223 | END DO |
---|
224 | WRITE(numout,*) |
---|
225 | WRITE(numout,*) |
---|
226 | ! DO ji = 1, SIZE(cltxt2) |
---|
227 | ! IF( TRIM(cltxt2(ji)) /= '' ) WRITE(numout,*) TRIM(cltxt2(ji)) ! control print of domain size |
---|
228 | ! END DO |
---|
229 | ! |
---|
230 | WRITE(numout,cform_aaa) ! Flag AAAAAAA |
---|
231 | ! |
---|
232 | ENDIF |
---|
233 | ! open /dev/null file to be able to supress output write easily |
---|
234 | ! CALL ctl_opn( numnul, '/dev/null', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. ) |
---|
235 | ! |
---|
236 | ! ! Domain decomposition |
---|
237 | CALL mpp_init ! MPP |
---|
238 | |
---|
239 | ! IF( Agrif_Root() ) THEN |
---|
240 | ! jpi = ( jpiglo -2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim. |
---|
241 | ! jpj = ( jpjglo -2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim. |
---|
242 | ! ENDIF |
---|
243 | jpk = jpkdta ! third dim |
---|
244 | jpim1 = jpi-1 ! inner domain indices |
---|
245 | jpjm1 = jpj-1 ! " " |
---|
246 | jpkm1 = jpk-1 ! " " |
---|
247 | jpij = jpi*jpj ! jpi x j |
---|
248 | |
---|
249 | #if defined key_agrif |
---|
250 | CALL Agrif_Declare_Var |
---|
251 | #endif |
---|
252 | |
---|
253 | ! Now we know the dimensions of the grid and numout has been set: we can allocate arrays |
---|
254 | CALL nemo_alloc() |
---|
255 | |
---|
256 | ! !-------------------------------! |
---|
257 | ! ! NEMO general initialization ! |
---|
258 | ! !-------------------------------! |
---|
259 | |
---|
260 | CALL nemo_ctl ! Control prints & Benchmark |
---|
261 | |
---|
262 | ! ! Domain decomposition |
---|
263 | ! |
---|
264 | ! ! General initialization |
---|
265 | CALL phy_cst ! Physical constants |
---|
266 | CALL dom_cfg ! Domain configuration |
---|
267 | CALL dom_init ! Domain |
---|
268 | ! |
---|
269 | END SUBROUTINE nemo_init |
---|
270 | |
---|
271 | |
---|
272 | SUBROUTINE nemo_ctl |
---|
273 | !!---------------------------------------------------------------------- |
---|
274 | !! *** ROUTINE nemo_ctl *** |
---|
275 | !! |
---|
276 | !! ** Purpose : control print setting |
---|
277 | !! |
---|
278 | !! ** Method : - print namctl information and check some consistencies |
---|
279 | !!---------------------------------------------------------------------- |
---|
280 | ! |
---|
281 | IF(lwp) THEN ! control print |
---|
282 | WRITE(numout,*) |
---|
283 | WRITE(numout,*) 'nemo_ctl: Control prints' |
---|
284 | WRITE(numout,*) '~~~~~~~~' |
---|
285 | WRITE(numout,*) ' Namelist namctl' |
---|
286 | WRITE(numout,*) ' run control (for debugging) ln_ctl = ', ln_ctl |
---|
287 | WRITE(numout,*) ' finer control over o/p sn_cfctl%l_config = ', sn_cfctl%l_config |
---|
288 | WRITE(numout,*) ' sn_cfctl%l_runstat = ', sn_cfctl%l_runstat |
---|
289 | WRITE(numout,*) ' sn_cfctl%l_trcstat = ', sn_cfctl%l_trcstat |
---|
290 | WRITE(numout,*) ' sn_cfctl%l_oceout = ', sn_cfctl%l_oceout |
---|
291 | WRITE(numout,*) ' sn_cfctl%l_layout = ', sn_cfctl%l_layout |
---|
292 | WRITE(numout,*) ' sn_cfctl%l_mppout = ', sn_cfctl%l_mppout |
---|
293 | WRITE(numout,*) ' sn_cfctl%l_mpptop = ', sn_cfctl%l_mpptop |
---|
294 | WRITE(numout,*) ' sn_cfctl%procmin = ', sn_cfctl%procmin |
---|
295 | WRITE(numout,*) ' sn_cfctl%procmax = ', sn_cfctl%procmax |
---|
296 | WRITE(numout,*) ' sn_cfctl%procincr = ', sn_cfctl%procincr |
---|
297 | WRITE(numout,*) ' sn_cfctl%ptimincr = ', sn_cfctl%ptimincr |
---|
298 | WRITE(numout,*) ' level of print nn_print = ', nn_print |
---|
299 | WRITE(numout,*) ' Start i indice for SUM control nn_ictls = ', nn_ictls |
---|
300 | WRITE(numout,*) ' End i indice for SUM control nn_ictle = ', nn_ictle |
---|
301 | WRITE(numout,*) ' Start j indice for SUM control nn_jctls = ', nn_jctls |
---|
302 | WRITE(numout,*) ' End j indice for SUM control nn_jctle = ', nn_jctle |
---|
303 | WRITE(numout,*) ' number of proc. following i nn_isplt = ', nn_isplt |
---|
304 | WRITE(numout,*) ' number of proc. following j nn_jsplt = ', nn_jsplt |
---|
305 | WRITE(numout,*) ' timing by routine ln_timing = ', ln_timing |
---|
306 | WRITE(numout,*) ' CFL diagnostics ln_diacfl = ', ln_diacfl |
---|
307 | ENDIF |
---|
308 | ! |
---|
309 | nprint = nn_print ! convert DOCTOR namelist names into OLD names |
---|
310 | nictls = nn_ictls |
---|
311 | nictle = nn_ictle |
---|
312 | njctls = nn_jctls |
---|
313 | njctle = nn_jctle |
---|
314 | isplt = nn_isplt |
---|
315 | jsplt = nn_jsplt |
---|
316 | |
---|
317 | ! |
---|
318 | ! ! Parameter control |
---|
319 | ! |
---|
320 | IF( ln_ctl ) THEN ! sub-domain area indices for the control prints |
---|
321 | IF( lk_mpp .AND. jpnij > 1 ) THEN |
---|
322 | isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj ! the domain is forced to the real split domain |
---|
323 | ELSE |
---|
324 | IF( isplt == 1 .AND. jsplt == 1 ) THEN |
---|
325 | CALL ctl_warn( ' - isplt & jsplt are equal to 1', & |
---|
326 | & ' - the print control will be done over the whole domain' ) |
---|
327 | ENDIF |
---|
328 | ijsplt = isplt * jsplt ! total number of processors ijsplt |
---|
329 | ENDIF |
---|
330 | IF(lwp) WRITE(numout,*)' - The total number of processors over which the' |
---|
331 | IF(lwp) WRITE(numout,*)' print control will be done is ijsplt : ', ijsplt |
---|
332 | ! |
---|
333 | ! ! indices used for the SUM control |
---|
334 | IF( nictls+nictle+njctls+njctle == 0 ) THEN ! print control done over the default area |
---|
335 | lsp_area = .FALSE. |
---|
336 | ELSE ! print control done over a specific area |
---|
337 | lsp_area = .TRUE. |
---|
338 | IF( nictls < 1 .OR. nictls > jpiglo ) THEN |
---|
339 | CALL ctl_warn( ' - nictls must be 1<=nictls>=jpiglo, it is forced to 1' ) |
---|
340 | nictls = 1 |
---|
341 | ENDIF |
---|
342 | IF( nictle < 1 .OR. nictle > jpiglo ) THEN |
---|
343 | CALL ctl_warn( ' - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' ) |
---|
344 | nictle = jpiglo |
---|
345 | ENDIF |
---|
346 | IF( njctls < 1 .OR. njctls > jpjglo ) THEN |
---|
347 | CALL ctl_warn( ' - njctls must be 1<=njctls>=jpjglo, it is forced to 1' ) |
---|
348 | njctls = 1 |
---|
349 | ENDIF |
---|
350 | IF( njctle < 1 .OR. njctle > jpjglo ) THEN |
---|
351 | CALL ctl_warn( ' - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' ) |
---|
352 | njctle = jpjglo |
---|
353 | ENDIF |
---|
354 | ENDIF |
---|
355 | ENDIF |
---|
356 | ! |
---|
357 | ! IF( 1._wp /= SIGN(1._wp,-0._wp) ) CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows f2003 standard.', & |
---|
358 | ! & 'Compile with key_nosignedzero enabled:', & |
---|
359 | ! & '--> add -Dkey_nosignedzero to the definition of %CPP in your arch file' ) |
---|
360 | ! |
---|
361 | #if defined key_agrif |
---|
362 | IF( ln_timing ) CALL ctl_stop( 'AGRIF not implemented with ln_timing = true') |
---|
363 | #endif |
---|
364 | ! |
---|
365 | END SUBROUTINE nemo_ctl |
---|
366 | |
---|
367 | |
---|
368 | SUBROUTINE nemo_closefile |
---|
369 | !!---------------------------------------------------------------------- |
---|
370 | !! *** ROUTINE nemo_closefile *** |
---|
371 | !! |
---|
372 | !! ** Purpose : Close the files |
---|
373 | !!---------------------------------------------------------------------- |
---|
374 | ! |
---|
375 | IF( lk_mpp ) CALL mppsync |
---|
376 | ! |
---|
377 | CALL iom_close ! close all input/output files managed by iom_* |
---|
378 | ! |
---|
379 | IF( numstp /= -1 ) CLOSE( numstp ) ! time-step file |
---|
380 | IF( numnam_ref /= -1 ) CLOSE( numnam_ref ) ! oce reference namelist |
---|
381 | IF( numnam_cfg /= -1 ) CLOSE( numnam_cfg ) ! oce configuration namelist |
---|
382 | IF( lwm.AND.numond /= -1 ) CLOSE( numond ) ! oce output namelist |
---|
383 | IF( numnam_ice_ref /= -1 ) CLOSE( numnam_ice_ref ) ! ice reference namelist |
---|
384 | IF( numnam_ice_cfg /= -1 ) CLOSE( numnam_ice_cfg ) ! ice configuration namelist |
---|
385 | IF( lwm.AND.numoni /= -1 ) CLOSE( numoni ) ! ice output namelist |
---|
386 | IF( numevo_ice /= -1 ) CLOSE( numevo_ice ) ! ice variables (temp. evolution) |
---|
387 | IF( numout /= 6 ) CLOSE( numout ) ! standard model output file |
---|
388 | IF( numdct_vol /= -1 ) CLOSE( numdct_vol ) ! volume transports |
---|
389 | IF( numdct_heat /= -1 ) CLOSE( numdct_heat ) ! heat transports |
---|
390 | IF( numdct_salt /= -1 ) CLOSE( numdct_salt ) ! salt transports |
---|
391 | ! |
---|
392 | numout = 6 ! redefine numout in case it is used after this point... |
---|
393 | ! |
---|
394 | END SUBROUTINE nemo_closefile |
---|
395 | |
---|
396 | |
---|
397 | SUBROUTINE nemo_alloc |
---|
398 | !!---------------------------------------------------------------------- |
---|
399 | !! *** ROUTINE nemo_alloc *** |
---|
400 | !! |
---|
401 | !! ** Purpose : Allocate all the dynamic arrays of the OPA modules |
---|
402 | !! |
---|
403 | !! ** Method : |
---|
404 | !!---------------------------------------------------------------------- |
---|
405 | USE dom_oce , ONLY: dom_oce_alloc |
---|
406 | ! |
---|
407 | INTEGER :: ierr |
---|
408 | !!---------------------------------------------------------------------- |
---|
409 | ! |
---|
410 | ierr = 0 |
---|
411 | ierr = ierr + dom_oce_alloc () ! ocean domain |
---|
412 | ! |
---|
413 | CALL mpp_sum( 'nemogcm', ierr ) |
---|
414 | IF( ierr /= 0 ) CALL ctl_stop( 'STOP', 'nemo_alloc : unable to allocate standard ocean arrays' ) |
---|
415 | ! |
---|
416 | END SUBROUTINE nemo_alloc |
---|
417 | |
---|
418 | |
---|
419 | SUBROUTINE nemo_partition( num_pes ) |
---|
420 | !!---------------------------------------------------------------------- |
---|
421 | !! *** ROUTINE nemo_partition *** |
---|
422 | !! |
---|
423 | !! ** Purpose : |
---|
424 | !! |
---|
425 | !! ** Method : |
---|
426 | !!---------------------------------------------------------------------- |
---|
427 | INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have |
---|
428 | ! |
---|
429 | INTEGER, PARAMETER :: nfactmax = 20 |
---|
430 | INTEGER :: nfact ! The no. of factors returned |
---|
431 | INTEGER :: ierr ! Error flag |
---|
432 | INTEGER :: ji |
---|
433 | INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value |
---|
434 | INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors |
---|
435 | !!---------------------------------------------------------------------- |
---|
436 | ! |
---|
437 | ierr = 0 |
---|
438 | ! |
---|
439 | CALL factorise( ifact, nfactmax, nfact, num_pes, ierr ) |
---|
440 | ! |
---|
441 | IF( nfact <= 1 ) THEN |
---|
442 | WRITE (numout, *) 'WARNING: factorisation of number of PEs failed' |
---|
443 | WRITE (numout, *) ' : using grid of ',num_pes,' x 1' |
---|
444 | jpnj = 1 |
---|
445 | jpni = num_pes |
---|
446 | ELSE |
---|
447 | ! Search through factors for the pair that are closest in value |
---|
448 | mindiff = 1000000 |
---|
449 | imin = 1 |
---|
450 | DO ji = 1, nfact-1, 2 |
---|
451 | idiff = ABS( ifact(ji) - ifact(ji+1) ) |
---|
452 | IF( idiff < mindiff ) THEN |
---|
453 | mindiff = idiff |
---|
454 | imin = ji |
---|
455 | ENDIF |
---|
456 | END DO |
---|
457 | jpnj = ifact(imin) |
---|
458 | jpni = ifact(imin + 1) |
---|
459 | ENDIF |
---|
460 | ! |
---|
461 | jpnij = jpni*jpnj |
---|
462 | ! |
---|
463 | END SUBROUTINE nemo_partition |
---|
464 | |
---|
465 | |
---|
466 | SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr ) |
---|
467 | !!---------------------------------------------------------------------- |
---|
468 | !! *** ROUTINE factorise *** |
---|
469 | !! |
---|
470 | !! ** Purpose : return the prime factors of n. |
---|
471 | !! knfax factors are returned in array kfax which is of |
---|
472 | !! maximum dimension kmaxfax. |
---|
473 | !! ** Method : |
---|
474 | !!---------------------------------------------------------------------- |
---|
475 | INTEGER , INTENT(in ) :: kn, kmaxfax |
---|
476 | INTEGER , INTENT( out) :: kerr, knfax |
---|
477 | INTEGER, DIMENSION(kmaxfax), INTENT( out) :: kfax |
---|
478 | ! |
---|
479 | INTEGER :: ifac, jl, inu |
---|
480 | INTEGER, PARAMETER :: ntest = 14 |
---|
481 | INTEGER, DIMENSION(ntest) :: ilfax |
---|
482 | !!---------------------------------------------------------------------- |
---|
483 | ! |
---|
484 | ! lfax contains the set of allowed factors. |
---|
485 | ilfax(:) = (/(2**jl,jl=ntest,1,-1)/) |
---|
486 | ! |
---|
487 | ! Clear the error flag and initialise output vars |
---|
488 | kerr = 0 |
---|
489 | kfax = 1 |
---|
490 | knfax = 0 |
---|
491 | ! |
---|
492 | ! Find the factors of n. |
---|
493 | IF( kn == 1 ) GOTO 20 |
---|
494 | |
---|
495 | ! nu holds the unfactorised part of the number. |
---|
496 | ! knfax holds the number of factors found. |
---|
497 | ! l points to the allowed factor list. |
---|
498 | ! ifac holds the current factor. |
---|
499 | ! |
---|
500 | inu = kn |
---|
501 | knfax = 0 |
---|
502 | ! |
---|
503 | DO jl = ntest, 1, -1 |
---|
504 | ! |
---|
505 | ifac = ilfax(jl) |
---|
506 | IF( ifac > inu ) CYCLE |
---|
507 | |
---|
508 | ! Test whether the factor will divide. |
---|
509 | |
---|
510 | IF( MOD(inu,ifac) == 0 ) THEN |
---|
511 | ! |
---|
512 | knfax = knfax + 1 ! Add the factor to the list |
---|
513 | IF( knfax > kmaxfax ) THEN |
---|
514 | kerr = 6 |
---|
515 | write (*,*) 'FACTOR: insufficient space in factor array ', knfax |
---|
516 | return |
---|
517 | ENDIF |
---|
518 | kfax(knfax) = ifac |
---|
519 | ! Store the other factor that goes with this one |
---|
520 | knfax = knfax + 1 |
---|
521 | kfax(knfax) = inu / ifac |
---|
522 | !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax) |
---|
523 | ENDIF |
---|
524 | ! |
---|
525 | END DO |
---|
526 | ! |
---|
527 | 20 CONTINUE ! Label 20 is the exit point from the factor search loop. |
---|
528 | ! |
---|
529 | END SUBROUTINE factorise |
---|
530 | |
---|
531 | |
---|
532 | SUBROUTINE nemo_northcomms |
---|
533 | !!---------------------------------------------------------------------- |
---|
534 | !! *** ROUTINE nemo_northcomms *** |
---|
535 | !! ** Purpose : Setup for north fold exchanges with explicit |
---|
536 | !! point-to-point messaging |
---|
537 | !! |
---|
538 | !! ** Method : Initialization of the northern neighbours lists. |
---|
539 | !!---------------------------------------------------------------------- |
---|
540 | !! 1.0 ! 2011-10 (A. C. Coward, NOCS & J. Donners, PRACE) |
---|
541 | !! 2.0 ! 2013-06 Setup avoiding MPI communication (I. Epicoco, S. Mocavero, CMCC) |
---|
542 | !!---------------------------------------------------------------------- |
---|
543 | INTEGER :: sxM, dxM, sxT, dxT, jn |
---|
544 | INTEGER :: njmppmax |
---|
545 | !!---------------------------------------------------------------------- |
---|
546 | ! |
---|
547 | njmppmax = MAXVAL( njmppt ) |
---|
548 | ! |
---|
549 | !initializes the north-fold communication variables |
---|
550 | isendto(:) = 0 |
---|
551 | nsndto = 0 |
---|
552 | ! |
---|
553 | !if I am a process in the north |
---|
554 | IF ( njmpp == njmppmax ) THEN |
---|
555 | !sxM is the first point (in the global domain) needed to compute the |
---|
556 | !north-fold for the current process |
---|
557 | sxM = jpiglo - nimppt(narea) - nlcit(narea) + 1 |
---|
558 | !dxM is the last point (in the global domain) needed to compute the |
---|
559 | !north-fold for the current process |
---|
560 | dxM = jpiglo - nimppt(narea) + 2 |
---|
561 | |
---|
562 | !loop over the other north-fold processes to find the processes |
---|
563 | !managing the points belonging to the sxT-dxT range |
---|
564 | |
---|
565 | DO jn = 1, jpni |
---|
566 | !sxT is the first point (in the global domain) of the jn |
---|
567 | !process |
---|
568 | sxT = nfiimpp(jn, jpnj) |
---|
569 | !dxT is the last point (in the global domain) of the jn |
---|
570 | !process |
---|
571 | dxT = nfiimpp(jn, jpnj) + nfilcit(jn, jpnj) - 1 |
---|
572 | IF ((sxM .gt. sxT) .AND. (sxM .lt. dxT)) THEN |
---|
573 | nsndto = nsndto + 1 |
---|
574 | isendto(nsndto) = jn |
---|
575 | ELSEIF ((sxM .le. sxT) .AND. (dxM .ge. dxT)) THEN |
---|
576 | nsndto = nsndto + 1 |
---|
577 | isendto(nsndto) = jn |
---|
578 | ELSEIF ((dxM .lt. dxT) .AND. (sxT .lt. dxM)) THEN |
---|
579 | nsndto = nsndto + 1 |
---|
580 | isendto(nsndto) = jn |
---|
581 | END IF |
---|
582 | END DO |
---|
583 | nfsloop = 1 |
---|
584 | nfeloop = nlci |
---|
585 | DO jn = 2,jpni-1 |
---|
586 | IF(nfipproc(jn,jpnj) .eq. (narea - 1)) THEN |
---|
587 | IF (nfipproc(jn - 1 ,jpnj) .eq. -1) THEN |
---|
588 | nfsloop = nldi |
---|
589 | ENDIF |
---|
590 | IF (nfipproc(jn + 1,jpnj) .eq. -1) THEN |
---|
591 | nfeloop = nlei |
---|
592 | ENDIF |
---|
593 | ENDIF |
---|
594 | END DO |
---|
595 | |
---|
596 | ENDIF |
---|
597 | #if defined key_mpp_mpi |
---|
598 | l_north_nogather = .TRUE. |
---|
599 | #endif |
---|
600 | END SUBROUTINE nemo_northcomms |
---|
601 | |
---|
602 | |
---|
603 | !!====================================================================== |
---|
604 | END MODULE nemogcm |
---|
605 | |
---|