ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
getpbbuf.c
Go to the documentation of this file.
00001 #include "tools.h"
00002 
00003 char * getpbbuf( mess, length )
00004 /*
00005 *  .. Scalar Arguments ..
00006 */
00007    int         length;
00008 /*
00009 *  .. Array Arguments ..
00010 */
00011    char        * mess;
00012 {
00013 /*
00014 *  Purpose
00015 *  =======
00016 *
00017 *  getpbbuf returns a pointer to a working buffer of size length alloca-
00018 *  ted for the PBLAS routines.
00019 *
00020 * ======================================================================
00021 *
00022 *  .. Local Scalars ..
00023 */
00024    static char * pblasbuf = NULL;
00025    static int  pbbuflen = 0, mone = -1;
00026 /* ..
00027 *  .. External Functions ..
00028 */
00029    void        blacs_abort_();
00030 /* ..
00031 *  .. Executable Statements ..
00032 */
00033    if( length >= 0 )
00034    {
00035       if( length > pbbuflen )
00036       {
00037          if( pblasbuf )
00038             free( pblasbuf );
00039          pblasbuf = (char *) malloc((unsigned)length);
00040          if( !pblasbuf )
00041          {
00042             fprintf( stderr,
00043                      "PBLAS %s ERROR: Memory allocation failed\n",
00044                      mess );
00045             blacs_abort_( &mone, &mone );
00046          }
00047          pbbuflen = length;
00048       }
00049    }
00050    else if( pblasbuf )
00051    {
00052       free( pblasbuf );
00053       pblasbuf = NULL;
00054       pbbuflen = 0;
00055    }
00056    return( pblasbuf );
00057 }