PageRenderTime 49ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wrfv2_fire/external/RSL_LITE/period.c

http://github.com/jbeezley/wrf-fire
C | 462 lines | 431 code | 23 blank | 8 comment | 123 complexity | d6cd81ed0c6f1085938fe6f1f0a43fcc MD5 | raw file
Possible License(s): AGPL-1.0
  1. #ifndef MS_SUA
  2. # include <stdio.h>
  3. #endif
  4. #include <fcntl.h>
  5. #define STANDARD_ERROR 2
  6. #define STANDARD_OUTPUT 1
  7. #ifndef STUBMPI
  8. # include "mpi.h"
  9. #endif
  10. #include "rsl_lite.h"
  11. static int yp_curs, ym_curs, xp_curs, xm_curs ;
  12. RSL_LITE_INIT_PERIOD (
  13. int * Fcomm0,
  14. int * shw0,
  15. int * n3dR0, int *n2dR0, int * typesizeR0 ,
  16. int * n3dI0, int *n2dI0, int * typesizeI0 ,
  17. int * n3dD0, int *n2dD0, int * typesizeD0 ,
  18. int * n3dL0, int *n2dL0, int * typesizeL0 ,
  19. int * me0, int * np0 , int * np_x0 , int * np_y0 ,
  20. int * ips0 , int * ipe0 , int * jps0 , int * jpe0 , int * kps0 , int * kpe0 )
  21. {
  22. #ifndef STUBMPI
  23. int n3dR, n2dR, typesizeR ;
  24. int n3dI, n2dI, typesizeI ;
  25. int n3dD, n2dD, typesizeD ;
  26. int n3dL, n2dL, typesizeL ;
  27. int shw ;
  28. int me, np, np_x, np_y ;
  29. int ips , ipe , jps , jpe , kps , kpe ;
  30. int yp, ym, xp, xm ;
  31. int nbytes ;
  32. int coords[2] ;
  33. MPI_Comm comm, *comm0, dummy_comm ;
  34. comm0 = &dummy_comm ;
  35. *comm0 = MPI_Comm_f2c( *Fcomm0 ) ;
  36. shw = *shw0 ;
  37. n3dR = *n3dR0 ; n2dR = *n2dR0 ; typesizeR = *typesizeR0 ;
  38. n3dI = *n3dI0 ; n2dI = *n2dI0 ; typesizeI = *typesizeI0 ;
  39. n3dD = *n3dD0 ; n2dD = *n2dD0 ; typesizeD = *typesizeD0 ;
  40. n3dL = *n3dL0 ; n2dL = *n2dL0 ; typesizeL = *typesizeL0 ;
  41. me = *me0 ; np = *np0 ; np_x = *np_x0 ; np_y = *np_y0 ;
  42. ips = *ips0-1 ; ipe = *ipe0-1 ; jps = *jps0-1 ; jpe = *jpe0-1 ; kps = *kps0-1 ; kpe = *kpe0-1 ;
  43. /*
  44. This assumes that the topoology associated with the communicator is periodic
  45. the period routines should be called with "local_communicator_periodic", which
  46. is set up in module_dm.F for RSL_LITE. Registry generated code automatically
  47. does this (gen_comms.c for RSL_LITE).
  48. */
  49. if ( np_y > 1 ) {
  50. nbytes = typesizeR*(ipe-ips+1+2*shw)*(shw+1)*(n3dR*(kpe-kps+1)+n2dR) +
  51. typesizeI*(ipe-ips+1+2*shw)*(shw+1)*(n3dI*(kpe-kps+1)+n2dI) +
  52. typesizeD*(ipe-ips+1+2*shw)*(shw+1)*(n3dD*(kpe-kps+1)+n2dD) +
  53. typesizeL*(ipe-ips+1+2*shw)*(shw+1)*(n3dL*(kpe-kps+1)+n2dL) ;
  54. MPI_Comm_rank( *comm0, &me ) ;
  55. MPI_Cart_coords( *comm0, me, 2, coords ) ;
  56. MPI_Cart_shift( *comm0, 0, 1, &ym, &yp ) ;
  57. if ( yp != MPI_PROC_NULL && coords[0] == np_y - 1 ) { /* process on top of mesh */
  58. buffer_for_proc ( yp , nbytes, RSL_RECVBUF ) ;
  59. buffer_for_proc ( yp , nbytes, RSL_SENDBUF ) ;
  60. }
  61. if ( ym != MPI_PROC_NULL && coords[0] == 0 ) { /* process on bottom of mesh */
  62. buffer_for_proc ( ym , nbytes, RSL_RECVBUF ) ;
  63. buffer_for_proc ( ym , nbytes, RSL_SENDBUF ) ;
  64. }
  65. }
  66. if ( np_x > 1 ) {
  67. nbytes = typesizeR*(jpe-jps+1+2*shw)*(shw+1)*(n3dR*(kpe-kps+1)+n2dR) +
  68. typesizeI*(jpe-jps+1+2*shw)*(shw+1)*(n3dI*(kpe-kps+1)+n2dI) +
  69. typesizeD*(jpe-jps+1+2*shw)*(shw+1)*(n3dD*(kpe-kps+1)+n2dD) +
  70. typesizeL*(jpe-jps+1+2*shw)*(shw+1)*(n3dL*(kpe-kps+1)+n2dL) ;
  71. MPI_Comm_rank( *comm0, &me ) ;
  72. MPI_Cart_coords( *comm0, me, 2, coords ) ;
  73. MPI_Cart_shift( *comm0, 1, 1, &xm, &xp ) ;
  74. if ( xm != MPI_PROC_NULL && coords[1] == np_x - 1 ) { /* process on right hand side of mesh */
  75. buffer_for_proc ( xp , nbytes, RSL_RECVBUF ) ;
  76. buffer_for_proc ( xp , nbytes, RSL_SENDBUF ) ;
  77. }
  78. if ( xp != MPI_PROC_NULL && coords[1] == 0 ) { /* process on left hand side of mesh */
  79. buffer_for_proc ( xm, nbytes, RSL_RECVBUF ) ;
  80. buffer_for_proc ( xm , nbytes, RSL_SENDBUF ) ;
  81. }
  82. }
  83. yp_curs = 0 ; ym_curs = 0 ; xp_curs = 0 ; xm_curs = 0 ;
  84. #endif
  85. }
  86. RSL_LITE_PACK_PERIOD ( int* Fcomm0, char * buf , int * shw0 , int * typesize0 , int * xy0 , int * pu0 , int * imemord , int * stag0 ,
  87. int *me0, int * np0 , int * np_x0 , int * np_y0 ,
  88. int * ids0 , int * ide0 , int * jds0 , int * jde0 , int * kds0 , int * kde0 ,
  89. int * ims0 , int * ime0 , int * jms0 , int * jme0 , int * kms0 , int * kme0 ,
  90. int * ips0 , int * ipe0 , int * jps0 , int * jpe0 , int * kps0 , int * kpe0 )
  91. {
  92. #ifndef STUBMPI
  93. int me, np, np_x, np_y ;
  94. int shw , typesize ;
  95. int ids , ide , jds , jde , kds , kde ;
  96. int ims , ime , jms , jme , kms , kme ;
  97. int ips , ipe , jps , jpe , kps , kpe ;
  98. int stag ; /* 0 not stag, 1 stag */
  99. int xy ; /* y = 0 , x = 1 */
  100. int pu ; /* pack = 0 , unpack = 1 */
  101. register int i, j, k, t ;
  102. #ifdef crayx1
  103. register int i2,i3,i4,i_offset;
  104. #endif
  105. char *p ;
  106. int the_buf ;
  107. int yp, ym, xp, xm ;
  108. int nbytes, ierr ;
  109. register int *pi, *qi ;
  110. int coords[2] ;
  111. int js, je, ks, ke, is, ie, wcount ;
  112. MPI_Comm comm, *comm0, dummy_comm ;
  113. comm0 = &dummy_comm ;
  114. *comm0 = MPI_Comm_f2c( *Fcomm0 ) ;
  115. me = *me0 ; np = *np0 ; np_x = *np_x0 ; np_y = *np_y0 ;
  116. stag = *stag0 ;
  117. shw = *shw0 ; typesize = *typesize0 ;
  118. ids = *ids0-1 ; ide = *ide0-1 ; jds = *jds0-1 ; jde = *jde0-1 ; kds = *kds0-1 ; kde = *kde0-1 ;
  119. ims = *ims0-1 ; ime = *ime0-1 ; jms = *jms0-1 ; jme = *jme0-1 ; kms = *kms0-1 ; kme = *kme0-1 ;
  120. ips = *ips0-1 ; ipe = *ipe0-1 ; jps = *jps0-1 ; jpe = *jpe0-1 ; kps = *kps0-1 ; kpe = *kpe0-1 ;
  121. xy = *xy0 ;
  122. pu = *pu0 ;
  123. #define RANGE(S1,E1,S2,E2,S3,E3,S4,E4) (((E1)-(S1)+1)*((E2)-(S2)+1)*((E3)-(S3)+1)*((E4)-(S4)+1))
  124. #if 0
  125. #define IMAX(A) (((A)>ids)?(A):ids)
  126. #define IMIN(A) (((A)<ide)?(A):ide)
  127. #define JMAX(A) (((A)>jds)?(A):jds)
  128. #define JMIN(A) (((A)<jde)?(A):jde)
  129. #else
  130. /* allow the extent in other dimension to go into boundary region (e.g. < ids or > ide) since
  131. this will handle corner points for doubly periodic updates (he wrote hopefully) */
  132. #define IMAX(A) (A)
  133. #define IMIN(A) (A)
  134. #define JMAX(A) (A)
  135. #define JMIN(A) (A)
  136. #endif
  137. the_buf = ( pu == 0 ) ? RSL_SENDBUF : RSL_RECVBUF ;
  138. if ( np_x > 1 && xy == 1 ) { /* exchange period in x dim */
  139. MPI_Comm_rank( *comm0, &me ) ;
  140. MPI_Cart_coords( *comm0, me, 2, coords ) ;
  141. MPI_Cart_shift( *comm0, 1, 1, &xm, &xp ) ;
  142. if ( coords[1] == np_x - 1 ) { /* process on right hand edge of domain */
  143. p = buffer_for_proc( xp , 0 , the_buf ) ;
  144. if ( pu == 0 ) {
  145. js = JMAX(jps-shw) ; je = JMIN(jpe+shw) ;
  146. ks = kps ; ke = kpe ;
  147. is = ipe-shw ; ie = ipe-1 ;
  148. nbytes = buffer_size_for_proc( xp , the_buf ) ;
  149. if ( xp_curs + RANGE( JMAX(jps-shw), JMIN(jpe+shw), kps, kpe, ipe-shw, ipe-1, 1, typesize ) > nbytes ) {
  150. #ifndef MS_SUA
  151. fprintf(stderr,"memory overwrite in rsl_lite_pack_period_x, right hand X to %d, %d > %d\n",xp,
  152. xp_curs + RANGE( JMAX(jps-shw), JMIN(jpe+shw), kps, kpe, ipe-shw, ipe-1, 1, typesize ), nbytes ) ;
  153. #endif
  154. MPI_Abort(MPI_COMM_WORLD, 98) ;
  155. }
  156. if ( typesize == 8 ) {
  157. F_PACK_LINT ( buf, p+xp_curs, imemord, &js, &je, &ks, &ke, &is, &ie,
  158. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  159. xp_curs += wcount*typesize ;
  160. } else
  161. if ( typesize == 4 ) {
  162. F_PACK_INT ( buf, p+xp_curs, imemord, &js, &je, &ks, &ke, &is, &ie,
  163. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  164. xp_curs += wcount*typesize ;
  165. }
  166. else {
  167. #ifndef MS_SUA
  168. fprintf(stderr,"internal error: %s %d\n",__FILE__,__LINE__) ;
  169. #endif
  170. }
  171. } else {
  172. js = JMAX(jps-shw) ; je = JMIN(jpe+shw) ;
  173. ks = kps ; ke = kpe ;
  174. is = ipe ; ie = ipe+shw-1+stag ;
  175. if ( typesize == 8 ) {
  176. F_UNPACK_LINT ( p+xp_curs, buf, imemord, &js, &je, &ks, &ke, &is, &ie,
  177. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  178. xp_curs += wcount*typesize ;
  179. } else
  180. if ( typesize == 4 ) {
  181. F_UNPACK_INT ( p+xp_curs, buf, imemord, &js, &je, &ks, &ke, &is, &ie,
  182. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  183. xp_curs += wcount*typesize ;
  184. }
  185. else {
  186. #ifndef MS_SUA
  187. fprintf(stderr,"internal error: %s %d\n",__FILE__,__LINE__) ;
  188. #endif
  189. }
  190. }
  191. }
  192. if ( coords[1] == 0 ) { /* process on left hand edge of domain */
  193. p = buffer_for_proc( xm , 0 , the_buf ) ;
  194. if ( pu == 0 ) {
  195. js = JMAX(jps-shw) ; je = JMIN(jpe+shw) ;
  196. ks = kps ; ke = kpe ;
  197. is = ips ; ie = ips+shw-1+stag ;
  198. nbytes = buffer_size_for_proc( xm , the_buf ) ;
  199. if ( xm_curs + RANGE( JMAX(jps-shw), JMIN(jpe+shw), kps, kpe, ips, ips+shw-1+stag, 1, typesize ) > nbytes ) {
  200. #ifndef MS_SUA
  201. fprintf(stderr,"memory overwrite in rsl_lite_pack_period_x, left hand X to %d , %d > %d\n",xm,
  202. xm_curs + RANGE( JMAX(jps-shw), JMIN(jpe+shw), kps, kpe, ips, ips+shw-1+stag, 1, typesize ), nbytes ) ;
  203. #endif
  204. MPI_Abort(MPI_COMM_WORLD, 98) ;
  205. }
  206. if ( typesize == 8 ) {
  207. F_PACK_LINT ( buf, p+xm_curs, imemord, &js, &je, &ks, &ke, &is, &ie,
  208. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  209. xm_curs += wcount*typesize ;
  210. } else
  211. if ( typesize == 4 ) {
  212. F_PACK_INT ( buf, p+xm_curs, imemord, &js, &je, &ks, &ke, &is, &ie,
  213. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  214. xm_curs += wcount*typesize ;
  215. }
  216. else {
  217. #ifndef MS_SUA
  218. fprintf(stderr,"internal error: %s %d\n",__FILE__,__LINE__) ;
  219. #endif
  220. }
  221. } else {
  222. js = JMAX(jps-shw) ; je = JMIN(jpe+shw) ;
  223. ks = kps ; ke = kpe ;
  224. is = ips-shw ; ie = ips-1 ;
  225. if ( typesize == 8 ) {
  226. F_UNPACK_LINT ( p+xm_curs, buf, imemord, &js, &je, &ks, &ke, &is, &ie,
  227. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  228. xm_curs += wcount*typesize ;
  229. } else
  230. if ( typesize == 4 ) {
  231. F_UNPACK_INT ( p+xm_curs, buf, imemord, &js, &je, &ks, &ke, &is, &ie,
  232. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  233. xm_curs += wcount*typesize ;
  234. }
  235. else {
  236. #ifndef MS_SUA
  237. fprintf(stderr,"internal error: %s %d\n",__FILE__,__LINE__) ;
  238. #endif
  239. }
  240. }
  241. }
  242. }
  243. if ( np_y > 1 && xy == 0 ) { /* exchange period in Y dim */
  244. MPI_Comm_rank( *comm0, &me ) ;
  245. MPI_Cart_coords( *comm0, me, 2, coords ) ;
  246. MPI_Cart_shift( *comm0, 0, 1, &ym, &yp ) ;
  247. if ( coords[0] == np_y - 1 ) { /* process on top edge of domain */
  248. p = buffer_for_proc( yp , 0 , the_buf ) ;
  249. if ( pu == 0 ) {
  250. is = IMAX(ips-shw) ; ie = IMIN(ipe+shw) ;
  251. ks = kps ; ke = kpe ;
  252. js = jpe-shw ; je = jpe-1 ;
  253. nbytes = buffer_size_for_proc( yp , the_buf ) ;
  254. if ( yp_curs + RANGE( IMAX(ips-shw), IMIN(ipe+shw), kps, kpe, jpe-shw, jpe-1, 1, typesize ) > nbytes ) {
  255. #ifndef MS_SUA
  256. fprintf(stderr,"memory overwrite in rsl_lite_pack_period_y, right hand Y to %d, %d > %d\n",yp,
  257. yp_curs + RANGE( IMAX(ips-shw), IMIN(ipe+shw), kps, kpe, jpe-shw, jpe-1, 1, typesize ), nbytes ) ;
  258. #endif
  259. MPI_Abort(MPI_COMM_WORLD, 98) ;
  260. }
  261. if ( typesize == 8 ) {
  262. F_PACK_LINT ( buf, p+yp_curs, imemord, &js, &je, &ks, &ke, &is, &ie,
  263. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  264. yp_curs += wcount*typesize ;
  265. } else
  266. if ( typesize == 4 ) {
  267. F_PACK_INT ( buf, p+yp_curs, imemord, &js, &je, &ks, &ke, &is, &ie,
  268. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  269. yp_curs += wcount*typesize ;
  270. }
  271. else {
  272. #ifndef MS_SUA
  273. fprintf(stderr,"internal error: %s %d\n",__FILE__,__LINE__) ;
  274. #endif
  275. }
  276. } else {
  277. is = IMAX(ips-shw) ; ie = IMIN(ipe+shw) ;
  278. ks = kps ; ke = kpe ;
  279. js = jpe ; je = jpe+shw-1+stag ;
  280. if ( typesize == 8 ) {
  281. F_UNPACK_LINT ( p+yp_curs, buf, imemord, &js, &je, &ks, &ke, &is, &ie,
  282. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  283. yp_curs += wcount*typesize ;
  284. } else
  285. if ( typesize == 4 ) {
  286. F_UNPACK_INT ( p+yp_curs, buf, imemord, &js, &je, &ks, &ke, &is, &ie,
  287. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  288. yp_curs += wcount*typesize ;
  289. }
  290. else {
  291. #ifndef MS_SUA
  292. fprintf(stderr,"internal error: %s %d\n",__FILE__,__LINE__) ;
  293. #endif
  294. }
  295. }
  296. }
  297. if ( coords[0] == 0 ) { /* process on bottom edge of domain */
  298. p = buffer_for_proc( ym , 0 , the_buf ) ;
  299. if ( pu == 0 ) {
  300. is = IMAX(ips-shw) ; ie = IMIN(ipe+shw) ;
  301. ks = kps ; ke = kpe ;
  302. js = jps ; je = jps+shw-1+stag ;
  303. nbytes = buffer_size_for_proc( ym , the_buf ) ;
  304. if ( ym_curs + RANGE( IMAX(ips-shw), IMIN(ipe+shw), kps, kpe, jps, jps+shw-1+stag, 1, typesize ) > nbytes ) {
  305. #ifndef MS_SUA
  306. fprintf(stderr,"memory overwrite in rsl_lite_pack_period_y, left hand Y to %d , %d > %d\n",xm,
  307. ym_curs + RANGE( IMAX(ips-shw), IMIN(ipe+shw), kps, kpe, jps, jps+shw-1+stag, 1, typesize ), nbytes ) ;
  308. #endif
  309. MPI_Abort(MPI_COMM_WORLD, 98) ;
  310. }
  311. if ( typesize == 8 ) {
  312. F_PACK_LINT ( buf, p+ym_curs, imemord, &js, &je, &ks, &ke, &is, &ie,
  313. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  314. ym_curs += wcount*typesize ;
  315. } else
  316. if ( typesize == 4 ) {
  317. F_PACK_INT ( buf, p+ym_curs, imemord, &js, &je, &ks, &ke, &is, &ie,
  318. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  319. ym_curs += wcount*typesize ;
  320. }
  321. else {
  322. #ifndef MS_SUA
  323. fprintf(stderr,"internal error: %s %d\n",__FILE__,__LINE__) ;
  324. #endif
  325. }
  326. } else {
  327. is = IMAX(ips-shw) ; ie = IMIN(ipe+shw) ;
  328. ks = kps ; ke = kpe ;
  329. js = jps-shw ; je = jps-1 ;
  330. if ( typesize == 8 ) {
  331. F_UNPACK_LINT ( p+ym_curs, buf, imemord, &js, &je, &ks, &ke, &is, &ie,
  332. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  333. ym_curs += wcount*typesize ;
  334. } else
  335. if ( typesize == 4 ) {
  336. F_UNPACK_INT ( p+ym_curs, buf, imemord, &js, &je, &ks, &ke, &is, &ie,
  337. &jms,&jme,&kms,&kme,&ims,&ime, &wcount ) ;
  338. ym_curs += wcount*typesize ;
  339. }
  340. else {
  341. #ifndef MS_SUA
  342. fprintf(stderr,"internal error: %s %d\n",__FILE__,__LINE__) ;
  343. #endif
  344. }
  345. }
  346. }
  347. }
  348. #endif
  349. }
  350. #ifndef STUBMPI
  351. static MPI_Request yp_recv, ym_recv, yp_send, ym_send ;
  352. static MPI_Request xp_recv, xm_recv, xp_send, xm_send ;
  353. #endif
  354. RSL_LITE_EXCH_PERIOD_X ( int * Fcomm0, int *me0, int * np0 , int * np_x0 , int * np_y0 )
  355. {
  356. #ifndef STUBMPI
  357. int me, np, np_x, np_y ;
  358. int yp, ym, xp, xm, nbytes ;
  359. MPI_Status stat ;
  360. MPI_Comm comm, *comm0, dummy_comm ;
  361. int coords[2] ;
  362. comm0 = &dummy_comm ;
  363. *comm0 = MPI_Comm_f2c( *Fcomm0 ) ;
  364. #if 1
  365. comm = *comm0 ; me = *me0 ; np = *np0 ; np_x = *np_x0 ; np_y = *np_y0 ;
  366. if ( np_x > 1 ) {
  367. MPI_Comm_rank( *comm0, &me ) ;
  368. MPI_Cart_coords( *comm0, me, 2, coords ) ;
  369. MPI_Cart_shift( *comm0, 1, 1, &xm, &xp ) ;
  370. if ( coords[1] == np_x - 1 ) { /* proc on right hand side of domain */
  371. nbytes = buffer_size_for_proc( xp, RSL_RECVBUF ) ;
  372. MPI_Irecv ( buffer_for_proc( xp , xp_curs, RSL_RECVBUF ), nbytes, MPI_CHAR, xp, me, comm, &xp_recv ) ;
  373. }
  374. if ( coords[1] == 0 ) { /* proc on left hand side of domain */
  375. nbytes = buffer_size_for_proc( xm, RSL_RECVBUF ) ;
  376. MPI_Irecv ( buffer_for_proc( xm, xm_curs, RSL_RECVBUF ), nbytes, MPI_CHAR, xm, me, comm, &xm_recv ) ;
  377. }
  378. if ( coords[1] == np_x - 1 ) { /* proc on right hand side of domain */
  379. MPI_Isend ( buffer_for_proc( xp , 0, RSL_SENDBUF ), xp_curs, MPI_CHAR, xp, xp, comm, &xp_send ) ;
  380. }
  381. if ( coords[1] == 0 ) { /* proc on left hand side of domain */
  382. MPI_Isend ( buffer_for_proc( xm, 0, RSL_SENDBUF ), xm_curs, MPI_CHAR, xm, xm, comm, &xm_send ) ;
  383. }
  384. if ( coords[1] == np_x - 1 ) MPI_Wait( &xp_recv, &stat ) ;
  385. if ( coords[1] == 0 ) MPI_Wait( &xm_recv, &stat ) ;
  386. if ( coords[1] == np_x - 1 ) MPI_Wait( &xp_send, &stat ) ;
  387. if ( coords[1] == 0 ) MPI_Wait( &xm_send, &stat ) ;
  388. }
  389. #else
  390. # ifndef MS_SUA
  391. fprintf(stderr,"RSL_LITE_EXCH_PERIOD_X disabled\n") ;
  392. # endif
  393. #endif
  394. yp_curs = 0 ; ym_curs = 0 ; xp_curs = 0 ; xm_curs = 0 ;
  395. #endif
  396. }
  397. RSL_LITE_EXCH_PERIOD_Y ( int * Fcomm0, int *me0, int * np0 , int * np_x0 , int * np_y0 )
  398. {
  399. #ifndef STUBMPI
  400. int me, np, np_x, np_y ;
  401. int yp, ym, xp, xm, nbytes ;
  402. MPI_Status stat ;
  403. MPI_Comm comm, *comm0, dummy_comm ;
  404. int coords[2] ;
  405. comm0 = &dummy_comm ;
  406. *comm0 = MPI_Comm_f2c( *Fcomm0 ) ;
  407. #if 1
  408. comm = *comm0 ; me = *me0 ; np = *np0 ; np_x = *np_x0 ; np_y = *np_y0 ;
  409. if ( np_y > 1 ) {
  410. MPI_Comm_rank( *comm0, &me ) ;
  411. MPI_Cart_coords( *comm0, me, 2, coords ) ;
  412. MPI_Cart_shift( *comm0, 0, 1, &ym, &yp ) ;
  413. if ( coords[0] == np_y - 1 ) { /* proc on top of domain */
  414. nbytes = buffer_size_for_proc( yp, RSL_RECVBUF ) ;
  415. MPI_Irecv ( buffer_for_proc( yp , yp_curs, RSL_RECVBUF ), nbytes, MPI_CHAR, yp, me, comm, &yp_recv ) ;
  416. }
  417. if ( coords[0] == 0 ) { /* proc on bottom of domain */
  418. nbytes = buffer_size_for_proc( ym, RSL_RECVBUF ) ;
  419. MPI_Irecv ( buffer_for_proc( ym, ym_curs, RSL_RECVBUF ), nbytes, MPI_CHAR, ym, me, comm, &ym_recv ) ;
  420. }
  421. if ( coords[0] == np_y - 1 ) { /* proc on top of domain */
  422. MPI_Isend ( buffer_for_proc( yp , 0, RSL_SENDBUF ), yp_curs, MPI_CHAR, yp, yp, comm, &yp_send ) ;
  423. }
  424. if ( coords[0] == 0 ) { /* proc on bottom of domain */
  425. MPI_Isend ( buffer_for_proc( ym, 0, RSL_SENDBUF ), ym_curs, MPI_CHAR, ym, ym, comm, &ym_send ) ;
  426. }
  427. if ( coords[0] == np_y - 1 ) MPI_Wait( &yp_recv, &stat ) ;
  428. if ( coords[0] == 0 ) MPI_Wait( &ym_recv, &stat ) ;
  429. if ( coords[0] == np_y - 1 ) MPI_Wait( &yp_send, &stat ) ;
  430. if ( coords[0] == 0 ) MPI_Wait( &ym_send, &stat ) ;
  431. }
  432. #else
  433. # ifndef MS_SUA
  434. fprintf(stderr,"RSL_LITE_EXCH_PERIOD_Y disabled\n") ;
  435. # endif
  436. #endif
  437. yp_curs = 0 ; ym_curs = 0 ; xp_curs = 0 ; xm_curs = 0 ;
  438. #endif
  439. }