00001 #include "numchol.h"
00002
00003 int iSum(int,int*);
00004 void ShutDown();
00005 int ExitProc(int,char *);
00006
00007 int iAlloc(int len,
00008 char *info,
00009 int **r)
00010 {
00011 *r=NULL;
00012
00013 if (len)
00014 {
00015 *r=(int*)calloc(len,sizeof(int));
00016 if (!(*r)){ ExitProc(OutOfSpc,info); return 1;}
00017 }
00018 return 0;
00019 }
00020
00021 void iFree(int **x)
00022 {
00023 int *r=*x;
00024
00025 if (r)
00026 {
00027 free(r);
00028 *x=NULL;
00029 }
00030 }
00031
00032 void cFree(char **x)
00033 {
00034 char *r = *x;
00035
00036
00037
00038
00039 if(r)
00040 { free(r);
00041 *x = NULL;
00042 }
00043
00044 }
00045
00046 int dAlloc(int len,
00047 char *info,
00048 double **rr)
00049 {
00050 double *r=NULL;
00051
00052 if (len) {
00053 r=(double*)calloc(len,sizeof(double));
00054 if (!r){ ExitProc(OutOfSpc,info); return 1;}
00055 }
00056 *rr=r;
00057 return 0;
00058 }
00059
00060 void dFree(double **x)
00061 {
00062 double *r=*x;
00063
00064 if (r)
00065 {
00066 free(r);
00067 *x=NULL;
00068 }
00069 }
00070
00071
00072
00073 int LvalAlloc(chfac *sf,
00074 char *info)
00075 {
00076 int ierr=0,nnz;
00077
00078 nnz=iSum(sf->nrow,sf->ujsze);
00079 if ( nnz<=sf->unnz )
00080 return 1;
00081
00082 sf->unnz=0;
00083 if (sf->uval) dFree(&sf->uval);
00084 ierr=dAlloc(nnz,info,&sf->uval);
00085
00086 sf->unnz=nnz;
00087 if (ierr) return 1;
00088 return 0;
00089 }
00090
00091 int CfcAlloc(int maxrow,
00092 char *info,chfac**rr)
00093 {
00094 chfac *r=NULL;
00095 int ierr=0;
00096
00097 if (maxrow) {
00098 r=(chfac*)calloc(1,sizeof(chfac));
00099 if (!r) ExitProc(OutOfSpc,info);
00100
00101 r->mrow =maxrow;
00102 r->nrow =maxrow;
00103
00104 r->snnz =0;
00105 ierr=iAlloc(maxrow,info,&r->shead); if(ierr) return 1;
00106 ierr=iAlloc(maxrow,info,&r->ssize); if(ierr) return 1;
00107 r->ssub =NULL;
00108 ierr=dAlloc(maxrow,info,&r->diag); if(ierr) return 1;
00109 ierr=dAlloc(maxrow,info,&r->sqrtdiag); if(ierr) return 1;
00110 r->unnz =0;
00111 r->ujnz =0;
00112 ierr=iAlloc(maxrow,info,&r->ujbeg); if(ierr) return 1;
00113 ierr=iAlloc(maxrow,info,&r->uhead); if(ierr) return 1;
00114 ierr=iAlloc(maxrow,info,&r->ujsze); if(ierr) return 1;
00115 r->usub =NULL;
00116 r->uval =NULL;
00117 ierr=iAlloc(maxrow,info,&r->perm); if(ierr) return 1;
00118 ierr=iAlloc(maxrow,info,&r->invp); if(ierr) return 1;
00119 r->nsnds=0;
00120 ierr=iAlloc(maxrow+1,info,&r->subg); if(ierr) return 1;
00121 r->n=maxrow;
00122 r->alldense=0;
00123 r->tolpiv=1.0e-13;
00124 r->tolpiv=1.0e-35;
00125 r->cachesize =256;
00126 #ifdef DSDPCACHESIZE
00127 if (DSDPCACHESIZE>0){
00128 r->cachesize = (int)DSDPCACHESIZE;
00129 }
00130 #endif
00131 r->cacheunit =1000;
00132
00133 }
00134 *rr=r;
00135 return 0;
00136 }
00137
00138 void CfcFree(chfac **sf)
00139 {
00140 chfac *r=*sf;
00141
00142 if (*sf) {
00143 iFree(&r->shead);
00144 iFree(&r->ssize);
00145 iFree(&r->ssub);
00146 dFree(&r->diag);
00147 dFree(&r->sqrtdiag);
00148 iFree(&r->uhead);
00149 iFree(&r->ujsze);
00150 dFree(&r->uval);
00151 iFree(&r->perm);
00152 iFree(&r->subg);
00153 iFree(&r->dhead);
00154 iFree(&r->dbeg);
00155 iFree(&r->dsub);
00156 iFree(&r->iw);
00157 dFree(&r->rw);
00158 if (r->alldense){
00159 r->invp=0;
00160 r->ujbeg=0;
00161 r->usub=0;
00162 }else{
00163 iFree(&r->invp);
00164 iFree(&r->ujbeg);
00165 iFree(&r->usub);
00166 }
00167 free(r);
00168 }
00169 *sf=NULL;
00170 }
00171
00172 int dPtAlloc(int n,
00173 char *info,double ***rr)
00174 {
00175 int ierr,i;
00176 double **r;
00177
00178 r=NULL;
00179 *rr=NULL;
00180 if (!n) return 0;
00181
00182 r=(double **)calloc(n,sizeof(double*));
00183 if (!r){
00184 ExitProc(OutOfSpc,info);
00185 return 1;
00186 }
00187 ierr=dAlloc(n*(n-1)/2,info,&r[0]);
00188 if(ierr) return 1;
00189 for (i=1; i<n; i++)
00190 r[i]=r[i-1]+n-i;
00191
00192 *rr=r;
00193 return 0;
00194 }
00195
00196 void dPtFree(double ***x)
00197 {
00198 double **r=*x;
00199
00200 if (r) {
00201 if (r[0])
00202 dFree(&r[0]);
00203 free(r);
00204 *x=NULL;
00205 }
00206 }
00207