1 template<
typename AFIELD>
4 template<
typename AFIELD>
9 int nin = m_fopr->field_nin();
10 int nvol = m_fopr->field_nvol();
11 int nex = m_fopr->field_nex();
13 m_x.reset(nin, nvol, nex);
14 m_r.reset(nin, nvol, nex);
15 m_p.reset(nin, nvol, nex);
16 m_s.reset(nin, nvol, nex);
25 template<
typename AFIELD>
34 template<
typename AFIELD>
37 const string str_vlevel = params.
get_string(
"verbose_level");
46 err += params.
fetch_int(
"maximum_number_of_iteration", Niter);
47 err += params.
fetch_int(
"maximum_number_of_restart", Nrestart);
48 err += params.
fetch_double(
"convergence_criterion_squared", Stop_cond);
51 vout.
crucial(m_vl,
"Error at %s: input parameter not found.\n",
58 const string initial_guess_mode = params.
get_string(
"initial_guess_mode");
59 vout.
detailed(m_vl,
" initila_guess_mode %s\n", initial_guess_mode.c_str());
60 if (initial_guess_mode ==
"RHS") {
61 init_guess_mode = InitialGuess::RHS;
62 }
else if (initial_guess_mode ==
"GIVEN") {
63 init_guess_mode = InitialGuess::GIVEN;
64 }
else if (initial_guess_mode ==
"ZERO") {
65 init_guess_mode = InitialGuess::ZERO;
67 vout.
crucial(m_vl,
"Error at %s: unknown initial guess mode, %s\n", class_name.c_str(), initial_guess_mode.c_str());
72 int Niter2 = Niter * Nrestart;
73 set_parameters(Niter2, Stop_cond, init_guess_mode);
78 template<
typename AFIELD>
82 set_parameters(Niter, Stop_cond, InitialGuess::RHS);
87 template<
typename AFIELD>
95 m_Stop_cond = Stop_cond;
96 m_initial_mode = init_guess_mode;
97 std::string prec =
"double";
98 if (
sizeof(
real_t) == 4) prec =
"float";
101 vout.
general(m_vl,
" Precision: %s\n", prec.c_str());
103 vout.
general(m_vl,
" Stop_cond = %16.8e\n", m_Stop_cond);
104 vout.
general(m_vl,
" init_guess_mode: %d\n", m_initial_mode);
109 template<
typename AFIELD>
122 solve_CG_init(rrp, rr);
125 for (
int iter = 0; iter < m_Niter; ++iter) {
126 solve_CG_step(rrp, rr);
129 if (rr * snorm < m_Stop_cond) {
143 m_Niter, rr * snorm);
153 m_fopr->mult(m_s, xq);
168 template<
typename AFIELD>
171 if (m_initial_mode == InitialGuess::RHS) {
173 vout.
general(m_vl,
"%s: using InitialGuess::RHS\n", class_name.c_str());
177 m_fopr->mult(m_s, m_x);
182 }
else if (m_initial_mode == InitialGuess::GIVEN) {
183 vout.
crucial(
"%s: InitialGuess::GIVEN is not yet ready\n", class_name.c_str());
185 }
else if (m_initial_mode == InitialGuess::ZERO) {
187 vout.
general(m_vl,
"%s: using InitialGuess::ZERO\n", class_name.c_str());
196 vout.
crucial(
"%s: unkown init guess mode\n", class_name.c_str());
203 template<
typename AFIELD>
208 m_fopr->mult(m_s, m_p);
228 template<
typename AFIELD>
231 int Nin = m_fopr->field_nin();
232 int Nvol = m_fopr->field_nvol();
233 int Nex = m_fopr->field_nex();
238 double flop_field =
static_cast<double>(Nin * Nvol * Nex) * NPE;
239 double flop_vector = (6 + ninit * 4 + m_nconv * 11) * flop_field;
240 double flop_fopr = (1 + ninit + m_nconv) * m_fopr->flop_count();
242 double flop = flop_vector + flop_fopr;