[2574] | 1 | MODULE nemogcm |
---|
| 2 | !!====================================================================== |
---|
| 3 | !! *** MODULE nemogcm *** |
---|
| 4 | !! Off-line Ocean : passive tracer evolution, dynamics read in files |
---|
| 5 | !!====================================================================== |
---|
| 6 | !! History : 3.3 ! 2010-05 (C. Ethe) Full reorganization of the off-line: phasing with the on-line |
---|
[2715] | 7 | !! 4.0 ! 2011-01 (C. Ethe, A. R. Porter, STFC Daresbury) dynamical allocation |
---|
[2574] | 8 | !!---------------------------------------------------------------------- |
---|
| 9 | |
---|
| 10 | !!---------------------------------------------------------------------- |
---|
| 11 | !! nemo_gcm : off-line: solve ocean tracer only |
---|
| 12 | !! nemo_init : initialization of the nemo model |
---|
| 13 | !! nemo_ctl : initialisation of algorithm flag |
---|
| 14 | !! nemo_closefile : close remaining files |
---|
| 15 | !!---------------------------------------------------------------------- |
---|
| 16 | USE dom_oce ! ocean space domain variables |
---|
| 17 | USE oce ! dynamics and tracers variables |
---|
| 18 | USE c1d ! 1D configuration |
---|
| 19 | USE domcfg ! domain configuration (dom_cfg routine) |
---|
| 20 | USE domain ! domain initialization (dom_init routine) |
---|
| 21 | USE istate ! initial state setting (istate_init routine) |
---|
| 22 | USE eosbn2 ! equation of state (eos bn2 routine) |
---|
| 23 | ! ! ocean physics |
---|
| 24 | USE ldftra ! lateral diffusivity setting (ldf_tra_init routine) |
---|
| 25 | USE ldfslp ! slopes of neutral surfaces (ldf_slp_init routine) |
---|
| 26 | USE traqsr ! solar radiation penetration (tra_qsr_init routine) |
---|
| 27 | USE trabbl ! bottom boundary layer (tra_bbl_init routine) |
---|
| 28 | USE zdfini ! vertical physics: initialization |
---|
[2715] | 29 | USE sbcmod ! surface boundary condition (sbc_init routine) |
---|
[2574] | 30 | USE phycst ! physical constant (par_cst routine) |
---|
| 31 | USE dtadyn ! Lecture and Interpolation of the dynamical fields |
---|
| 32 | USE trcini ! Initilization of the passive tracers |
---|
| 33 | USE daymod ! calendar (day routine) |
---|
| 34 | USE trcstp ! passive tracer time-stepping (trc_stp routine) |
---|
| 35 | USE dtadyn ! Lecture and interpolation of the dynamical fields |
---|
| 36 | USE stpctl ! time stepping control (stp_ctl routine) |
---|
| 37 | ! ! I/O & MPP |
---|
| 38 | USE iom ! I/O library |
---|
| 39 | USE in_out_manager ! I/O manager |
---|
| 40 | USE mppini ! shared/distributed memory setting (mpp_init routine) |
---|
| 41 | USE lib_mpp ! distributed memory computing |
---|
| 42 | #if defined key_iomput |
---|
[2715] | 43 | USE mod_ioclient |
---|
[2574] | 44 | #endif |
---|
[3294] | 45 | USE prtctl ! Print control (prt_ctl_init routine) |
---|
| 46 | USE timing ! Timing |
---|
[3558] | 47 | USE lib_fortran ! Fortran utilities (allows no signed zero when 'key_nosignedzero' defined) |
---|
[2574] | 48 | |
---|
| 49 | IMPLICIT NONE |
---|
| 50 | PRIVATE |
---|
| 51 | |
---|
| 52 | PUBLIC nemo_gcm ! called by nemo.F90 |
---|
| 53 | |
---|
| 54 | CHARACTER (len=64) :: cform_aaa="( /, 'AAAAAAAA', / ) " ! flag for output listing |
---|
| 55 | |
---|
| 56 | !!---------------------------------------------------------------------- |
---|
| 57 | !! NEMO/OFF 3.3 , NEMO Consortium (2010) |
---|
| 58 | !! $Id: nemogcm.F90 2528 2010-12-27 17:33:53Z rblod $ |
---|
| 59 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
| 60 | !!---------------------------------------------------------------------- |
---|
| 61 | CONTAINS |
---|
| 62 | |
---|
| 63 | SUBROUTINE nemo_gcm |
---|
| 64 | !!---------------------------------------------------------------------- |
---|
| 65 | !! *** ROUTINE nemo_gcm *** |
---|
| 66 | !! |
---|
| 67 | !! ** Purpose : nemo solves the primitive equations on an orthogonal |
---|
| 68 | !! curvilinear mesh on the sphere. |
---|
| 69 | !! |
---|
| 70 | !! ** Method : - model general initialization |
---|
| 71 | !! - launch the time-stepping (dta_dyn and trc_stp) |
---|
| 72 | !! - finalize the run by closing files and communications |
---|
| 73 | !! |
---|
| 74 | !! References : Madec, Delecluse,Imbard, and Levy, 1997: internal report, IPSL. |
---|
| 75 | !! Madec, 2008, internal report, IPSL. |
---|
| 76 | !!---------------------------------------------------------------------- |
---|
| 77 | INTEGER :: istp, indic ! time step index |
---|
| 78 | !!---------------------------------------------------------------------- |
---|
| 79 | |
---|
| 80 | CALL nemo_init ! Initializations |
---|
| 81 | |
---|
| 82 | IF( lk_mpp ) CALL mpp_max( nstop ) |
---|
| 83 | |
---|
| 84 | ! check that all process are still there... If some process have an error, |
---|
| 85 | ! they will never enter in step and other processes will wait until the end of the cpu time! |
---|
| 86 | IF( lk_mpp ) CALL mpp_max( nstop ) |
---|
| 87 | |
---|
| 88 | ! !-----------------------! |
---|
| 89 | ! !== time stepping ==! |
---|
| 90 | ! !-----------------------! |
---|
| 91 | istp = nit000 |
---|
| 92 | ! |
---|
| 93 | DO WHILE ( istp <= nitend .AND. nstop == 0 ) ! time stepping |
---|
| 94 | ! |
---|
| 95 | IF( istp /= nit000 ) CALL day ( istp ) ! Calendar (day was already called at nit000 in day_init) |
---|
| 96 | CALL iom_setkt( istp ) ! say to iom that we are at time step kstp |
---|
| 97 | CALL dta_dyn ( istp ) ! Interpolation of the dynamical fields |
---|
| 98 | CALL trc_stp ( istp ) ! time-stepping |
---|
| 99 | CALL stp_ctl ( istp, indic ) ! Time loop: control and print |
---|
| 100 | istp = istp + 1 |
---|
| 101 | IF( lk_mpp ) CALL mpp_max( nstop ) |
---|
| 102 | END DO |
---|
| 103 | |
---|
| 104 | ! !------------------------! |
---|
| 105 | ! !== finalize the run ==! |
---|
| 106 | ! !------------------------! |
---|
| 107 | IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA |
---|
| 108 | |
---|
| 109 | IF( nstop /= 0 .AND. lwp ) THEN ! error print |
---|
| 110 | WRITE(numout,cform_err) |
---|
| 111 | WRITE(numout,*) nstop, ' error have been found' |
---|
| 112 | ENDIF |
---|
| 113 | ! |
---|
[3294] | 114 | IF( nn_timing == 1 ) CALL timing_finalize |
---|
| 115 | ! |
---|
[2574] | 116 | CALL nemo_closefile |
---|
| 117 | ! |
---|
| 118 | IF( lk_mpp ) CALL mppstop ! Close all files (mpp) |
---|
| 119 | ! |
---|
| 120 | END SUBROUTINE nemo_gcm |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | SUBROUTINE nemo_init |
---|
| 124 | !!---------------------------------------------------------------------- |
---|
| 125 | !! *** ROUTINE nemo_init *** |
---|
| 126 | !! |
---|
| 127 | !! ** Purpose : initialization of the nemo model in off-line mode |
---|
| 128 | !!---------------------------------------------------------------------- |
---|
| 129 | INTEGER :: ji ! dummy loop indices |
---|
| 130 | INTEGER :: ilocal_comm ! local integer |
---|
[2715] | 131 | CHARACTER(len=80), DIMENSION(16) :: cltxt = '' |
---|
[2574] | 132 | !! |
---|
| 133 | NAMELIST/namctl/ ln_ctl , nn_print, nn_ictls, nn_ictle, & |
---|
[3294] | 134 | & nn_isplt, nn_jsplt, nn_jctls, nn_jctle, & |
---|
| 135 | & nn_bench, nn_timing |
---|
[2574] | 136 | !!---------------------------------------------------------------------- |
---|
| 137 | ! |
---|
| 138 | ! ! open Namelist file |
---|
| 139 | CALL ctl_opn( numnam, 'namelist', 'OLD', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE. ) |
---|
| 140 | ! |
---|
| 141 | READ( numnam, namctl ) ! Namelist namctl : Control prints & Benchmark |
---|
| 142 | ! |
---|
| 143 | ! !--------------------------------------------! |
---|
| 144 | ! ! set communicator & select the local node ! |
---|
| 145 | ! !--------------------------------------------! |
---|
| 146 | #if defined key_iomput |
---|
[2715] | 147 | CALL init_ioclient( ilocal_comm ) ! exchange io_server nemo local communicator with the io_server |
---|
| 148 | narea = mynode( cltxt, numnam, nstop, ilocal_comm ) ! Nodes selection |
---|
[2574] | 149 | #else |
---|
[2715] | 150 | ilocal_comm = 0 |
---|
| 151 | narea = mynode( cltxt, numnam, nstop ) ! Nodes selection (control print return in cltxt) |
---|
[2574] | 152 | #endif |
---|
[2715] | 153 | |
---|
[2574] | 154 | narea = narea + 1 ! mynode return the rank of proc (0 --> jpnij -1 ) |
---|
| 155 | |
---|
| 156 | lwp = (narea == 1) .OR. ln_ctl ! control of all listing output print |
---|
| 157 | |
---|
[2715] | 158 | ! If dimensions of processor grid weren't specified in the namelist file |
---|
| 159 | ! then we calculate them here now that we have our communicator size |
---|
| 160 | IF( (jpni < 1) .OR. (jpnj < 1) )THEN |
---|
| 161 | #if defined key_mpp_mpi || defined key_mpp_shmem |
---|
| 162 | CALL nemo_partition(mppsize) |
---|
| 163 | #else |
---|
| 164 | jpni = 1 |
---|
| 165 | jpnj = 1 |
---|
| 166 | jpnij = jpni*jpnj |
---|
| 167 | #endif |
---|
| 168 | END IF |
---|
| 169 | |
---|
| 170 | ! Calculate domain dimensions given calculated jpni and jpnj |
---|
| 171 | ! This used to be done in par_oce.F90 when they were parameters rather |
---|
| 172 | ! than variables |
---|
| 173 | jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ! first dim. |
---|
| 174 | jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ! second dim. |
---|
| 175 | jpk = jpkdta ! third dim |
---|
| 176 | jpim1 = jpi-1 ! inner domain indices |
---|
| 177 | jpjm1 = jpj-1 ! " " |
---|
| 178 | jpkm1 = jpk-1 ! " " |
---|
| 179 | jpij = jpi*jpj ! jpi x j |
---|
| 180 | |
---|
| 181 | |
---|
[2574] | 182 | IF(lwp) THEN ! open listing units |
---|
| 183 | ! |
---|
| 184 | CALL ctl_opn( numout, 'ocean.output', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, 6, .FALSE., narea ) |
---|
| 185 | ! |
---|
| 186 | WRITE(numout,*) |
---|
| 187 | WRITE(numout,*) ' CNRS - NERC - Met OFFICE - MERCATOR-ocean' |
---|
| 188 | WRITE(numout,*) ' NEMO team' |
---|
| 189 | WRITE(numout,*) ' Ocean General Circulation Model' |
---|
| 190 | WRITE(numout,*) ' version 3.3 (2010) ' |
---|
| 191 | WRITE(numout,*) |
---|
| 192 | WRITE(numout,*) |
---|
| 193 | DO ji = 1, SIZE(cltxt) |
---|
| 194 | IF( TRIM(cltxt(ji)) /= '' ) WRITE(numout,*) cltxt(ji) ! control print of mynode |
---|
| 195 | END DO |
---|
| 196 | WRITE(numout,cform_aaa) ! Flag AAAAAAA |
---|
| 197 | ! |
---|
| 198 | ENDIF |
---|
[2715] | 199 | |
---|
| 200 | ! Now we know the dimensions of the grid and numout has been set we can |
---|
| 201 | ! allocate arrays |
---|
| 202 | CALL nemo_alloc() |
---|
| 203 | |
---|
[2574] | 204 | ! !--------------------------------! |
---|
| 205 | ! ! Model general initialization ! |
---|
| 206 | ! !--------------------------------! |
---|
| 207 | |
---|
| 208 | CALL nemo_ctl ! Control prints & Benchmark |
---|
| 209 | |
---|
| 210 | ! ! Domain decomposition |
---|
| 211 | IF( jpni*jpnj == jpnij ) THEN ; CALL mpp_init ! standard cutting out |
---|
| 212 | ELSE ; CALL mpp_init2 ! eliminate land processors |
---|
| 213 | ENDIF |
---|
| 214 | ! |
---|
[3294] | 215 | IF( nn_timing == 1 ) CALL timing_init |
---|
| 216 | ! |
---|
| 217 | |
---|
[2574] | 218 | ! ! General initialization |
---|
[3294] | 219 | IF( nn_timing == 1 ) CALL timing_start( 'nemo_init') |
---|
| 220 | ! |
---|
[2574] | 221 | CALL phy_cst ! Physical constants |
---|
| 222 | CALL eos_init ! Equation of state |
---|
| 223 | CALL dom_cfg ! Domain configuration |
---|
| 224 | CALL dom_init ! Domain |
---|
| 225 | CALL istate_init ! ocean initial state (Dynamics and tracers) |
---|
| 226 | |
---|
[3294] | 227 | IF( ln_nnogather ) CALL nemo_northcomms ! Initialise the northfold neighbour lists (must be done after the masks are defined) |
---|
[2715] | 228 | |
---|
| 229 | IF( ln_ctl ) CALL prt_ctl_init ! Print control |
---|
| 230 | |
---|
[2574] | 231 | ! ! Ocean physics |
---|
[2715] | 232 | CALL sbc_init ! Forcings : surface module |
---|
[2574] | 233 | #if ! defined key_degrad |
---|
| 234 | CALL ldf_tra_init ! Lateral ocean tracer physics |
---|
| 235 | #endif |
---|
| 236 | IF( lk_ldfslp ) CALL ldf_slp_init ! slope of lateral mixing |
---|
| 237 | |
---|
| 238 | ! ! Active tracers |
---|
| 239 | CALL tra_qsr_init ! penetrative solar radiation qsr |
---|
| 240 | IF( lk_trabbl ) CALL tra_bbl_init ! advective (and/or diffusive) bottom boundary layer scheme |
---|
| 241 | |
---|
| 242 | ! ! Passive tracers |
---|
| 243 | CALL trc_init ! Passive tracers initialization |
---|
| 244 | ! ! Dynamics |
---|
| 245 | CALL dta_dyn_init ! Initialization for the dynamics |
---|
| 246 | CALL iom_init ! iom_put initialization |
---|
| 247 | |
---|
| 248 | IF(lwp) WRITE(numout,cform_aaa) ! Flag AAAAAAA |
---|
| 249 | ! |
---|
[3294] | 250 | IF( nn_timing == 1 ) CALL timing_stop( 'nemo_init') |
---|
| 251 | ! |
---|
[2574] | 252 | END SUBROUTINE nemo_init |
---|
| 253 | |
---|
| 254 | |
---|
| 255 | SUBROUTINE nemo_ctl |
---|
| 256 | !!---------------------------------------------------------------------- |
---|
| 257 | !! *** ROUTINE nemo_ctl *** |
---|
| 258 | !! |
---|
| 259 | !! ** Purpose : control print setting |
---|
| 260 | !! |
---|
| 261 | !! ** Method : - print namctl information and check some consistencies |
---|
| 262 | !!---------------------------------------------------------------------- |
---|
| 263 | ! |
---|
| 264 | IF(lwp) THEN ! Parameter print |
---|
| 265 | WRITE(numout,*) |
---|
| 266 | WRITE(numout,*) 'nemo_flg: Control prints & Benchmark' |
---|
| 267 | WRITE(numout,*) '~~~~~~~ ' |
---|
| 268 | WRITE(numout,*) ' Namelist namctl' |
---|
| 269 | WRITE(numout,*) ' run control (for debugging) ln_ctl = ', ln_ctl |
---|
| 270 | WRITE(numout,*) ' level of print nn_print = ', nn_print |
---|
| 271 | WRITE(numout,*) ' Start i indice for SUM control nn_ictls = ', nn_ictls |
---|
| 272 | WRITE(numout,*) ' End i indice for SUM control nn_ictle = ', nn_ictle |
---|
| 273 | WRITE(numout,*) ' Start j indice for SUM control nn_jctls = ', nn_jctls |
---|
| 274 | WRITE(numout,*) ' End j indice for SUM control nn_jctle = ', nn_jctle |
---|
| 275 | WRITE(numout,*) ' number of proc. following i nn_isplt = ', nn_isplt |
---|
| 276 | WRITE(numout,*) ' number of proc. following j nn_jsplt = ', nn_jsplt |
---|
| 277 | WRITE(numout,*) ' benchmark parameter (0/1) nn_bench = ', nn_bench |
---|
| 278 | ENDIF |
---|
| 279 | ! |
---|
| 280 | nprint = nn_print ! convert DOCTOR namelist names into OLD names |
---|
| 281 | nictls = nn_ictls |
---|
| 282 | nictle = nn_ictle |
---|
| 283 | njctls = nn_jctls |
---|
| 284 | njctle = nn_jctle |
---|
| 285 | isplt = nn_isplt |
---|
| 286 | jsplt = nn_jsplt |
---|
| 287 | nbench = nn_bench |
---|
| 288 | ! ! Parameter control |
---|
| 289 | ! |
---|
| 290 | IF( ln_ctl ) THEN ! sub-domain area indices for the control prints |
---|
| 291 | IF( lk_mpp ) THEN |
---|
| 292 | isplt = jpni ; jsplt = jpnj ; ijsplt = jpni*jpnj ! the domain is forced to the real splitted domain |
---|
| 293 | ELSE |
---|
| 294 | IF( isplt == 1 .AND. jsplt == 1 ) THEN |
---|
| 295 | CALL ctl_warn( ' - isplt & jsplt are equal to 1', & |
---|
| 296 | & ' - the print control will be done over the whole domain' ) |
---|
| 297 | ENDIF |
---|
| 298 | ijsplt = isplt * jsplt ! total number of processors ijsplt |
---|
| 299 | ENDIF |
---|
| 300 | IF(lwp) WRITE(numout,*)' - The total number of processors over which the' |
---|
| 301 | IF(lwp) WRITE(numout,*)' print control will be done is ijsplt : ', ijsplt |
---|
| 302 | ! |
---|
| 303 | ! ! indices used for the SUM control |
---|
| 304 | IF( nictls+nictle+njctls+njctle == 0 ) THEN ! print control done over the default area |
---|
| 305 | lsp_area = .FALSE. |
---|
| 306 | ELSE ! print control done over a specific area |
---|
| 307 | lsp_area = .TRUE. |
---|
| 308 | IF( nictls < 1 .OR. nictls > jpiglo ) THEN |
---|
| 309 | CALL ctl_warn( ' - nictls must be 1<=nictls>=jpiglo, it is forced to 1' ) |
---|
| 310 | nictls = 1 |
---|
| 311 | ENDIF |
---|
| 312 | IF( nictle < 1 .OR. nictle > jpiglo ) THEN |
---|
| 313 | CALL ctl_warn( ' - nictle must be 1<=nictle>=jpiglo, it is forced to jpiglo' ) |
---|
| 314 | nictle = jpiglo |
---|
| 315 | ENDIF |
---|
| 316 | IF( njctls < 1 .OR. njctls > jpjglo ) THEN |
---|
| 317 | CALL ctl_warn( ' - njctls must be 1<=njctls>=jpjglo, it is forced to 1' ) |
---|
| 318 | njctls = 1 |
---|
| 319 | ENDIF |
---|
| 320 | IF( njctle < 1 .OR. njctle > jpjglo ) THEN |
---|
| 321 | CALL ctl_warn( ' - njctle must be 1<=njctle>=jpjglo, it is forced to jpjglo' ) |
---|
| 322 | njctle = jpjglo |
---|
| 323 | ENDIF |
---|
| 324 | ENDIF |
---|
| 325 | ENDIF |
---|
| 326 | ! |
---|
| 327 | IF( nbench == 1 ) THEN ! Benchmark |
---|
| 328 | SELECT CASE ( cp_cfg ) |
---|
| 329 | CASE ( 'gyre' ) ; CALL ctl_warn( ' The Benchmark is activated ' ) |
---|
| 330 | CASE DEFAULT ; CALL ctl_stop( ' The Benchmark is based on the GYRE configuration:', & |
---|
| 331 | & ' key_gyre must be used or set nbench = 0' ) |
---|
| 332 | END SELECT |
---|
| 333 | ENDIF |
---|
| 334 | ! |
---|
| 335 | IF( lk_c1d .AND. .NOT.lk_iomput ) CALL ctl_stop( 'nemo_ctl: The 1D configuration must be used ', & |
---|
| 336 | & 'with the IOM Input/Output manager. ' , & |
---|
| 337 | & 'Compile with key_iomput enabled' ) |
---|
| 338 | ! |
---|
[3558] | 339 | IF( 1_wp /= SIGN(1._wp,-0._wp) ) CALL ctl_stop( 'nemo_ctl: The intrinsec SIGN function follows ', & |
---|
| 340 | & 'f2003 standard. ' , & |
---|
| 341 | & 'Compile with key_nosignedzero enabled' ) |
---|
| 342 | ! |
---|
[2574] | 343 | END SUBROUTINE nemo_ctl |
---|
| 344 | |
---|
| 345 | |
---|
| 346 | SUBROUTINE nemo_closefile |
---|
| 347 | !!---------------------------------------------------------------------- |
---|
| 348 | !! *** ROUTINE nemo_closefile *** |
---|
| 349 | !! |
---|
| 350 | !! ** Purpose : Close the files |
---|
| 351 | !!---------------------------------------------------------------------- |
---|
| 352 | ! |
---|
| 353 | IF ( lk_mpp ) CALL mppsync |
---|
| 354 | ! |
---|
| 355 | CALL iom_close ! close all input/output files managed by iom_* |
---|
| 356 | ! |
---|
| 357 | IF( numstp /= -1 ) CLOSE( numstp ) ! time-step file |
---|
| 358 | IF( numnam /= -1 ) CLOSE( numnam ) ! oce namelist |
---|
| 359 | IF( numout /= 6 ) CLOSE( numout ) ! standard model output file |
---|
| 360 | numout = 6 ! redefine numout in case it is used after this point... |
---|
| 361 | ! |
---|
| 362 | END SUBROUTINE nemo_closefile |
---|
| 363 | |
---|
[2715] | 364 | |
---|
| 365 | SUBROUTINE nemo_alloc |
---|
| 366 | !!---------------------------------------------------------------------- |
---|
| 367 | !! *** ROUTINE nemo_alloc *** |
---|
| 368 | !! |
---|
| 369 | !! ** Purpose : Allocate all the dynamic arrays of the OPA modules |
---|
| 370 | !! |
---|
| 371 | !! ** Method : |
---|
| 372 | !!---------------------------------------------------------------------- |
---|
| 373 | USE diawri, ONLY: dia_wri_alloc |
---|
| 374 | USE dom_oce, ONLY: dom_oce_alloc |
---|
| 375 | USE zdf_oce, ONLY: zdf_oce_alloc |
---|
| 376 | USE ldftra_oce, ONLY: ldftra_oce_alloc |
---|
| 377 | USE trc_oce, ONLY: trc_oce_alloc |
---|
| 378 | ! |
---|
| 379 | INTEGER :: ierr |
---|
| 380 | !!---------------------------------------------------------------------- |
---|
| 381 | ! |
---|
| 382 | ierr = oce_alloc () ! ocean |
---|
| 383 | ierr = ierr + dia_wri_alloc () |
---|
| 384 | ierr = ierr + dom_oce_alloc () ! ocean domain |
---|
| 385 | ierr = ierr + ldftra_oce_alloc() ! ocean lateral physics : tracers |
---|
| 386 | ierr = ierr + zdf_oce_alloc () ! ocean vertical physics |
---|
| 387 | ! |
---|
| 388 | ierr = ierr + lib_mpp_alloc (numout) ! mpp exchanges |
---|
| 389 | ierr = ierr + trc_oce_alloc () ! shared TRC / TRA arrays |
---|
| 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 | |
---|
[3294] | 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 |
---|
[2574] | 653 | !!====================================================================== |
---|
| 654 | END MODULE nemogcm |
---|