24#include "fasp_functs.h"
64 INT iter = 0, m = A->
row, i;
72 REAL *r, *Br, *beta, *p;
79 if (PrtLvl >
PRINT_NONE) printf(
"\nCalling GCG solver (CSR) ...\n");
82 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
83 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
112 factor = absres / absres0;
115 relres = absres / normb;
118 fasp_itinfo(PrtLvl, StopType, iter, relres, absres, factor);
123 for (iter = 1; iter < MaxIt; iter++) {
134 for (i = 0; i < iter; i++) {
157 factor = absres / absres0;
160 relres = absres / normb;
163 fasp_itinfo(PrtLvl, StopType, iter, relres, absres, factor);
165 if (relres < tol || absres < abstol)
break;
173 if (PrtLvl >
PRINT_NONE) ITS_FINAL(iter, MaxIt, relres);
180 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
214 const REAL tol,
const REAL abstol,
const INT MaxIt,
217 INT iter = 0, m = b->
row, i;
220 REAL alpha, factor, gama_1, gama_2;
225 REAL *r, *Br, *beta, *p, *q;
233 if (PrtLvl >
PRINT_NONE) printf(
"\nCalling GCG solver (MatFree) ...\n");
236 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
237 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
268 factor = absres / absres0;
271 relres = absres / normb;
274 fasp_itinfo(PrtLvl, StopType, iter + 1, relres, absres, factor);
279 for (iter = 1; iter < MaxIt; iter++) {
290 for (i = 0; i < iter; i++) {
293 mf->
fct(mf->
data, p + i * m, q);
295 beta[i] = (-1.0) * (gama_1 / gama_2);
305 mf->
fct(mf->
data, p + iter * m, q);
313 mf->
fct(mf->
data, p + iter * m, q);
318 factor = absres / absres0;
321 relres = absres / normb;
324 fasp_itinfo(PrtLvl, StopType, iter + 1, relres, absres, factor);
326 if (relres < tol || absres < abstol)
break;
334 if (PrtLvl >
PRINT_NONE) ITS_FINAL(iter, MaxIt, relres);
341 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
void fasp_darray_cp(const INT n, const REAL *x, REAL *y)
Copy an array to the other y=x.
void fasp_mem_free(void *mem)
Free up previous allocated memory body and set pointer to NULL.
void * fasp_mem_calloc(const unsigned int size, const unsigned int type)
Allocate, initiate, and check memory.
void fasp_itinfo(const INT ptrlvl, const INT stop_type, const INT iter, const REAL relres, const REAL absres, const REAL factor)
Print out iteration information for iterative solvers.
REAL fasp_blas_darray_dotprod(const INT n, const REAL *x, const REAL *y)
Inner product of two arraies x and y.
void fasp_blas_darray_axpby(const INT n, const REAL a, const REAL *x, const REAL b, REAL *y)
y = a*x + b*y
REAL fasp_blas_darray_norm2(const INT n, const REAL *x)
L2 norm of array x.
void fasp_blas_darray_axpy(const INT n, const REAL a, const REAL *x, REAL *y)
y = a*x + y
REAL fasp_blas_dcsr_vmv(const dCSRmat *A, const REAL *x, const REAL *y)
vector-Matrix-vector multiplication alpha = y'*A*x
void fasp_blas_dcsr_aAxpy(const REAL alpha, const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = alpha*A*x + y.
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.
INT fasp_solver_dcsr_pgcg(dCSRmat *A, 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.
Main header file for the FASP project.
#define SHORT
FASP integer and floating point numbers.
#define ERROR_SOLVER_MAXIT
#define BIGREAL
Some global constants.
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Sparse matrix of REAL type in CSR format.
INT row
row number of matrix A, m
Vector with n entries of REAL type.
REAL * val
actual vector entries
Matrix-vector multiplication, replace the actual matrix.
void * data
data for MxV, can be a Matrix or something else
void(* fct)(const void *, const REAL *, REAL *)
action for MxV, void function pointer
Preconditioner data and action.
void * data
data for preconditioner, void pointer
void(* fct)(REAL *, REAL *, void *)
action for preconditioner, void function pointer