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>
126 solve_CG_init(rrp, rr);
129 if(rr * snorm < m_Stop_cond) {
131 if(ith == 0) m_nconv = nconv;
135 for (
int iter = 0; iter < m_Niter; ++iter) {
137 solve_CG_step(rrp, rr);
140 if (rr * snorm < m_Stop_cond) {
142 if(ith == 0) m_nconv = nconv + 1;
151 m_Niter, rr * snorm);
164 m_fopr->mult(m_s, xq);
179 template<
typename AFIELD>
182 if (m_initial_mode == InitialGuess::RHS) {
184 vout.
general(m_vl,
"%s: using InitialGuess::RHS\n", class_name.c_str());
188 m_fopr->mult(m_s, m_x);
193 }
else if (m_initial_mode == InitialGuess::GIVEN) {
194 vout.
crucial(
"%s: InitialGuess::GIVEN is not yet ready\n", class_name.c_str());
196 }
else if (m_initial_mode == InitialGuess::ZERO) {
198 vout.
general(m_vl,
"%s: using InitialGuess::ZERO\n", class_name.c_str());
207 vout.
crucial(
"%s: unkown init guess mode\n", class_name.c_str());
214 template<
typename AFIELD>
219 m_fopr->mult(m_s, m_p);
239 template<
typename AFIELD>
242 int Nin = m_fopr->field_nin();
243 int Nvol = m_fopr->field_nvol();
244 int Nex = m_fopr->field_nex();
249 double flop_field =
static_cast<double>(Nin * Nvol * Nex) * NPE;
250 double flop_vector = (6 + ninit * 4 + m_nconv * 11) * flop_field;
251 double flop_fopr = (1 + ninit + m_nconv) * m_fopr->flop_count();
253 double flop = flop_vector + flop_fopr;