PageRenderTime 45ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/wrfv2_fire/external/RSL_LITE/rsl_bcast.c

http://github.com/jbeezley/wrf-fire
C | 686 lines | 510 code | 85 blank | 91 comment | 70 complexity | 30243e2a0a4c6ef76c2fc1fdd11e6783 MD5 | raw file
Possible License(s): AGPL-1.0
  1. /* #define LEARN_BCAST */
  2. /***********************************************************************
  3. COPYRIGHT
  4. The following is a notice of limited availability of the code and
  5. Government license and disclaimer which must be included in the
  6. prologue of the code and in all source listings of the code.
  7. Copyright notice
  8. (c) 1977 University of Chicago
  9. Permission is hereby granted to use, reproduce, prepare
  10. derivative works, and to redistribute to others at no charge. If
  11. you distribute a copy or copies of the Software, or you modify a
  12. copy or copies of the Software or any portion of it, thus forming
  13. a work based on the Software and make and/or distribute copies of
  14. such work, you must meet the following conditions:
  15. a) If you make a copy of the Software (modified or verbatim)
  16. it must include the copyright notice and Government
  17. license and disclaimer.
  18. b) You must cause the modified Software to carry prominent
  19. notices stating that you changed specified portions of
  20. the Software.
  21. This software was authored by:
  22. Argonne National Laboratory
  23. J. Michalakes: (630) 252-6646; email: michalak@mcs.anl.gov
  24. Mathematics and Computer Science Division
  25. Argonne National Laboratory, Argonne, IL 60439
  26. ARGONNE NATIONAL LABORATORY (ANL), WITH FACILITIES IN THE STATES
  27. OF ILLINOIS AND IDAHO, IS OWNED BY THE UNITED STATES GOVERNMENT,
  28. AND OPERATED BY THE UNIVERSITY OF CHICAGO UNDER PROVISION OF A
  29. CONTRACT WITH THE DEPARTMENT OF ENERGY.
  30. GOVERNMENT LICENSE AND DISCLAIMER
  31. This computer code material was prepared, in part, as an account
  32. of work sponsored by an agency of the United States Government.
  33. The Government is granted for itself and others acting on its
  34. behalf a paid-up, nonexclusive, irrevocable worldwide license in
  35. this data to reproduce, prepare derivative works, distribute
  36. copies to the public, perform publicly and display publicly, and
  37. to permit others to do so. NEITHER THE UNITED STATES GOVERNMENT
  38. NOR ANY AGENCY THEREOF, NOR THE UNIVERSITY OF CHICAGO, NOR ANY OF
  39. THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
  40. ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
  41. COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS,
  42. PRODUCT, OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD
  43. NOT INFRINGE PRIVATELY OWNED RIGHTS.
  44. ***************************************************************************/
  45. #define MOD_9707
  46. #ifndef MS_SUA
  47. # include <stdio.h>
  48. #endif
  49. #include <stdlib.h>
  50. #ifndef STUBMPI
  51. # include "mpi.h"
  52. #endif
  53. #include "rsl_lite.h"
  54. typedef struct bcast_point_desc {
  55. int ig ;
  56. int jg ;
  57. } bcast_point_desc_t ;
  58. static destroy_par_info ( p )
  59. char * p ;
  60. {
  61. if ( p != NULL ) RSL_FREE( p ) ;
  62. }
  63. static rsl_list_t *Xlist, *Xp, *Xprev ;
  64. static rsl_list_t *stage ;
  65. static int stage_len = 0 ; /* 96/3/15 */
  66. static int Sendbufsize ;
  67. static int Sendbufcurs ;
  68. static char *Sendbuf ;
  69. static int Sdisplacements[RSL_MAXPROC] ;
  70. static int Ssizes[RSL_MAXPROC] ;
  71. static int Recsizeindex ;
  72. static int Rbufsize ;
  73. static int Rbufcurs ;
  74. static int Rpointcurs ;
  75. static char *Recvbuf ;
  76. static int Rdisplacements[RSL_MAXPROC+1] ;
  77. static int Rsizes[RSL_MAXPROC] ;
  78. static int Rreclen ;
  79. static int s_d ;
  80. static int s_nst ;
  81. static int s_msize ;
  82. static int s_idim ;
  83. static int s_jdim ;
  84. static int s_idim_nst ;
  85. static int s_jdim_nst ;
  86. static int s_irax_n ;
  87. static int s_irax_m ;
  88. static int s_ntasks_x ;
  89. static int s_ntasks_y ;
  90. static rsl_list_t **Plist ;
  91. static int Psize[RSL_MAXPROC] ;
  92. static char *s_parent_msgs ;
  93. static int s_parent_msgs_curs ;
  94. static int s_remaining ; /* number of bytes left in a parent message before
  95. the next point descriptor */
  96. /* add a field to a message outgoing for the specified child domain cell */
  97. /* relies on rsl_ready_bcast having been called already */
  98. /* sends are specified in terms of coarse domain */
  99. static int s_i, s_j, s_ig, s_jg, s_cm, s_cn,
  100. s_nig, s_njg ;
  101. static int Pcurs ;
  102. static rsl_list_t *Pptr ;
  103. #ifdef LEARN_BCAST
  104. static int s_putmsg = 0 ;
  105. #endif
  106. /* parent->nest */
  107. RSL_LITE_TO_CHILD_INFO ( Fcomm, msize_p,
  108. cips_p, cipe_p, cjps_p, cjpe_p, /* patch dims of SOURCE DOMAIN */
  109. iids_p, iide_p, ijds_p, ijde_p, /* domain dims of INTERMEDIATE DOMAIN */
  110. nids_p, nide_p, njds_p, njde_p, /* domain dims of CHILD DOMAIN */
  111. pgr_p, shw_p , /* nest ratio and stencil half width */
  112. ntasks_x_p , ntasks_y_p , /* proc counts in x and y */
  113. min_subdomain , /* minimum width allowed for a subdomain in a dim ON PARENT */
  114. icoord_p, jcoord_p,
  115. idim_cd_p, jdim_cd_p,
  116. ig_p, jg_p,
  117. retval_p )
  118. int_p
  119. Fcomm /* Fortran version of MPI communicator */
  120. ,cips_p, cipe_p, cjps_p, cjpe_p /* (i) c.d. patch dims */
  121. ,iids_p, iide_p, ijds_p, ijde_p /* (i) n.n. global dims */
  122. ,nids_p, nide_p, njds_p, njde_p /* (i) n.n. global dims */
  123. ,pgr_p /* nesting ratio */
  124. ,ntasks_x_p , ntasks_y_p /* proc counts in x and y */
  125. ,min_subdomain
  126. ,icoord_p /* i coordinate of nest in cd */
  127. ,jcoord_p /* j coordinate of nest in cd */
  128. ,shw_p /* stencil half width */
  129. ,idim_cd_p /* i width of nest in cd */
  130. ,jdim_cd_p /* j width of nest in cd */
  131. ,msize_p /* (I) Message size in bytes. */
  132. ,ig_p /* (O) Global N index of parent domain point. */
  133. ,jg_p /* (O) Global N index of parent domain point. */
  134. ,retval_p ; /* (O) =1 if a valid point returned; =0 (zero) otherwise. */
  135. {
  136. int P, Px, Py ;
  137. rsl_list_t *q ;
  138. int *r ;
  139. int i, j, ni, nj ;
  140. int coords[2] ;
  141. int ierr ;
  142. #ifndef STUBMPI
  143. MPI_Comm *comm, dummy_comm ;
  144. comm = &dummy_comm ;
  145. *comm = MPI_Comm_f2c( *Fcomm ) ;
  146. #endif
  147. if ( Plist == NULL ) {
  148. s_ntasks_x = *ntasks_x_p ;
  149. s_ntasks_y = *ntasks_y_p ;
  150. /* construct Plist */
  151. Sendbufsize = 0 ;
  152. Plist = RSL_MALLOC( rsl_list_t * , s_ntasks_x * s_ntasks_y ) ; /* big enough for nest points */
  153. for ( j = 0 ; j < s_ntasks_x * s_ntasks_y ; j++ ) {
  154. Plist[j] = NULL ;
  155. Sdisplacements[j] = 0 ;
  156. Ssizes[j] = 0 ;
  157. }
  158. ierr = 0 ;
  159. for ( j = *cjps_p ; j <= *cjpe_p ; j++ )
  160. {
  161. for ( i = *cips_p ; i <= *cipe_p ; i++ )
  162. {
  163. if ( ( *jcoord_p <= j && j <= *jcoord_p+*jdim_cd_p-1 ) && ( *icoord_p <= i && i <= *icoord_p+*idim_cd_p-1 ) ) {
  164. ni = ( i - (*icoord_p + *shw_p) ) * *pgr_p + 1 + 1 ; /* add 1 to give center point */
  165. nj = ( j - (*jcoord_p + *shw_p) ) * *pgr_p + 1 + 1 ;
  166. #ifndef STUBMPI
  167. TASK_FOR_POINT ( &ni, &nj, nids_p, nide_p, njds_p, njde_p, &s_ntasks_x, &s_ntasks_y, &Px, &Py,
  168. min_subdomain, min_subdomain, &ierr ) ;
  169. coords[1] = Px ; coords[0] = Py ;
  170. MPI_Cart_rank( *comm, coords, &P ) ;
  171. #else
  172. P = 0 ;
  173. #endif
  174. q = RSL_MALLOC( rsl_list_t , 1 ) ;
  175. q->info1 = i ;
  176. q->info2 = j ;
  177. q->next = Plist[P] ;
  178. Plist[P] = q ;
  179. Sendbufsize += *msize_p + 3 * sizeof( int ) ; /* point data plus 3 ints for i, j, and size */
  180. }
  181. }
  182. }
  183. if ( ierr != 0 ) {
  184. fprintf(stderr,"rsl_to_child_info: ") ;
  185. TASK_FOR_POINT_MESSAGE () ;
  186. }
  187. Sendbuf = RSL_MALLOC( char , Sendbufsize ) ;
  188. Sendbufcurs = 0 ;
  189. Recsizeindex = -1 ;
  190. Pcurs = -1 ;
  191. Pptr = NULL ;
  192. }
  193. if ( Pptr != NULL ) {
  194. Pptr = Pptr->next ;
  195. }
  196. if ( Recsizeindex >= 0 ) {
  197. r = (int *) &(Sendbuf[Recsizeindex]) ;
  198. *r = Sendbufcurs - Recsizeindex + 2 * sizeof(int) ;
  199. Ssizes[Pcurs] += *r ;
  200. }
  201. while ( Pptr == NULL ) {
  202. Pcurs++ ;
  203. while ( Pcurs < s_ntasks_x * s_ntasks_y && Plist[Pcurs] == NULL ) Pcurs++ ;
  204. if ( Pcurs < s_ntasks_x * s_ntasks_y ) {
  205. Sdisplacements[Pcurs] = Sendbufcurs ;
  206. Ssizes[Pcurs] = 0 ;
  207. Pptr = Plist[Pcurs] ;
  208. } else {
  209. *retval_p = 0 ;
  210. return ; /* done */
  211. }
  212. }
  213. *ig_p = Pptr->info1 ;
  214. *jg_p = Pptr->info2 ;
  215. r = (int *) &(Sendbuf[Sendbufcurs]) ;
  216. *r++ = Pptr->info1 ; Sendbufcurs += sizeof(int) ; /* ig to buffer */
  217. *r++ = Pptr->info2 ; Sendbufcurs += sizeof(int) ; /* jg to buffer */
  218. Recsizeindex = Sendbufcurs ;
  219. *r++ = 0 ; Sendbufcurs += sizeof(int) ; /* store start for size */
  220. *retval_p = 1 ;
  221. return ;
  222. }
  223. /********************************************/
  224. /* nest->parent */
  225. RSL_LITE_TO_PARENT_INFO ( Fcomm, msize_p,
  226. nips_p, nipe_p, njps_p, njpe_p, /* patch dims of SOURCE DOMAIN (CHILD) */
  227. cids_p, cide_p, cjds_p, cjde_p, /* domain dims of TARGET DOMAIN (PARENT) */
  228. ntasks_x_p , ntasks_y_p , /* proc counts in x and y */
  229. min_subdomain ,
  230. icoord_p, jcoord_p,
  231. idim_cd_p, jdim_cd_p,
  232. ig_p, jg_p,
  233. retval_p )
  234. int_p
  235. Fcomm /* Fortran version of MPI communicator */
  236. ,nips_p, nipe_p, njps_p, njpe_p /* (i) n.d. patch dims */
  237. ,cids_p, cide_p, cjds_p, cjde_p /* (i) n.n. global dims */
  238. ,ntasks_x_p , ntasks_y_p /* proc counts in x and y */
  239. ,min_subdomain
  240. ,icoord_p /* i coordinate of nest in cd */
  241. ,jcoord_p /* j coordinate of nest in cd */
  242. ,idim_cd_p /* i width of nest in cd */
  243. ,jdim_cd_p /* j width of nest in cd */
  244. ,msize_p /* (I) Message size in bytes. */
  245. ,ig_p /* (O) Global N index of parent domain point. */
  246. ,jg_p /* (O) Global N index of parent domain point. */
  247. ,retval_p ; /* (O) =1 if a valid point returned; =0 (zero) otherwise. */
  248. {
  249. int P, Px, Py ;
  250. rsl_list_t *q ;
  251. int *r ;
  252. int i, j ;
  253. int coords[2] ;
  254. int ierr ;
  255. #ifndef STUBMPI
  256. MPI_Comm *comm, dummy_comm ;
  257. comm = &dummy_comm ;
  258. *comm = MPI_Comm_f2c( *Fcomm ) ;
  259. #endif
  260. if ( Plist == NULL ) {
  261. s_ntasks_x = *ntasks_x_p ;
  262. s_ntasks_y = *ntasks_y_p ;
  263. /* construct Plist */
  264. Sendbufsize = 0 ;
  265. Plist = RSL_MALLOC( rsl_list_t * , s_ntasks_x * s_ntasks_y ) ;
  266. for ( j = 0 ; j < s_ntasks_x * s_ntasks_y ; j++ ) {
  267. Plist[j] = NULL ;
  268. Sdisplacements[j] = 0 ;
  269. Ssizes[j] = 0 ;
  270. }
  271. ierr = 0 ;
  272. for ( j = *njps_p ; j <= *njpe_p ; j++ )
  273. {
  274. for ( i = *nips_p ; i <= *nipe_p ; i++ )
  275. {
  276. if ( ( *jcoord_p <= j && j <= *jcoord_p+*jdim_cd_p-1 ) && ( *icoord_p <= i && i <= *icoord_p+*idim_cd_p-1 ) ) {
  277. #ifndef STUBMPI
  278. TASK_FOR_POINT ( &i, &j, cids_p, cide_p, cjds_p, cjde_p, &s_ntasks_x, &s_ntasks_y, &Px, &Py,
  279. min_subdomain, min_subdomain, &ierr ) ;
  280. coords[1] = Px ; coords[0] = Py ;
  281. MPI_Cart_rank( *comm, coords, &P ) ;
  282. #else
  283. P = 0 ;
  284. #endif
  285. q = RSL_MALLOC( rsl_list_t , 1 ) ;
  286. q->info1 = i ;
  287. q->info2 = j ;
  288. q->next = Plist[P] ;
  289. Plist[P] = q ;
  290. Sendbufsize += *msize_p + 3 * sizeof( int ) ; /* point data plus 3 ints for i, j, and size */
  291. }
  292. }
  293. }
  294. if ( ierr != 0 ) {
  295. fprintf(stderr,"rsl_to_parent_info: ") ;
  296. TASK_FOR_POINT_MESSAGE () ;
  297. }
  298. Sendbuf = RSL_MALLOC( char , Sendbufsize ) ;
  299. Sendbufcurs = 0 ;
  300. Recsizeindex = -1 ;
  301. Pcurs = -1 ;
  302. Pptr = NULL ;
  303. }
  304. if ( Pptr != NULL ) {
  305. Pptr = Pptr->next ;
  306. }
  307. if ( Recsizeindex >= 0 ) {
  308. r = (int *) &(Sendbuf[Recsizeindex]) ;
  309. *r = Sendbufcurs - Recsizeindex + 2 * sizeof(int) ;
  310. Ssizes[Pcurs] += *r ;
  311. }
  312. while ( Pptr == NULL ) {
  313. Pcurs++ ;
  314. while ( Pcurs < s_ntasks_x * s_ntasks_y && Plist[Pcurs] == NULL ) Pcurs++ ;
  315. if ( Pcurs < s_ntasks_x * s_ntasks_y ) {
  316. Sdisplacements[Pcurs] = Sendbufcurs ;
  317. Ssizes[Pcurs] = 0 ;
  318. Pptr = Plist[Pcurs] ;
  319. } else {
  320. *retval_p = 0 ;
  321. return ; /* done */
  322. }
  323. }
  324. *ig_p = Pptr->info1 ;
  325. *jg_p = Pptr->info2 ;
  326. r = (int *) &(Sendbuf[Sendbufcurs]) ;
  327. *r++ = Pptr->info1 ; Sendbufcurs += sizeof(int) ; /* ig to buffer */
  328. *r++ = Pptr->info2 ; Sendbufcurs += sizeof(int) ; /* jg to buffer */
  329. Recsizeindex = Sendbufcurs ;
  330. *r++ = 0 ; Sendbufcurs += sizeof(int) ; /* store start for size */
  331. *retval_p = 1 ;
  332. return ;
  333. }
  334. /********************************************/
  335. /*@
  336. RSL_TO_CHILD_MSG -- Pack force data into a message for a nest point.
  337. @*/
  338. /* parent->nest */
  339. RSL_LITE_TO_CHILD_MSG ( nbuf_p, buf )
  340. int_p
  341. nbuf_p ; /* (I) Number of bytes to be packed. */
  342. char *
  343. buf ; /* (I) Buffer containing the data to be packed. */
  344. {
  345. rsl_lite_to_peerpoint_msg ( nbuf_p, buf ) ;
  346. }
  347. /* nest->parent */
  348. RSL_LITE_TO_PARENT_MSG ( nbuf_p, buf )
  349. int_p
  350. nbuf_p ; /* (I) Number of bytes to be packed. */
  351. char *
  352. buf ; /* (I) Buffer containing the data to be packed. */
  353. {
  354. rsl_lite_to_peerpoint_msg ( nbuf_p, buf ) ;
  355. }
  356. /* common code */
  357. rsl_lite_to_peerpoint_msg ( nbuf_p, buf )
  358. int_p
  359. nbuf_p ; /* (I) Number of bytes to be packed. */
  360. char *
  361. buf ; /* (I) Buffer containing the data to be packed. */
  362. {
  363. int nbuf ;
  364. int *p, *q ;
  365. char *c, *d ;
  366. int i ;
  367. char mess[4096] ;
  368. RSL_TEST_ERR(buf==NULL,"2nd argument is NULL. Field allocated?") ;
  369. nbuf = *nbuf_p ;
  370. if ( Sendbufcurs + nbuf >= Sendbufsize ) {
  371. sprintf(mess,"RSL_LITE_TO_CHILD_MSG: Sendbufcurs + nbuf (%d) would exceed Sendbufsize (%d)\n",
  372. Sendbufcurs + nbuf , Sendbufsize ) ;
  373. RSL_TEST_ERR(1,mess) ;
  374. }
  375. if ( nbuf % sizeof(int) == 0 ) {
  376. for ( p = (int *)buf, q = (int *) &(Sendbuf[Sendbufcurs]), i = 0 ; i < nbuf ; i += sizeof(int) )
  377. {
  378. *q++ = *p++ ;
  379. }
  380. }
  381. else
  382. {
  383. for ( c = buf, d = &(Sendbuf[Sendbufcurs]), i = 0 ; i < nbuf ; i++ )
  384. {
  385. *d++ = *c++ ;
  386. }
  387. }
  388. Sendbufcurs += nbuf ;
  389. }
  390. /********************************************/
  391. /* parent->nest */
  392. RSL_LITE_BCAST_MSGS ( mytask_p, ntasks_p, Fcomm )
  393. int_p mytask_p, ntasks_p, Fcomm ;
  394. {
  395. #ifndef STUBMPI
  396. MPI_Comm comm ;
  397. comm = MPI_Comm_f2c( *Fcomm ) ;
  398. #else
  399. int comm ;
  400. #endif
  401. rsl_lite_allgather_msgs ( mytask_p, ntasks_p, comm ) ;
  402. }
  403. /* nest->parent */
  404. RSL_LITE_MERGE_MSGS ( mytask_p, ntasks_p, Fcomm )
  405. int_p mytask_p, ntasks_p, Fcomm ;
  406. {
  407. #ifndef STUBMPI
  408. MPI_Comm comm ;
  409. comm = MPI_Comm_f2c( *Fcomm ) ;
  410. #else
  411. int comm ;
  412. #endif
  413. rsl_lite_allgather_msgs ( mytask_p, ntasks_p, comm ) ;
  414. }
  415. /* common code */
  416. rsl_lite_allgather_msgs ( mytask_p, ntasks_p, comm )
  417. int_p mytask_p, ntasks_p ;
  418. #ifndef STUBMPI
  419. MPI_Comm comm ;
  420. #else
  421. int comm ;
  422. #endif
  423. {
  424. int P ;
  425. char *work ;
  426. int * r ;
  427. bcast_point_desc_t pdesc ;
  428. int curs ;
  429. int msglen, mdest, mtag ;
  430. int ntasks, mytask ;
  431. int ii, i, j ;
  432. int ig, jg ;
  433. int *Psize_all ;
  434. int *sp, *bp ;
  435. int rc ;
  436. #ifndef STUBMPI
  437. ntasks = *ntasks_p ;
  438. mytask = *mytask_p ;
  439. #else
  440. ntasks = 1 ;
  441. mytask = 0 ;
  442. #endif
  443. RSL_TEST_ERR( Plist == NULL,
  444. "RSL_BCAST_MSGS: rsl_to_child_info not called first" ) ;
  445. RSL_TEST_ERR( ntasks == RSL_MAXPROC ,
  446. "RSL_BCAST_MSGS: raise the compile time value of MAXPROC" ) ;
  447. Psize_all = RSL_MALLOC( int, ntasks * ntasks ) ;
  448. #ifndef STUBMPI
  449. MPI_Allgather( Ssizes, ntasks, MPI_INT , Psize_all, ntasks, MPI_INT, comm ) ;
  450. #else
  451. Psize_all[0] = Ssizes[0] ;
  452. #endif
  453. for ( j = 0 ; j < ntasks ; j++ )
  454. Rsizes[j] = 0 ;
  455. for ( j = 0 ; j < ntasks ; j++ )
  456. {
  457. Rsizes[j] += Psize_all[ INDEX_2( j , mytask , ntasks ) ] ;
  458. }
  459. for ( Rbufsize = 0, P = 0, Rdisplacements[0] = 0 ; P < ntasks ; P++ )
  460. {
  461. Rdisplacements[P+1] = Rsizes[P] + Rdisplacements[P] ;
  462. Rbufsize += Rsizes[P] ;
  463. }
  464. /* this will be freed later */
  465. Recvbuf = RSL_MALLOC( char , Rbufsize + 3 * sizeof(int) ) ; /* for sentinal record */
  466. Rbufcurs = 0 ;
  467. Rreclen = 0 ;
  468. #ifndef STUBMPI
  469. rc = MPI_Alltoallv ( Sendbuf, Ssizes, Sdisplacements, MPI_BYTE ,
  470. Recvbuf, Rsizes, Rdisplacements, MPI_BYTE , comm ) ;
  471. #else
  472. work = Sendbuf ;
  473. Sendbuf = Recvbuf ;
  474. Recvbuf = work ;
  475. #endif
  476. /* add sentinel to the end of Recvbuf */
  477. r = (int *)&(Recvbuf[Rbufsize + 2 * sizeof(int)]) ;
  478. *r = RSL_INVALID ;
  479. RSL_FREE( Sendbuf ) ;
  480. RSL_FREE( Psize_all ) ;
  481. for ( j = 0 ; j < *ntasks_p ; j++ ) {
  482. destroy_list ( &(Plist[j]), NULL ) ;
  483. }
  484. RSL_FREE( Plist ) ;
  485. Plist = NULL ;
  486. }
  487. /********************************************/
  488. /* parent->nest */
  489. RSL_LITE_FROM_PARENT_INFO ( ig_p, jg_p, retval_p )
  490. int_p
  491. ig_p /* (O) Global index in M dimension of nest. */
  492. ,jg_p /* (O) Global index in N dimension of nest. */
  493. ,retval_p ; /* (O) Return value; =1 valid point, =0 done. */
  494. {
  495. rsl_lite_from_peerpoint_info ( ig_p, jg_p, retval_p ) ;
  496. }
  497. /* nest->parent */
  498. RSL_LITE_FROM_CHILD_INFO ( ig_p, jg_p, retval_p )
  499. int_p
  500. ig_p /* (O) Global index in M dimension of nest. */
  501. ,jg_p /* (O) Global index in N dimension of nest. */
  502. ,retval_p ; /* (O) Return value; =1 valid point, =0 done. */
  503. {
  504. rsl_lite_from_peerpoint_info ( ig_p, jg_p, retval_p ) ;
  505. }
  506. /* common code */
  507. rsl_lite_from_peerpoint_info ( ig_p, jg_p, retval_p )
  508. int_p
  509. ig_p /* (O) Global index in M dimension of nest. */
  510. ,jg_p /* (O) Global index in N dimension of nest. */
  511. ,retval_p ; /* (O) Return value; =1 valid point, =0 done. */
  512. {
  513. int ii ;
  514. Rbufcurs = Rbufcurs + Rreclen ;
  515. Rpointcurs = 0 ;
  516. *ig_p = *(int *)&( Recvbuf[Rbufcurs + Rpointcurs ] ) ; Rpointcurs += sizeof(int) ;
  517. *jg_p = *(int *)&( Recvbuf[Rbufcurs + Rpointcurs ] ) ; Rpointcurs += sizeof(int) ;
  518. /* read sentinel */
  519. Rreclen = *(int *)&( Recvbuf[Rbufcurs + Rpointcurs ] ) ; Rpointcurs += sizeof(int) ;
  520. *retval_p = 1 ;
  521. if ( Rreclen == RSL_INVALID ) {
  522. *retval_p = 0 ;
  523. RSL_FREE( Recvbuf ) ;
  524. }
  525. return ;
  526. }
  527. /********************************************/
  528. /* parent->nest */
  529. RSL_LITE_FROM_PARENT_MSG ( len_p, buf )
  530. int_p
  531. len_p ; /* (I) Number of bytes to unpack. */
  532. int *
  533. buf ; /* (O) Destination buffer. */
  534. {
  535. rsl_lite_from_peerpoint_msg ( len_p, buf ) ;
  536. }
  537. /* nest->parent */
  538. RSL_LITE_FROM_CHILD_MSG ( len_p, buf )
  539. int_p
  540. len_p ; /* (I) Number of bytes to unpack. */
  541. int *
  542. buf ; /* (O) Destination buffer. */
  543. {
  544. rsl_lite_from_peerpoint_msg ( len_p, buf ) ;
  545. }
  546. /* common code */
  547. rsl_lite_from_peerpoint_msg ( len_p, buf )
  548. int_p
  549. len_p ; /* (I) Number of bytes to unpack. */
  550. int *
  551. buf ; /* (O) Destination buffer. */
  552. {
  553. int *p, *q ;
  554. char *c, *d ;
  555. int i ;
  556. if ( *len_p % sizeof(int) == 0 ) {
  557. for ( p = (int *)&(Recvbuf[Rbufcurs+Rpointcurs]), q = buf , i = 0 ; i < *len_p ; i += sizeof(int) )
  558. {
  559. *q++ = *p++ ;
  560. }
  561. } else {
  562. for ( c = &(Recvbuf[Rbufcurs+Rpointcurs]), d = (char *) buf , i = 0 ; i < *len_p ; i++ )
  563. {
  564. *d++ = *c++ ;
  565. }
  566. }
  567. Rpointcurs += *len_p ;
  568. }
  569. /********************************************/
  570. destroy_list( list, dfcn )
  571. rsl_list_t ** list ; /* pointer to pointer to list */
  572. int (*dfcn)() ; /* pointer to function for destroying
  573. the data field of the list */
  574. {
  575. rsl_list_t *p, *trash ;
  576. if ( list == NULL ) return(0) ;
  577. if ( *list == NULL ) return(0) ;
  578. for ( p = *list ; p != NULL ; )
  579. {
  580. if ( dfcn != NULL ) (*dfcn)( p->data ) ;
  581. trash = p ;
  582. p = p->next ;
  583. RSL_FREE( trash ) ;
  584. }
  585. *list = NULL ;
  586. return(0) ;
  587. }
  588. /********************************************/