Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
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_functs.h"
24#include "fasp_block.h"
25
26/*---------------------------------*/
27/*-- Declare Private Functions --*/
28/*---------------------------------*/
29
30#include "KryUtil.inl"
31#include "BlaSpmvMatFree.inl"
32
33/*---------------------------------*/
34/*-- Public Functions --*/
35/*---------------------------------*/
36
59 dvector *b,
60 dvector *x,
61 precond *pc,
62 ITS_param *itparam)
63{
64 const SHORT prtlvl = itparam->print_level;
65 const SHORT itsolver_type = itparam->itsolver_type;
66 const SHORT stop_type = itparam->stop_type;
67 const INT restart = itparam->restart;
68 const INT MaxIt = itparam->maxit;
69 const REAL tol = itparam->tol;
70
71 /* Local Variables */
72 REAL solve_start, solve_end, solve_time;
74
75 fasp_gettime(&solve_start);
76
77#if DEBUG_MODE > 0
78 printf("### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
79 printf("### DEBUG: rhs/sol size: %d %d\n", b->row, x->row);
80#endif
81
82 /* Safe-guard checks on parameters */
83 ITS_CHECK ( MaxIt, tol );
84
85 /* Choose a desirable Krylov iterative solver */
86 switch ( itsolver_type ) {
87
88 case SOLVER_CG:
89 iter = fasp_solver_pcg(mf, b, x, pc, tol, MaxIt, stop_type, prtlvl);
90 break;
91
92 case SOLVER_BiCGstab:
93 iter = fasp_solver_pbcgs(mf, b, x, pc, tol, MaxIt, stop_type, prtlvl);
94 break;
95
96 case SOLVER_MinRes:
97 iter = fasp_solver_pminres(mf, b, x, pc, tol, MaxIt, stop_type, prtlvl);
98 break;
99
100 case SOLVER_GMRES:
101 iter = fasp_solver_pgmres(mf, b, x, pc, tol, MaxIt, restart, stop_type, prtlvl);
102 break;
103
104 case SOLVER_VGMRES:
105 iter = fasp_solver_pvgmres(mf, b, x, pc, tol, MaxIt, restart, stop_type, prtlvl);
106 break;
107
108 case SOLVER_VFGMRES:
109 iter = fasp_solver_pvfgmres(mf, b, x, pc, tol, MaxIt, restart, stop_type, prtlvl);
110 break;
111
112 case SOLVER_GCG:
113 iter = fasp_solver_pgcg(mf, b, x, pc, tol, MaxIt, stop_type, prtlvl);
114 break;
115
116 default:
117 printf("### ERROR: Unknown iterative solver type %d! [%s]\n",
118 itsolver_type, __FUNCTION__);
119 return ERROR_SOLVER_TYPE;
120
121 }
122
123 if ( (prtlvl >= PRINT_SOME) && (iter >= 0) ) {
124 fasp_gettime(&solve_end);
125 solve_time = solve_end - solve_start;
126 fasp_cputime("Iterative method", solve_time);
127 }
128
129#if DEBUG_MODE > 0
130 printf("### DEBUG: [--End--] %s ...\n", __FUNCTION__);
131#endif
132
133 return iter;
134}
135
155 dvector *b,
156 dvector *x,
157 ITS_param *itparam)
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,
202 mxv_matfree *mf,
203 void *A)
204{
205 switch ( matrix_format ) {
206
207 case MAT_CSR:
208 mf->fct = fasp_blas_mxv_csr;
209 break;
210
211 case MAT_BSR:
212 mf->fct = fasp_blas_mxv_bsr;
213 break;
214
215 case MAT_STR:
216 mf->fct = fasp_blas_mxv_str;
217 break;
218
219 case MAT_BLC:
220 mf->fct = fasp_blas_mxv_blc;
221 break;
222
223 case MAT_CSRL:
224 mf->fct = fasp_blas_mxv_csrl;
225 break;
226
227 default:
228 printf("### ERROR: Unknown matrix format %d!\n", matrix_format);
230
231 }
232
233 mf->data = A;
234}
235
236/*---------------------------------*/
237/*-- End of File --*/
238/*---------------------------------*/
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_pbcgs(mxv_matfree *mf, dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned BiCGstab method for solving Au=b.
Definition: KryPbcgs.c:1365
INT fasp_solver_pcg(mxv_matfree *mf, dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned conjugate gradient (CG) method for solving Au=b.
Definition: KryPcg.c:1272
INT fasp_solver_pgcg(mxv_matfree *mf, dvector *b, dvector *u, precond *pc, const REAL tol, 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 INT MaxIt, const SHORT restart, const SHORT StopType, const SHORT PrtLvl)
Solve "Ax=b" using PGMRES (right preconditioned) iterative method.
Definition: KryPgmres.c:1283
INT fasp_solver_pminres(mxv_matfree *mf, dvector *b, dvector *u, precond *pc, const REAL tol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
A preconditioned minimal residual (Minres) method for solving Au=b.
Definition: KryPminres.c:1296
INT fasp_solver_pvfgmres(mxv_matfree *mf, dvector *b, dvector *x, precond *pc, const REAL tol, 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:1036
INT fasp_solver_pvgmres(mxv_matfree *mf, dvector *b, dvector *x, precond *pc, const REAL tol, 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:1451
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:154
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:67
#define SHORT
FASP integer and floating point numbers.
Definition: fasp.h:63
#define INT
Definition: fasp.h:64
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:379
SHORT itsolver_type
Definition: fasp.h:382
SHORT print_level
Definition: fasp.h:381
REAL tol
Definition: fasp.h:388
INT restart
Definition: fasp.h:386
SHORT stop_type
Definition: fasp.h:385
INT maxit
Definition: fasp.h:387
Vector with n entries of REAL type.
Definition: fasp.h:346
INT row
number of rows
Definition: fasp.h:349
Matrix-vector multiplication, replace the actual matrix.
Definition: fasp.h:1095
void * data
data for MxV, can be a Matrix or something else
Definition: fasp.h:1098
void(* fct)(const void *, const REAL *, REAL *)
action for MxV, void function pointer
Definition: fasp.h:1101
Preconditioner data and action.
Definition: fasp.h:1081