~ubuntu-branches/ubuntu/oneiric/python-scipy/oneiric-proposed

« back to all changes in this revision

Viewing changes to scipy/linsolve/SuperLU/SRC/memory.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * -- SuperLU routine (version 2.0) --
 
3
 * Univ. of California Berkeley, Xerox Palo Alto Research Center,
 
4
 * and Lawrence Berkeley National Lab.
 
5
 * November 15, 1997
 
6
 *
 
7
 */
 
8
/** Precision-independent memory-related routines.
 
9
    (Shared by [sdcz]memory.c) **/
 
10
 
 
11
#include "dsp_defs.h"
 
12
 
 
13
 
 
14
#if ( DEBUGlevel>=1 )           /* Debug malloc/free. */
 
15
int superlu_malloc_total = 0;
 
16
 
 
17
#define PAD_FACTOR  2
 
18
#define DWORD  (sizeof(double)) /* Be sure it's no smaller than double. */
 
19
 
 
20
void *superlu_malloc(size_t size)
 
21
{
 
22
    char *buf;
 
23
 
 
24
    buf = (char *) malloc(size + DWORD);
 
25
    if ( !buf ) {
 
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");
 
29
    }
 
30
 
 
31
    ((int_t *) buf)[0] = size;
 
32
#if 0
 
33
    superlu_malloc_total += size + DWORD;
 
34
#else
 
35
    superlu_malloc_total += size;
 
36
#endif
 
37
    return (void *) (buf + DWORD);
 
38
}
 
39
 
 
40
void superlu_free(void *addr)
 
41
{
 
42
    char *p = ((char *) addr) - DWORD;
 
43
 
 
44
    if ( !addr )
 
45
        ABORT("superlu_free: tried to free NULL pointer");
 
46
 
 
47
    if ( !p )
 
48
        ABORT("superlu_free: tried to free NULL+DWORD pointer");
 
49
 
 
50
    { 
 
51
        int_t n = ((int_t *) p)[0];
 
52
        
 
53
        if ( !n )
 
54
            ABORT("superlu_free: tried to free a freed pointer");
 
55
        *((int_t *) p) = 0; /* Set to zero to detect duplicate free's. */
 
56
#if 0   
 
57
        superlu_malloc_total -= (n + DWORD);
 
58
#else
 
59
        superlu_malloc_total -= n;
 
60
#endif
 
61
 
 
62
        if ( superlu_malloc_total < 0 )
 
63
            ABORT("superlu_malloc_total went negative!");
 
64
        
 
65
        /*free (addr);*/
 
66
        free (p);
 
67
    }
 
68
 
 
69
}
 
70
 
 
71
#else   /* production mode */
 
72
 
 
73
void *superlu_malloc(size_t size)
 
74
{
 
75
    void *buf;
 
76
    buf = (void *) malloc(size);
 
77
    return (buf);
 
78
}
 
79
 
 
80
void superlu_free(void *addr)
 
81
{
 
82
    free (addr);
 
83
}
 
84
 
 
85
#endif
 
86
 
 
87
 
 
88
/*
 
89
 * Set up pointers for integer working arrays.
 
90
 */
 
91
void
 
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)
 
95
{
 
96
    *segrep = iworkptr;
 
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);
 
105
}
 
106
 
 
107
 
 
108
void
 
109
copy_mem_int(int howmany, void *old, void *new)
 
110
{
 
111
    register int i;
 
112
    int *iold = old;
 
113
    int *inew = new;
 
114
    for (i = 0; i < howmany; i++) inew[i] = iold[i];
 
115
}
 
116
 
 
117
 
 
118
void
 
119
user_bcopy(char *src, char *dest, int bytes)
 
120
{
 
121
    char *s_ptr, *d_ptr;
 
122
 
 
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;
 
126
}
 
127
 
 
128
 
 
129
 
 
130
int *intMalloc(int n)
 
131
{
 
132
    int *buf;
 
133
    buf = (int *) SUPERLU_MALLOC(n * sizeof(int));
 
134
    if ( !buf ) {
 
135
        ABORT("SUPERLU_MALLOC fails for buf in intMalloc()");
 
136
    }
 
137
    return (buf);
 
138
}
 
139
 
 
140
int *intCalloc(int n)
 
141
{
 
142
    int *buf;
 
143
    register int i;
 
144
    buf = (int *) SUPERLU_MALLOC(n * sizeof(int));
 
145
    if ( !buf ) {
 
146
        ABORT("SUPERLU_MALLOC fails for buf in intCalloc()");
 
147
    }
 
148
    for (i = 0; i < n; ++i) buf[i] = 0;
 
149
    return (buf);
 
150
}
 
151
 
 
152
 
 
153
 
 
154
#if 0
 
155
check_expanders()
 
156
{
 
157
    int p;
 
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);
 
162
    }
 
163
 
 
164
    return 0;
 
165
}
 
166
 
 
167
 
 
168
StackInfo()
 
169
{
 
170
    printf("Stack: size %d, used %d, top1 %d, top2 %d\n",
 
171
           stack.size, stack.used, stack.top1, stack.top2);
 
172
    return 0;
 
173
}
 
174
 
 
175
 
 
176
 
 
177
PrintStack(char *msg, GlobalLU_t *Glu)
 
178
{
 
179
    int i;
 
180
    int *xlsub, *lsub, *xusub, *usub;
 
181
 
 
182
    xlsub = Glu->xlsub;
 
183
    lsub  = Glu->lsub;
 
184
    xusub = Glu->xusub;
 
185
    usub  = Glu->usub;
 
186
 
 
187
    printf("%s\n", msg);
 
188
    
 
189
/*    printf("\nUCOL: ");
 
190
    for (i = 0; i < xusub[ndim]; ++i)
 
191
        printf("%f  ", ucol[i]);
 
192
 
 
193
    printf("\nLSUB: ");
 
194
    for (i = 0; i < xlsub[ndim]; ++i)
 
195
        printf("%d  ", lsub[i]);
 
196
 
 
197
    printf("\nUSUB: ");
 
198
    for (i = 0; i < xusub[ndim]; ++i)
 
199
        printf("%d  ", usub[i]);
 
200
 
 
201
    printf("\n");*/
 
202
    return 0;
 
203
}   
 
204
#endif
 
205
 
 
206
 
 
207