This class is able to do Matrix inversion in parallel with PETSC solvers. More...
This class is able to do Matrix inversion in parallel with PETSC solvers.
Definition at line 101 of file petsc_solver.hpp.
#include <petsc_solver.hpp>
Data Structures | |
struct | itError |
contain the infinity norm of the residual at each iteration More... | |
struct | solv_bench_info |
It contain the benchmark information for each solver. More... | |
Public Types | |
typedef Vector< double, PETSC_BASE > | return_type |
Type of the solution object. | |
Public Member Functions | |
void | print_preconditioner () |
Print the preconditioner used by the solver. | |
void | print_ksptype () |
Print the ksp_type used by the solver. | |
void | addTestSolver (std::string &solver) |
Add a test solver. | |
void | removeTestSolver (const std::string &solver) |
Remove a test solver. | |
void | log_monitor () |
Set the Petsc solver. | |
void | setSolver (KSPType type) |
Set the Petsc solver. | |
void | setRelTol (PetscReal rtol_) |
Set the relative tolerance as stop criteria. | |
void | setAbsTol (PetscReal abstol_) |
Set the absolute tolerance as stop criteria. | |
void | setDivTol (PetscReal dtol_) |
Set the divergence tolerance. | |
void | setMaxIter (PetscInt n) |
Set the maximum number of iteration for Krylov solvers. | |
void | searchDirections (PetscInt l) |
void | setRestart (PetscInt n) |
For GMRES based method, the number of Krylov directions to orthogonalize against. | |
void | setPreconditioner (PCType type) |
Set the preconditioner of the linear solver. | |
void | setPreconditionerAMG_nl (int nl) |
Set the number of levels for the algebraic-multigrid preconditioner. | |
void | setPreconditionerAMG_maxit (int nit) |
Set the maximum number of V or W cycle for algebraic-multi-grid. | |
void | setPreconditionerAMG_relax (const std::string &type, int k=REL_ALL) |
Set the relaxation method for the algebraic-multi-grid preconditioner. | |
void | setPreconditionerAMG_cycleType (const std::string &cycle_type, int sweep_up=-1, int sweep_dw=-1, int sweep_crs=-1) |
It set the type of cycle and optionally the number of sweep. | |
void | setPreconditionerAMG_coarsen (const std::string &type) |
Set the coarsening method for the algebraic-multi-grid preconditioner. | |
void | setPreconditionerAMG_interp (const std::string &type) |
Set the interpolation method for the algebraic-multi-grid preconditioner. | |
void | setPreconditionerAMG_coarsenNodalType (int norm) |
Set the block coarsening norm type. | |
void | setPreconditionerAMG_interp_eu_level (int k) |
Indicate the number of levels in the ILU(k) for the Euclid smoother. | |
void | setBlockSize (int block_sz) |
Set how many degree of freedom each node has. | |
Vector< double, PETSC_BASE > | solve (SparseMatrix< double, int, PETSC_BASE > &A, const Vector< double, PETSC_BASE > &b, bool initial_guess=false) |
Here we invert the matrix and solve the system. | |
Vector< double, PETSC_BASE > | solve (SparseMatrix< double, int, PETSC_BASE > &A, Vector< double, PETSC_BASE > &x, const Vector< double, PETSC_BASE > &b) |
Here we invert the matrix and solve the system. | |
Vector< double, PETSC_BASE > | solve_successive (const Vector< double, PETSC_BASE > &b, bool initial_guess=false) |
Here we invert the matrix and solve the system with previous operator. | |
Vector< double, PETSC_BASE > | solve_successive (Vector< double, PETSC_BASE > &x, const Vector< double, PETSC_BASE > &b) |
Here we invert the matrix and solve the system with previous operator and initial guess. | |
Vector< double, PETSC_BASE > | with_nullspace_solve (SparseMatrix< double, int, PETSC_BASE > &A, const Vector< double, PETSC_BASE > &b, bool initial_guess=false, bool symmetric=false) |
Here we invert the matrix and solve the system using a Nullspace for Neumann BC. | |
KSP | getKSP () |
Return the KSP solver. | |
solError | get_residual_error (SparseMatrix< double, int, PETSC_BASE > &A, const Vector< double, PETSC_BASE > &x, const Vector< double, PETSC_BASE > &b) |
It return the resiual error. | |
solError | get_residual_error (const Vector< double, PETSC_BASE > &x, const Vector< double, PETSC_BASE > &b) |
It return the resiual error. | |
Vector< double, PETSC_BASE > | solve (const Vector< double, PETSC_BASE > &b) |
Here we invert the matrix and solve the system. | |
bool | solve (Vector< double, PETSC_BASE > &x, const Vector< double, PETSC_BASE > &b) |
Here we invert the matrix and solve the system. | |
void | setPetscOption (const char *name, const char *value) |
this function give you the possibility to set PETSC options | |
Vector< double, PETSC_BASE > | try_solve (SparseMatrix< double, int, PETSC_BASE > &A, const Vector< double, PETSC_BASE > &b) |
Try to solve the system using all the solvers and generate a report. | |
Private Member Functions | |
void | write_bench_report () |
Here we write the benchmark report. | |
void | pre_solve_impl (const Mat &A_, const Vec &b_, Vec &x_) |
It set up the solver based on the provided options. | |
void | print_progress_bar () |
Print a progress bar on standard out. | |
void | progress (PetscInt it) |
This function print an "*" showing the progress of the solvers. | |
void | print_stat (solError &err) |
Print statistic about the solution error and method used. | |
std::string | to_string_method (const std::string &solv) |
It convert the KSP type into a human read-able string. | |
void | new_bench (const std::string &str) |
Allocate a new benchmark slot for a method. | |
void | copy_if_better (double res, Vec &sol, double &best_res, Vec &best_sol) |
Copy the solution if better. | |
void | try_solve_simple (const Mat &A_, const Vec &b_, Vec &x_) |
Try to solve the system x=inv(A)*b using all the Krylov solvers with simple Jacobi pre-conditioner. | |
void | bench_solve_simple (const Mat &A_, const Vec &b_, Vec &x_, solv_bench_info &bench) |
Benchmark solve simple solving x=inv(A)*b. | |
void | solve_simple (const Mat &A_, const Vec &b_, Vec &x_) |
solve simple use a Krylov solver + Simple selected Parallel Pre-conditioner | |
void | solve_simple (const Vec &b_, Vec &x_) |
solve simple use a Krylov solver + Simple selected Parallel Pre-conditioner | |
void | initKSP () |
initialize the KSP object | |
void | initKSPForTest () |
initialize the KSP object for solver testing | |
void | destroyKSP () |
Destroy the KSP object. | |
Static Private Member Functions | |
static double | calculate_it (double t, solv_bench_info &slv) |
Calculate the residual error at time t for one method. | |
static PetscErrorCode | monitor_progress_residual (KSP ksp, PetscInt it, PetscReal res, void *data) |
procedure print the progress of the solver in benchmark mode | |
static solError | statSolutionError (const Mat &A_, const Vec &b_, Vec &x_, KSP ksp) |
Calculate statistic on the error solution. | |
static solError | getSolNormError (const Vec &b_, const Vec &x_, KSP ksp) |
Return the norm error of the solution. | |
static solError | getSolNormError (const Mat &A_, const Vec &b_, const Vec &x_) |
Return the norm error of the solution. | |
Private Attributes | |
bool | is_preconditioner_set = false |
indicate if the preconditioner is set | |
PetscInt | maxits |
KSP Maximum number of iterations. | |
KSP | ksp |
Main parallel solver. | |
size_t | tmp |
Temporal variable used for calculation of static members. | |
openfpm::vector< std::string > | solvs |
The full set of solvers. | |
openfpm::vector< solv_bench_info > | bench |
It contain the solver benchmark results. | |
AMG_type | atype = NONE_AMG |
Type of the algebraic multi-grid preconditioner. | |
int | block_sz = 0 |
Block size. | |
typedef Vector<double,PETSC_BASE> petsc_solver< double >::return_type |
Type of the solution object.
Definition at line 799 of file petsc_solver.hpp.
|
inline |
Definition at line 801 of file petsc_solver.hpp.
|
inline |
Definition at line 806 of file petsc_solver.hpp.
|
inline |
Add a test solver.
The try solve function use the most robust solvers in PETSC, if you want to add additionally solver like KSPIBCGS,KSPFBCGSR,KSPPGMRES, use addTestSolver(std::string(KSPIBCGS))
solver | additional solver solver to test |
Definition at line 875 of file petsc_solver.hpp.
|
inlineprivate |
Benchmark solve simple solving x=inv(A)*b.
A_ | Matrix A |
b_ | vector b |
x_ | solution x |
bench | structure that store the benchmark information |
Definition at line 605 of file petsc_solver.hpp.
|
inlinestaticprivate |
Calculate the residual error at time t for one method.
t | time |
slv | solver |
Definition at line 168 of file petsc_solver.hpp.
|
inlineprivate |
Copy the solution if better.
res | Residual of the solution |
sol | solution |
best_res | residual of the best solution |
best_sol | best solution |
Definition at line 494 of file petsc_solver.hpp.
|
inlineprivate |
Destroy the KSP object.
Definition at line 727 of file petsc_solver.hpp.
|
inline |
It return the resiual error.
x | solution |
b | right-hand-side |
Definition at line 1564 of file petsc_solver.hpp.
|
inline |
It return the resiual error.
A | Sparse matrix |
x | solution |
b | right-hand-side |
Definition at line 1551 of file petsc_solver.hpp.
|
inline |
Return the KSP solver.
In case you want to do fine tuning of the KSP solver before solve your system whith this function you can retrieve the KSP object
Definition at line 1537 of file petsc_solver.hpp.
|
inlinestaticprivate |
Return the norm error of the solution.
A_ | the matrix that identity the linear system |
x_ | the solution |
b_ | the right-hand-side |
Definition at line 759 of file petsc_solver.hpp.
|
inlinestaticprivate |
Return the norm error of the solution.
x_ | the solution |
b_ | the right-hand-side |
ksp | Krylov solver |
Definition at line 741 of file petsc_solver.hpp.
|
inlineprivate |
initialize the KSP object
Definition at line 707 of file petsc_solver.hpp.
|
inlineprivate |
initialize the KSP object for solver testing
Definition at line 716 of file petsc_solver.hpp.
|
inline |
Set the Petsc solver.
Definition at line 905 of file petsc_solver.hpp.
|
inlinestaticprivate |
procedure print the progress of the solver in benchmark mode
ksp | Solver |
it | Iteration number |
res | resudual |
data | custom pointer to data |
Definition at line 339 of file petsc_solver.hpp.
|
inlineprivate |
Allocate a new benchmark slot for a method.
str | Method name |
Definition at line 478 of file petsc_solver.hpp.
|
inlineprivate |
It set up the solver based on the provided options.
A_ | Matrix |
x_ | solution |
b_ | right-hand-side |
Definition at line 300 of file petsc_solver.hpp.
|
inline |
Print the ksp_type used by the solver.
Definition at line 852 of file petsc_solver.hpp.
|
inline |
Print the preconditioner used by the solver.
Definition at line 831 of file petsc_solver.hpp.
|
inlineprivate |
Print a progress bar on standard out.
Definition at line 320 of file petsc_solver.hpp.
|
inlineprivate |
Print statistic about the solution error and method used.
err | structure that contain the solution errors |
Definition at line 405 of file petsc_solver.hpp.
|
inlineprivate |
This function print an "*" showing the progress of the solvers.
it | iteration number |
Definition at line 380 of file petsc_solver.hpp.
|
inline |
Remove a test solver.
The try solve function use the most robust solvers in PETSC, if you want to remove a solver like use removeTestSolver(std::string(KSPIBCGS))
solver | remove solver to test |
Definition at line 888 of file petsc_solver.hpp.
|
inline |
For the BiCGStab(L) it define the number of search directions
BiCG Methods can fail for base break-down (or near break-down). BiCGStab(L) try to avoid this problem. Such method has a parameter L (2 by default) Bigger is L more the system will try to avoid the breakdown
l | Increasing L should reduce the probability of failure of the solver because of break-down of the base |
Definition at line 1004 of file petsc_solver.hpp.
|
inline |
Set the absolute tolerance as stop criteria.
abstol_ | Absolute tolerance |
Definition at line 948 of file petsc_solver.hpp.
|
inline |
Set how many degree of freedom each node has.
In case you are solving a system of equations this function, help in setting the degree of freedom each grid point has. Setting this parameter to the number of variables for each grid point it should improve the convergenve of the solvers in particular using algebraic-multi-grid
block_sz | number of degree of freedom |
Definition at line 1286 of file petsc_solver.hpp.
|
inline |
Set the divergence tolerance.
dtol_ | tolerance |
Definition at line 966 of file petsc_solver.hpp.
|
inline |
Set the maximum number of iteration for Krylov solvers.
n | maximum number of iterations |
Definition at line 982 of file petsc_solver.hpp.
|
inline |
this function give you the possibility to set PETSC options
this function call PetscOptionsSetValue
name | the name of the option |
value | the value of the option |
Definition at line 1630 of file petsc_solver.hpp.
|
inline |
Set the preconditioner of the linear solver.
The preconditoner that can be set are the same as PETSC
For a full list please visit Please visit: http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/PC/PCType.html#PCType
An exception is PCHYPRE with BOOMERAMG in this case use PCHYPRE_BOOMERAMG. Many preconditioners has default values, but many times the default values are not good. Here we list some interesting case
Parameters for this type of preconditioner can be set using setPreconditionerAMG_* functions.
type | of the preconditioner |
Definition at line 1046 of file petsc_solver.hpp.
|
inline |
Set the coarsening method for the algebraic-multi-grid preconditioner.
Possible values can be "CLJP","Ruge-Stueben","modifiedRuge-Stueben","Falgout", "PMIS", "HMIS"
type | of the preconditioner smoothing operator |
Definition at line 1193 of file petsc_solver.hpp.
|
inline |
Set the block coarsening norm type.
The use of this function make sanse if you specify the degree of freedom for each node using setBlockSize
In case the matrix represent a system of equations in general
norm | type |
Definition at line 1244 of file petsc_solver.hpp.
|
inline |
It set the type of cycle and optionally the number of sweep.
This function set the cycle type for the multigrid methods. Possible values are:
Optionally you can set the number of sweep or relaxation steps on each grid when going up and when going down
cycle_type | cycle type |
sweep_up | |
sweep_dw | |
sweep_crs | speep at the coarse level |
Definition at line 1162 of file petsc_solver.hpp.
|
inline |
Set the interpolation method for the algebraic-multi-grid preconditioner.
Possible values can be "classical", "direct", "multipass", "multipass-wts", "ext+i", "ext+i-cc", "standard", "standard-wts", "FF", "FF1"
type | of the interpolation scheme |
Definition at line 1215 of file petsc_solver.hpp.
|
inline |
Indicate the number of levels in the ILU(k) for the Euclid smoother.
k | number of levels for the Euclid smoother |
Definition at line 1261 of file petsc_solver.hpp.
|
inline |
Set the maximum number of V or W cycle for algebraic-multi-grid.
nit | number of levels |
Definition at line 1097 of file petsc_solver.hpp.
|
inline |
Set the number of levels for the algebraic-multigrid preconditioner.
In case you select an algebraic preconditioner like PCHYPRE or PCGAMG you can set the number of levels using this function
nl | number of levels |
Definition at line 1080 of file petsc_solver.hpp.
|
inline |
Set the relaxation method for the algebraic-multi-grid preconditioner.
Possible values for relazation can be "Jacobi","sequential-Gauss-Seidel","seqboundary-Gauss-Seidel", "SOR/Jacobi","backward-SOR/Jacobi",hybrid chaotic Gauss-Seidel (works only with OpenMP), "symmetric-SOR/Jacobi","l1scaled-SOR/Jacobi","Gaussian-elimination","CG","Chebyshev", "FCF-Jacobi","l1scaled-Jacobi"
Every smooth operator can have additional parameters to be set in order to correctly work.
type | of relax method |
k | where is applied REL_UP,REL_DOWN,REL_ALL (default is all) |
Definition at line 1129 of file petsc_solver.hpp.
|
inline |
Set the relative tolerance as stop criteria.
rtol_ | Relative tolerance |
Definition at line 930 of file petsc_solver.hpp.
|
inline |
For GMRES based method, the number of Krylov directions to orthogonalize against.
n | number of directions |
Definition at line 1014 of file petsc_solver.hpp.
|
inline |
Set the Petsc solver.
type | petsc solver type |
Definition at line 918 of file petsc_solver.hpp.
|
inline |
Here we invert the matrix and solve the system.
b | vector |
Definition at line 1576 of file petsc_solver.hpp.
|
inline |
Here we invert the matrix and solve the system.
impl | Implementation of the SparseMatrix |
A | sparse matrix |
b | vector |
initial_guess | true if x has the initial guess |
Definition at line 1306 of file petsc_solver.hpp.
|
inline |
Here we invert the matrix and solve the system.
A | sparse matrix |
b | vector |
x | solution and initial guess |
Definition at line 1341 of file petsc_solver.hpp.
|
inline |
Here we invert the matrix and solve the system.
In this call we are interested in solving the system with multiple right-hand-side and the same Matrix. We do not set the Matrix again and this give us the possibility to-skip the preconditioning setting that in some case like Algebraic-multi-grid can be expensive
b | vector |
x | solution and initial guess |
Definition at line 1611 of file petsc_solver.hpp.
|
inlineprivate |
solve simple use a Krylov solver + Simple selected Parallel Pre-conditioner
A_ | SparseMatrix |
b_ | right-hand-side |
x_ | solution |
Definition at line 642 of file petsc_solver.hpp.
|
inlineprivate |
solve simple use a Krylov solver + Simple selected Parallel Pre-conditioner
b_ | right hand side |
x_ | solution |
Definition at line 673 of file petsc_solver.hpp.
|
inline |
Here we invert the matrix and solve the system with previous operator.
A | sparse matrix |
b | vector |
x | solution and initial guess |
Definition at line 1381 of file petsc_solver.hpp.
|
inline |
Here we invert the matrix and solve the system with previous operator and initial guess.
A | sparse matrix |
b | vector |
x | solution and initial guess |
Definition at line 1417 of file petsc_solver.hpp.
|
inlinestaticprivate |
Calculate statistic on the error solution.
A_ | Matrix of the system |
b_ | Right hand side of the matrix |
x_ | Solution |
ksp | Krylov solver |
Definition at line 689 of file petsc_solver.hpp.
|
inlineprivate |
It convert the KSP type into a human read-able string.
solv | solver (short form) |
Definition at line 427 of file petsc_solver.hpp.
|
inline |
Try to solve the system using all the solvers and generate a report.
In this mode the system will try different Solvers, Preconditioner and combination of solvers in order to find the best solver in speed, and precision. As output it will produce a performance report
A | Matrix to invert |
b | right hand side |
Definition at line 1646 of file petsc_solver.hpp.
|
inlineprivate |
Try to solve the system x=inv(A)*b using all the Krylov solvers with simple Jacobi pre-conditioner.
It try to solve the system using JACOBI pre-conditioner and all the Krylov solvers available at the end it write a report
A_ | Matrix |
b_ | vector of coefficents |
x_ | solution |
Definition at line 513 of file petsc_solver.hpp.
|
inline |
Here we invert the matrix and solve the system using a Nullspace for Neumann BC.
impl | Implementation of the SparseMatrix |
A | sparse matrix |
b | vector |
initial_guess | true if x has the initial guess |
Definition at line 1463 of file petsc_solver.hpp.
|
inlineprivate |
Here we write the benchmark report.
Definition at line 185 of file petsc_solver.hpp.
|
private |
Type of the algebraic multi-grid preconditioner.
Definition at line 155 of file petsc_solver.hpp.
|
private |
It contain the solver benchmark results.
Definition at line 152 of file petsc_solver.hpp.
|
private |
Block size.
Definition at line 158 of file petsc_solver.hpp.
|
private |
indicate if the preconditioner is set
Definition at line 136 of file petsc_solver.hpp.
|
private |
Main parallel solver.
Definition at line 142 of file petsc_solver.hpp.
|
private |
KSP Maximum number of iterations.
Definition at line 139 of file petsc_solver.hpp.
|
private |
The full set of solvers.
Definition at line 148 of file petsc_solver.hpp.
|
private |
Temporal variable used for calculation of static members.
Definition at line 145 of file petsc_solver.hpp.