ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
BI_Pack.c
Go to the documentation of this file.
00001 #include "Bdef.h"
00002 BLACBUFF *BI_Pack(BLACSCONTEXT *ctxt,BVOID *A,BLACBUFF *bp,MPI_Datatype Dtype)
00003 {
00004    BLACBUFF *BI_GetBuff(int);
00005    int i, info, one=1;
00006    MPI_Aint eltsiz;
00007 #ifdef ZeroByteTypeBug
00008    char *cptr;
00009    extern BLACBUFF BI_AuxBuff;
00010    extern int BI_Np;
00011 #endif
00012 
00013 /*
00014  * Some versions of mpich and its derivitives cannot handle 0 byte typedefs,
00015  * so we have set MPI_BYTE as a flag for a 0 byte message
00016  */
00017 #ifdef ZeroByteTypeBug
00018    if (Dtype == MPI_BYTE)
00019    {
00020       info = sizeof(BLACBUFF);
00021       if (info % sizeof(MPI_Request))
00022          info += sizeof(MPI_Request) - info % sizeof(MPI_Request);
00023       i = info + BI_Np*sizeof(MPI_Request);
00024       if (i % BUFFALIGN) i += BUFFALIGN - i % BUFFALIGN;
00025       cptr = malloc(i);
00026       if (cptr)
00027       {
00028          bp = (BLACBUFF *) cptr;
00029          bp->Len = bp->N = bp->nAops = 0;
00030          bp->Aops = (MPI_Request *) &cptr[info];
00031          bp->Buff = (char *) &bp->Len;
00032          bp->dtype = MPI_BYTE;
00033          return(bp);
00034       }
00035       else BI_BlacsErr(BI_ContxtNum(ctxt), __LINE__, __FILE__, 
00036                        "Not enough memory to allocate 0 byte buffer\n");
00037    }
00038 #endif
00039    if (bp == NULL)
00040    {
00041       info=MPI_Pack_size(one, Dtype, ctxt->scp->comm, &i);
00042       bp = BI_GetBuff(i);
00043    }
00044 
00045    i = 0;
00046    info=MPI_Pack(A, one, Dtype, bp->Buff, bp->Len, &i, ctxt->scp->comm);
00047    bp->dtype = MPI_PACKED;
00048    bp->N = i;
00049 
00050    return(bp);
00051 }