22 template <
class Matrix,
class Vector,
class Preconditioner,
class Real >
25 const Preconditioner &M, int64_t &max_iter, Real &
tol)
28 Vector rho_1(1), rho_2(1), alpha(1), beta(1);
29 Vector p, phat, q, qhat, vhat, u, uhat;
38 if ((resid = norm(r) / normb) <= tol) {
44 for (int64_t i = 1; i <= max_iter; i++) {
45 rho_1(0) = dot(rtilde, r);
47 tol = norm(r) / normb;
54 beta(0) = rho_1(0) / rho_2(0);
56 p = u + beta(0) * (q + beta(0) * p);
60 alpha(0) = rho_1(0) / dot(rtilde, vhat);
61 q = u - alpha(0) * vhat;
62 uhat = M.solve(u + q);
67 if ((resid = norm(r) / normb) < tol) {
int CGS(const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, int64_t &max_iter, Real &tol)
CGS solves the unsymmetric linear system using the Conjugate Gradient Squared method.