Go to the documentation of this file.
26 #ifndef TILEDARRAY_MATH_LINALG_CONJGRAD_H__INCLUDED
27 #define TILEDARRAY_MATH_LINALG_CONJGRAD_H__INCLUDED
61 template <
typename D,
typename F>
74 std::size_t n =
volume(preconditioner);
76 const bool use_diis =
false;
94 const value_type cond_number = precond_max / precond_min;
99 if (convergence_target < 0.0) {
100 convergence_target = 1e-15 * cond_number;
103 if (convergence_target < 1e-15 * cond_number)
104 std::cout <<
"WARNING: ConjugateGradient convergence target ("
105 << convergence_target
106 <<
") may be too low for 64-bit precision" << std::endl;
109 bool converged =
false;
110 const unsigned int max_niter = n;
112 const std::size_t rhs_size =
volume(b);
132 unsigned int iter = 0;
133 while (not converged) {
142 axpy(XX_i, alpha_i, PP_i);
145 axpy(RR_i, -alpha_i, APP_i);
150 if (r_ip1_norm < convergence_target) {
161 const value_type beta_i = rz_ip1_norm2 / rz_norm2;
167 axpy(PP_i, 1.0, ZZ_i);
174 }
else if (iter >= max_niter)
175 throw std::domain_error(
176 "ConjugateGradient: max # of iterations exceeded");
191 #endif // TILEDARRAY_MATH_LINALG_CONJGRAD_H__INCLUDED
auto norm2(const DistArray< Tile, Policy > &a)
auto inner_product(const DistArray< Tile, Policy > &a, const DistArray< Tile, Policy > &b)
DIIS (`‘direct inversion of iterative subspace’') extrapolation.
DistArray< Tile, Policy > clone(const DistArray< Tile, Policy > &arg)
Create a deep copy of an array.
void scale(DistArray< Tile, Policy > &a, S scaling_factor)
auto abs_min(const DistArray< Tile, Policy > &a)
value_type operator()(F &a, const D &b, D &x, const D &preconditioner, value_type convergence_target=-1.0)
auto abs_max(const DistArray< Tile, Policy > &a)
void extrapolate(D &x, D &error, bool extrapolate_error=false)
void vec_multiply(DistArray< Tile, Policy > &a1, const DistArray< Tile, Policy > &a2)
size_t volume(const DistArray< Tile, Policy > &a)
void axpy(DistArray< Tile, Policy > &y, S alpha, const DistArray< Tile, Policy > &x)
D::element_type value_type