Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
XtrSuperlu.c
Go to the documentation of this file.
1
14#include <stdio.h>
15#include <stdlib.h>
16#include <time.h>
17
18#include "fasp.h"
19#include "fasp_functs.h"
20
21#if WITH_SuperLU
22#include "slu_ddefs.h"
23#endif
24
25/*---------------------------------*/
26/*-- Public Functions --*/
27/*---------------------------------*/
28
47int fasp_solver_superlu(dCSRmat* ptrA, dvector* b, dvector* u, const SHORT prtlvl)
48{
49
50#if WITH_SuperLU
51
52 SuperMatrix A, L, U, B;
53
54 int* perm_r; /* row permutations from partial pivoting */
55 int* perm_c; /* column permutation vector */
56 int nrhs = 1, info, m = ptrA->row, n = ptrA->col, nnz = ptrA->nnz;
57
58 if (prtlvl > PRINT_NONE) printf("superlu: nr=%d, nc=%d, nnz=%d\n", m, n, nnz);
59
60 REAL start_time, end_time;
61 fasp_gettime(&start_time);
62
63 dCSRmat tempA = fasp_dcsr_create(m, n, nnz);
64 fasp_dcsr_cp(ptrA, &tempA);
65
66 dvector tempb = fasp_dvec_create(n);
67 fasp_dvec_cp(b, &tempb);
68
69 /* Create matrix A in the format expected by SuperLU. */
70 dCreate_CompCol_Matrix(&A, m, n, nnz, tempA.val, tempA.JA, tempA.IA, SLU_NR, SLU_D,
71 SLU_GE);
72
73 /* Create right-hand side B. */
74 dCreate_Dense_Matrix(&B, m, nrhs, tempb.val, m, SLU_DN, SLU_D, SLU_GE);
75
76 if (!(perm_r = intMalloc(m))) ABORT("Malloc fails for perm_r[].");
77 if (!(perm_c = intMalloc(n))) ABORT("Malloc fails for perm_c[].");
78
79 /* Set the default input options. */
80 superlu_options_t options;
81 set_default_options(&options);
82 options.ColPerm = COLAMD; // MMD_AT_PLUS_A; MMD_ATA; NATURAL;
83
84 /* Initialize the statistics variables. */
85 SuperLUStat_t stat;
86 StatInit(&stat);
87
88 /* SuperLU */
89 dgssv(&options, &A, perm_c, perm_r, &L, &U, &B, &stat, &info);
90
91 DNformat* BB = (DNformat*)B.Store;
92 u->val = (double*)BB->nzval;
93 u->row = n;
94
95 if (prtlvl > PRINT_MIN) {
96 fasp_gettime(&end_time);
97 fasp_cputime("SUPERLU solver", end_time - start_time);
98 }
99
100 /* De-allocate storage */
101 SUPERLU_FREE(perm_r);
102 SUPERLU_FREE(perm_c);
103 Destroy_CompCol_Matrix(&A);
104 Destroy_SuperMatrix_Store(&B);
105 Destroy_SuperNode_Matrix(&L);
106 Destroy_CompCol_Matrix(&U);
107 StatFree(&stat);
108
109 return FASP_SUCCESS;
110
111#else
112
113 printf("### ERROR: SuperLU is not available!\n");
114 return ERROR_SOLVER_EXIT;
115
116#endif
117}
118
119/*---------------------------------*/
120/*-- End of File --*/
121/*---------------------------------*/
void fasp_cputime(const char *message, const REAL cputime)
Print CPU walltime.
Definition: AuxMessage.c:179
void fasp_gettime(REAL *time)
Get system time.
Definition: AuxTiming.c:37
dvector fasp_dvec_create(const INT m)
Create dvector data space of REAL type.
Definition: AuxVector.c:62
void fasp_dvec_cp(const dvector *x, dvector *y)
Copy dvector x to dvector y.
Definition: AuxVector.c:334
dCSRmat fasp_dcsr_create(const INT m, const INT n, const INT nnz)
Create CSR sparse matrix data memory space.
Definition: BlaSparseCSR.c:47
void fasp_dcsr_cp(const dCSRmat *A, dCSRmat *B)
copy a dCSRmat to a new one B=A
Definition: BlaSparseCSR.c:851
int fasp_solver_superlu(dCSRmat *ptrA, dvector *b, dvector *u, const SHORT prtlvl)
Solve Au=b by SuperLU.
Definition: XtrSuperlu.c:47
Main header file for the FASP project.
#define REAL
Definition: fasp.h:75
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:71
#define FASP_SUCCESS
Definition of return status and error messages.
Definition: fasp_const.h:19
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Definition: fasp_const.h:73
#define ERROR_SOLVER_EXIT
Definition: fasp_const.h:49
#define PRINT_MIN
Definition: fasp_const.h:74
Sparse matrix of REAL type in CSR format.
Definition: fasp.h:151
INT col
column of matrix A, n
Definition: fasp.h:157
REAL * val
nonzero entries of A
Definition: fasp.h:169
INT row
row number of matrix A, m
Definition: fasp.h:154
INT * IA
integer array of row pointers, the size is m+1
Definition: fasp.h:163
INT nnz
number of nonzero entries
Definition: fasp.h:160
INT * JA
integer array of column indexes, the size is nnz
Definition: fasp.h:166
Vector with n entries of REAL type.
Definition: fasp.h:354
REAL * val
actual vector entries
Definition: fasp.h:360
INT row
number of rows
Definition: fasp.h:357