gko::solver::Cgs#
Conjugate gradient squared. Replaces Bicg’s Aᵀ apply with another
apply of A, doubling the per-iteration residual reduction but
amplifying numerical noise. Cheap per iteration but less robust than
Bicgstab; useful when A is well conditioned.
-
template<typename ValueType = default_precision>
class Cgs # Inherits from
public gko::LinOp
public gko::solver::EnablePreconditionedIterativeSolver<default_precision, Cgs<default_precision>>
public gko::Transposable
CGS or the conjugate gradient square method is an iterative type Krylov subspace method which is suitable for general systems.
CGS rests on the identity that BiCG produces a residual of the form \( r_k^{\mathrm{BiCG}} = \psi_k(A) r_0 \), where \( \psi_k \) is the residual polynomial. Squaring this polynomial yields the CGS residual
\[ r_k^{\mathrm{CGS}} = \psi_k(A)^2 r_0, \]so the iteration avoids the explicit \( A^H \) apply that BiCG requires, and it contracts the residual twice as fast per step when BiCG converges.Starting from \( r_0 = b - A x_0 \), a shadow residual \( \tilde r_0 \) (Ginkgo uses \( \tilde r_0 = r_0 \)), \( q_{-1} = p_{-1} = 0 \) and \( \rho_{-1} = 1 \), one iteration with the preconditioner \( M \approx A^{-1} \) reads
\[\begin{split} \begin{aligned} \rho_k &= \langle \tilde r_0, r_k \rangle, &\qquad \beta_k &= \rho_k / \rho_{k-1}, \\ u_k &= r_k + \beta_k q_{k-1}, &\qquad p_k &= u_k + \beta_k (q_{k-1} + \beta_k p_{k-1}), \\ \hat v_k &= A M p_k, &\qquad \alpha_k &= \rho_k / \langle \tilde r_0, \hat v_k \rangle, \\ q_k &= u_k - \alpha_k \hat v_k, &\qquad \hat u_k &= M (u_k + q_k), \\ x_{k+1} &= x_k + \alpha_k \hat u_k, &\qquad r_{k+1} &= r_k - \alpha_k A \hat u_k. \end{aligned} \end{split}\]The pair \( u_k, q_k \) takes the place of the single BiCG search direction, which is why the update of \( x \) uses their sum. The trade-off for dropping \( A^H \) is that the squared polynomial also squares the error: the residuals lose monotonicity and can oscillate strongly on poorly conditioned systems. When this matters in practice, BiCGSTAB replaces the second application of \( \psi_k \) by a locally minimizing polynomial for the same number of operator applies and one extra inner product.The implementation in Ginkgo makes use of the merged kernel to make the best use of data locality. The inner operations in one iteration of CGS are merged into 3 separate steps.
- Template Parameters:
ValueType – precision of matrix elements
Public Functions
-
virtual std::unique_ptr<LinOp> transpose() const override#
Returns a LinOp representing the transpose of the Transposable object.
- Returns:
a pointer to the new transposed object
-
virtual std::unique_ptr<LinOp> conj_transpose() const override#
Returns a LinOp representing the conjugate transpose of the Transposable object.
- Returns:
a pointer to the new conjugate transposed object
-
inline bool apply_uses_initial_guess() const override#
Return true as iterative solvers use the data in x as an initial guess.
- Returns:
true as iterative solvers use the data in x as an initial guess.
Public Static Functions
- static parameters_type parse(
- const config::pnode &config,
- const config::registry &context,
- const config::type_descriptor &td_for_child = config::make_type_descriptor<ValueType>(),
Create the parameters from the property_tree. Because this is directly tied to the specific type, the value/index type settings within config are ignored and type_descriptor is only used for children configs.
- Parameters:
config – the property tree for setting
context – the registry
td_for_child – the type descriptor for children configs. The default uses the value type of this class.
- Returns:
parameters
-
struct parameters_type #
Inherits from
public gko::solver::enable_preconditioned_iterative_solver_factory_parameters<parameters_type, Factory>