File: PB_Cgetbuf.c

package info (click to toggle)
scalapack 1.8.0-12
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,712 kB
  • ctags: 29,423
  • sloc: fortran: 288,069; ansic: 64,035; makefile: 1,966
file content (96 lines) | stat: -rw-r--r-- 2,517 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ---------------------------------------------------------------------
*
*  -- PBLAS auxiliary routine (version 2.0) --
*     University of Tennessee, Knoxville, Oak Ridge National Laboratory,
*     and University of California, Berkeley.
*     April 1, 1998
*
*  ---------------------------------------------------------------------
*/
/*
*  Include files
*/
#include "../pblas.h"
#include "../PBpblas.h"
#include "../PBtools.h"
#include "../PBblacs.h"
#include "../PBblas.h"

#ifdef __STDC__
char * PB_Cgetbuf( char * MESS, int LENGTH )
#else
char * PB_Cgetbuf( MESS, LENGTH )
/*
*  .. Scalar Arguments ..
*/
   int            LENGTH;
/*
*  .. Array Arguments ..
*/
   char           * MESS;
#endif
{
/*
*  Purpose
*  =======
*
*  PB_Cgetbuf  allocates a dynamic memory buffer. The routine checks the
*  size of the already allocated buffer against the value of the  formal
*  parameter LENGTH. If the current buffer is large enough, this a poin-
*  ter to it is returned. Otherwise, this function tries to allocate it.
*  In case of failure,  the program is stopped by calling  Cblacs_abort.
*  When LENGTH is zero, this function returns a NULL pointer. If the va-
*  lue of LENGTH is strictly less than zero, the buffer is released.
*
*  Arguments
*  =========
*
*  MESS    (local input) pointer to CHAR
*          On entry, MESS is a string containing a message to be printed
*          in case of allocation failure.
*
*  LENGTH  (local input) INTEGER
*          On entry, LENGTH  specifies the length in bytes of the buffer
*          to be allocated.  If LENGTH is less or equal than zero,  this
*          function returns NULL.
*
*  -- Written on April 1, 1998 by
*     Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
*
*  ---------------------------------------------------------------------
*/
/*
*  .. Local Scalars ..
*/
   static char    * pblasbuf = NULL;
   static int     pbbuflen = 0;
/* ..
*  .. Executable Statements ..
*
*/
   if( LENGTH >= 0 )
   {
      if( LENGTH > pbbuflen )
      {
         if( pblasbuf ) free( pblasbuf );
         pblasbuf = (char *) malloc( (unsigned) LENGTH );
         if( !pblasbuf )
         {
            (void) fprintf( stderr, "ERROR: Memory allocation failed\n%s\n",
                            MESS );
            Cblacs_abort( -1, -1 );
         }
         pbbuflen = LENGTH;
      }
   }
   else if( pblasbuf )
   {
      free( pblasbuf );
      pblasbuf = NULL;
      pbbuflen = 0;
   }
   return( pblasbuf );
/*
*  End of PB_Cgetbuf
*/
}