Bridge++  Ver. 2.0.2
fprop_alt_Standard_SAP-tmpl.h
Go to the documentation of this file.
1 
11 
13 
14 
15 template<typename AFIELD>
17  = "Fprop_alt_Standard_SAP";
18 
19 //====================================================================
20 template<typename AFIELD>
22  const Parameters& params_fopr,
23  const Parameters& params_solver)
24 {
25  vout.general(m_vl, "\n");
26  vout.general(m_vl, "%s: being setup (without link smearing).\n",
27  class_name.c_str());
28 
29  m_dr_smear = 0;
30 
31  string fopr_type = params_fopr.get_string("fermion_type");
32  vout.general("%s: fopr_type: %s\n", class_name.c_str(), fopr_type.c_str());
33  string fopr_type_dd = fopr_type + "_dd";
34  m_kernel = 0;
35 
36  m_afopr = dynamic_cast<AFopr_dd<AFIELD> *>(
37  AFopr<AFIELD>::New(fopr_type_dd, params_fopr));
38 
39  if (m_afopr == nullptr) {
40  vout.crucial(m_vl, "%s: failed to create AFopr_dd with fermion type %s.\n", class_name.c_str(), fopr_type.c_str());
41  exit(EXIT_FAILURE);
42  }
43  init_common(params_fopr, params_solver);
44 
45  vout.general(m_vl, "%s: setup finished.\n", class_name.c_str());
46 }
47 
48 
49 //====================================================================
50 template<typename AFIELD>
52  const Parameters& params_fopr,
53  const Parameters& params_solver,
54  Director_Smear *dr_smear)
55 {
56  vout.general(m_vl, "\n");
57  vout.general(m_vl, "%s: being setup (with link smearing).\n",
58  class_name.c_str());
59 
60  vout.crucial(m_vl, "sorry, not available.\n");
61  exit(EXIT_FAILURE);
62 
63  /*
64  m_dr_smear = dr_smear;
65 
66  string fopr_type = params_fopr.get_string("fermion_type");
67 
68  m_kernel_d = AFopr<AFIELD_d>::New(fopr_type, params_fopr);
69  m_fopr_d = new AFopr_Smeared<AFIELD_d>(m_kernel_d, m_dr_smear);
70 
71  m_kernel_f = AFopr<AFIELD_f>::New(fopr_type, params_fopr);
72  m_fopr_f = new AFopr_Smeared<AFIELD_f>(m_kernel_f, m_dr_smear);
73 
74  init_common(params_fopr, params_solver);
75 
76  vout.general(m_vl, "%s: setup finished.\n", class_name.c_str());
77  */
78 }
79 
80 
81 //====================================================================
82 template<typename AFIELD>
84  const Parameters& params_fopr,
85  const Parameters& params_solver)
86 {
87  int Ndim = CommonParameters::Ndim();
88  m_fine_lattice.resize(Ndim);
89  m_coarse_lattice.resize(Ndim);
90 
91  m_fine_lattice[0] = CommonParameters::Nx();
92  m_fine_lattice[1] = CommonParameters::Ny();
93  m_fine_lattice[2] = CommonParameters::Nz();
94  m_fine_lattice[3] = CommonParameters::Nt();
95 
96  std::vector<int> block_size;
97  int err = 0;
98  err += params_fopr.fetch_int_vector("block_size", block_size);
99  if (err) {
100  vout.crucial(m_vl, "Error at %s: block_size not found.\n",
101  class_name.c_str());
102  exit(EXIT_FAILURE);
103  }
104 
105  for (int mu = 0; mu < Ndim; ++mu) {
106  m_coarse_lattice[mu] = m_fine_lattice[mu] / block_size[mu];
107  }
108 
109  for (int mu = 0; mu < Ndim; ++mu) {
110  vout.general(m_vl, " block_size[%d] = %3d"
111  " coarse_lattice[%d] = %3d\n",
112  mu, block_size[mu], mu, m_coarse_lattice[mu]);
113  }
114 
115  m_block_index = new AIndex_block_lex<real_t, AFIELD::IMPL>(
116  m_coarse_lattice,
117  m_fine_lattice);
118 
119  m_asolver = new ASolver_SAP<AFIELD>(m_afopr, m_block_index);
120  vout.general(m_vl, "SAP is initiated, done\n");
121 
122  int niter;
123  double stop_cond;
124  err += params_solver.fetch_int("maximum_number_of_iteration",
125  niter);
126  err += params_solver.fetch_double("convergence_criterion_squared",
127  stop_cond);
128  if (err) {
129  vout.crucial(m_vl, "Error at %s: input parameter not found.\n",
130  class_name.c_str());
131  exit(EXIT_FAILURE);
132  }
133 
134  m_asolver->set_parameters(niter, real_t(stop_cond));
135 
136  reset_performance();
137 }
138 
139 
140 //====================================================================
141 template<typename AFIELD>
143 {
144  delete m_asolver;
145  delete m_afopr;
146  delete m_block_index;
147  if (m_kernel != 0) delete m_kernel;
148 }
149 
150 
151 //====================================================================
152 template<typename AFIELD>
154 {
155  m_afopr->set_config(U);
156 }
157 
158 
159 //====================================================================
160 template<typename AFIELD>
162  Field& xq, const Field& b,
163  int& nconv, double& diff)
164 {
165  vout.paranoiac(m_vl, "%s: invert is called.\n", class_name.c_str());
166  vout.paranoiac(m_vl, "mode = %s.\n", m_mode.c_str());
167 
168  m_timer.reset();
169  m_timer.start();
170 
171  if (m_mode == "D") {
172  invert_D(xq, b, nconv, diff);
173  } else if (m_mode == "DdagD") {
174  invert_DdagD(xq, b, nconv, diff);
175  } else {
176  vout.crucial(m_vl, "%s: unsupported mode: %s\n",
177  class_name.c_str(), m_mode.c_str());
178  exit(EXIT_FAILURE);
179  }
180 
181  m_timer.stop();
182  m_elapsed_time += m_timer.elapsed_sec();
183  // m_flop_count += m_solver->flop_count();
184 }
185 
186 
187 //====================================================================
188 template<typename AFIELD>
190  Field& xq, const Field& b,
191  int& nconv, double& diff)
192 {
193  int Nin = m_afopr->field_nin();
194  int Nvol = m_afopr->field_nvol();
195  int Nex = m_afopr->field_nex();
196 
197  // Source vector
198  AFIELD ab(Nin, Nvol, Nex);
199 
200  // Solution vector
201  AFIELD ax(Nin, Nvol, Nex);
202 
203  // conversion
205  vout.paranoiac(m_vl, "index is ready\n");
206 
207 #pragma omp parallel
208  {
209  if (m_afopr->needs_convert()) {
210  vout.detailed(m_vl, "convert required.\n");
211  m_afopr->convert(ab, b);
212  } else {
213  vout.detailed(m_vl, "convert not required.\n");
214  convert(index_alt, ab, b);
215  }
216  }
217  vout.general(m_vl, "converting source, done\n");
218 
219  real_t nr = ab.norm2();
220  nr = sqrt(1.0 / nr);
221  ab.scal(nr);
222 
223  invert_D(ax, ab, nconv, diff);
224 
225 #pragma omp parallel
226  {
227  if (m_afopr->needs_convert()) {
228  vout.detailed(m_vl, "convert required.\n");
229  m_afopr->reverse(xq, ax);
230  } else {
231  vout.detailed(m_vl, "convert not required.\n");
232  reverse(index_alt, xq, ax);
233  }
234  }
235 }
236 
237 
238 //====================================================================
239 template<typename AFIELD>
241  Field& xq, const Field& b,
242  int& nconv, double& diff)
243 {
244  vout.crucial(m_vl, "%s: invert_DdagD is not available.\n",
245  class_name.c_str());
246  exit(EXIT_FAILURE);
247 }
248 
249 
250 //====================================================================
251 template<typename AFIELD>
253  AFIELD& xq, const AFIELD& b,
254  int& nconv, double& diff)
255 {
256  vout.paranoiac(m_vl, "%s: invert is called.\n", class_name.c_str());
257  vout.paranoiac(m_vl, "mode = %s.\n", m_mode.c_str());
258 
259  if (m_mode == "D") {
260  invert_D(xq, b, nconv, diff);
261  } else if (m_mode == "DdagD") {
262  invert_DdagD(xq, b, nconv, diff);
263  } else {
264  vout.crucial(m_vl, "%s: unsupported mode: %s\n",
265  class_name.c_str(), m_mode.c_str());
266  exit(EXIT_FAILURE);
267  }
268 }
269 
270 
271 //====================================================================
272 template<typename AFIELD>
274  AFIELD& ax, const AFIELD& ab,
275  int& nconv, double& diff)
276 {
277  int Nin = m_afopr->field_nin();
278  int Nvol = m_afopr->field_nvol();
279  int Nex = m_afopr->field_nex();
280 
281  m_afopr->set_mode(m_mode);
282 
283  real_t diff1, diff2;
284 
285 #pragma omp parallel
286  {
287  m_asolver->solve(ax, ab, nconv, diff1);
288  }
289 
290  AFIELD ay(Nin, Nvol, Nex);
291 
292 #pragma omp parallel
293  {
294  m_afopr->mult(ay, ax);
295 #pragma omp barrier
296 
297  axpy(ay, real_t(-1.0), ab);
298 #pragma omp barrier
299 
300  diff2 = ay.norm2();
301  }
302 
303  diff = double(diff2);
304 
305  real_t norm2 = ab.norm2();
306 
307  vout.general("AField solver done:\n");
308  vout.general(" solver residue squared = %22.15e\n", diff1);
309  vout.general(" real residue squared = %22.15e\n", diff2);
310  vout.general(" relative residue = %22.15e\n", diff2 / norm2);
311 }
312 
313 
314 //====================================================================
315 template<typename AFIELD>
317  AFIELD& xq, const AFIELD& b,
318  int& nconv, double& diff)
319 {
320  vout.crucial(m_vl, "%s: invert_DdagD is not available.\n",
321  class_name.c_str());
322  exit(EXIT_FAILURE);
323 }
324 
325 
326 //====================================================================
327 template<typename AFIELD>
329 {
330  return m_asolver->flop_count();
331 }
332 
333 
334 //====================================================================
335 template<typename AFIELD>
337 {
338  m_flop_count = 0.0;
339  m_elapsed_time = 0.0;
340 }
341 
342 
343 //====================================================================
344 template<typename AFIELD>
346 {
347  double flops = m_flop_count / m_elapsed_time;
348  double gflops = flops * 1.0e-9;
349 
350  vout.general(m_vl, "\n");
351  vout.general(m_vl, "%s: solver performance:\n", class_name.c_str());
352  vout.general(m_vl, " NOT YET implelemted.\n");
353 
354  /*
355  vout.general(m_vl, " Elapsed time = %14.6f sec\n", m_elapsed_time);
356  vout.general(m_vl, " Flop(total) = %18.0f\n",m_flop_count);
357  vout.general(m_vl, " Performance = %11.3f GFlops\n", gflops);
358  */
359 }
360 
361 
362 //====================================================================
363 template<typename AFIELD>
365  const std::string mode,
366  const int Nrepeat)
367 {
368  /*
369  int nin = m_afopr->field_nin();
370  int nvol = m_afopr->field_nvol();
371  int nex = m_afopr->field_nex();
372 
373  unique_ptr<Timer> timer(new Timer);
374 
375  std::string mode_prev_d = m_fopr_d->get_mode();
376  std::string mode_prev_f = m_fopr_f->get_mode();
377 
378  m_fopr_d->set_mode(mode);
379  m_fopr_f->set_mode(mode);
380 
381  {
382  AFIELD axq(nin, nvol, nex), abq(nin, nvol, nex);
383  abq.set(0.0);
384  abq.set(0, 1.0);
385 
386  timer->start();
387 
388 #pragma omp parallel
389  {
390  for(int i = 0; i < Nrepeat; ++i){
391  m_fopr_d->mult(axq, abq);
392  m_fopr_d->mult(abq, axq);
393  }
394  }
395 
396  timer->stop();
397  }
398 
399  double flop_fopr = m_fopr_d->flop_count();
400  double flop_total = flop_fopr * double(2 * Nrepeat);
401 
402  double elapsed_time = timer->elapsed_sec();
403  double flops = flop_total/elapsed_time;
404  double gflops = flops * 1.0e-9;
405 
406  vout.general(m_vl, "\n");
407  vout.general(m_vl, "%s: mult performance:\n", class_name.c_str());
408  vout.general(m_vl, " Double precision:\n");
409  vout.general(m_vl, " Elapsed time = %14.6f sec\n", elapsed_time);
410  vout.general(m_vl, " Flop(Fopr) = %18.0f\n",flop_fopr);
411  vout.general(m_vl, " Flop(total) = %18.0f\n",flop_total);
412  vout.general(m_vl, " Performance = %11.3f GFlops\n", gflops);
413 
414  {
415  AFIELD axq(nin, nvol, nex), abq(nin, nvol, nex);
416  abq.set(0.0);
417  abq.set(0, 1.0);
418 
419  timer->reset();
420  timer->start();
421 
422 #pragma omp parallel
423  {
424  for(int i = 0; i < Nrepeat; ++i){
425  m_fopr_f->mult(axq, abq);
426  m_fopr_f->mult(abq, axq);
427  }
428  }
429 
430  timer->stop();
431  }
432 
433  flop_fopr = m_fopr_f->flop_count();
434  flop_total = flop_fopr * double(2 * Nrepeat);
435 
436  elapsed_time = timer->elapsed_sec();
437  flops = flop_total/elapsed_time;
438  gflops = flops * 1.0e-9;
439 
440  vout.general(m_vl, " Single precision:\n");
441  vout.general(m_vl, " Elapsed time = %14.6f sec\n", elapsed_time);
442  vout.general(m_vl, " Flop(Fopr) = %18.0f\n",flop_fopr);
443  vout.general(m_vl, " Flop(total) = %18.0f\n",flop_total);
444  vout.general(m_vl, " Performance = %11.3f GFlops\n", gflops);
445 
446  m_fopr_d->set_mode(mode_prev_d);
447  m_fopr_f->set_mode(mode_prev_f);
448  */
449 }
450 
451 
452 //============================================================END=====
CommonParameters::Ny
static int Ny()
Definition: commonParameters.h:106
Fprop_alt_Standard_SAP::invert_D
void invert_D(Field &, const Field &, int &, double &)
Definition: fprop_alt_Standard_SAP-tmpl.h:189
CommonParameters::Nz
static int Nz()
Definition: commonParameters.h:107
Fprop_alt_Standard_SAP
Get quark propagator for domain-decomposed AFopr.
Definition: fprop_alt_Standard_SAP.h:32
Fprop_alt_Standard_SAP::reset_performance
void reset_performance()
Definition: fprop_alt_Standard_SAP-tmpl.h:336
Fprop_alt_Standard_SAP::tidyup
void tidyup()
Definition: fprop_alt_Standard_SAP-tmpl.h:142
Fprop_alt_Standard_SAP::init_common
void init_common(const Parameters &params_fopr, const Parameters &params_solver)
Definition: fprop_alt_Standard_SAP-tmpl.h:83
AFopr
Definition: afopr.h:48
ASolver_SAP
Definition: asolver_SAP.h:29
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
Parameters
Class for parameters.
Definition: parameters.h:46
AIndex_lex
Definition: aindex_lex_base.h:17
Fprop_alt_Standard_SAP::report_performance
void report_performance()
Definition: fprop_alt_Standard_SAP-tmpl.h:345
convert
void convert(INDEX &index, AFIELD &v, const Field &w)
Definition: afield-inc.h:129
Field::scal
friend void scal(Field &x, const double a)
scal(x, a): x = a * x
Definition: field.cpp:261
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
real_t
double real_t
Definition: bridgeQXS_Clover_coarse_double.cpp:16
norm2
REALTYPE norm2(const AField< REALTYPE, QXS > &v)
Definition: afield-inc.h:453
AIndex_block_lex< real_t, AFIELD::IMPL >
AFopr_dd
Base class of fermion operator family.
Definition: afopr_dd.h:24
Fprop_alt_Standard_SAP::set_config
void set_config(Field *)
Definition: fprop_alt_Standard_SAP-tmpl.h:153
Bridge::BridgeIO::paranoiac
void paranoiac(const char *format,...)
Definition: bridgeIO.cpp:238
fprop_alt_Standard_SAP.h
Field::norm2
double norm2() const
Definition: field.cpp:113
CommonParameters::Nx
static int Nx()
Definition: commonParameters.h:105
Fprop_alt_Standard_SAP::flop_count
double flop_count()
Definition: fprop_alt_Standard_SAP-tmpl.h:328
Fprop_alt_Standard_SAP::invert
void invert(Field &, const Field &, int &, double &)
invert accordingly to the mode. [22 Sep 2018 H.Matsufuru]
Definition: fprop_alt_Standard_SAP-tmpl.h:161
CommonParameters::Nt
static int Nt()
Definition: commonParameters.h:108
Parameters::fetch_int_vector
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:429
threadManager.h
Fprop_alt::real_t
AFIELD::real_t real_t
Definition: fprop_alt.h:32
Director_Smear
Manager of smeared configurations.
Definition: director_Smear.h:39
reverse
void reverse(INDEX &index, Field &v, const AFIELD &w)
Definition: afield-inc.h:159
Fprop_alt_Standard_SAP::mult_performance
void mult_performance(const std::string mode, const int Nrepeat)
Definition: fprop_alt_Standard_SAP-tmpl.h:364
Fprop_alt_Standard_SAP::init
void init(const Parameters &params_fopr, const Parameters &params_solver)
Definition: fprop_alt_Standard_SAP-tmpl.h:21
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
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
Fprop_alt_Standard_SAP::invert_DdagD
void invert_DdagD(Field &, const Field &, int &, double &)
Definition: fprop_alt_Standard_SAP-tmpl.h:240
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512