mppini_2.h90 23 KB

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