18#include "fasp_functs.h"
63 int i, j, k, rst = -1;
65 REAL gamma, alpha, beta, checktol;
70 REAL * c = NULL, *z = NULL, *alp = NULL, *tmpx = NULL;
71 REAL * norms = NULL, *r = NULL, *work = NULL;
74 INT Restart =
MIN(restart, MaxIt);
75 LONG worksize = n + 2 * Restart * n + Restart + Restart;
78 if (PrtLvl >
PRINT_NONE) printf(
"\nCalling GCR solver (CSR) ...\n");
81 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
82 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
88 while ((work == NULL) && (Restart > 5)) {
89 Restart = Restart - 5;
90 worksize = n + 2 * Restart * n + Restart + Restart;
95 printf(
"### ERROR: No enough memory for GCR! [%s:%d]\n", __FILE__, __LINE__);
99 if (PrtLvl >
PRINT_MIN && Restart < restart) {
100 printf(
"### WARNING: GCR restart number set to %d!\n", Restart);
106 alp = c + Restart * n;
107 tmpx = alp + Restart;
122 relres = absres / absres0;
125 fasp_itinfo(PrtLvl, StopType, 0, relres, sqrt(absres0), 0.0);
130 checktol =
MAX(tol * tol * absres0, absres * 1.0e-4);
132 while (iter < MaxIt && sqrt(relres) > tol) {
137 while (i < Restart - 1 && iter < MaxIt) {
146 pc->
fct(r, &z[i * n], pc->
data);
152 for (j = 0; j < i; j++) {
154 h[i][j] = gamma / h[j][j];
165 beta = alpha / gamma;
173 absres = absres - alpha * alpha / gamma;
175 if (absres < checktol) {
177 checktol =
MAX(tol * tol * absres0, absres * 1.0e-4);
180 relres = absres / absres0;
182 norms[iter] = relres;
184 fasp_itinfo(PrtLvl, StopType, iter, sqrt(relres), sqrt(absres),
185 sqrt(norms[iter] / norms[iter - 1]));
187 if (sqrt(relres) < tol)
break;
190 for (k = i; k >= 0; k--) {
192 for (j = 0; j < k; ++j) {
193 alp[j] -= h[k][j] * tmpx[k];
198 dense_aAtxpby(n, i + 1, z, 1.0, tmpx, 0.0, x->
val);
200 dense_aAtxpby(n, i + 1, z, 1.0, tmpx, 1.0, x->
val);
203 if (PrtLvl >
PRINT_NONE) ITS_FINAL(iter, MaxIt, sqrt(relres));
206 for (i = 0; i < Restart; i++) {
219 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
255 const REAL tol,
const REAL abstol,
const INT MaxIt,
262 int i, j, k, rst = -1;
264 REAL gamma, alpha, beta, checktol;
269 REAL * c = NULL, *z = NULL, *alp = NULL, *tmpx = NULL;
270 REAL * norms = NULL, *r = NULL, *work = NULL;
273 INT Restart =
MIN(restart, MaxIt);
274 LONG worksize = n + 2 * Restart * n + Restart + Restart;
277 if (PrtLvl >
PRINT_NONE) printf(
"\nCalling GCR solver (BLC) ...\n");
280 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
281 printf(
"### DEBUG: maxit = %d, tol = %.4le\n", MaxIt, tol);
287 while ((work == NULL) && (Restart > 5)) {
288 Restart = Restart - 5;
289 worksize = n + 2 * Restart * n + Restart + Restart;
294 printf(
"### ERROR: No enough memory for GCR! [%s:%d]\n", __FILE__, __LINE__);
298 if (PrtLvl >
PRINT_MIN && Restart < restart) {
299 printf(
"### WARNING: GCR restart number set to %d!\n", Restart);
305 alp = c + Restart * n;
306 tmpx = alp + Restart;
321 relres = absres / absres0;
324 fasp_itinfo(PrtLvl, StopType, 0, relres, sqrt(absres0), 0.0);
329 checktol =
MAX(tol * tol * absres0, absres * 1.0e-4);
331 while (iter < MaxIt && sqrt(relres) > tol) {
335 while (i < Restart && iter < MaxIt) {
343 pc->
fct(r, &z[i * n], pc->
data);
349 for (j = 0; j < i; j++) {
351 h[i][j] = gamma / h[j][j];
362 beta = alpha / gamma;
370 absres = absres - alpha * alpha / gamma;
372 if (absres < checktol) {
374 checktol =
MAX(tol * tol * absres0, absres * 1.0e-4);
377 relres = absres / absres0;
379 norms[iter] = relres;
381 fasp_itinfo(PrtLvl, StopType, iter, sqrt(relres), sqrt(absres),
382 sqrt(norms[iter] / norms[iter - 1]));
384 if (sqrt(relres) < tol)
break;
389 for (k = i; k >= 0; k--) {
391 for (j = 0; j < k; ++j) {
392 alp[j] -= h[k][j] * tmpx[k];
397 dense_aAtxpby(n, i + 1, z, 1.0, tmpx, 0.0, x->
val);
399 dense_aAtxpby(n, i + 1, z, 1.0, tmpx, 1.0, x->
val);
402 if (PrtLvl >
PRINT_NONE) ITS_FINAL(iter, MaxIt, sqrt(relres));
405 for (i = 0; i < Restart; i++) {
418 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
457 for (j = 1; j < m; j++) {
458 for (i = 0; i < n; i++) {
459 A[i] += A[i + j * n];
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.
void fasp_chkerr(const SHORT status, const char *fctname)
Check error status and print out error messages before quit.
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
void fasp_blas_darray_ax(const INT n, const REAL a, REAL *x)
x = a*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_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.
INT fasp_solver_dblc_pgcr(dBLCmat *A, dvector *b, dvector *x, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT restart, const SHORT StopType, const SHORT PrtLvl)
A preconditioned GCR method for solving Au=b.
INT fasp_solver_dcsr_pgcr(dCSRmat *A, dvector *b, dvector *x, precond *pc, const REAL tol, const REAL abstol, const INT MaxIt, const SHORT restart, const SHORT StopType, const SHORT PrtLvl)
A preconditioned GCR 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_MAXIT
#define BIGREAL
Some global constants.
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Block REAL CSR matrix format.
Sparse matrix of REAL type in CSR format.
Vector with n entries of REAL type.
REAL * val
actual vector entries
Preconditioner data and action.
void * data
data for preconditioner, void pointer
void(* fct)(REAL *, REAL *, void *)
action for preconditioner, void function pointer