mppini_2.h90 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. SUBROUTINE mpp_init2
  2. !!----------------------------------------------------------------------
  3. !! *** ROUTINE mpp_init2 ***
  4. !!
  5. !! * Purpose : Lay out the global domain over processors.
  6. !! FOR USING THIS VERSION, A PREPROCESSING TRAITMENT IS RECOMMENDED
  7. !! FOR DEFINING BETTER CUTTING OUT.
  8. !! This routine is used with a the bathymetry file.
  9. !! In this version, the land processors are avoided and the adress
  10. !! processor (nproc, narea,noea, ...) are calculated again.
  11. !! The jpnij parameter can be lesser than jpni x jpnj
  12. !! and this jpnij parameter must be calculated before with an
  13. !! algoritmic preprocessing program.
  14. !!
  15. !! ** Method : Global domain is distributed in smaller local domains.
  16. !! Periodic condition is a function of the local domain position
  17. !! (global boundary or neighbouring domain) and of the global
  18. !! periodic
  19. !! Type : jperio global periodic condition
  20. !! nperio local periodic condition
  21. !!
  22. !! ** Action : nimpp : longitudinal index
  23. !! njmpp : latitudinal index
  24. !! nperio : lateral condition type
  25. !! narea : number for local area
  26. !! nlci : first dimension
  27. !! nlcj : second dimension
  28. !! nproc : number for local processor
  29. !! noea : number for local neighboring processor
  30. !! nowe : number for local neighboring processor
  31. !! noso : number for local neighboring processor
  32. !! nono : number for local neighboring processor
  33. !!
  34. !! History :
  35. !! ! 94-11 (M. Guyon) Original code
  36. !! ! 95-04 (J. Escobar, M. Imbard)
  37. !! ! 98-02 (M. Guyon) FETI method
  38. !! ! 98-05 (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI versions
  39. !! 9.0 ! 04-01 (G. Madec, J.M Molines) F90 : free form , north fold jpni > 1
  40. !!----------------------------------------------------------------------
  41. USE in_out_manager ! I/O Manager
  42. USE iom
  43. USE dom_xios
  44. !!
  45. INTEGER :: ji, jj, jn, jproc, jarea ! dummy loop indices
  46. INTEGER :: inum ! temporary logical unit
  47. INTEGER :: idir ! temporary integers
  48. INTEGER :: jstartrow ! temporary integers
  49. INTEGER :: ios ! Local integer output status for namelist read
  50. INTEGER :: &
  51. ii, ij, ifreq, il1, il2, & ! temporary integers
  52. icont, ili, ilj, & ! " "
  53. isurf, ijm1, imil, & ! " "
  54. iino, ijno, iiso, ijso, & ! " "
  55. iiea, ijea, iiwe, ijwe, & ! " "
  56. iinw, ijnw, iine, ijne, & ! " "
  57. iisw, ijsw, iise, ijse, & ! " "
  58. iresti, irestj, iproc ! " "
  59. INTEGER, DIMENSION(jpnij) :: &
  60. iin, ijn
  61. INTEGER, DIMENSION(jpni,jpnj) :: &
  62. iimppt, ijmppt, ilci , ilcj , & ! temporary workspace
  63. ipproc, ibondj, ibondi, ipolj , & ! " "
  64. ilei , ilej , ildi , ildj , & ! " "
  65. ioea , iowe , ioso , iono , & ! " "
  66. ione , ionw , iose , iosw , & ! " "
  67. ibne , ibnw , ibse , ibsw ! " "
  68. INTEGER, DIMENSION(jpiglo,jpjglo) :: &
  69. imask ! temporary global workspace
  70. REAL(wp), DIMENSION(jpiglo,jpjglo) :: &
  71. zdta, zdtaisf ! temporary data workspace
  72. REAL(wp) :: zidom , zjdom ! temporary scalars
  73. ! read namelist for ln_zco
  74. NAMELIST/namzgr/ ln_zco, ln_zps, ln_sco, ln_isfcav
  75. !!----------------------------------------------------------------------
  76. !! OPA 9.0 , LOCEAN-IPSL (2005)
  77. !! $Id: mppini_2.h90 6413 2016-03-31 16:22:52Z lovato $
  78. !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
  79. !!----------------------------------------------------------------------
  80. REWIND( numnam_ref ) ! Namelist namzgr in reference namelist : Vertical coordinate
  81. READ ( numnam_ref, namzgr, IOSTAT = ios, ERR = 901)
  82. 901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr in reference namelist', lwp )
  83. REWIND( numnam_cfg ) ! Namelist namzgr in configuration namelist : Vertical coordinate
  84. READ ( numnam_cfg, namzgr, IOSTAT = ios, ERR = 902 )
  85. 902 IF( ios /= 0 ) CALL ctl_nam ( ios , 'namzgr in configuration namelist', lwp )
  86. IF(lwm) WRITE ( numond, namzgr )
  87. IF(lwp)WRITE(numout,*)
  88. IF(lwp)WRITE(numout,*) 'mpp_init : Message Passing MPI'
  89. IF(lwp)WRITE(numout,*) '~~~~~~~~'
  90. IF(lwp)WRITE(numout,*) ' '
  91. IF( jpni*jpnj < jpnij ) CALL ctl_stop( ' jpnij > jpni x jpnj impossible' )
  92. ! 0. initialisation
  93. ! -----------------
  94. ! open the file
  95. ! Remember that at this level in the code, mpp is not yet initialized, so
  96. ! the file must be open with jpdom_unknown, and kstart and kcount forced
  97. jstartrow = 1
  98. IF ( ln_zco ) THEN
  99. CALL iom_open ( 'bathy_level.nc', inum ) ! Level bathymetry
  100. ! Optionally use a file attribute (open_ocean_jstart) to set a start row for reading from the global file
  101. ! This allows the unextended grid bathymetry to be stored in the same file as the under ice-shelf extended bathymetry
  102. CALL iom_getatt(inum, 'open_ocean_jstart', jstartrow ) ! -999 is returned if the attribute is not found
  103. jstartrow = MAX(1,jstartrow)
  104. CALL iom_get ( inum, jpdom_unknown, 'Bathy_level', zdta, kstart=(/jpizoom,jpjzoom+jstartrow-1/), kcount=(/jpiglo,jpjglo/) )
  105. ELSE
  106. CALL iom_open ( 'bathy_meter.nc', inum ) ! Meter bathy in case of partial steps
  107. IF ( ln_isfcav ) THEN
  108. CALL iom_get ( inum, jpdom_unknown, 'Bathymetry_isf' , zdta, kstart=(/jpizoom,jpjzoom/), kcount=(/jpiglo,jpjglo/) )
  109. ELSE
  110. ! Optionally use a file attribute (open_ocean_jstart) to set a start row for reading from the global file
  111. ! This allows the unextended grid bathymetry to be stored in the same file as the under ice-shelf extended bathymetry
  112. CALL iom_getatt(inum, 'open_ocean_jstart', jstartrow ) ! -999 is returned if the attribute is not found
  113. jstartrow = MAX(1,jstartrow)
  114. CALL iom_get ( inum, jpdom_unknown, 'Bathymetry' , zdta, kstart=(/jpizoom,jpjzoom+jstartrow-1/) &
  115. & , kcount=(/jpiglo,jpjglo/) )
  116. ENDIF
  117. ENDIF
  118. CALL iom_close (inum)
  119. ! used to compute the land processor in case of not masked bathy file.
  120. zdtaisf(:,:) = 0.0_wp
  121. IF ( ln_isfcav ) THEN
  122. CALL iom_open ( 'bathy_meter.nc', inum ) ! Meter bathy in case of partial steps
  123. CALL iom_get ( inum, jpdom_unknown, 'isf_draft' , zdtaisf, kstart=(/jpizoom,jpjzoom/), kcount=(/jpiglo,jpjglo/) )
  124. END IF
  125. CALL iom_close (inum)
  126. ! land/sea mask over the global/zoom domain
  127. imask(:,:)=1
  128. WHERE ( zdta(:,:) - zdtaisf(:,:) <= 0. ) imask = 0
  129. ! 1. Dimension arrays for subdomains
  130. ! -----------------------------------
  131. ! Computation of local domain sizes ilci() ilcj()
  132. ! These dimensions depend on global sizes jpni,jpnj and jpiglo,jpjglo
  133. ! The subdomains are squares leeser than or equal to the global
  134. ! dimensions divided by the number of processors minus the overlap
  135. ! array.
  136. nreci=2*jpreci
  137. nrecj=2*jprecj
  138. iresti = 1 + MOD( jpiglo - nreci -1 , jpni )
  139. irestj = 1 + MOD( jpjglo - nrecj -1 , jpnj )
  140. #if defined key_nemocice_decomp
  141. ! Change padding to be consistent with CICE
  142. ilci(1:jpni-1 ,:) = jpi
  143. ilci(jpni ,:) = jpiglo - (jpni - 1) * (jpi - nreci)
  144. ilcj(:, 1:jpnj-1) = jpj
  145. ilcj(:, jpnj) = jpjglo - (jpnj - 1) * (jpj - nrecj)
  146. #else
  147. ilci(1:iresti ,:) = jpi
  148. ilci(iresti+1:jpni ,:) = jpi-1
  149. ilcj(:, 1:irestj) = jpj
  150. ilcj(:, irestj+1:jpnj) = jpj-1
  151. #endif
  152. nfilcit(:,:) = ilci(:,:)
  153. IF(lwp) WRITE(numout,*)
  154. IF(lwp) WRITE(numout,*) ' mpp_init2: defines mpp subdomains'
  155. IF(lwp) WRITE(numout,*) ' ~~~~~~ ----------------------'
  156. IF(lwp) WRITE(numout,*)
  157. IF(lwp) WRITE(numout,*) 'iresti=',iresti,' irestj=',irestj
  158. IF(lwp) WRITE(numout,*)
  159. IF(lwp) WRITE(numout,*) 'jpni=',jpni,' jpnj=',jpnj
  160. zidom = nreci + sum(ilci(:,1) - nreci )
  161. IF(lwp) WRITE(numout,*)
  162. IF(lwp) WRITE(numout,*)' sum ilci(i,1)=',zidom,' jpiglo=',jpiglo
  163. zjdom = nrecj + sum(ilcj(1,:) - nrecj )
  164. IF(lwp) WRITE(numout,*) ' sum ilcj(1,j)=',zjdom,' jpjglo=',jpjglo
  165. IF(lwp) WRITE(numout,*)
  166. ! 2. Index arrays for subdomains
  167. ! -------------------------------
  168. iimppt(:,:) = 1
  169. ijmppt(:,:) = 1
  170. ipproc(:,:) = -1
  171. IF( jpni > 1 )THEN
  172. DO jj = 1, jpnj
  173. DO ji = 2, jpni
  174. iimppt(ji,jj) = iimppt(ji-1,jj) + ilci(ji-1,jj) - nreci
  175. END DO
  176. END DO
  177. ENDIF
  178. nfiimpp(:,:) = iimppt(:,:)
  179. IF( jpnj > 1 )THEN
  180. DO jj = 2, jpnj
  181. DO ji = 1, jpni
  182. ijmppt(ji,jj) = ijmppt(ji,jj-1) + ilcj(ji,jj-1) - nrecj
  183. END DO
  184. END DO
  185. ENDIF
  186. ! 3. Subdomain description in the Regular Case
  187. ! --------------------------------------------
  188. nperio = 0
  189. icont = -1
  190. DO jarea = 1, jpni*jpnj
  191. ii = 1 + MOD(jarea-1,jpni)
  192. ij = 1 + (jarea-1)/jpni
  193. ili = ilci(ii,ij)
  194. ilj = ilcj(ii,ij)
  195. ibondj(ii,ij) = -1
  196. IF( jarea > jpni ) ibondj(ii,ij) = 0
  197. IF( jarea > (jpnj-1)*jpni ) ibondj(ii,ij) = 1
  198. IF( jpnj == 1 ) ibondj(ii,ij) = 2
  199. ibondi(ii,ij) = 0
  200. IF( MOD(jarea,jpni) == 1 ) ibondi(ii,ij) = -1
  201. IF( MOD(jarea,jpni) == 0 ) ibondi(ii,ij) = 1
  202. IF( jpni == 1 ) ibondi(ii,ij) = 2
  203. ! 2.4 Subdomain neighbors
  204. iproc = jarea - 1
  205. ioso(ii,ij) = iproc - jpni
  206. iowe(ii,ij) = iproc - 1
  207. ioea(ii,ij) = iproc + 1
  208. iono(ii,ij) = iproc + jpni
  209. ildi(ii,ij) = 1 + jpreci
  210. ilei(ii,ij) = ili -jpreci
  211. ionw(ii,ij) = iono(ii,ij) - 1
  212. ione(ii,ij) = iono(ii,ij) + 1
  213. iosw(ii,ij) = ioso(ii,ij) - 1
  214. iose(ii,ij) = ioso(ii,ij) + 1
  215. ibsw(ii,ij) = 1
  216. ibnw(ii,ij) = 1
  217. IF( MOD(iproc,jpni) == 0 ) THEN
  218. ibsw(ii,ij) = 0
  219. ibnw(ii,ij) = 0
  220. ENDIF
  221. ibse(ii,ij) = 1
  222. ibne(ii,ij) = 1
  223. IF( MOD(iproc,jpni) == jpni-1 ) THEN
  224. ibse(ii,ij) = 0
  225. ibne(ii,ij) = 0
  226. ENDIF
  227. IF( iproc < jpni ) THEN
  228. ibsw(ii,ij) = 0
  229. ibse(ii,ij) = 0
  230. ENDIF
  231. IF( iproc >= (jpnj-1)*jpni ) THEN
  232. ibnw(ii,ij) = 0
  233. ibne(ii,ij) = 0
  234. ENDIF
  235. IF( ibondi(ii,ij) == -1 .OR. ibondi(ii,ij) == 2 ) ildi(ii,ij) = 1
  236. IF( ibondi(ii,ij) == 1 .OR. ibondi(ii,ij) == 2 ) ilei(ii,ij) = ili
  237. ildj(ii,ij) = 1 + jprecj
  238. ilej(ii,ij) = ilj - jprecj
  239. IF( ibondj(ii,ij) == -1 .OR. ibondj(ii,ij) == 2 ) ildj(ii,ij) = 1
  240. IF( ibondj(ii,ij) == 1 .OR. ibondj(ii,ij) == 2 ) ilej(ii,ij) = ilj
  241. ! warning ii*ij (zone) /= nproc (processors)!
  242. IF( jperio == 1 .OR. jperio == 4 .OR. jperio == 6 ) THEN
  243. IF( jpni == 1 )THEN
  244. ibondi(ii,ij) = 2
  245. nperio = 1
  246. ELSE
  247. ibondi(ii,ij) = 0
  248. ENDIF
  249. IF( MOD(jarea,jpni) == 0 ) THEN
  250. ioea(ii,ij) = iproc - (jpni-1)
  251. ione(ii,ij) = ione(ii,ij) - jpni
  252. iose(ii,ij) = iose(ii,ij) - jpni
  253. ENDIF
  254. IF( MOD(jarea,jpni) == 1 ) THEN
  255. iowe(ii,ij) = iproc + jpni - 1
  256. ionw(ii,ij) = ionw(ii,ij) + jpni
  257. iosw(ii,ij) = iosw(ii,ij) + jpni
  258. ENDIF
  259. ibsw(ii,ij) = 1
  260. ibnw(ii,ij) = 1
  261. ibse(ii,ij) = 1
  262. ibne(ii,ij) = 1
  263. IF( iproc < jpni ) THEN
  264. ibsw(ii,ij) = 0
  265. ibse(ii,ij) = 0
  266. ENDIF
  267. IF( iproc >= (jpnj-1)*jpni ) THEN
  268. ibnw(ii,ij) = 0
  269. ibne(ii,ij) = 0
  270. ENDIF
  271. ENDIF
  272. ipolj(ii,ij) = 0
  273. IF( jperio == 3 .OR. jperio == 4 ) THEN
  274. ijm1 = jpni*(jpnj-1)
  275. imil = ijm1+(jpni+1)/2
  276. IF( jarea > ijm1 ) ipolj(ii,ij) = 3
  277. IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 4
  278. IF( ipolj(ii,ij) == 3 ) iono(ii,ij) = jpni*jpnj-jarea+ijm1 ! MPI rank of northern neighbour
  279. ENDIF
  280. IF( jperio == 5 .OR. jperio == 6 ) THEN
  281. ijm1 = jpni*(jpnj-1)
  282. imil = ijm1+(jpni+1)/2
  283. IF( jarea > ijm1) ipolj(ii,ij) = 5
  284. IF( MOD(jpni,2) == 1 .AND. jarea == imil ) ipolj(ii,ij) = 6
  285. IF( ipolj(ii,ij) == 5) iono(ii,ij) = jpni*jpnj-jarea+ijm1 ! MPI rank of northern neighbour
  286. ENDIF
  287. ! Check wet points over the entire domain to preserve the MPI communication stencil
  288. isurf = 0
  289. DO jj = 1, ilj
  290. DO ji = 1, ili
  291. IF( imask(ji+iimppt(ii,ij)-1, jj+ijmppt(ii,ij)-1) == 1) isurf = isurf+1
  292. END DO
  293. END DO
  294. IF(isurf /= 0) THEN
  295. icont = icont + 1
  296. ipproc(ii,ij) = icont
  297. iin(icont+1) = ii
  298. ijn(icont+1) = ij
  299. ENDIF
  300. END DO
  301. nfipproc(:,:) = ipproc(:,:)
  302. ! Control
  303. IF(icont+1 /= jpnij) THEN
  304. WRITE(ctmp1,*) ' jpni =',jpni,' jpnj =',jpnj
  305. WRITE(ctmp2,*) ' jpnij =',jpnij, '< jpni x jpnj'
  306. WRITE(ctmp3,*) ' ***********, mpp_init2 finds jpnij=',icont+1
  307. CALL ctl_stop( ' Eliminate land processors algorithm', '', ctmp1, ctmp2, '', ctmp3 )
  308. ENDIF
  309. ! 4. Subdomain print
  310. ! ------------------
  311. IF(lwp) THEN
  312. ifreq = 4
  313. il1 = 1
  314. DO jn = 1,(jpni-1)/ifreq+1
  315. il2 = MIN(jpni,il1+ifreq-1)
  316. WRITE(numout,*)
  317. WRITE(numout,9400) ('***',ji=il1,il2-1)
  318. DO jj = jpnj, 1, -1
  319. WRITE(numout,9403) (' ',ji=il1,il2-1)
  320. WRITE(numout,9402) jj, (ilci(ji,jj),ilcj(ji,jj),ji=il1,il2)
  321. WRITE(numout,9404) (ipproc(ji,jj),ji=il1,il2)
  322. WRITE(numout,9403) (' ',ji=il1,il2-1)
  323. WRITE(numout,9400) ('***',ji=il1,il2-1)
  324. END DO
  325. WRITE(numout,9401) (ji,ji=il1,il2)
  326. il1 = il1+ifreq
  327. END DO
  328. 9400 FORMAT(' ***',20('*************',a3))
  329. 9403 FORMAT(' * ',20(' * ',a3))
  330. 9401 FORMAT(' ',20(' ',i3,' '))
  331. 9402 FORMAT(' ',i3,' * ',20(i3,' x',i3,' * '))
  332. 9404 FORMAT(' * ',20(' ',i3,' * '))
  333. ENDIF
  334. ! 5. neighbour treatment
  335. ! ----------------------
  336. DO jarea = 1, jpni*jpnj
  337. iproc = jarea-1
  338. ii = 1 + MOD(jarea-1,jpni)
  339. ij = 1 + (jarea-1)/jpni
  340. IF( ipproc(ii,ij) == -1 .AND. iono(ii,ij) >= 0 &
  341. .AND. iono(ii,ij) <= jpni*jpnj-1 ) THEN
  342. iino = 1 + MOD(iono(ii,ij),jpni)
  343. ijno = 1 + (iono(ii,ij))/jpni
  344. ! JD based on SM BEGIN
  345. icont = 0
  346. IF( ipproc(iino,ijno) /= -1 .AND. ij /= jpnj .AND. ij /= 1 ) THEN
  347. DO jj = 1, ij-1
  348. IF( ipproc(ii,jj) /= -1 ) THEN
  349. ioso(iino,ijno) = ii - 1 + (jj-1)*jpni
  350. icont=1
  351. ENDIF
  352. END DO
  353. ENDIF
  354. IF( icont == 0) THEN
  355. ! Need to reverse the logical direction of communication
  356. ! for northern neighbours of northern row processors (north-fold)
  357. ! i.e. need to check that the northern neighbour only communicates
  358. ! to the SOUTH (or not at all) if this area is land-only (#1057)
  359. idir = 1
  360. IF( ij .eq. jpnj .AND. ijno .eq. jpnj ) idir = -1
  361. IF( ibondj(iino,ijno) == idir ) ibondj(iino,ijno)=2
  362. IF( ibondj(iino,ijno) == 0 ) ibondj(iino,ijno) = -idir
  363. ENDIF
  364. ENDIF
  365. IF( ipproc(ii,ij) == -1 .AND. ioso(ii,ij) >= 0 &
  366. .AND. ioso(ii,ij) <= jpni*jpnj-1 ) THEN
  367. iiso = 1 + MOD(ioso(ii,ij),jpni)
  368. ijso = 1 + (ioso(ii,ij))/jpni
  369. icont = 0
  370. IF( ipproc(iiso,ijso) /= -1 .AND. ij /= jpnj .AND. ij /= 1 ) THEN
  371. DO jj = jpnj, ij+1,-1
  372. IF( ipproc(ii,jj) /= -1 ) THEN
  373. iono(iiso,ijso) = ii - 1 + (jj-1)*jpni
  374. icont=1
  375. ENDIF
  376. END DO
  377. ENDIF
  378. IF( icont == 0) THEN
  379. IF( ibondj(iiso,ijso) == -1 ) ibondj(iiso,ijso) = 2
  380. IF( ibondj(iiso,ijso) == 0 ) ibondj(iiso,ijso) = 1
  381. ENDIF
  382. ! JD based on SM END
  383. ENDIF
  384. IF( ipproc(ii,ij) == -1 .AND. ioea(ii,ij) >= 0 &
  385. .AND. ioea(ii,ij) <= jpni*jpnj-1) THEN
  386. iiea = 1 + MOD(ioea(ii,ij),jpni)
  387. ijea = 1 + (ioea(ii,ij))/jpni
  388. IF( ibondi(iiea,ijea) == 1 ) ibondi(iiea,ijea) = 2
  389. IF( ibondi(iiea,ijea) == 0 ) ibondi(iiea,ijea) = -1
  390. ENDIF
  391. IF( ipproc(ii,ij) == -1 .AND. iowe(ii,ij) >= 0 &
  392. .AND. iowe(ii,ij) <= jpni*jpnj-1) THEN
  393. iiwe = 1 + MOD(iowe(ii,ij),jpni)
  394. ijwe = 1 + (iowe(ii,ij))/jpni
  395. IF( ibondi(iiwe,ijwe) == -1 ) ibondi(iiwe,ijwe) = 2
  396. IF( ibondi(iiwe,ijwe) == 0 ) ibondi(iiwe,ijwe) = 1
  397. ENDIF
  398. IF( ipproc(ii,ij) == -1 .AND. ibne(ii,ij) == 1 ) THEN
  399. iine = 1 + MOD(ione(ii,ij),jpni)
  400. ijne = 1 + (ione(ii,ij))/jpni
  401. IF( ibsw(iine,ijne) == 1 ) ibsw(iine,ijne) = 0
  402. ENDIF
  403. IF( ipproc(ii,ij) == -1 .AND. ibsw(ii,ij) == 1 ) THEN
  404. iisw = 1 + MOD(iosw(ii,ij),jpni)
  405. ijsw = 1 + (iosw(ii,ij))/jpni
  406. IF( ibne(iisw,ijsw) == 1 ) ibne(iisw,ijsw) = 0
  407. ENDIF
  408. IF( ipproc(ii,ij) == -1 .AND. ibnw(ii,ij) == 1 ) THEN
  409. iinw = 1 + MOD(ionw(ii,ij),jpni)
  410. ijnw = 1 + (ionw(ii,ij))/jpni
  411. IF( ibse(iinw,ijnw) == 1 ) ibse(iinw,ijnw)=0
  412. ENDIF
  413. IF( ipproc(ii,ij) == -1 .AND. ibse(ii,ij) == 1 ) THEN
  414. iise = 1 + MOD(iose(ii,ij),jpni)
  415. ijse = 1 + (iose(ii,ij))/jpni
  416. IF( ibnw(iise,ijse) == 1 ) ibnw(iise,ijse) = 0
  417. ENDIF
  418. END DO
  419. ! 6. Change processor name
  420. ! ------------------------
  421. nproc = narea-1
  422. ii = iin(narea)
  423. ij = ijn(narea)
  424. ! set default neighbours
  425. noso = ioso(ii,ij)
  426. nowe = iowe(ii,ij)
  427. noea = ioea(ii,ij)
  428. nono = iono(ii,ij)
  429. npse = iose(ii,ij)
  430. npsw = iosw(ii,ij)
  431. npne = ione(ii,ij)
  432. npnw = ionw(ii,ij)
  433. ! check neighbours location
  434. IF( ioso(ii,ij) >= 0 .AND. ioso(ii,ij) <= (jpni*jpnj-1) ) THEN
  435. iiso = 1 + MOD(ioso(ii,ij),jpni)
  436. ijso = 1 + (ioso(ii,ij))/jpni
  437. noso = ipproc(iiso,ijso)
  438. ENDIF
  439. IF( iowe(ii,ij) >= 0 .AND. iowe(ii,ij) <= (jpni*jpnj-1) ) THEN
  440. iiwe = 1 + MOD(iowe(ii,ij),jpni)
  441. ijwe = 1 + (iowe(ii,ij))/jpni
  442. nowe = ipproc(iiwe,ijwe)
  443. ENDIF
  444. IF( ioea(ii,ij) >= 0 .AND. ioea(ii,ij) <= (jpni*jpnj-1) ) THEN
  445. iiea = 1 + MOD(ioea(ii,ij),jpni)
  446. ijea = 1 + (ioea(ii,ij))/jpni
  447. noea = ipproc(iiea,ijea)
  448. ENDIF
  449. IF( iono(ii,ij) >= 0 .AND. iono(ii,ij) <= (jpni*jpnj-1) ) THEN
  450. iino = 1 + MOD(iono(ii,ij),jpni)
  451. ijno = 1 + (iono(ii,ij))/jpni
  452. nono = ipproc(iino,ijno)
  453. ENDIF
  454. IF( iose(ii,ij) >= 0 .AND. iose(ii,ij) <= (jpni*jpnj-1) ) THEN
  455. iise = 1 + MOD(iose(ii,ij),jpni)
  456. ijse = 1 + (iose(ii,ij))/jpni
  457. npse = ipproc(iise,ijse)
  458. ENDIF
  459. IF( iosw(ii,ij) >= 0 .AND. iosw(ii,ij) <= (jpni*jpnj-1) ) THEN
  460. iisw = 1 + MOD(iosw(ii,ij),jpni)
  461. ijsw = 1 + (iosw(ii,ij))/jpni
  462. npsw = ipproc(iisw,ijsw)
  463. ENDIF
  464. IF( ione(ii,ij) >= 0 .AND. ione(ii,ij) <= (jpni*jpnj-1) ) THEN
  465. iine = 1 + MOD(ione(ii,ij),jpni)
  466. ijne = 1 + (ione(ii,ij))/jpni
  467. npne = ipproc(iine,ijne)
  468. ENDIF
  469. IF( ionw(ii,ij) >= 0 .AND. ionw(ii,ij) <= (jpni*jpnj-1) ) THEN
  470. iinw = 1 + MOD(ionw(ii,ij),jpni)
  471. ijnw = 1 + (ionw(ii,ij))/jpni
  472. npnw = ipproc(iinw,ijnw)
  473. ENDIF
  474. nbnw = ibnw(ii,ij)
  475. nbne = ibne(ii,ij)
  476. nbsw = ibsw(ii,ij)
  477. nbse = ibse(ii,ij)
  478. nlcj = ilcj(ii,ij)
  479. nlci = ilci(ii,ij)
  480. nldi = ildi(ii,ij)
  481. nlei = ilei(ii,ij)
  482. nldj = ildj(ii,ij)
  483. nlej = ilej(ii,ij)
  484. nbondi = ibondi(ii,ij)
  485. nbondj = ibondj(ii,ij)
  486. nimpp = iimppt(ii,ij)
  487. njmpp = ijmppt(ii,ij)
  488. DO jproc = 1, jpnij
  489. ii = iin(jproc)
  490. ij = ijn(jproc)
  491. nimppt(jproc) = iimppt(ii,ij)
  492. njmppt(jproc) = ijmppt(ii,ij)
  493. nlcjt(jproc) = ilcj(ii,ij)
  494. nlcit(jproc) = ilci(ii,ij)
  495. nldit(jproc) = ildi(ii,ij)
  496. nleit(jproc) = ilei(ii,ij)
  497. nldjt(jproc) = ildj(ii,ij)
  498. nlejt(jproc) = ilej(ii,ij)
  499. END DO
  500. CALL init_dom_xios(iin,ijn,iimppt,ijmppt,ildi,ildj,ilei,ilej)
  501. ! Save processor layout in ascii file
  502. IF (lwp) THEN
  503. CALL ctl_opn( inum, 'layout.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., narea )
  504. WRITE(inum,'(a)') ' jpnij jpi jpj jpk jpiglo jpjglo'
  505. WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
  506. WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
  507. DO jproc = 1, jpnij
  508. WRITE(inum,'(9i5)') jproc, nlcit(jproc), nlcjt(jproc), &
  509. nldit(jproc), nldjt(jproc), &
  510. nleit(jproc), nlejt(jproc), &
  511. nimppt(jproc), njmppt(jproc)
  512. END DO
  513. CLOSE(inum)
  514. END IF
  515. ! Defined npolj, either 0, 3 , 4 , 5 , 6
  516. ! In this case the important thing is that npolj /= 0
  517. ! Because if we go through these line it is because jpni >1 and thus
  518. ! we must use lbcnorthmpp, which tests only npolj =0 or npolj /= 0
  519. npolj = 0
  520. ij = ijn(narea)
  521. IF( jperio == 3 .OR. jperio == 4 ) THEN
  522. IF( ij == jpnj ) npolj = 3
  523. ENDIF
  524. IF( jperio == 5 .OR. jperio == 6 ) THEN
  525. IF( ij == jpnj ) npolj = 5
  526. ENDIF
  527. ! Periodicity : no corner if nbondi = 2 and nperio != 1
  528. IF(lwp) THEN
  529. WRITE(numout,*) ' nproc = ', nproc
  530. WRITE(numout,*) ' nowe = ', nowe , ' noea = ', noea
  531. WRITE(numout,*) ' nono = ', nono , ' noso = ', noso
  532. WRITE(numout,*) ' nbondi = ', nbondi
  533. WRITE(numout,*) ' nbondj = ', nbondj
  534. WRITE(numout,*) ' npolj = ', npolj
  535. WRITE(numout,*) ' nperio = ', nperio
  536. WRITE(numout,*) ' nlci = ', nlci
  537. WRITE(numout,*) ' nlcj = ', nlcj
  538. WRITE(numout,*) ' nimpp = ', nimpp
  539. WRITE(numout,*) ' njmpp = ', njmpp
  540. WRITE(numout,*) ' nreci = ', nreci , ' npse = ', npse
  541. WRITE(numout,*) ' nrecj = ', nrecj , ' npsw = ', npsw
  542. WRITE(numout,*) ' jpreci = ', jpreci , ' npne = ', npne
  543. WRITE(numout,*) ' jprecj = ', jprecj , ' npnw = ', npnw
  544. WRITE(numout,*)
  545. ENDIF
  546. IF( nperio == 1 .AND. jpni /= 1 ) CALL ctl_stop( ' mpp_init2: error on cyclicity' )
  547. ! Prepare mpp north fold
  548. IF( jperio >= 3 .AND. jperio <= 6 .AND. jpni > 1 ) THEN
  549. CALL mpp_ini_north
  550. IF(lwp) WRITE(numout,*) ' mpp_init2 : North fold boundary prepared for jpni >1'
  551. ENDIF
  552. ! Prepare NetCDF output file (if necessary)
  553. CALL mpp_init_ioipsl
  554. !
  555. CALL dom_xios_read_coordinates
  556. !
  557. END SUBROUTINE mpp_init2