SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
PB_Cgetbuf.c
Go to the documentation of this file.
1/* ---------------------------------------------------------------------
2*
3* -- PBLAS auxiliary routine (version 2.0) --
4* University of Tennessee, Knoxville, Oak Ridge National Laboratory,
5* and University of California, Berkeley.
6* April 1, 1998
7*
8* ---------------------------------------------------------------------
9*/
10/*
11* Include files
12*/
13#include "../pblas.h"
14#include "../PBpblas.h"
15#include "../PBtools.h"
16#include "../PBblacs.h"
17#include "../PBblas.h"
18
19#ifdef __STDC__
20char * PB_Cgetbuf( char * MESS, Int LENGTH )
21#else
22char * PB_Cgetbuf( MESS, LENGTH )
23/*
24* .. Scalar Arguments ..
25*/
26 Int LENGTH;
27/*
28* .. Array Arguments ..
29*/
30 char * MESS;
31#endif
32{
33/*
34* Purpose
35* =======
36*
37* PB_Cgetbuf allocates a dynamic memory buffer. The routine checks the
38* size of the already allocated buffer against the value of the formal
39* parameter LENGTH. If the current buffer is large enough, this a poin-
40* ter to it is returned. Otherwise, this function tries to allocate it.
41* In case of failure, the program is stopped by calling Cblacs_abort.
42* When LENGTH is zero, this function returns a NULL pointer. If the va-
43* lue of LENGTH is strictly less than zero, the buffer is released.
44*
45* Arguments
46* =========
47*
48* MESS (local input) pointer to CHAR
49* On entry, MESS is a string containing a message to be printed
50* in case of allocation failure.
51*
52* LENGTH (local input) INTEGER
53* On entry, LENGTH specifies the length in bytes of the buffer
54* to be allocated. If LENGTH is less or equal than zero, this
55* function returns NULL.
56*
57* -- Written on April 1, 1998 by
58* Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
59*
60* ---------------------------------------------------------------------
61*/
62/*
63* .. Local Scalars ..
64*/
65 static char * pblasbuf = NULL;
66 static Int pbbuflen = 0;
67/* ..
68* .. Executable Statements ..
69*
70*/
71 if( LENGTH >= 0 )
72 {
73 if( LENGTH > pbbuflen )
74 {
75 if( pblasbuf ) free( pblasbuf );
76 pblasbuf = (char *) malloc( (unsigned) LENGTH );
77 if( !pblasbuf )
78 {
79 (void) fprintf( stderr, "ERROR: Memory allocation failed\n%s\n",
80 MESS );
81 Cblacs_abort( -1, -1 );
82 }
83 pbbuflen = LENGTH;
84 }
85 }
86 else if( pblasbuf )
87 {
88 free( pblasbuf );
89 pblasbuf = NULL;
90 pbbuflen = 0;
91 }
92 return( pblasbuf );
93/*
94* End of PB_Cgetbuf
95*/
96}
#define Int
Definition Bconfig.h:22
void Cblacs_abort()
char * PB_Cgetbuf()