Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
interface_umfpack.c
Go to the documentation of this file.
1 
8 #include <time.h>
9 
10 #include "fasp.h"
11 #include "fasp_functs.h"
12 
13 #if WITH_UMFPACK
14 #include "umfpack.h"
15 #endif
16 
17 /*---------------------------------*/
18 /*-- Public Functions --*/
19 /*---------------------------------*/
20 
38  dvector *b,
39  dvector *u,
40  const SHORT prtlvl)
41 {
42 
43 #if WITH_UMFPACK
44 
45  const INT n = ptrA->col;
46  const INT m = ptrA->row;
47  const INT nnz = ptrA->nnz;
48 
49  INT *Ap = ptrA->IA;
50  INT *Ai = ptrA->JA;
51  double *Ax = ptrA->val;
52  void *Symbolic, *Numeric;
53  INT status = FASP_SUCCESS;
54 
55 #if DEBUG_MODE
56  printf("### DEBUG: %s ...... [Start]\n", __FUNCTION__);
57  printf("### DEBUG: nr=%d, nc=%d, nnz=%d\n", m, n, nnz);
58 #endif
59 
60  clock_t start_time = clock();
61 
62  status = umfpack_di_symbolic (n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL);
63  status = umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, NULL, NULL);
64  umfpack_di_free_symbolic (&Symbolic);
65  status = umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, u->val, b->val, Numeric, NULL, NULL);
66  umfpack_di_free_numeric (&Numeric);
67 
68  if ( prtlvl > PRINT_MIN ) {
69  clock_t end_time = clock();
70  double solve_time = (double)(end_time - start_time)/(double)(CLOCKS_PER_SEC);
71  printf("UMFPACK costs %f seconds.\n", solve_time);
72  }
73 
74 #if DEBUG_MODE
75  printf("### DEBUG: %s ...... [Finish]\n", __FUNCTION__);
76 #endif
77 
78  return status;
79 
80 #else
81 
82  printf("### ERROR: UMFPACK is not available!\n");
83  return ERROR_SOLVER_EXIT;
84 
85 #endif
86 
87 }
88 
89 #if WITH_UMFPACK
90 
102 void* fasp_umfpack_factorize (dCSRmat *ptrA,
103  const SHORT prtlvl)
104 {
105  const INT n = ptrA->col;
106  const INT m = ptrA->row;
107  const INT nnz = ptrA->nnz;
108 
109  INT *Ap = ptrA->IA;
110  INT *Ai = ptrA->JA;
111  double *Ax = ptrA->val;
112  void *Symbolic;
113  void *Numeric;
114  INT status = FASP_SUCCESS;
115 
116 #if DEBUG_MODE
117  printf("### DEBUG: %s ...... [Start]\n", __FUNCTION__);
118  printf("### DEBUG: nr=%d, nc=%d, nnz=%d\n", m, n, nnz);
119 #endif
120 
121  clock_t start_time = clock();
122 
123  status = umfpack_di_symbolic (n, n, Ap, Ai, Ax, &Symbolic, NULL, NULL);
124  status = umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, NULL, NULL);
125  umfpack_di_free_symbolic (&Symbolic);
126 
127  if ( prtlvl > PRINT_MIN ) {
128  clock_t end_time = clock();
129  double fac_time = (double)(end_time - start_time)/(double)(CLOCKS_PER_SEC);
130  printf("UMFPACK factorize costs %f seconds.\n", fac_time);
131  }
132 
133 #if DEBUG_MODE
134  printf("### DEBUG: %s ...... [Finish]\n", __FUNCTION__);
135 #endif
136 
137  return Numeric;
138 }
139 
156 INT fasp_umfpack_solve (dCSRmat *ptrA,
157  dvector *b,
158  dvector *u,
159  void *Numeric,
160  const SHORT prtlvl)
161 {
162  const INT n = ptrA->col;
163  const INT m = ptrA->row;
164  const INT nnz = ptrA->nnz;
165 
166  INT *Ap = ptrA->IA;
167  INT *Ai = ptrA->JA;
168  double *Ax = ptrA->val;
169  INT status = FASP_SUCCESS;
170 
171 #if DEBUG_MODE
172  printf("### DEBUG: %s ...... [Start]\n", __FUNCTION__);
173  printf("### DEBUG: nr=%d, nc=%d, nnz=%d\n", m, n, nnz);
174 #endif
175 
176  clock_t start_time = clock();
177 
178  status = umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, u->val, b->val, Numeric, NULL, NULL);
179 
180  if ( prtlvl > PRINT_NONE ) {
181  clock_t end_time = clock();
182  double solve_time = (double)(end_time - start_time)/(double)(CLOCKS_PER_SEC);
183  printf("UMFPACK costs %f seconds.\n", solve_time);
184  }
185 
186 #if DEBUG_MODE
187  printf("### DEBUG: %s ...... [Finish]\n", __FUNCTION__);
188 #endif
189 
190  return status;
191 }
192 
202 INT fasp_umfpack_free_numeric (void *Numeric)
203 {
204  INT status = FASP_SUCCESS;
205 
206 #if DEBUG_MODE
207  printf("### DEBUG: %s ...... [Start]\n", __FUNCTION__);
208 #endif
209 
210  umfpack_di_free_numeric (&Numeric);
211 
212 #if DEBUG_MODE
213  printf("### DEBUG: %s ...... [Finish]\n", __FUNCTION__);
214 #endif
215 
216  return status;
217 }
218 
219 #endif
220 
221 /*---------------------------------*/
222 /*-- End of File --*/
223 /*---------------------------------*/
INT * JA
integer array of column indexes, the size is nnz
Definition: fasp.h:163
REAL * val
nonzero entries of A
Definition: fasp.h:166
INT fasp_solver_umfpack(dCSRmat *ptrA, dvector *b, dvector *u, const SHORT prtlvl)
Solve Au=b by UMFpack.
REAL * val
actual vector entries
Definition: fasp.h:348
Vector with n entries of REAL type.
Definition: fasp.h:342
#define INT
Definition: fasp.h:64
#define FASP_SUCCESS
Definition of return status and error messages.
Definition: fasp_const.h:27
INT nnz
number of nonzero entries
Definition: fasp.h:157
INT col
column of matrix A, n
Definition: fasp.h:154
Main header file for FASP.
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Definition: fasp_const.h:79
INT row
row number of matrix A, m
Definition: fasp.h:151
Sparse matrix of REAL type in CSR format.
Definition: fasp.h:148
#define ERROR_SOLVER_EXIT
Definition: fasp_const.h:55
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:63
INT * IA
integer array of row pointers, the size is m+1
Definition: fasp.h:160
#define PRINT_MIN
Definition: fasp_const.h:80