ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
BI_GetBuff.c File Reference
#include "Bdef.h"
Include dependency graph for BI_GetBuff.c:

Go to the source code of this file.

Functions/Subroutines

BLACBUFF * BI_GetBuff (int length)

Function/Subroutine Documentation

BLACBUFF* BI_GetBuff ( int  length)

Definition at line 37 of file BI_GetBuff.c.

{
   void BI_EmergencyBuff(int length);

   char *cptr;
   int i, j;
   extern int BI_Np;
   extern BLACBUFF *BI_ReadyB;

/*
 * If ready buffer already exists, and is big enough, return it.  Otherwise,
 * free the buffer (if it exists) and get one of correct size
 */
   if (BI_ReadyB)
   {
      if (BI_ReadyB->Len >= length) return(BI_ReadyB);
      else free(BI_ReadyB);
   }
/*
 * Make sure all buffers aligned correctly
 */
   j = sizeof(BLACBUFF);
   if (j % sizeof(MPI_Request))
      j += sizeof(MPI_Request) - j % sizeof(MPI_Request);
   i = j + BI_Np*sizeof(MPI_Request);
   if (i % BUFFALIGN) i += BUFFALIGN - i % BUFFALIGN;
   cptr = malloc(i + length);
   BI_ReadyB = (BLACBUFF *) cptr;

   if (BI_ReadyB != NULL)
   {
      BI_ReadyB->nAops = 0;
      BI_ReadyB->Aops = (MPI_Request *) &cptr[j];
      BI_ReadyB->Buff = &cptr[i];
      BI_ReadyB->Len = length;
   }
   else BI_EmergencyBuff(length);

   return(BI_ReadyB);
}

Here is the call graph for this function: