113int superlu(
int *op_flag,
int *n,
int *nnz,
int *nrhs,
114 double *values,
int *rowind,
int *colptr,
115 double *b,
int *ldb,
int *transpose,
int *doc,
116 fptr *f_factors,
int *info)
120 SuperMatrix A, AC, B;
127 int i, j, panel_size, permc_spec, relax;
130 mem_usage_t mem_usage;
131 superlu_options_t options;
137 double *diagU, *dblock;
138 int_t fsupc, nsupr, nsupc, luptr;
139 int_t i2, k2, nsupers;
157 set_default_options(&options);
162 dCreate_CompCol_Matrix(&A, *n, *n, *nnz, values, rowind, colptr,
163 SLU_NC, SLU_D, SLU_GE);
164 L = (SuperMatrix *) SUPERLU_MALLOC(
sizeof(SuperMatrix));
165 U = (SuperMatrix *) SUPERLU_MALLOC(
sizeof(SuperMatrix));
166 if (!(perm_r = intMalloc(*n))) ABORT(
"Malloc fails for perm_r[].");
167 if (!(perm_c = intMalloc(*n))) ABORT(
"Malloc fails for perm_c[].");
168 if (!(etree = intMalloc(*n))) ABORT(
"Malloc fails for etree[].");
177 permc_spec = options.ColPerm;
178 get_perm_c(permc_spec, &A, perm_c);
180 sp_preorder(&options, &A, perm_c, etree, &AC);
182 panel_size = sp_ienv(1);
185 dgstrf(&options, &AC, relax, panel_size,
186 etree, NULL, 0, perm_c, perm_r, L, U,
192 Lstore = (SCformat *)L->Store;
193 Ustore = (NCformat *)U->Store;
196 printf(
" No of nonzeros in factor L = %d\n", Lstore->nnz);
197 printf(
" No of nonzeros in factor U = %d\n", Ustore->nnz);
198 printf(
" No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz);
199 printf(
" L\\U MB %.3f\ttotal MB needed %.3f\n",
208 printf(
"dgstrf() error returns INFO= %d\n", *info);
211 printf(
"Argument number %d had an illegal value", *info);
213 else if (*info <= *n)
215 printf(
"U(%i,%i) is exactly zero so U is exactly singular.",
218 printf(
" L\\U MB %.3f\ttotal MB needed %.3f\n",
230 LUfactors->
perm_c = perm_c;
231 LUfactors->
perm_r = perm_r;
232 *f_factors = (
fptr)LUfactors;
238 Lval = Lstore->nzval;
239 nsupers = Lstore->nsuper + 1;
243 if (!(diagU = SUPERLU_MALLOC(*n *
sizeof(SuperMatrix))))
244 ABORT(
"Malloc fails for diagU[].");
246 for (k2 = 0; k2 < nsupers; k2++)
248 fsupc = L_FST_SUPC(k2);
249 nsupc = L_FST_SUPC(k2 + 1) - fsupc;
250 nsupr = L_SUB_START(fsupc + 1) - L_SUB_START(fsupc);
251 luptr = L_NZ_START(fsupc);
253 dblock = &diagU[fsupc];
254 for (i2 = 0; i2 < nsupc; i2++)
256 dblock[i2] = Lval[luptr];
264 double determinant_mantissa = 1.0;
265 int determinant_exponent = 0, iexp;
266 for (
i = 0;
i < *n;
i++)
268 determinant_mantissa *= frexp(diagU[
i], &iexp);
269 determinant_exponent += iexp;
271 determinant_mantissa = frexp(determinant_mantissa,&iexp);
272 determinant_exponent += iexp;
278 if (perm_r[j] < perm_r[
i]) {signature *= -1;}
279 if (perm_c[j] < perm_c[
i]) {signature *= -1;}
284 if (determinant_mantissa > 0.0) {sign = 1;}
285 if (determinant_mantissa < 0.0) {sign = -1;}
293 Destroy_SuperMatrix_Store(&A);
294 Destroy_CompCol_Permuted(&AC);
300 else if (*op_flag == 2)
309 perm_c = LUfactors->
perm_c;
310 perm_r = LUfactors->
perm_r;
312 dCreate_Dense_Matrix(&B, *n, *nrhs, b, *ldb, SLU_DN, SLU_D, SLU_GE);
315 dgstrs(trans, L, U, perm_c, perm_r, &B, &stat, info);
317 Destroy_SuperMatrix_Store(&B);
323 else if (*op_flag == 3)
327 SUPERLU_FREE(LUfactors->
perm_r);
328 SUPERLU_FREE(LUfactors->
perm_c);
329 Destroy_SuperNode_Matrix(LUfactors->
L);
330 Destroy_CompCol_Matrix(LUfactors->
U);
331 SUPERLU_FREE(LUfactors->
L);
332 SUPERLU_FREE(LUfactors->
U);
333 SUPERLU_FREE(LUfactors);
338 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)