24#include "fasp_functs.h"
68 REAL solve_start, solve_end;
71 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
72 printf(
"### DEBUG: rhs/sol size: %d %d\n", b->
row, x->
row);
78 ITS_CHECK(MaxIt, tol);
80 switch (itsolver_type) {
108 printf(
"### ERROR: Unknown iterative solver type %d! [%s]\n", itsolver_type,
113 if ((prtlvl >
PRINT_MIN) && (iter >= 0)) {
115 fasp_cputime(
"Iterative method", solve_end - solve_start);
119 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
145 REAL solve_start, solve_end;
148 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
159 fasp_cputime(
"Krylov method totally", solve_end - solve_start);
162 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
190 REAL solve_start, solve_end;
192 INT nb = A->
nb, i, k;
198 INT myid, mybegin, myend;
199 INT nthreads = fasp_get_num_threads();
206 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
212#pragma omp parallel for private(myid, mybegin, myend, i, k)
213 for (myid = 0; myid < nthreads; ++myid) {
215 for (i = mybegin; i < myend; ++i) {
216 for (k = A->
IA[i]; k < A->IA[i + 1]; ++k) {
218 memcpy(diag.
diag.
val + i * nb2, A->
val + k * nb2,
225 for (i = 0; i < ROW; ++i) {
226 for (k = A->
IA[i]; k < A->IA[i + 1]; ++k) {
228 memcpy(diag.
diag.
val + i * nb2, A->
val + k * nb2,
239#pragma omp parallel for if (ROW > OPENMP_HOLDS)
241 for (i = 0; i < ROW; ++i) {
257 fasp_cputime(
"Diag_Krylov method totally", solve_end - solve_start);
263 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
290 REAL solve_start, solve_end;
297 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
298 printf(
"### DEBUG: matrix size: %d %d %d\n", A->
ROW, A->
COL, A->
NNZ);
299 printf(
"### DEBUG: rhs/sol size: %d %d\n", b->
row, x->
row);
320 fasp_cputime(
"ILUk_Krylov method totally", solve_end - solve_start);
326 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
367 REAL setup_start, setup_end, solve_end;
370 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
396 if (status < 0)
goto FINISHED;
401 precdata.
tol = amgparam->
tol;
417 prec.
data = &precdata;
441 fasp_amg_data_bsr_free(mgl, amgparam);
444 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
451 printf(
"### ERROR: Cannot allocate memory! [%s]\n", __FUNCTION__);
499 REAL setup_start, setup_end, setup_time;
500 REAL solve_start, solve_end, solve_time;
503 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
533 if (status < 0)
goto FINISHED;
538 precdata.
tol = amgparam->
tol;
560 precdata.
A_nk = &A_tran;
562 precdata.
A_nk = A_nk;
565 precdata.
P_nk = P_nk;
566 precdata.
R_nk = R_nk;
568 if (status < 0)
goto FINISHED;
571 prec.
data = &precdata;
577 setup_time = setup_end - setup_start;
590 solve_time = solve_end - solve_start;
593 fasp_cputime(
"BSR Krylov method", setup_time + solve_time);
597 fasp_amg_data_bsr_free(mgl, amgparam);
600 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
610 printf(
"### ERROR: Cannot allocate memory! [%s]\n", __FUNCTION__);
659 REAL setup_start, setup_end, setup_time;
660 REAL solve_start, solve_end, solve_time;
663 printf(
"### DEBUG: [-Begin-] %s ...\n", __FUNCTION__);
686 for (i = 0; i < mgl->
near_kernel_dim; ++i) mgl[0].near_kernel_basis[i] = nk[i].val;
699 if (status < 0)
goto FINISHED;
704 precdata.
tol = amgparam->
tol;
719 if (status < 0)
goto FINISHED;
722 prec.
data = &precdata;
734 setup_time = setup_end - setup_start;
747 solve_time = solve_end - solve_start;
750 fasp_cputime(
"BSR Krylov method", setup_time + solve_time);
754 fasp_amg_data_bsr_free(mgl, amgparam);
757 printf(
"### DEBUG: [--End--] %s ...\n", __FUNCTION__);
764 printf(
"### ERROR: Cannot allocate memory! [%s]\n", __FUNCTION__);
SHORT fasp_mem_iludata_check(const ILU_data *iludata)
Check wether a ILU_data has enough work space.
void * fasp_mem_calloc(const unsigned int size, const unsigned int type)
Allocate, initiate, and check memory.
void fasp_cputime(const char *message, const REAL cputime)
Print CPU walltime.
void fasp_get_start_end(const INT procid, const INT nprocs, const INT n, INT *start, INT *end)
Assign Load to each thread.
void fasp_gettime(REAL *time)
Get system time.
void fasp_dvec_free(dvector *u)
Free vector data space of REAL type.
dvector fasp_dvec_create(const INT m)
Create dvector data space of REAL type.
void fasp_dvec_alloc(const INT m, dvector *u)
Create dvector data space of REAL type.
SHORT fasp_ilu_dbsr_setup(dBSRmat *A, ILU_data *iludata, ILU_param *iluparam)
Get ILU decoposition of a BSR matrix A.
SHORT fasp_smat_inv(REAL *a, const INT n)
Compute the inverse matrix of a small full matrix a.
dBSRmat fasp_dbsr_create(const INT ROW, const INT COL, const INT NNZ, const INT nb, const INT storage_manner)
Create BSR sparse matrix data memory space.
void fasp_dbsr_cp(const dBSRmat *A, dBSRmat *B)
copy a dCSRmat to a new one B=A
dCSRmat fasp_dcsr_create(const INT m, const INT n, const INT nnz)
Create CSR sparse matrix data memory space.
void fasp_dcsr_free(dCSRmat *A)
Free CSR sparse matrix data memory space.
void fasp_dcsr_transz(dCSRmat *A, INT *p, dCSRmat *AT)
Generalized transpose of A: (n x m) matrix given in dCSRmat format.
INT fasp_solver_dbsr_pbcgs(dBSRmat *A, 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 for BSR matrix.
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.
INT fasp_solver_dbsr_pgmres(dBSRmat *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)
Preconditioned GMRES method for solving Au=b.
INT fasp_solver_dbsr_pvfgmres(dBSRmat *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)
Solve "Ax=b" using PFGMRES(right preconditioned) iterative method in which the restart parameter can ...
INT fasp_solver_dbsr_pvgmres(dBSRmat *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)
Right preconditioned GMRES method in which the restart parameter can be adaptively modified during it...
SHORT fasp_amg_setup_sa_bsr(AMG_data_bsr *mgl, AMG_param *param)
Set up phase of smoothed aggregation AMG (BSR format)
SHORT fasp_amg_setup_ua_bsr(AMG_data_bsr *mgl, AMG_param *param)
Set up phase of unsmoothed aggregation AMG (BSR format)
void fasp_precond_dbsr_amg(REAL *r, REAL *z, void *data)
AMG preconditioner.
void fasp_precond_dbsr_amg_nk(REAL *r, REAL *z, void *data)
AMG with extra near kernel solve preconditioner.
void fasp_precond_dbsr_diag(REAL *r, REAL *z, void *data)
Diagonal preconditioner z=inv(D)*r.
void fasp_precond_dbsr_ilu(REAL *r, REAL *z, void *data)
ILU preconditioner.
void fasp_precond_dbsr_namli(REAL *r, REAL *z, void *data)
Nonlinear AMLI-cycle AMG preconditioner.
AMG_data_bsr * fasp_amg_data_bsr_create(SHORT max_levels)
Create and initialize AMG_data data sturcture for AMG/SAMG (BSR format)
void fasp_ilu_data_free(ILU_data *iludata)
Create ILU_data sturcture.
INT fasp_solver_dbsr_krylov_amg_nk(dBSRmat *A, dvector *b, dvector *x, ITS_param *itparam, AMG_param *amgparam, dCSRmat *A_nk, dCSRmat *P_nk, dCSRmat *R_nk)
Solve Ax=b by AMG with extra near kernel solve preconditioned Krylov methods.
INT fasp_solver_dbsr_krylov_ilu(dBSRmat *A, dvector *b, dvector *x, ITS_param *itparam, ILU_param *iluparam)
Solve Ax=b by ILUs preconditioned Krylov methods.
INT fasp_solver_dbsr_krylov_diag(dBSRmat *A, dvector *b, dvector *x, ITS_param *itparam)
Solve Ax=b by diagonal preconditioned Krylov methods.
INT fasp_solver_dbsr_krylov(dBSRmat *A, dvector *b, dvector *x, ITS_param *itparam)
Solve Ax=b by standard Krylov methods for BSR matrices.
INT fasp_solver_dbsr_itsolver(dBSRmat *A, dvector *b, dvector *x, precond *pc, ITS_param *itparam)
Solve Ax=b by preconditioned Krylov methods for BSR matrices.
INT fasp_solver_dbsr_krylov_nk_amg(dBSRmat *A, dvector *b, dvector *x, ITS_param *itparam, AMG_param *amgparam, const INT nk_dim, dvector *nk)
Solve Ax=b by AMG preconditioned Krylov methods with extra kernal space.
INT fasp_solver_dbsr_krylov_amg(dBSRmat *A, dvector *b, dvector *x, ITS_param *itparam, AMG_param *amgparam)
Solve Ax=b by AMG preconditioned Krylov methods.
Main header file for the FASP project.
#define SHORT
FASP integer and floating point numbers.
#define FASP_SUCCESS
Definition of return status and error messages.
#define ERROR_SOLVER_TYPE
#define PRINT_NONE
Print level for all subroutines – not including DEBUG output.
Data for multigrid levels in dBSRmat format.
INT near_kernel_dim
dimension of the near kernel for SAMG
dBSRmat A
pointer to the matrix at level level_num
dCSRmat * A_nk
Matrix data for near kernal.
dvector b
pointer to the right-hand side at level level_num
REAL ** near_kernel_basis
basis of near kernel space for SAMG
INT num_levels
number of levels in use <= max_levels
dCSRmat * R_nk
Resriction for near kernal.
dvector x
pointer to the iterative solution at level level_num
dCSRmat * P_nk
Prolongation for near kernal.
Parameters for AMG methods.
SHORT print_level
print level for AMG
SHORT coarsening_type
coarsening type
SHORT coarse_scaling
switch of scaling of the coarse grid correction
REAL * amli_coef
coefficients of the polynomial used by AMLI cycle
SHORT AMG_type
type of AMG method
REAL tol
stopping tolerance for AMG solver
REAL relaxation
relaxation parameter for Jacobi and SOR smoother
SHORT smoother
smoother type
SHORT cycle_type
type of AMG cycle
SHORT amli_degree
degree of the polynomial used by AMLI cycle
REAL tentative_smooth
relaxation parameter for smoothing the tentative prolongation
SHORT postsmooth_iter
number of postsmoothers
SHORT max_levels
max number of levels of AMG
SHORT presmooth_iter
number of presmoothers
INT maxit
max number of iterations of AMG
Parameters for iterative solvers.
Block sparse row storage matrix of REAL type.
INT COL
number of cols of sub-blocks in matrix A, N
INT NNZ
number of nonzero sub-blocks in matrix A, NNZ
INT nb
dimension of each sub-block
INT * IA
integer array of row pointers, the size is ROW+1
INT ROW
number of rows of sub-blocks in matrix A, M
INT storage_manner
storage manner for each sub-block
Sparse matrix of REAL type in CSR format.
INT col
column of matrix A, n
INT row
row number of matrix A, m
INT nnz
number of nonzero entries
Vector with n entries of REAL type.
REAL * val
actual vector entries
Data for preconditioners in dBSRmat format.
SHORT print_level
print level in AMG preconditioner
SHORT coarsening_type
coarsening type
SHORT coarse_scaling
switch of scaling of the coarse grid correction
dCSRmat * A_nk
Matrix data for near kernal.
REAL * amli_coef
coefficients of the polynomial used by AMLI cycle
REAL tol
tolerance for AMG preconditioner
REAL relaxation
relaxation parameter for SOR smoother
SHORT smoother
AMG smoother type.
SHORT cycle_type
AMG cycle type.
SHORT amli_degree
degree of the polynomial used by AMLI cycle
REAL tentative_smooth
smooth factor for smoothing the tentative prolongation
SHORT postsmooth_iter
number of postsmoothing
dCSRmat * R_nk
Resriction for near kernal.
AMG_data_bsr * mgl_data
AMG preconditioner data.
INT max_levels
max number of AMG levels
dCSRmat * P_nk
Prolongation for near kernal.
SHORT presmooth_iter
number of presmoothing
INT maxit
max number of iterations of AMG preconditioner
Data for diagnal preconditioners in dBSRmat format.
INT nb
dimension of each sub-block
dvector diag
diagnal elements
Preconditioner data and action.
void * data
data for preconditioner, void pointer
void(* fct)(REAL *, REAL *, void *)
action for preconditioner, void function pointer