1 #include "Bdef.h"
BI_Pack(BLACSCONTEXT * ctxt,BVOID * A,BLACBUFF * bp,BI_MPI_Datatype Dtype)2 BLACBUFF *BI_Pack(BLACSCONTEXT *ctxt, BVOID *A, BLACBUFF *bp,
3 BI_MPI_Datatype Dtype)
4 {
5 BLACBUFF *BI_GetBuff(int);
6 int i, info, one=1;
7 BI_MPI_Aint eltsiz;
8 #ifdef ZeroByteTypeBug
9 char *cptr;
10 extern BLACBUFF BI_AuxBuff;
11 extern int BI_Np;
12 #endif
13
14 /*
15 * Some versions of mpich and its derivitives cannot handle 0 byte typedefs,
16 * so we have set MPI_BYTE as a flag for a 0 byte message
17 */
18 #ifdef ZeroByteTypeBug
19 if (Dtype == BI_MPI_BYTE)
20 {
21 info = sizeof(BLACBUFF);
22 if (info % sizeof(BI_MPI_Request))
23 info += sizeof(BI_MPI_Request) - info % sizeof(BI_MPI_Request);
24 i = info + BI_Np*sizeof(BI_MPI_Request);
25 if (i % BUFFALIGN) i += BUFFALIGN - i % BUFFALIGN;
26 cptr = malloc(i);
27 if (cptr)
28 {
29 bp = (BLACBUFF *) cptr;
30 bp->Len = bp->N = bp->nAops = 0;
31 bp->Aops = (BI_MPI_Request *) &cptr[info];
32 bp->Buff = (char *) &bp->Len;
33 bp->dtype = BI_MPI_BYTE;
34 return(bp);
35 }
36 else BI_BlacsErr(BI_ContxtNum(ctxt), __LINE__, __FILE__,
37 "Not enough memory to allocate 0 byte buffer\n");
38 }
39 #endif
40 if (bp == NULL)
41 {
42 BI_MPI_Pack_size(one, Dtype, ctxt->scp->comm, &i, info);
43 bp = BI_GetBuff(i);
44 }
45
46 i = 0;
47 BI_MPI_Pack(A, one, Dtype, bp->Buff, bp->Len, &i, ctxt->scp->comm, info);
48 bp->dtype = BI_MPI_PACKED;
49 bp->N = i;
50
51 return(bp);
52 }
53