Skip to main content

Module cg

Module cg 

Source
Expand description

Conjugate Gradient (CG) iterative solver.

Solves the linear system A * x = b where A is symmetric positive definite. The solver is matrix-free: it only requires a closure that computes the matrix-vector product y = A * x.

§Algorithm

The standard Conjugate Gradient algorithm (Hestenes & Stiefel, 1952):

  1. r = b - A*x; p = r; rsold = r^T * r
  2. For each iteration: a. Ap = A * p b. alpha = rsold / (p^T * Ap) c. x += alpha * p d. r -= alpha * Ap e. rsnew = r^T * r f. If sqrt(rsnew) < tol * ||b||: converged g. p = r + (rsnew / rsold) * p h. rsold = rsnew

The solver operates on host-side vectors. For GPU-accelerated sparse matrix-vector products, the spmv closure should internally manage device memory transfers.

Structs§

CgConfig
Configuration for the Conjugate Gradient solver.

Functions§

cg_solve
Solves A * x = b using the Conjugate Gradient method.