Bridge++  Ver. 2.0.2
fprop_alt_QWS.cpp
Go to the documentation of this file.
1 
13 
16 
18 
19 #ifdef USE_QWSLIB
21 #endif
22 
23 
24 template<typename AFIELD>
25 const std::string Fprop_alt_QWS<AFIELD>::class_name
26  = "Fprop_alt_QWS";
27 //====================================================================
28 template<typename AFIELD>
29 void Fprop_alt_QWS<AFIELD>::init(const Parameters& params_fopr,
30  const Parameters& params_solver)
31 { // this constructor assumes that the factories are available.
32  // vout.general(m_vl, "\n");
33  vout.general(m_vl, "%s: being setup (without link smearing).\n",
34  class_name.c_str());
35 
36  // typedef AFopr<AField<real_t> > AltFopr;
37  // typedef ASolver<AField<real_t> > AltSolver;
38  typedef AFopr_dd<AFIELD> AltFopr;
39 
40  string fopr_type = params_fopr.get_string("fermion_type");
41  // m_fopr = AltFopr::New("AFopr_Clover_QWS_dd", params_fopr);
42  m_fopr = new AFopr_Clover_QWS_dd<AFIELD>(params_fopr);
43  m_dr_smear = 0;
44 
45  m_kernel = 0;
46 
47  // string solver_type = params_solver.get_string("solver_type");
48 
49  set_parameters(params_solver);
50  reset_performance();
51 
52  vout.general(m_vl, "%s: setup finished.\n", class_name.c_str());
53 }
54 
55 
56 template<typename AFIELD>
58 {
59  //- fetch and check input parameters
60  int Niter, Nrestart, Niter_s;
61  double Stop_cond;
62 
63 
64  int err = 0;
65  err += params_solver.fetch_int("maximum_number_of_iteration_single_prec", Niter_s);
66  err += params_solver.fetch_int("maximum_number_of_iteration", Niter);
67  err += params_solver.fetch_int("maximum_number_of_restart", Nrestart);
68  err += params_solver.fetch_double("convergence_criterion_squared", Stop_cond);
69  if (err) {
70  vout.crucial(m_vl, "Error at %s: input parameter not found.\n",
71  class_name.c_str());
72  exit(EXIT_FAILURE);
73  }
74 
75  m_Niter_d = Niter;
76  m_Niter_s = Niter_s;
77  m_nm = 2;
78  m_Nsap = 4;
79  if (Stop_cond > 0) {
80  m_tol_d = sqrt(Stop_cond);
81  m_tol_s = 1.0e-6;
82  } else {
83  m_tol_d = -1.0;
84  m_tol_s = -1.0;
85  vout.general(m_vl, "%s: negative convergence criterion is given, run as a fixed iteration sovler\n", class_name.c_str());
86  }
87 
88 
89  m_Stop_cond = Stop_cond;
90  std::string prec = "double";
91  if (sizeof(real_t) == 4) prec = "float";
92 
93  vout.general(m_vl, "%s:\n", class_name.c_str());
94  vout.general(m_vl, " Precision: %s\n", prec.c_str());
95  vout.general(m_vl, " Niter_d = %d\n", m_Niter_d);
96  vout.general(m_vl, " Niter_s = %d\n", m_Niter_s);
97  vout.general(m_vl, " nm = %d\n", m_nm);
98  vout.general(m_vl, " nsap = %d\n", m_Nsap);
99  vout.general(m_vl, " tol_d = %e\n", m_tol_d);
100  vout.general(m_vl, " tol_s = %e\n", m_tol_s);
101 }
102 
103 
104 /*
105 //====================================================================
106 template<typename AFIELD>
107 void Fprop_alt_QWS<AFIELD>::init(const Parameters& params_fopr,
108  const Parameters& params_solver,
109  Director_Smear* dr_smear)
110 { // this constructor assumes that the factories are available.
111 
112  // vout.general(m_vl, "\n");
113  vout.general(m_vl, "%s: being setup (with link smearing).\n",
114  class_name.c_str());
115 
116  typedef AFopr<AFIELD> AltFopr;
117  typedef ASolver<AFIELD> AltSolver;
118 
119  m_dr_smear = dr_smear;
120 
121  string fopr_type = params_fopr.get_string("fermion_type");
122  m_kernel = AltFopr::New(fopr_type, params_fopr);
123 
124  // m_fopr = AltFopr::New("Smeared", m_kernel, m_dr_smear);
125  m_fopr = new AFopr_Smeared<AFIELD>(m_kernel, m_dr_smear);
126 
127  string solver_type = params_solver.get_string("solver_type");
128  m_solver = AltSolver::New(solver_type, m_fopr);
129  m_solver->set_parameters(params_solver);
130 
131  reset_performance();
132 
133  vout.general(m_vl, "%s: setup finished.\n", class_name.c_str());
134 
135 }
136 */
137 
138 //====================================================================
139 template<typename AFIELD>
141 {
142  delete m_fopr;
143  if (m_kernel != 0) delete m_kernel;
144 }
145 
146 
147 //====================================================================
148 template<typename AFIELD>
150 {
151  m_fopr->set_config(U);
152 }
153 
154 
155 //====================================================================
156 template<typename AFIELD>
158  int& nconv, double& diff)
159 {
160  vout.paranoiac(m_vl, "%s: invert is called.\n", class_name.c_str());
161  vout.paranoiac(m_vl, "mode = %s.\n", m_mode.c_str());
162 
163  if (m_mode == "D") {
164  invert_D(xq, b, nconv, diff);
165  // }else if(m_mode == "DdagD"){
166  // invert_DdagD(xq, b, nconv, diff);
167  // }else if(m_mode == "D_prec"){
168  // invert_D_prec(xq, b, nconv, diff);
169  // }else if(m_mode == "DdagD_prec"){
170  // invert_DdagD_prec(xq, b, nconv, diff);
171  } else {
172  vout.crucial(m_vl, "%s: unsupported mode: %s\n",
173  class_name.c_str(), m_mode.c_str());
174  exit(EXIT_FAILURE);
175  }
176 }
177 
178 
179 //====================================================================
180 template<typename AFIELD>
182  int& nconv, double& diff)
183 {
184  m_timer.reset();
185 
186  if (sizeof(real_t) != 8) {
187  vout.crucial(m_vl, "%s: single prec is not supported\n", class_name.c_str());
188  exit(EXIT_FAILURE);
189  }
190  int nin = m_fopr->field_nin();
191  int nvol = m_fopr->field_nvol();
192  int nex = m_fopr->field_nex();
193 
194  vout.paranoiac(m_vl, "nin = %d nvol = %d nex = %d\n", nin, nvol, nex);
195 
196  AFIELD abq(nin, nvol, nex);
197  AFIELD axq(nin, nvol, nex);
198 
200 
201 #pragma omp parallel
202  {
203  m_fopr->convert(abq, b);
204  axq.set(0.0); // set initial guess
205  }
206  // copy(axq, abq);
207 
208 
209 #ifdef USE_QWSLIB
210  int nsap = m_Nsap;
211  int nm = m_nm;
212  int dd_maxiter_s = m_Niter_s;
213  int dd_maxiter = m_Niter_d;
214  double tol_s = m_tol_s;
215  double tol = m_tol_d;
216  int iter = -1;
217 
218  m_timer.start();
219 #pragma omp parallel
220  {
221  ((AFopr_Clover_QWS_dd<AFIELD> *)m_fopr)->mult_clv_inv(abq);
222  }
223  // bicgstab_dd_mix_(x, b, &tol, &iter, &dd_maxiter, &tol_s, &dd_maxiter_s, &nsap, &nm);
224 
225  bicgstab_dd_mix_((scd_t *)axq.ptr(0), (scd_t *)abq.ptr(0), &tol, &iter, &dd_maxiter, &tol_s, &dd_maxiter_s, &nsap, &nm);
226 
227  m_timer.stop();
228  nconv = iter;
229  diff = -1.0;
230 
231 #pragma omp parallel
232  {
233  m_fopr->reverse(xq, axq);
234  }
235 #endif
236 
237 
238  m_elapsed_time += m_timer.elapsed_sec();
239 }
240 
241 
242 template<typename AFIELD>
244  const Field& b,
245  int& nconv, double& diff)
246 {
247  // dummy
248 }
249 
250 
251 /*
252 //====================================================================
253 template<typename AFIELD>
254 void Fprop_alt_QWS<AFIELD>::invert(AFIELD& xq,
255  const AFIELD& b,
256  int& nconv, double& diff)
257 {
258  vout.paranoiac(m_vl, "%s: invert is called.\n", class_name.c_str());
259  vout.paranoiac(m_vl, "mode = %s.\n", m_mode.c_str());
260 
261  if(m_mode == "D"){
262  invert_D(xq, b, nconv, diff);
263  // }else if(m_mode == "DdagD"){
264  // invert_DdagD(xq, b, nconv, diff);
265  // }else if(m_mode == "D_prec"){
266  // invert_D_prec(xq, b, nconv, diff);
267  // }else if(m_mode == "DdagD_prec"){
269  }else{
270  vout.crucial(m_vl, "%s: unsupported mode: %s\n",
271  class_name.c_str(), m_mode.c_str());
272  exit(EXIT_FAILURE);
273  }
274 }
275 */
276 
277 //====================================================================
278 template<typename AFIELD>
280 {
281  return 0.0;
282 }
283 
284 
285 //====================================================================
286 template<typename AFIELD>
288 {
289  m_flop_count = 0.0;
290  m_elapsed_time = 0.0;
291 }
292 
293 
294 //====================================================================
295 template<typename AFIELD>
297  double& elapsed_time)
298 {
299  flop_count = 0.0;
300  elapsed_time = m_elapsed_time;
301 }
302 
303 
304 //====================================================================
305 template<typename AFIELD>
307 {
308  // double flops = m_flop_count/m_elapsed_time;
309  double flops = 0;
310  double gflops = flops * 1.0e-9;
311 
312  // vout.general(m_vl, "\n");
313  vout.general(m_vl, "%s: solver performance:\n", class_name.c_str());
314  vout.general(m_vl, " Elapsed time = %14.6f sec\n", m_elapsed_time);
315  vout.general(m_vl, " Flop(total) = %18.0f\n", m_flop_count);
316  vout.general(m_vl, " Performance = %11.3f GFlops\n", gflops);
317 }
318 
319 
320 //====================================================================
321 template<typename AFIELD>
323  const std::string mode,
324  const int Nrepeat)
325 {
326  /*
327  int nin = m_fopr->field_nin();
328  int nvol = m_fopr->field_nvol();
329  int nex = m_fopr->field_nex();
330 
331  AFIELD axq(nin, nvol, nex), abq(nin, nvol, nex);
332  abq.set(0.0);
333  abq.set(0, 1.0);
334 
335  unique_ptr<Timer> timer(new Timer);
336 
337  std::string mode_prev = m_fopr->get_mode();
338 
339  m_fopr->set_mode(mode);
340 
341  timer->start();
342 
343 #pragma omp parallel
344  {
345  for(int i = 0; i < Nrepeat; ++i){
346  m_fopr->mult(axq, abq);
347  m_fopr->mult(abq, axq);
348  }
349  }
350 
351  timer->stop();
352 
353  double flop_fopr = m_fopr->flop_count();
354  double flop_total = flop_fopr * double(2 * Nrepeat);
355 
356  double elapsed_time = timer->elapsed_sec();
357  double flops = flop_total/elapsed_time;
358  double gflops = flops * 1.0e-9;
359 
360  vout.general(m_vl, "\n");
361  vout.general(m_vl, "%s: mult performance:\n", class_name.c_str());
362  vout.general(m_vl, " mult mode = %s\n", mode.c_str());
363  vout.general(m_vl, " Elapsed time = %14.6f sec\n", elapsed_time);
364  vout.general(m_vl, " Flop(Fopr) = %18.0f\n",flop_fopr);
365  vout.general(m_vl, " Flop(total) = %18.0f\n",flop_total);
366  vout.general(m_vl, " Performance = %11.3f GFlops\n", gflops);
367 
368  m_fopr->set_mode(mode_prev);
369  */
370 }
371 
372 
373 //====================================================================
374 // explicit instanciation for AField<double,QXS>.
375 template<>
376 const std::string Fprop_alt_QWS<AField<double, QXS> >::class_name
377  = "Fprop_alt_QWS<Afield<double,QXS> >";
378 
379 
380 template class Fprop_alt_QWS<AField<double, QXS> >;
381 
382 //============================================================END=====
afield-inc.h
Fprop_alt_QWS::mult_performance
void mult_performance(const std::string mode, const int Nrepeat)
Definition: fprop_alt_QWS.cpp:322
afield.h
Fprop_alt_QWS
Definition: fprop_alt_QWS.h:30
Field::set
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
Parameters
Class for parameters.
Definition: parameters.h:46
AIndex_lex
Definition: aindex_lex_base.h:17
Fprop_alt_QWS::reset_performance
void reset_performance()
Definition: fprop_alt_QWS.cpp:287
Fprop_alt_QWS::init
void init(const Parameters &params_fopr, const Parameters &params_solver)
Definition: fprop_alt_QWS.cpp:29
Fprop_alt_QWS::report_performance
void report_performance()
Definition: fprop_alt_QWS.cpp:306
afopr_Clover_QWS_dd.h
AFopr_dd
Base class of fermion operator family.
Definition: afopr_dd.h:24
Fprop_alt_QWS::invert_DdagD
void invert_DdagD(Field &, const Field &, int &, double &)
Definition: fprop_alt_QWS.cpp:243
Fprop_alt_QWS::invert_D
void invert_D(Field &, const Field &, int &, double &)
Definition: fprop_alt_QWS.cpp:181
Bridge::BridgeIO::paranoiac
void paranoiac(const char *format,...)
Definition: bridgeIO.cpp:238
qws_lib.h
Fprop_alt_QWS::tidyup
void tidyup()
Definition: fprop_alt_QWS.cpp:140
fprop_alt_QWS.h
Fprop_alt_QWS::set_parameters
void set_parameters(const Parameters &params_solver)
Definition: fprop_alt_QWS.cpp:57
threadManager.h
Fprop_alt::real_t
AFIELD::real_t real_t
Definition: fprop_alt.h:32
Fprop_alt_QWS::flop_count
double flop_count()
Definition: fprop_alt_QWS.cpp:279
Fprop_alt_QWS::invert
void invert(Field &, const Field &, int &, double &)
invert accordingly to the mode. [22 Sep 2018 H.Matsufuru]
Definition: fprop_alt_QWS.cpp:157
Field::ptr
const double * ptr(const int jin, const int site, const int jex) const
Definition: field.h:153
AFopr_Clover_QWS_dd
Definition: afopr_Clover_QWS_dd.h:40
Parameters::fetch_double
int fetch_double(const string &key, double &value) const
Definition: parameters.cpp:327
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Fprop_alt_QWS::get_performance
void get_performance(double &flop_count, double &elapsed_time)
Definition: fprop_alt_QWS.cpp:296
Fprop_alt_QWS::set_config
void set_config(Field *)
Definition: fprop_alt_QWS.cpp:149
Field
Container of Field-type object.
Definition: field.h:46
Parameters::fetch_int
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512