Line data Source code
1 : /*
2 : Copyright (c) 2003, The Regents of the University of California, through
3 : Lawrence Berkeley National Laboratory (subject to receipt of any required
4 : approvals from U.S. Dept. of Energy)
5 :
6 : All rights reserved.
7 :
8 : The source code is distributed under BSD license, see the file License.txt
9 : at the top-level directory.
10 : */
11 : /*
12 : * -- SuperLU routine (version 2.0) --
13 : * Univ. of California Berkeley, Xerox Palo Alto Research Center,
14 : * and Lawrence Berkeley National Lab.
15 : * November 15, 1997
16 : */
17 : /*! \file
18 : * \brief Precision-independent memory-related routines
19 : *
20 : * Shared by [sdcz]memory.c)
21 : *
22 : * \ingroup Common
23 : */
24 :
25 : #include "slu_ddefs.h"
26 :
27 :
28 : #if ( DEBUGlevel>=1 ) /* Debug malloc/free. */
29 : int64_t superlu_malloc_total = 0;
30 :
31 : #define PAD_FACTOR 2
32 : #define DWORD (sizeof(double)) /* Be sure it's no smaller than double. */
33 : /* size_t is usually defined as 'unsigned long' */
34 :
35 : void *superlu_malloc(size_t size)
36 : {
37 : char *buf;
38 :
39 : buf = (char *) malloc(size + DWORD);
40 : if ( !buf ) {
41 : printf("superlu_malloc fails: malloc_total %.0f MB, size %lld\n",
42 : superlu_malloc_total*1e-6, (long long)size);
43 : ABORT("superlu_malloc: out of memory");
44 : }
45 :
46 : ((size_t *) buf)[0] = size;
47 : #if 0
48 : superlu_malloc_total += size + DWORD;
49 : #else
50 : superlu_malloc_total += size;
51 : #endif
52 : return (void *) (buf + DWORD);
53 : }
54 :
55 : void superlu_free(void *addr)
56 : {
57 : char *p = ((char *) addr) - DWORD;
58 :
59 : if ( !addr )
60 : ABORT("superlu_free: tried to free NULL pointer");
61 :
62 : if ( !p )
63 : ABORT("superlu_free: tried to free NULL+DWORD pointer");
64 :
65 : {
66 : int_t n = ((size_t *) p)[0];
67 :
68 : if ( !n )
69 : ABORT("superlu_free: tried to free a freed pointer");
70 : *((size_t *) p) = 0; /* Set to zero to detect duplicate free's. */
71 : #if 0
72 : superlu_malloc_total -= (n + DWORD);
73 : #else
74 : superlu_malloc_total -= n;
75 : #endif
76 :
77 : if ( superlu_malloc_total < 0 )
78 : ABORT("superlu_malloc_total went negative!");
79 :
80 : /*free (addr);*/
81 : free (p);
82 : }
83 :
84 : }
85 :
86 : #else /* production mode */
87 :
88 0 : void *superlu_malloc(size_t size)
89 : {
90 : void *buf;
91 0 : buf = (void *) malloc(size);
92 0 : return (buf);
93 : }
94 :
95 0 : void superlu_free(void *addr)
96 : {
97 0 : free (addr);
98 0 : }
99 :
100 : #endif
101 :
102 :
103 : /*! \brief Set up pointers for integer working arrays.
104 : */
105 : void
106 0 : SetIWork(int m, int n, int panel_size, int *iworkptr, int **segrep,
107 : int **parent, int_t **xplore, int **repfnz, int **panel_lsub,
108 : int_t **xprune, int **marker)
109 : {
110 0 : *segrep = iworkptr;
111 0 : *parent = iworkptr + m;
112 : // *xplore = *parent + m;
113 0 : *repfnz = *parent + m;
114 0 : *panel_lsub = *repfnz + panel_size * m;
115 : // *xprune = *panel_lsub + panel_size * m;
116 : // *marker = *xprune + n;
117 0 : *marker = *panel_lsub + panel_size * m;
118 :
119 0 : ifill (*repfnz, m * panel_size, SLU_EMPTY);
120 0 : ifill (*panel_lsub, m * panel_size, SLU_EMPTY);
121 :
122 0 : *xplore = intMalloc(m); /* can be 64 bit */
123 0 : *xprune = intMalloc(n);
124 0 : }
125 :
126 :
127 : void
128 0 : copy_mem_int(int_t howmany, void *old, void *new)
129 : {
130 : register int_t i;
131 : int_t *iold = old;
132 : int_t *inew = new;
133 0 : for (i = 0; i < howmany; i++) inew[i] = iold[i];
134 0 : }
135 :
136 :
137 : void
138 0 : user_bcopy(char *src, char *dest, int bytes)
139 : {
140 : char *s_ptr, *d_ptr;
141 :
142 0 : s_ptr = src + bytes - 1;
143 0 : d_ptr = dest + bytes - 1;
144 0 : for (; d_ptr >= dest; --s_ptr, --d_ptr ) *d_ptr = *s_ptr;
145 0 : }
146 :
147 0 : int *int32Malloc(int n)
148 : {
149 : int *buf;
150 0 : buf = (int *) SUPERLU_MALLOC((size_t) n * sizeof(int));
151 0 : if ( !buf ) {
152 0 : ABORT("SUPERLU_MALLOC fails for buf in int32Malloc()");
153 : }
154 0 : return (buf);
155 : }
156 :
157 0 : int_t *intMalloc(int_t n)
158 : {
159 : int_t *buf;
160 0 : buf = (int_t *) SUPERLU_MALLOC((size_t) n * sizeof(int_t));
161 0 : if ( !buf ) {
162 0 : ABORT("SUPERLU_MALLOC fails for buf in intMalloc()");
163 : }
164 0 : return (buf);
165 : }
166 :
167 0 : int *int32Calloc(int n)
168 : {
169 : int *buf;
170 : register int i;
171 0 : buf = (int *) SUPERLU_MALLOC(n * sizeof(int));
172 0 : if ( !buf ) {
173 0 : ABORT("SUPERLU_MALLOC fails for buf in intCalloc()");
174 : }
175 0 : for (i = 0; i < n; ++i) buf[i] = 0;
176 0 : return (buf);
177 : }
178 :
179 0 : int_t *intCalloc(int_t n)
180 : {
181 : int_t *buf;
182 : register int_t i;
183 0 : buf = (int_t *) SUPERLU_MALLOC(n * sizeof(int_t));
184 0 : if ( !buf ) {
185 0 : ABORT("SUPERLU_MALLOC fails for buf in intCalloc()");
186 : }
187 0 : for (i = 0; i < n; ++i) buf[i] = 0;
188 0 : return (buf);
189 : }
190 :
191 :
192 : #if 0
193 : check_expanders()
194 : {
195 : int p;
196 : printf("Check expanders:\n");
197 : for (p = 0; p < NO_MEMTYPE; p++) {
198 : printf("type %d, size %d, mem %d\n",
199 : p, expanders[p].size, (int)expanders[p].mem);
200 : }
201 :
202 : return 0;
203 : }
204 :
205 :
206 : StackInfo()
207 : {
208 : printf("Stack: size %d, used %d, top1 %d, top2 %d\n",
209 : stack.size, stack.used, stack.top1, stack.top2);
210 : return 0;
211 : }
212 :
213 :
214 :
215 : PrintStack(char *msg, GlobalLU_t *Glu)
216 : {
217 : int i;
218 : int *xlsub, *lsub, *xusub, *usub;
219 :
220 : xlsub = Glu->xlsub;
221 : lsub = Glu->lsub;
222 : xusub = Glu->xusub;
223 : usub = Glu->usub;
224 :
225 : printf("%s\n", msg);
226 :
227 : /* printf("\nUCOL: ");
228 : for (i = 0; i < xusub[ndim]; ++i)
229 : printf("%f ", ucol[i]);
230 :
231 : printf("\nLSUB: ");
232 : for (i = 0; i < xlsub[ndim]; ++i)
233 : printf("%d ", lsub[i]);
234 :
235 : printf("\nUSUB: ");
236 : for (i = 0; i < xusub[ndim]; ++i)
237 : printf("%d ", usub[i]);
238 :
239 : printf("\n");*/
240 : return 0;
241 : }
242 : #endif
243 :
244 :
245 :
|