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