2
* -- SuperLU routine (version 2.0) --
3
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
4
* and Lawrence Berkeley National Lab.
8
/** Precision-independent memory-related routines.
9
(Shared by [sdcz]memory.c) **/
14
#if ( DEBUGlevel>=1 ) /* Debug malloc/free. */
15
int superlu_malloc_total = 0;
18
#define DWORD (sizeof(double)) /* Be sure it's no smaller than double. */
20
void *superlu_malloc(size_t size)
24
buf = (char *) malloc(size + DWORD);
26
printf("superlu_malloc fails: malloc_total %.0f MB, size %d\n",
27
superlu_malloc_total*1e-6, size);
28
ABORT("superlu_malloc: out of memory");
31
((int_t *) buf)[0] = size;
33
superlu_malloc_total += size + DWORD;
35
superlu_malloc_total += size;
37
return (void *) (buf + DWORD);
40
void superlu_free(void *addr)
42
char *p = ((char *) addr) - DWORD;
45
ABORT("superlu_free: tried to free NULL pointer");
48
ABORT("superlu_free: tried to free NULL+DWORD pointer");
51
int_t n = ((int_t *) p)[0];
54
ABORT("superlu_free: tried to free a freed pointer");
55
*((int_t *) p) = 0; /* Set to zero to detect duplicate free's. */
57
superlu_malloc_total -= (n + DWORD);
59
superlu_malloc_total -= n;
62
if ( superlu_malloc_total < 0 )
63
ABORT("superlu_malloc_total went negative!");
71
#else /* production mode */
73
void *superlu_malloc(size_t size)
76
buf = (void *) malloc(size);
80
void superlu_free(void *addr)
89
* Set up pointers for integer working arrays.
92
SetIWork(int m, int n, int panel_size, int *iworkptr, int **segrep,
93
int **parent, int **xplore, int **repfnz, int **panel_lsub,
94
int **xprune, int **marker)
97
*parent = iworkptr + m;
98
*xplore = *parent + m;
99
*repfnz = *xplore + m;
100
*panel_lsub = *repfnz + panel_size * m;
101
*xprune = *panel_lsub + panel_size * m;
102
*marker = *xprune + n;
103
ifill (*repfnz, m * panel_size, EMPTY);
104
ifill (*panel_lsub, m * panel_size, EMPTY);
109
copy_mem_int(int howmany, void *old, void *new)
114
for (i = 0; i < howmany; i++) inew[i] = iold[i];
119
user_bcopy(char *src, char *dest, int bytes)
123
s_ptr = src + bytes - 1;
124
d_ptr = dest + bytes - 1;
125
for (; d_ptr >= dest; --s_ptr, --d_ptr ) *d_ptr = *s_ptr;
130
int *intMalloc(int n)
133
buf = (int *) SUPERLU_MALLOC(n * sizeof(int));
135
ABORT("SUPERLU_MALLOC fails for buf in intMalloc()");
140
int *intCalloc(int n)
144
buf = (int *) SUPERLU_MALLOC(n * sizeof(int));
146
ABORT("SUPERLU_MALLOC fails for buf in intCalloc()");
148
for (i = 0; i < n; ++i) buf[i] = 0;
158
printf("Check expanders:\n");
159
for (p = 0; p < NO_MEMTYPE; p++) {
160
printf("type %d, size %d, mem %d\n",
161
p, expanders[p].size, (int)expanders[p].mem);
170
printf("Stack: size %d, used %d, top1 %d, top2 %d\n",
171
stack.size, stack.used, stack.top1, stack.top2);
177
PrintStack(char *msg, GlobalLU_t *Glu)
180
int *xlsub, *lsub, *xusub, *usub;
189
/* printf("\nUCOL: ");
190
for (i = 0; i < xusub[ndim]; ++i)
191
printf("%f ", ucol[i]);
194
for (i = 0; i < xlsub[ndim]; ++i)
195
printf("%d ", lsub[i]);
198
for (i = 0; i < xusub[ndim]; ++i)
199
printf("%d ", usub[i]);