Blender V2.61 - r43446

memory.c

Go to the documentation of this file.
00001 
00004 /*
00005  * -- SuperLU routine (version 2.0) --
00006  * Univ. of California Berkeley, Xerox Palo Alto Research Center,
00007  * and Lawrence Berkeley National Lab.
00008  * November 15, 1997
00009  *
00010  */
00014 #include "ssp_defs.h"
00015 
00016 /* prototypes --------------------------------- */
00017 void copy_mem_int(int, void *, void *);
00018 void user_bcopy(char *, char *, int);
00019 
00020 
00021 #if ( DEBUGlevel>=1 )           /* Debug malloc/free. */
00022 int superlu_malloc_total = 0;
00023 
00024 #define PAD_FACTOR  2
00025 #define DWORD  (sizeof(double)) /* Be sure it's no smaller than double. */
00026 
00027 void *superlu_malloc(size_t size)
00028 {
00029     char *buf;
00030 
00031     buf = (char *) malloc(size + DWORD);
00032     if ( !buf ) {
00033     printf("superlu_malloc fails: malloc_total %.0f MB, size %d\n",
00034            superlu_malloc_total*1e-6, size);
00035     ABORT("superlu_malloc: out of memory");
00036     }
00037 
00038     ((int_t *) buf)[0] = size;
00039 #if 0
00040     superlu_malloc_total += size + DWORD;
00041 #else
00042     superlu_malloc_total += size;
00043 #endif
00044     return (void *) (buf + DWORD);
00045 }
00046 
00047 void superlu_free(void *addr)
00048 {
00049     char *p = ((char *) addr) - DWORD;
00050 
00051     if ( !addr )
00052     ABORT("superlu_free: tried to free NULL pointer");
00053 
00054     if ( !p )
00055     ABORT("superlu_free: tried to free NULL+DWORD pointer");
00056 
00057     { 
00058     int_t n = ((int_t *) p)[0];
00059     
00060     if ( !n )
00061         ABORT("superlu_free: tried to free a freed pointer");
00062     *((int_t *) p) = 0; /* Set to zero to detect duplicate free's. */
00063 #if 0   
00064     superlu_malloc_total -= (n + DWORD);
00065 #else
00066     superlu_malloc_total -= n;
00067 #endif
00068 
00069     if ( superlu_malloc_total < 0 )
00070         ABORT("superlu_malloc_total went negative!");
00071     
00072     /*free (addr);*/
00073     free (p);
00074     }
00075 
00076 }
00077 
00078 #else   /* production mode */
00079 
00080 void *superlu_malloc(size_t size)
00081 {
00082     void *buf;
00083     buf = (void *) malloc(size);
00084     return (buf);
00085 }
00086 
00087 void superlu_free(void *addr)
00088 {
00089     free (addr);
00090 }
00091 
00092 #endif
00093 
00094 
00095 /*
00096  * Set up pointers for integer working arrays.
00097  */
00098 void
00099 SetIWork(int m, int n, int panel_size, int *iworkptr, int **segrep,
00100      int **parent, int **xplore, int **repfnz, int **panel_lsub,
00101      int **xprune, int **marker)
00102 {
00103     *segrep = iworkptr;
00104     *parent = iworkptr + m;
00105     *xplore = *parent + m;
00106     *repfnz = *xplore + m;
00107     *panel_lsub = *repfnz + panel_size * m;
00108     *xprune = *panel_lsub + panel_size * m;
00109     *marker = *xprune + n;
00110     ifill (*repfnz, m * panel_size, EMPTY);
00111     ifill (*panel_lsub, m * panel_size, EMPTY);
00112 }
00113 
00114 
00115 void
00116 copy_mem_int(int howmany, void *old, void *new)
00117 {
00118     register int i;
00119     int *iold = old;
00120     int *inew = new;
00121     for (i = 0; i < howmany; i++) inew[i] = iold[i];
00122 }
00123 
00124 
00125 void
00126 user_bcopy(char *src, char *dest, int bytes)
00127 {
00128     char *s_ptr, *d_ptr;
00129 
00130     s_ptr = src + bytes - 1;
00131     d_ptr = dest + bytes - 1;
00132     for (; d_ptr >= dest; --s_ptr, --d_ptr ) *d_ptr = *s_ptr;
00133 }
00134 
00135 
00136 
00137 int *intMalloc(int n)
00138 {
00139     int *buf;
00140     buf = (int *) SUPERLU_MALLOC(n * sizeof(int));
00141     if ( !buf ) {
00142     ABORT("SUPERLU_MALLOC fails for buf in intMalloc()");
00143     }
00144     return (buf);
00145 }
00146 
00147 int *intCalloc(int n)
00148 {
00149     int *buf;
00150     register int i;
00151     buf = (int *) SUPERLU_MALLOC(n * sizeof(int));
00152     if ( !buf ) {
00153     ABORT("SUPERLU_MALLOC fails for buf in intCalloc()");
00154     }
00155     for (i = 0; i < n; ++i) buf[i] = 0;
00156     return (buf);
00157 }
00158 
00159 
00160 
00161 #if 0
00162 check_expanders()
00163 {
00164     int p;
00165     printf("Check expanders:\n");
00166     for (p = 0; p < NO_MEMTYPE; p++) {
00167     printf("type %d, size %d, mem %d\n",
00168            p, expanders[p].size, (int)expanders[p].mem);
00169     }
00170 
00171     return 0;
00172 }
00173 
00174 
00175 StackInfo()
00176 {
00177     printf("Stack: size %d, used %d, top1 %d, top2 %d\n",
00178        stack.size, stack.used, stack.top1, stack.top2);
00179     return 0;
00180 }
00181 
00182 
00183 
00184 PrintStack(char *msg, GlobalLU_t *Glu)
00185 {
00186     int i;
00187     int *xlsub, *lsub, *xusub, *usub;
00188 
00189     xlsub = Glu->xlsub;
00190     lsub  = Glu->lsub;
00191     xusub = Glu->xusub;
00192     usub  = Glu->usub;
00193 
00194     printf("%s\n", msg);
00195     
00196 /*    printf("\nUCOL: ");
00197     for (i = 0; i < xusub[ndim]; ++i)
00198     printf("%f  ", ucol[i]);
00199 
00200     printf("\nLSUB: ");
00201     for (i = 0; i < xlsub[ndim]; ++i)
00202     printf("%d  ", lsub[i]);
00203 
00204     printf("\nUSUB: ");
00205     for (i = 0; i < xusub[ndim]; ++i)
00206     printf("%d  ", usub[i]);
00207 
00208     printf("\n");*/
00209     return 0;
00210 }   
00211 #endif
00212 
00213 
00214