13 #ifdef USING_OOMPH_SUPERLU 14 #include "../../external_src/oomph_superlu_4.3/slu_ddefs.h" 16 #include "slu_ddefs.h" 64 int superlu(
int *op_flag,
int *n,
int *nnz,
int *nrhs,
65 double *values,
int *rowind,
int *colptr,
66 double *b,
int *ldb,
int *transpose,
int *
doc,
67 fptr *f_factors,
int *info)
78 int i, j, panel_size, permc_spec, relax;
81 mem_usage_t mem_usage;
82 superlu_options_t options;
87 double *diagU, *dblock;
88 int_t fsupc, nsupr, nsupc, luptr;
89 int_t i2, k2, nsupers;
103 if ( *op_flag == 1 ) {
106 set_default_options(&options);
111 dCreate_CompCol_Matrix(&A, *n, *n, *nnz, values, rowind, colptr,
112 SLU_NC, SLU_D, SLU_GE);
113 L = (SuperMatrix *) SUPERLU_MALLOC(
sizeof(SuperMatrix) );
114 U = (SuperMatrix *) SUPERLU_MALLOC(
sizeof(SuperMatrix) );
115 if ( !(perm_r = intMalloc(*n)) ) ABORT(
"Malloc fails for perm_r[].");
116 if ( !(perm_c = intMalloc(*n)) ) ABORT(
"Malloc fails for perm_c[].");
117 if ( !(etree = intMalloc(*n)) ) ABORT(
"Malloc fails for etree[].");
126 permc_spec = options.ColPerm;
127 get_perm_c(permc_spec, &A, perm_c);
129 sp_preorder(&options, &A, perm_c, etree, &AC);
131 panel_size = sp_ienv(1);
134 dgstrf(&options, &AC, relax, panel_size,
135 etree, NULL, 0, perm_c, perm_r, L, U, &stat, info);
138 Lstore = (SCformat *) L->Store;
139 Ustore = (NCformat *) U->Store;
142 printf(
" No of nonzeros in factor L = %d\n", Lstore->nnz);
143 printf(
" No of nonzeros in factor U = %d\n", Ustore->nnz);
144 printf(
" No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz);
145 dQuerySpace(L, U, &mem_usage);
146 printf(
" L\\U MB %.3f\ttotal MB needed %.3f\n",
148 mem_usage.for_lu/1e6, mem_usage.total_needed/1e6);
153 printf(
"dgstrf() error returns INFO= %d\n", *info);
155 printf(
"Argument number %d had an illegal value", *info);
157 else if ( *info <= *n ) {
158 printf(
"U(%i,%i) is exactly zero so U is exactly singular.",
160 dQuerySpace(L, U, &mem_usage);
161 printf(
" L\\U MB %.3f\ttotal MB needed %.3f\n",
163 mem_usage.for_lu/1e6, mem_usage.total_needed/1e6);
172 LUfactors->
perm_c = perm_c;
173 LUfactors->
perm_r = perm_r;
174 *f_factors = (
fptr) LUfactors;
180 Lval = Lstore->nzval;
181 nsupers = Lstore->nsuper + 1;
185 if ( !(diagU = SUPERLU_MALLOC( *n *
sizeof(SuperMatrix) )) )
186 ABORT(
"Malloc fails for diagU[].");
188 for(k2=0; k2< nsupers; k2++)
190 fsupc = L_FST_SUPC(k2);
191 nsupc = L_FST_SUPC(k2+1) - fsupc;
192 nsupr = L_SUB_START(fsupc+1) - L_SUB_START(fsupc);
193 luptr = L_NZ_START(fsupc);
195 dblock = &diagU[fsupc];
196 for(i2 = 0; i2 < nsupc; i2++)
198 dblock[i2] = Lval[luptr];
206 double determinant_mantissa=1.0;
207 int determinant_exponent = 0, iexp;
210 determinant_mantissa *= frexp(diagU[i], &iexp);
211 determinant_exponent += iexp;
213 determinant_mantissa = frexp(determinant_mantissa,&iexp);
214 determinant_exponent += iexp;
220 if(perm_r[j] < perm_r[i]) {signature *= -1;}
221 if(perm_c[j] < perm_c[i]) {signature *= -1;}
226 if(determinant_mantissa > 0.0) {sign = 1;}
227 if(determinant_mantissa < 0.0) {sign = -1;}
235 Destroy_SuperMatrix_Store(&A);
236 Destroy_CompCol_Permuted(&AC);
242 }
else if ( *op_flag == 2 ) {
250 perm_c = LUfactors->
perm_c;
251 perm_r = LUfactors->
perm_r;
253 dCreate_Dense_Matrix(&B, *n, *nrhs, b, *ldb, SLU_DN, SLU_D, SLU_GE);
256 dgstrs (trans, L, U, perm_c, perm_r, &B, &stat, info);
258 Destroy_SuperMatrix_Store(&B);
264 }
else if ( *op_flag == 3 ) {
267 SUPERLU_FREE (LUfactors->
perm_r);
268 SUPERLU_FREE (LUfactors->
perm_c);
269 Destroy_SuperNode_Matrix(LUfactors->
L);
270 Destroy_CompCol_Matrix(LUfactors->
U);
271 SUPERLU_FREE (LUfactors->
L);
272 SUPERLU_FREE (LUfactors->
U);
273 SUPERLU_FREE (LUfactors);
276 fprintf(stderr,
"Invalid op_flag=%d passed to c_cpp_dgssv()\n",*op_flag);
int superlu(int *op_flag, int *n, int *nnz, int *nrhs, double *values, int *rowind, int *colptr, double *b, int *ldb, int *transpose, int *doc, fptr *f_factors, int *info)