13 #ifdef USING_OOMPH_SUPERLU
14 #include "../../external_src/oomph_superlu_4.3/slu_ddefs.h"
16 #include "slu_ddefs.h"
118 int superlu(
int *op_flag,
int *n,
int *nnz,
int *nrhs,
119 double *values,
int *rowind,
int *colptr,
120 double *b,
int *ldb,
int *transpose,
int *
doc,
121 fptr *f_factors,
int *info)
125 SuperMatrix A, AC,
B;
132 int i, j, panel_size, permc_spec, relax;
136 superlu_options_t options;
141 double *diagU, *dblock;
142 int_t fsupc, nsupr, nsupc, luptr;
143 int_t i2, k2, nsupers;
161 set_default_options(&options);
166 dCreate_CompCol_Matrix(&A, *n, *n, *nnz, values, rowind, colptr,
167 SLU_NC, SLU_D, SLU_GE);
168 L = (SuperMatrix *) SUPERLU_MALLOC(
sizeof(SuperMatrix));
169 U = (SuperMatrix *) SUPERLU_MALLOC(
sizeof(SuperMatrix));
170 if (!(perm_r = intMalloc(*n))) ABORT(
"Malloc fails for perm_r[].");
171 if (!(perm_c = intMalloc(*n))) ABORT(
"Malloc fails for perm_c[].");
172 if (!(etree = intMalloc(*n))) ABORT(
"Malloc fails for etree[].");
181 permc_spec = options.ColPerm;
182 get_perm_c(permc_spec, &A, perm_c);
184 sp_preorder(&options, &A, perm_c, etree, &AC);
186 panel_size = sp_ienv(1);
189 dgstrf(&options, &AC, relax, panel_size,
190 etree, NULL, 0, perm_c, perm_r,
L,
U, &stat, info);
194 Lstore = (SCformat *)
L->Store;
195 Ustore = (NCformat *)
U->Store;
199 printf(
" No of nonzeros in factor L = %d\n", Lstore->nnz);
200 printf(
" No of nonzeros in factor U = %d\n", Ustore->nnz);
201 printf(
" No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz);
202 printf(
" L\\U MB %.3f\ttotal MB needed %.3f\n",
211 printf(
"dgstrf() error returns INFO= %d\n", *info);
214 printf(
"Argument number %d had an illegal value", *info);
216 else if (*info <= *n)
218 printf(
"U(%i,%i) is exactly zero so U is exactly singular.",
221 printf(
" L\\U MB %.3f\ttotal MB needed %.3f\n",
240 LUfactors->
perm_c = perm_c;
241 LUfactors->
perm_r = perm_r;
242 *f_factors = (
fptr) LUfactors;
248 Lval = Lstore->nzval;
249 nsupers = Lstore->nsuper + 1;
253 if (!(diagU = SUPERLU_MALLOC(*n *
sizeof(SuperMatrix))))
254 ABORT(
"Malloc fails for diagU[].");
256 for (k2=0; k2< nsupers; k2++)
258 fsupc = L_FST_SUPC(k2);
259 nsupc = L_FST_SUPC(k2+1) - fsupc;
260 nsupr = L_SUB_START(fsupc+1) - L_SUB_START(fsupc);
261 luptr = L_NZ_START(fsupc);
263 dblock = &diagU[fsupc];
264 for (i2 = 0; i2 < nsupc; i2++)
266 dblock[i2] = Lval[luptr];
274 double determinant_mantissa=1.0;
275 int determinant_exponent = 0, iexp;
278 determinant_mantissa *= frexp(diagU[
i], &iexp);
279 determinant_exponent += iexp;
281 determinant_mantissa = frexp(determinant_mantissa,&iexp);
282 determinant_exponent += iexp;
288 if (perm_r[j] < perm_r[
i]) {signature *= -1;}
289 if (perm_c[j] < perm_c[
i]) {signature *= -1;}
294 if (determinant_mantissa > 0.0) {sign = 1;}
295 if (determinant_mantissa < 0.0) {sign = -1;}
303 Destroy_SuperMatrix_Store(&A);
304 Destroy_CompCol_Permuted(&AC);
311 else if (*op_flag == 2)
320 perm_c = LUfactors->
perm_c;
321 perm_r = LUfactors->
perm_r;
323 dCreate_Dense_Matrix(&
B, *n, *nrhs, b, *ldb, SLU_DN, SLU_D, SLU_GE);
326 dgstrs(trans,
L,
U, perm_c, perm_r, &
B, &stat, info);
328 Destroy_SuperMatrix_Store(&
B);
335 else if (*op_flag == 3)
339 SUPERLU_FREE(LUfactors->
perm_r);
340 SUPERLU_FREE(LUfactors->
perm_c);
341 Destroy_SuperNode_Matrix(LUfactors->
L);
342 Destroy_CompCol_Matrix(LUfactors->
U);
343 SUPERLU_FREE(LUfactors->
L);
344 SUPERLU_FREE(LUfactors->
U);
345 SUPERLU_FREE(LUfactors);
350 fprintf(stderr,
"Invalid op_flag=%d passed to c_cpp_dgssv()\n",*op_flag);
int Memory_usage_has_been_recorded
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)
struct MemoryStatisticsStorage memory_statistics_storage
void get_memory_usage_in_bytes(double *lu_factor_memory, double *total_memory)
double get_lu_factor_memory_usage_in_bytes()
double get_total_memory_usage_in_bytes()