19 template<
typename AFIELD>
21 =
"ASolver_Richardson";
23 template<
typename AFIELD>
28 int nin = m_fopr->field_nin();
29 int nvol = m_fopr->field_nvol();
30 int nex = m_fopr->field_nex();
32 m_r.reset(nin, nvol, nex);
33 m_s.reset(nin, nvol, nex);
39 template<
typename AFIELD>
48 template<
typename AFIELD>
52 const string str_vlevel = params.
get_string(
"verbose_level");
61 err += params.
fetch_int(
"maximum_number_of_iteration", Niter);
62 err += params.
fetch_int(
"maximum_number_of_restart", Nrestart);
63 err += params.
fetch_double(
"convergence_criterion_squared", Stop_cond);
66 vout.
crucial(m_vl,
"Error at %s: input parameter not found.\n",
73 int Niter2 = Niter * Nrestart;
74 set_parameters(Niter2, Stop_cond);
79 template<
typename AFIELD>
87 m_Stop_cond = Stop_cond;
88 m_initial_mode = init_guess_mode;
89 std::string prec =
"double";
90 if (
sizeof(
real_t) == 4) prec =
"float";
93 vout.
general(m_vl,
" Precision: %s\n", prec.c_str());
95 vout.
general(m_vl,
" Stop_cond = %16.8e\n", m_Stop_cond);
96 vout.
general(m_vl,
" InitialGuess = %d\n", m_initial_mode);
98 if (m_initial_mode != InitialGuess::ZERO) {
99 vout.
crucial(m_vl,
"%s: WARNING: initial guess is not InitialGuess::ZERO\n",
106 template<
typename AFIELD>
110 set_parameters(Niter, Stop_cond, InitialGuess::ZERO);
115 template<
typename AFIELD>
118 const bool use_init_guess)
121 if (use_init_guess) {
122 set_parameters(Niter, Stop_cond, InitialGuess::GIVEN);
124 set_parameters(Niter, Stop_cond, InitialGuess::ZERO);
130 template<
typename AFIELD>
135 vout.
paranoiac(m_vl,
"%s: solver start.\n", class_name.c_str());
138 real_t bnorm2, bnorm, bnorm_inv, bnorm2_inv;
144 if (!(bnorm2 > 0.0)) {
151 bnorm = sqrt(bnorm2);
152 bnorm_inv =
real_t(1.0) / bnorm;
153 bnorm2_inv =
real_t(1.0) / bnorm2;
161 m_prec->reset_flop_count();
171 for (
int iter = 0; iter < m_Niter; ++iter) {
172 if (r2 < bnorm2 * m_Stop_cond) {
173 diff = r2 * bnorm2_inv;
177 double normalization = sqrt(r2);
178 m_r.scal(1.0 / normalization);
180 m_prec->mult(m_s, m_r);
182 axpy(xq, -normalization, m_s);
183 m_fopr->mult(m_r, xq);
200 m_fopr->mult(m_r, xq);
203 vout.
general(m_vl,
"Richardson nconv = %d, diff2 = %22.15e\n", nconv, diff2 * bnorm2_inv);
209 diff = sqrt(diff2 * bnorm2_inv);
217 template<
typename AFIELD>
226 template<
typename AFIELD>
229 return flop_count_intermediate(m_nconv);
234 template<
typename AFIELD>
237 int Nin = m_fopr->field_nin();
238 int Nvol = m_fopr->field_nvol();
239 int Nex = m_fopr->field_nex();
244 double flop_field =
static_cast<double>(Nin * Nvol * Nex) * NPE;
249 double flop_vector = (1 + (2 + 1 + 2 + 1) * iter) * flop_field;
250 double flop_fopr = iter * m_fopr->flop_count();
251 double flop_prec = m_prec->flop_count();
253 double flop = flop_vector + flop_fopr + flop_prec;