10 #ifndef STOKHOS_TPETRA_CG_HPP
11 #define STOKHOS_TPETRA_CG_HPP
16 template <
typename Matrix,
19 bool CG_Solve(
const Matrix&
A, Vector& x,
const Vector& b,
20 typename Vector::mag_type tol,
Ordinal max_its,
21 std::ostream* out = 0)
23 typedef typename Vector::mag_type mag_type;
24 typedef typename Vector::dot_type dot_type;
30 r.update(1.0, b, -1.0);
32 dot_type rho = r.dot(r);
33 dot_type rho_old = rho;
36 dot_type alpha, beta, pAp;
37 while (k < max_its && nrm > tol) {
39 p.update(1.0, r, 0.0);
43 p.update(1.0, r, beta);
48 x.update( alpha, p, 1.0);
49 r.update(-alpha, w, 1.0);
57 *out << k <<
": " << nrm << std::endl;
66 template <
typename Matrix,
70 bool PCG_Solve(
const Matrix&
A, Vector& x,
const Vector& b,
const Prec& M,
71 typename Vector::mag_type tol,
Ordinal max_its,
72 std::ostream* out = 0)
74 typedef typename Vector::mag_type mag_type;
75 typedef typename Vector::dot_type dot_type;
81 r.update(1.0, b, -1.0);
83 mag_type nrm = r.norm2();
86 dot_type rho_old, alpha, beta, pAp;
87 while (k < max_its && nrm > tol) {
93 p.update(1.0, w, 0.0);
97 p.update(1.0, w, beta);
102 x.update( alpha, p, 1.0);
103 r.update(-alpha, w, 1.0);
109 *out << k <<
": " << nrm << std::endl;
119 #endif // STOKHOS_TPETRA_CG
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
bool CG_Solve(const Matrix &A, Vector &x, const Vector &b, typename Vector::mag_type tol, Ordinal max_its, std::ostream *out=0)
bool PCG_Solve(const Matrix &A, Vector &x, const Vector &b, const Prec &M, typename Vector::mag_type tol, Ordinal max_its, std::ostream *out=0)