gko::solver::Cg#

Conjugate gradient. The canonical Krylov method for symmetric positive-definite systems. Each iteration costs one matrix-vector product, one preconditioner apply, two inner products, and three AXPYs.

template<typename ValueType = default_precision>
class Cg #

Inherits from

  • public gko::EnableLinOp<Cg<default_precision>>

  • public gko::solver::EnablePreconditionedIterativeSolver<default_precision, Cg<default_precision>>

  • public gko::Transposable

CG or the conjugate gradient method is an iterative type Krylov subspace method which is suitable for symmetric positive definite methods.

Though this method performs very well for symmetric positive definite matrices, it is in general not suitable for general matrices.

CG constructs a sequence of search directions \( p_0, p_1, \ldots \) that are mutually \( A \)-conjugate ( \( \langle p_i, A p_j \rangle = 0 \) for \( i \ne j \)). The iterate chosen along these directions minimises the error in the energy norm over the affine Krylov subspace,

\[ x_k = \arg\min_{x \,\in\, x_0 + \mathcal{K}_k(A, r_0)} \| x - x^{*} \|_A, \qquad \| e \|_A = \sqrt{\langle e, A e \rangle}, \]
which yields a short recurrence: at each step the new search direction is built from the preconditioned residual \( z_k = M r_k \) and the previous direction via the Fletcher-Reeves coefficient
\[ \beta_k = \frac{\langle r_k,\, z_k \rangle} {\langle r_{k-1},\, z_{k-1} \rangle}, \qquad p_k = z_k + \beta_k\, p_{k-1}. \]
This formula assumes that \( M \) stays fixed across iterations; for a varying preconditioner use the Polak-Ribière variant in FCG.

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 CG are merged into 2 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>