62#include "fasp_functs.h"
106 INT iter = 0, stag = 1, more_step = 1;
109 REAL reldiff, factor, normuinf;
110 REAL alpha, beta, temp1, temp2;
114 REAL *p = work, *z = work + m, *r = z + m, *t = r + m;
117 if (PrtLvl >
PRINT_NONE) printf(
"\nCalling CG solver (CSR) ...\n");
120 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
121 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
138 relres = absres0 / normr0;
143 relres = absres0 / normr0;
148 relres = absres0 / normu;
151 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
156 if (relres < tol || absres0 < abstol)
goto FINISHED;
159 fasp_itinfo(PrtLvl, StopType, iter, relres, absres0, 0.0);
165 while (iter++ < MaxIt) {
173 alpha = temp1 / temp2;
189 relres = absres / normr0;
198 relres = absres / normr0;
202 relres = absres / normu;
207 factor = absres / absres0;
210 fasp_itinfo(PrtLvl, StopType, iter, relres, absres, factor);
216 if (normuinf <= sol_inf_tol) {
227 if ((stag <= MaxStag) & (reldiff < maxdiff)) {
230 ITS_DIFFRES(reldiff, relres);
241 relres = absres / normr0;
250 relres = absres / normr0;
254 relres = absres / normu;
258 if (PrtLvl >=
PRINT_MORE) ITS_REALRES(relres);
263 if (stag >= MaxStag) {
279 REAL updated_relres = relres;
289 relres = absres / normr0;
298 relres = absres / normr0;
302 relres = absres / normu;
307 if (relres < tol)
break;
310 ITS_COMPRES(updated_relres);
314 if (more_step >= MaxRestartStep) {
339 beta = temp2 / temp1;
348 if (PrtLvl >
PRINT_NONE) ITS_FINAL(iter, MaxIt, relres);
355 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
387 const REAL tol,
const REAL abstol,
const INT MaxIt,
396 INT iter = 0, stag = 1, more_step = 1;
399 REAL reldiff, factor, normuinf;
400 REAL alpha, beta, temp1, temp2;
404 REAL *p = work, *z = work + m, *r = z + m, *t = r + m;
407 if (PrtLvl >
PRINT_NONE) printf(
"\nCalling CG solver (BSR) ...\n");
410 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
411 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
428 relres = absres0 / normr0;
433 relres = absres0 / normr0;
438 relres = absres0 / normu;
441 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
446 if (relres < tol || absres0 < abstol)
goto FINISHED;
449 fasp_itinfo(PrtLvl, StopType, iter, relres, absres0, 0.0);
455 while (iter++ < MaxIt) {
463 alpha = temp1 / temp2;
479 relres = absres / normr0;
488 relres = absres / normr0;
492 relres = absres / normu;
497 factor = absres / absres0;
500 fasp_itinfo(PrtLvl, StopType, iter, relres, absres, factor);
506 if (normuinf <= sol_inf_tol) {
517 if ((stag <= MaxStag) & (reldiff < maxdiff)) {
520 ITS_DIFFRES(reldiff, relres);
531 relres = absres / normr0;
540 relres = absres / normr0;
544 relres = absres / normu;
548 if (PrtLvl >=
PRINT_MORE) ITS_REALRES(relres);
553 if (stag >= MaxStag) {
569 REAL updated_relres = relres;
579 relres = absres / normr0;
588 relres = absres / normr0;
592 relres = absres / normu;
597 if (relres < tol)
break;
600 ITS_COMPRES(updated_relres);
604 if (more_step >= MaxRestartStep) {
629 beta = temp2 / temp1;
638 if (PrtLvl >
PRINT_NONE) ITS_FINAL(iter, MaxIt, relres);
645 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
679 const REAL tol,
const REAL abstol,
const INT MaxIt,
688 INT iter = 0, stag = 1, more_step = 1;
691 REAL reldiff, factor, normuinf;
692 REAL alpha, beta, temp1, temp2;
696 REAL *p = work, *z = work + m, *r = z + m, *t = r + m;
699 if (PrtLvl >
PRINT_NONE) printf(
"\nCalling CG solver (BLC) ...\n");
702 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
703 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
720 relres = absres0 / normr0;
725 relres = absres0 / normr0;
730 relres = absres0 / normu;
733 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
738 if (relres < tol || absres0 < abstol)
goto FINISHED;
741 fasp_itinfo(PrtLvl, StopType, iter, relres, absres0, 0.0);
747 while (iter++ < MaxIt) {
755 alpha = temp1 / temp2;
771 relres = absres / normr0;
780 relres = absres / normr0;
784 relres = absres / normu;
789 factor = absres / absres0;
792 fasp_itinfo(PrtLvl, StopType, iter, relres, absres, factor);
798 if (normuinf <= sol_inf_tol) {
809 if ((stag <= MaxStag) & (reldiff < maxdiff)) {
812 ITS_DIFFRES(reldiff, relres);
823 relres = absres / normr0;
832 relres = absres / normr0;
836 relres = absres / normu;
840 if (PrtLvl >=
PRINT_MORE) ITS_REALRES(relres);
845 if (stag >= MaxStag) {
861 REAL updated_relres = relres;
871 relres = absres / normr0;
880 relres = absres / normr0;
884 relres = absres / normu;
889 if (relres < tol)
break;
892 ITS_COMPRES(updated_relres);
896 if (more_step >= MaxRestartStep) {
921 beta = temp2 / temp1;
930 if (PrtLvl >
PRINT_NONE) ITS_FINAL(iter, MaxIt, relres);
937 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
971 const REAL tol,
const REAL abstol,
const INT MaxIt,
980 INT iter = 0, stag = 1, more_step = 1;
983 REAL reldiff, factor, normuinf;
984 REAL alpha, beta, temp1, temp2;
988 REAL *p = work, *z = work + m, *r = z + m, *t = r + m;
991 if (PrtLvl >
PRINT_NONE) printf(
"\nCalling CG solver (STR) ...\n");
994 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
995 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
1012 relres = absres0 / normr0;
1017 relres = absres0 / normr0;
1022 relres = absres0 / normu;
1025 printf(
"### ERROR: Unknown stopping type! [%s]\n", __FUNCTION__);
1030 if (relres < tol || absres0 < abstol)
goto FINISHED;
1033 fasp_itinfo(PrtLvl, StopType, iter, relres, absres0, 0.0);
1039 while (iter++ < MaxIt) {
1047 alpha = temp1 / temp2;
1063 relres = absres / normr0;
1072 relres = absres / normr0;
1076 relres = absres / normu;
1081 factor = absres / absres0;
1084 fasp_itinfo(PrtLvl, StopType, iter, relres, absres, factor);
1090 if (normuinf <= sol_inf_tol) {
1101 if ((stag <= MaxStag) & (reldiff < maxdiff)) {
1104 ITS_DIFFRES(reldiff, relres);
1115 relres = absres / normr0;
1124 relres = absres / normr0;
1128 relres = absres / normu;
1132 if (PrtLvl >=
PRINT_MORE) ITS_REALRES(relres);
1137 if (stag >= MaxStag) {
1153 REAL updated_relres = relres;
1163 relres = absres / normr0;
1172 relres = absres / normr0;
1176 relres = absres / normu;
1181 if (relres < tol)
break;
1184 ITS_COMPRES(updated_relres);
1185 ITS_REALRES(relres);
1188 if (more_step >= MaxRestartStep) {
1213 beta = temp2 / temp1;
1222 if (PrtLvl >
PRINT_NONE) ITS_FINAL(iter, MaxIt, relres);
1229 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
1261 const REAL tol,
const REAL abstol,
const INT MaxIt,
1270 INT iter = 0, stag, more_step, restart_step;
1273 REAL reldiff, factor, infnormu;
1274 REAL alpha, beta, temp1, temp2;
1278 REAL *p = work, *z = work + m, *r = z + m, *t = r + m;
1281 if (PrtLvl >
PRINT_NONE) printf(
"\nCalling CG solver (MatFree) ...\n");
1284 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
1285 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
1307 relres = absres0 / normr0;
1312 relres = absres0 / normu;
1317 relres = absres0 / normr0;
1322 if (relres < tol || absres0 < abstol)
goto FINISHED;
1327 while (iter++ < MaxIt) {
1334 alpha = temp1 / temp2;
1344 factor = absres / absres0;
1355 relres = sqrt(
ABS(temp2)) / normr0;
1358 relres = absres / normu;
1361 relres = absres / normr0;
1366 fasp_itinfo(PrtLvl, StopType, iter, relres, absres, factor);
1370 if (infnormu <= sol_inf_tol) {
1381 if ((stag <= MaxStag) & (reldiff < maxdiff)) {
1384 ITS_DIFFRES(reldiff, relres);
1401 relres = sqrt(
ABS(temp2)) / normr0;
1404 relres = absres / normu;
1407 relres = absres / normr0;
1411 if (PrtLvl >=
PRINT_MORE) ITS_REALRES(relres);
1416 if (stag >= MaxStag) {
1429 if (PrtLvl >=
PRINT_MORE) ITS_COMPRES(relres);
1443 relres = sqrt(
ABS(temp2)) / normr0;
1447 relres = absres / normu;
1451 relres = absres / normr0;
1455 if (PrtLvl >=
PRINT_MORE) ITS_REALRES(relres);
1458 if (relres < tol)
break;
1460 if (more_step >= MaxRestartStep) {
1486 beta = temp2 / temp1;
1495 if (PrtLvl >
PRINT_NONE) ITS_FINAL(iter, MaxIt, relres);
1502 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
void fasp_darray_set(const INT n, REAL *x, const REAL val)
Set initial value for an array to be x=val.
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.
REAL fasp_blas_darray_norminf(const INT n, const REAL *x)
Linf norm of array x.
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
void fasp_blas_dblc_mxv(const dBLCmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = A*x.
void fasp_blas_dblc_aAxpy(const REAL alpha, const dBLCmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = alpha*A*x + y.
void fasp_blas_dbsr_aAxpy(const REAL alpha, const dBSRmat *A, const REAL *x, REAL *y)
Compute y := alpha*A*x + y.
void fasp_blas_dbsr_mxv(const dBSRmat *A, const REAL *x, REAL *y)
Compute y := A*x.
void fasp_blas_dcsr_mxv(const dCSRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication 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.
void fasp_blas_dstr_aAxpy(const REAL alpha, const dSTRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = alpha*A*x + y.
void fasp_blas_dstr_mxv(const dSTRmat *A, const REAL *x, REAL *y)
Matrix-vector multiplication y = A*x.
INT fasp_solver_dblc_pcg(dBLCmat *A, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned conjugate gradient method for solving Au=b.
INT fasp_solver_dcsr_pcg(dCSRmat *A, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned conjugate gradient method for solving Au=b.
INT fasp_solver_dstr_pcg(dSTRmat *A, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned conjugate gradient method for solving Au=b.
INT fasp_solver_dbsr_pcg(dBSRmat *A, dvector *b, dvector *u, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT StopType, const SHORT PrtLvl)
Preconditioned conjugate gradient method for solving Au=b.
Main header file for the FASP project.
#define SHORT
FASP integer and floating point numbers.
#define MAX(a, b)
Definition of max, min, abs.
#define ERROR_SOLVER_STAG
#define ERROR_SOLVER_MAXIT
#define STOP_REL_RES
Definition of iterative solver stopping criteria types.
#define ERROR_SOLVER_SOLSTAG
#define BIGREAL
Some global constants.
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
#define ERROR_SOLVER_TOLSMALL
Block REAL CSR matrix format.
Block sparse row storage matrix of REAL type.
Sparse matrix of REAL type in CSR format.
Structure matrix of REAL type.
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