Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
XtrUmfpack.c
Go to the documentation of this file.
1
14#include <time.h>
15
16#include "fasp.h"
17#include "fasp_functs.h"
18
19#if WITH_UMFPACK
20#include "umfpack.h"
21#endif
22
23/*---------------------------------*/
24/*-- Public Functions --*/
25/*---------------------------------*/
26
45 dvector *b,
46 dvector *u,
47 const SHORT prtlvl)
48{
49
50#if WITH_UMFPACK
51
52 const INT n = ptrA->col;
53
54 INT *Ap = ptrA->IA;
55 INT *Ai = ptrA->JA;
56 double *Ax = ptrA->val;
57 void *Symbolic, *Numeric;
58 INT status = FASP_SUCCESS;
59
60#if DEBUG_MODE
61 const INT m = ptrA->row;
62 const INT nnz = ptrA->nnz;
63 printf("### DEBUG: %s ...... [Start]\n", __FUNCTION__);
64 printf("### DEBUG: nr=%d, nc=%d, nnz=%d\n", m, n, nnz);
65#endif
66
67 REAL start_time, end_time;
68 fasp_gettime(&start_time);
69
70 status = umfpack_di_symbolic(n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL);
71 if (status < 0) {
72 printf("### ERROR: %d, %s %d\n", status, __FUNCTION__, __LINE__);
73 printf("### ERROR: Symbolic factorization failed!\n");
75 }
76
77 status = umfpack_di_numeric(Ap, Ai, Ax, Symbolic, &Numeric, NULL, NULL);
78 if (status < 0) {
79 printf("### ERROR: %d, %s %d\n", status, __FUNCTION__, __LINE__);
80 printf("### ERROR: Numerica factorization failed!\n");
82 }
83 umfpack_di_free_symbolic(&Symbolic);
84
85 status = umfpack_di_solve(UMFPACK_A, Ap, Ai, Ax, u->val, b->val, Numeric, NULL, NULL);
86 if (status < 0) {
87 printf("### ERROR: %d, %s %d\n", status, __FUNCTION__, __LINE__);
88 printf("### ERROR: UMFPACK solver failed!\n");
90 }
91 umfpack_di_free_numeric(&Numeric);
92
93 if ( prtlvl > PRINT_MIN ) {
94 fasp_gettime(&end_time);
95 fasp_cputime("UMFPACK costs", end_time - start_time);
96 }
97
98#if DEBUG_MODE
99 printf("### DEBUG: %s ...... [Finish]\n", __FUNCTION__);
100#endif
101
102 return status;
103
104#else
105
106 printf("### ERROR: UMFPACK is not available!\n");
107 return ERROR_SOLVER_EXIT;
108
109#endif
110
111}
112
113#if WITH_UMFPACK
124void* fasp_umfpack_factorize (dCSRmat *ptrA,
125 const SHORT prtlvl)
126{
127 const INT n = ptrA->col;
128
129 INT *Ap = ptrA->IA;
130 INT *Ai = ptrA->JA;
131 double *Ax = ptrA->val;
132 void *Symbolic;
133 void *Numeric;
134
135#if DEBUG_MODE
136 const INT m = ptrA->row;
137 const INT nnz = ptrA->nnz;
138 printf("### DEBUG: %s ...... [Start]\n", __FUNCTION__);
139 printf("### DEBUG: nr=%d, nc=%d, nnz=%d\n", m, n, nnz);
140#endif
141
142 REAL start_time, end_time;
143 fasp_gettime(&start_time);
144
145 umfpack_di_symbolic (n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL);
146 umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, NULL, NULL);
147 umfpack_di_free_symbolic (&Symbolic);
148
149 if ( prtlvl > PRINT_MIN ) {
150 fasp_gettime(&end_time);
151 fasp_cputime("UMFPACK setup", end_time - start_time);
152 }
153
154#if DEBUG_MODE
155 printf("### DEBUG: %s ...... [Finish]\n", __FUNCTION__);
156#endif
157
158 return Numeric;
159}
160
175INT fasp_umfpack_solve (dCSRmat *ptrA,
176 dvector *b,
177 dvector *u,
178 void *Numeric,
179 const SHORT prtlvl)
180{
181 INT *Ap = ptrA->IA;
182 INT *Ai = ptrA->JA;
183 double *Ax = ptrA->val;
184 INT status = FASP_SUCCESS;
185
186#if DEBUG_MODE
187 const INT m = ptrA->row;
188 const INT n = ptrA->col;
189 const INT nnz = ptrA->nnz;
190 printf("### DEBUG: %s ...... [Start]\n", __FUNCTION__);
191 printf("### DEBUG: nr=%d, nc=%d, nnz=%d\n", m, n, nnz);
192#endif
193
194 REAL start_time, end_time;
195 fasp_gettime(&start_time);
196
197 status = umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, u->val, b->val, Numeric, NULL, NULL);
198
199 if ( prtlvl > PRINT_NONE ) {
200 fasp_gettime(&end_time);
201 fasp_cputime("UMFPACK solve", end_time - start_time);
202 }
203
204#if DEBUG_MODE
205 printf("### DEBUG: %s ...... [Finish]\n", __FUNCTION__);
206#endif
207
208 return status;
209}
210
220INT fasp_umfpack_free_numeric (void *Numeric)
221{
222 INT status = FASP_SUCCESS;
223
224#if DEBUG_MODE
225 printf("### DEBUG: %s ...... [Start]\n", __FUNCTION__);
226#endif
227
228 umfpack_di_free_numeric (&Numeric);
229
230#if DEBUG_MODE
231 printf("### DEBUG: %s ...... [Finish]\n", __FUNCTION__);
232#endif
233
234 return status;
235}
236
237#endif
238
239/*---------------------------------*/
240/*-- End of File --*/
241/*---------------------------------*/
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:36
INT fasp_solver_umfpack(dCSRmat *ptrA, dvector *b, dvector *u, const SHORT prtlvl)
Solve Au=b by UMFpack.
Definition: XtrUmfpack.c:44
Main header file for the FASP project.
#define REAL
Definition: fasp.h:67
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:63
#define INT
Definition: fasp.h:64
#define FASP_SUCCESS
Definition of return status and error messages.
Definition: fasp_const.h:19
#define ERROR_SOLVER_MISC
Definition: fasp_const.h:47
#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:143
INT col
column of matrix A, n
Definition: fasp.h:149
REAL * val
nonzero entries of A
Definition: fasp.h:161
INT row
row number of matrix A, m
Definition: fasp.h:146
INT * IA
integer array of row pointers, the size is m+1
Definition: fasp.h:155
INT nnz
number of nonzero entries
Definition: fasp.h:152
INT * JA
integer array of column indexes, the size is nnz
Definition: fasp.h:158
Vector with n entries of REAL type.
Definition: fasp.h:346
REAL * val
actual vector entries
Definition: fasp.h:352