Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
SolMatFree.c
Go to the documentation of this file.
1
16#include <time.h>
17
18#ifdef _OPENMP
19#include <omp.h>
20#endif
21
22#include "fasp.h"
23#include "fasp_block.h"
24#include "fasp_functs.h"
25
26/*---------------------------------*/
27/*-- Declare Private Functions --*/
28/*---------------------------------*/
29
30#include "BlaSpmvMatFree.inl"
31#include "KryUtil.inl"
32
33/*---------------------------------*/
34/*-- Public Functions --*/
35/*---------------------------------*/
36
59 ITS_param* itparam)
60{
61 const SHORT prtlvl = itparam->print_level;
62 const SHORT itsolver_type = itparam->itsolver_type;
63 const SHORT stop_type = itparam->stop_type;
64 const INT restart = itparam->restart;
65 const INT MaxIt = itparam->maxit;
66 const REAL tol = itparam->tol;
67 const REAL abstol = itparam->abstol;
68
69 /* Local Variables */
70 REAL solve_start, solve_end, solve_time;
72
73 fasp_gettime(&solve_start);
74
75#if DEBUG_MODE > 0
76 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
77 printf("### DEBUG: rhs/sol size: %d %d\n", b->row, x->row);
78#endif
79
80 /* Safe-guard checks on parameters */
81 ITS_CHECK(MaxIt, tol);
82
83 /* Choose a desirable Krylov iterative solver */
84 switch (itsolver_type) {
85
86 case SOLVER_CG:
87 iter = fasp_solver_pcg(mf, b, x, pc, tol, abstol, MaxIt, stop_type, prtlvl);
88 break;
89
90 case SOLVER_BiCGstab:
91 iter =
92 fasp_solver_pbcgs(mf, b, x, pc, tol, abstol, MaxIt, stop_type, prtlvl);
93 break;
94
95 case SOLVER_MinRes:
96 iter = fasp_solver_pminres(mf, b, x, pc, tol, abstol, MaxIt, stop_type,
97 prtlvl);
98 break;
99
100 case SOLVER_GMRES:
101 iter = fasp_solver_pgmres(mf, b, x, pc, tol, abstol, MaxIt, restart,
102 stop_type, prtlvl);
103 break;
104
105 case SOLVER_VGMRES:
106 iter = fasp_solver_pvgmres(mf, b, x, pc, tol, abstol, MaxIt, restart,
107 stop_type, prtlvl);
108 break;
109
110 case SOLVER_VFGMRES:
111 iter = fasp_solver_pvfgmres(mf, b, x, pc, tol, abstol, MaxIt, restart,
112 stop_type, prtlvl);
113 break;
114
115 case SOLVER_GCG:
116 iter =
117 fasp_solver_pgcg(mf, b, x, pc, tol, abstol, MaxIt, stop_type, prtlvl);
118 break;
119
120 default:
121 printf("### ERROR: Unknown iterative solver type %d! [%s]\n", itsolver_type,
122 __FUNCTION__);
123 return ERROR_SOLVER_TYPE;
124 }
125
126 if ((prtlvl >= PRINT_SOME) && (iter >= 0)) {
127 fasp_gettime(&solve_end);
128 solve_time = solve_end - solve_start;
129 fasp_cputime("Iterative method", solve_time);
130 }
131
132#if DEBUG_MODE > 0
133 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
134#endif
135
136 return iter;
137}
138
158{
159 const SHORT prtlvl = itparam->print_level;
160
161 /* Local Variables */
162 INT status = FASP_SUCCESS;
163 REAL solve_start, solve_end, solve_time;
164
165#if DEBUG_MODE > 0
166 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
167 printf("### DEBUG: rhs/sol size: %d %d\n", b->row, x->row);
168#endif
169
170 fasp_gettime(&solve_start);
171
172 status = fasp_solver_itsolver(mf, b, x, NULL, itparam);
173
174 if (prtlvl >= PRINT_MIN) {
175 fasp_gettime(&solve_end);
176 solve_time = solve_end - solve_start;
177 fasp_cputime("Krylov method totally", solve_time);
178 }
179
180#if DEBUG_MODE > 0
181 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
182#endif
183
184 return status;
185}
186
201void fasp_solver_matfree_init(INT matrix_format, mxv_matfree* mf, void* A)
202{
203 switch (matrix_format) {
204
205 case MAT_CSR:
206 mf->fct = fasp_blas_mxv_csr;
207 break;
208
209 case MAT_BSR:
210 mf->fct = fasp_blas_mxv_bsr;
211 break;
212
213 case MAT_STR:
214 mf->fct = fasp_blas_mxv_str;
215 break;
216
217 case MAT_BLC:
218 mf->fct = fasp_blas_mxv_blc;
219 break;
220
221 case MAT_CSRL:
222 mf->fct = fasp_blas_mxv_csrl;
223 break;
224
225 default:
226 printf("### ERROR: Unknown matrix format %d!\n", matrix_format);
228 }
229
230 mf->data = A;
231}
232
233/*---------------------------------*/
234/*-- End of File --*/
235/*---------------------------------*/
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
INT fasp_solver_pbcgs(mxv_matfree *mf, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned BiCGstab method for solving Au=b.
Definition: KryPbcgs.c:1349
INT fasp_solver_pgcg(mxv_matfree *mf, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned generilzed conjugate gradient (GCG) method for solving Au=b.
Definition: KryPgcg.c:213
INT fasp_solver_pgmres(mxv_matfree *mf, dvector *b, dvector *x, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT restart, const SHORT StopType, const SHORT PrtLvl)
Solve "Ax=b" using PGMRES (right preconditioned) iterative method.
Definition: KryPgmres.c:1309
INT fasp_solver_pminres(mxv_matfree *mf, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
A preconditioned minimal residual (Minres) method for solving Au=b.
Definition: KryPminres.c:1283
INT fasp_solver_pvfgmres(mxv_matfree *mf, dvector *b, dvector *x, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT restart, const SHORT StopType, const SHORT PrtLvl)
Solve "Ax=b" using PFGMRES(right preconditioned) iterative method in which the restart parameter can ...
Definition: KryPvfgmres.c:1026
INT fasp_solver_pvgmres(mxv_matfree *mf, dvector *b, dvector *x, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, SHORT restart, const SHORT StopType, const SHORT PrtLvl)
Solve "Ax=b" using PGMRES(right preconditioned) iterative method in which the restart parameter can b...
Definition: KryPvgmres.c:1468
void fasp_solver_matfree_init(INT matrix_format, mxv_matfree *mf, void *A)
Initialize MatFree (or non-specified format) itsovlers.
Definition: SolMatFree.c:201
INT fasp_solver_krylov(mxv_matfree *mf, dvector *b, dvector *x, ITS_param *itparam)
Solve Ax=b by standard Krylov methods – without preconditioner.
Definition: SolMatFree.c:157
INT fasp_solver_itsolver(mxv_matfree *mf, dvector *b, dvector *x, precond *pc, ITS_param *itparam)
Solve Ax=b by preconditioned Krylov methods for CSR matrices.
Definition: SolMatFree.c:58
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 INT
Definition: fasp.h:72
Header file for FASP block matrices.
#define MAT_CSR
Definition: fasp_const.h:85
#define SOLVER_GMRES
Definition: fasp_const.h:106
#define FASP_SUCCESS
Definition of return status and error messages.
Definition: fasp_const.h:19
#define MAT_CSRL
Definition: fasp_const.h:88
#define ERROR_SOLVER_TYPE
Definition: fasp_const.h:41
#define SOLVER_VGMRES
Definition: fasp_const.h:107
#define SOLVER_BiCGstab
Definition: fasp_const.h:104
#define ERROR_DATA_STRUCTURE
Definition: fasp_const.h:31
#define PRINT_SOME
Definition: fasp_const.h:75
#define MAT_STR
Definition: fasp_const.h:87
#define SOLVER_MinRes
Definition: fasp_const.h:105
#define SOLVER_VFGMRES
Definition: fasp_const.h:108
#define SOLVER_CG
Definition: fasp_const.h:103
#define MAT_BSR
Definition: fasp_const.h:86
#define MAT_BLC
Definition: fasp_const.h:90
#define PRINT_MIN
Definition: fasp_const.h:74
#define SOLVER_GCG
Definition: fasp_const.h:109
Parameters for iterative solvers.
Definition: fasp.h:386
SHORT itsolver_type
Definition: fasp.h:389
SHORT print_level
Definition: fasp.h:388
REAL tol
Definition: fasp.h:395
INT restart
Definition: fasp.h:393
SHORT stop_type
Definition: fasp.h:392
REAL abstol
Definition: fasp.h:396
INT maxit
Definition: fasp.h:394
Vector with n entries of REAL type.
Definition: fasp.h:354
INT row
number of rows
Definition: fasp.h:357
Matrix-vector multiplication, replace the actual matrix.
Definition: fasp.h:1109
void * data
data for MxV, can be a Matrix or something else
Definition: fasp.h:1112
void(* fct)(const void *, const REAL *, REAL *)
action for MxV, void function pointer
Definition: fasp.h:1115
Preconditioner data and action.
Definition: fasp.h:1095