17 template<
typename FIELD,
typename FOPR>
22 template<
typename FIELD,
typename FOPR>
34 vout.
general(m_vl,
"%s: construction\n", class_name.c_str());
37 set_parameters(params);
45 template<
typename FIELD,
typename FOPR>
52 template<
typename FIELD,
typename FOPR>
66 err += params.
fetch_int(
"number_of_shifts", Nshift);
67 err += params.
fetch_int(
"maximum_number_of_iteration", Niter);
68 err += params.
fetch_double(
"convergence_criterion_squared", Stop_cond);
71 vout.
crucial(m_vl,
"Error at %s: input parameter not found.\n",
76 set_parameters(Nshift, Niter, Stop_cond);
81 template<
typename FIELD,
typename FOPR>
84 params.
set_int(
"number_of_shifts", m_Nshift);
85 params.
set_int(
"maximum_number_of_iteration", m_Niter);
86 params.
set_double(
"convergence_criterion_squared", m_Stop_cond);
93 template<
typename FIELD,
typename FOPR>
97 const double Stop_cond)
105 m_Stop_cond = Stop_cond;
116 vout.
crucial(m_vl,
"Error at %s: parameter range check failed.\n",
122 vout.
general(m_vl,
"%s: parameters:\n", class_name.c_str());
125 vout.
general(m_vl,
" Stop_cond = %8.2e\n", m_Stop_cond);
127 if(m_Nshift != m_p.size()){
135 template<
typename FIELD,
typename FOPR>
140 vout.
crucial(
"%s: reset_field called.\n", class_name.c_str());
142 int Nin = m_fopr->field_nin();
143 int Nvol = m_fopr->field_nvol();
144 int Nex = m_fopr->field_nex();
146 m_p.resize(m_Nshift);
147 m_x.resize(m_Nshift);
148 m_zeta1.resize(m_Nshift);
149 m_zeta2.resize(m_Nshift);
150 m_csh2.resize(m_Nshift);
151 m_pp.resize(m_Nshift);
153 for (
int i = 0; i < m_Nshift; ++i) {
154 m_p[i].reset(Nin, Nvol, Nex);
155 m_x[i].reset(Nin, Nvol, Nex);
158 m_s.reset(Nin, Nvol, Nex);
159 m_r.reset(Nin, Nvol, Nex);
164 template<
typename FIELD,
typename FOPR>
166 std::vector<FIELD>& xq,
167 const std::vector<double>& sigma,
172 if(sigma.size() != m_Nshift){
173 vout.
crucial(
"%s: size of shift values incorrect: %d\n",
174 class_name.c_str(), sigma.size());
181 for (
int i = 0; i < m_Nshift; ++i) {
185 m_snorm = 1.0 / b.norm2();
198 vout.
detailed(m_vl,
" iter: %8d %22.15e\n", 0, rr * m_snorm);
200 bool is_converged =
false;
202 for (
int iter = 0; iter < m_Niter; iter++) {
208 (iter + 1), rr * m_snorm, m_Nshift2);
210 if (rr * m_snorm < m_Stop_cond) {
217 vout.
crucial(m_vl,
"Error at %s: not converged.\n",
223 std::vector<double> diffs(m_Nshift);
224 for (
int i = 0; i < m_Nshift; ++i) {
228 for (
int i = 0; i < m_Nshift; ++i) {
229 m_fopr->mult(m_s, m_x[i]);
230 axpy(m_s, sigma[i], m_x[i]);
233 double diff1 = sqrt(m_s.norm2() * m_snorm);
246 for (
int i = 0; i < m_Nshift; ++i) {
247 if (diffs[i] > diff2) diff2 = diffs[i];
256 for (
int i = 0; i < m_Nshift; ++i) {
265 template<
typename FIELD,
typename FOPR>
268 int Nshift = m_p.size();
272 for (
int i = 0; i < Nshift; ++i) {
291 template<
typename FIELD,
typename FOPR>
294 m_fopr->mult(m_s, m_p[0]);
295 axpy(m_s, m_sigma0, m_p[0]);
298 double pa_p =
dot(m_s, m_p[0]);
299 double beta = -rr_p / pa_p;
301 axpy(m_x[0], -beta, m_p[0]);
302 axpy(m_r, beta, m_s);
305 double alpha = rr / rr_p;
307 aypx(alpha, m_p[0], m_r);
316 double alpha_h = 1.0 + m_alpha_p * beta / m_beta_p;
318 for (
int ish = 1; ish < m_Nshift2; ++ish) {
319 double zeta = (alpha_h - m_csh2[ish] * beta) / m_zeta1[ish]
320 + (1.0 - alpha_h) / m_zeta2[ish];
322 double zr = zeta / m_zeta1[ish];
323 double beta_s = beta * zr;
324 double alpha_s = alpha * zr * zr;
326 axpy(m_x[ish], -beta_s, m_p[ish]);
327 scal(m_p[ish], alpha_s);
328 axpy(m_p[ish], zeta, m_r);
330 double ppr = m_p[ish].norm2();
335 m_pp[ish] = ppr * m_snorm;
337 m_zeta2[ish] = m_zeta1[ish];
343 int ish1 = m_Nshift2;
345 for (
int ish = m_Nshift2 - 1; ish >= 0; --ish) {
347 if (m_pp[ish] > m_Stop_cond) {
366 template<
typename FIELD,
typename FOPR>
368 const std::vector<double>& sigma)
374 for (
int i = 0; i < m_Nshift; ++i) {
377 m_csh2[i] = sigma[i] - sigma[0];
381 m_Nshift2 = m_Nshift;
389 template<
typename FIELD,
typename FOPR>
392 vout.
general(m_vl,
"Warning at %s: flop_count() not yet implemented.\n",