16 template<
typename FIELD,
typename FOPR>
21 template<
typename FIELD,
typename FOPR>
35 err += params.
fetch_int(
"maximum_number_of_iteration", Niter);
36 err += params.
fetch_double(
"convergence_criterion_squared", Stop_cond);
39 vout.
crucial(m_vl,
"Error at %s: input parameter not found.\n", class_name.c_str());
43 set_parameters(Niter, Stop_cond);
48 template<
typename FIELD,
typename FOPR>
51 params.
set_int(
"maximum_number_of_iteration", m_Niter);
52 params.
set_double(
"convergence_criterion_squared", m_Stop_cond);
59 template<
typename FIELD,
typename FOPR>
62 const double Stop_cond)
67 vout.
general(m_vl,
" Stop_cond = %8.2e\n", Stop_cond);
75 vout.
crucial(m_vl,
"Error at %s: parameter range check failed.\n",
82 m_Stop_cond = Stop_cond;
87 template<
typename FIELD,
typename FOPR>
89 std::vector<FIELD>& xq,
90 const std::vector<double>& sigma,
95 int Nshift = sigma.size();
100 for (
int i = 0; i < Nshift; ++i) {
104 m_snorm = 1.0 / b.norm2();
108 reset_field(b, sigma, Nshift);
117 vout.
detailed(m_vl,
" iter: %8d %22.15e\n", 0, rr * m_snorm);
119 bool is_converged =
false;
121 for (
int iter = 0; iter < m_Niter; iter++) {
127 (iter + 1), rr * m_snorm, m_Nshift2);
129 if (rr * m_snorm < m_Stop_cond) {
136 vout.
crucial(m_vl,
"Error at %s: not converged.\n",
142 std::vector<double> diffs(Nshift);
143 for (
int i = 0; i < Nshift; ++i) {
147 for (
int i = 0; i < Nshift; ++i) {
148 m_fopr->mult(m_s, m_x[i]);
149 axpy(m_s, sigma[i], m_x[i]);
152 double diff1 = sqrt(m_s.norm2() * m_snorm);
165 for (
int i = 0; i < Nshift; ++i) {
166 if (diffs[i] > diff2) diff2 = diffs[i];
175 for (
int i = 0; i < Nshift; ++i) {
184 template<
typename FIELD,
typename FOPR>
187 int Nshift = m_p.size();
191 for (
int i = 0; i < Nshift; ++i) {
210 template<
typename FIELD,
typename FOPR>
213 m_fopr->mult(m_s, m_p[0]);
214 axpy(m_s, m_sigma0, m_p[0]);
217 double pa_p =
dot(m_s, m_p[0]);
218 double beta = -rr_p / pa_p;
220 axpy(m_x[0], -beta, m_p[0]);
221 axpy(m_r, beta, m_s);
224 double alpha = rr / rr_p;
226 aypx(alpha, m_p[0], m_r);
235 double alpha_h = 1.0 + m_alpha_p * beta / m_beta_p;
237 for (
int ish = 1; ish < m_Nshift2; ++ish) {
238 double zeta = (alpha_h - m_csh2[ish] * beta) / m_zeta1[ish]
239 + (1.0 - alpha_h) / m_zeta2[ish];
241 double zr = zeta / m_zeta1[ish];
242 double beta_s = beta * zr;
243 double alpha_s = alpha * zr * zr;
245 axpy(m_x[ish], -beta_s, m_p[ish]);
246 scal(m_p[ish], alpha_s);
247 axpy(m_p[ish], zeta, m_r);
249 double ppr = m_p[ish].norm2();
254 m_pp[ish] = ppr * m_snorm;
256 m_zeta2[ish] = m_zeta1[ish];
262 int ish1 = m_Nshift2;
264 for (
int ish = m_Nshift2 - 1; ish >= 0; --ish) {
266 if (m_pp[ish] > m_Stop_cond) {
285 template<
typename FIELD,
typename FOPR>
287 const std::vector<double>& sigma,
299 m_zeta1.resize(Nshift);
300 m_zeta2.resize(Nshift);
301 m_csh2.resize(Nshift);
304 for (
int i = 0; i < Nshift; ++i) {
305 m_p[i].reset(Nin, Nvol, Nex);
306 m_x[i].reset(Nin, Nvol, Nex);
309 m_csh2[i] = sigma[i] - sigma[0];
314 m_s.reset(Nin, Nvol, Nex);
315 m_r.reset(Nin, Nvol, Nex);
326 template<
typename FIELD,
typename FOPR>
329 vout.
general(m_vl,
"Warning at %s: flop_count() not yet implemented.\n",