Bridge++  Ver. 2.0.2
fprop_Standard_eo.cpp
Go to the documentation of this file.
1 
14 #include "fprop_Standard_eo.h"
15 #include "Tools/timer.h"
16 
17 const std::string Fprop_Standard_eo::class_name = "Fprop_Standard_eo";
18 
19 //====================================================================
21 {
22  m_index->convertField(*m_Ueo, *U);
23 
25 }
26 
27 
28 //====================================================================
29 void Fprop_Standard_eo::invert_D(Field& xq, const Field& b, int& Nconv, double& diff)
30 {
31  const int Nin = b.nin();
32  const int Nvol = b.nvol();
33  const int Nex = b.nex();
34 
35  Field Be(Nin, Nvol / 2, Nex);
36  Field bo(Nin, Nvol / 2, Nex);
37  Field xe(Nin, Nvol / 2, Nex);
38 
39  int Nconv1 = 0;
40 
41  Fopr_eo *fopr = dynamic_cast<Fopr_eo*>(m_solver->get_fopr());
42  if(fopr==nullptr){
43  vout.general(m_vl, "Fprop_Standard_eo: the given Fopr is not Fopr_eo.\n");
44  abort();
45  }
46 
47  // std::string mode_prev = fopr->get_mode();
48 
49  fopr->set_mode("D");
50 #pragma omp parallel
51  {
52  fopr->preProp(Be, bo, b);
53 #pragma omp barrier
54  m_solver->solve(xe, Be, Nconv1, diff);
55 #pragma omp barrier
56  fopr->postProp(xq, xe, bo);
57  } // omp parallel
58 
59  //- NB. #mult is doubled for even-odd
60  Nconv = 2 * Nconv1;
61 }
62 
63 
64 //====================================================================
65 void Fprop_Standard_eo::invert_DdagD(Field& xq, const Field& b, int& Nconv, double& diff)
66 {
67  const int Nin = b.nin();
68  const int Nvol = b.nvol();
69  const int Nex = b.nex();
70 
71  Field Be(Nin, Nvol / 2, Nex);
72  Field bo(Nin, Nvol / 2, Nex);
73  Field xe(Nin, Nvol / 2, Nex);
74 
75  int Nconv1 = 0, Nconv2 = 0;
76  double diff1 = 1.0, diff2 = 1.0;
77 
78  Fopr_eo *fopr = dynamic_cast<Fopr_eo*>(m_solver->get_fopr());
79  if(fopr==nullptr){
80  vout.crucial(m_vl, "Fprop_Standard_eo: the given Fopr is not Fopr_eo.\n");
81  abort();
82  }
83 
84 #pragma omp parallel
85  {
86  fopr->set_mode("Ddag");
87  fopr->preProp(Be, bo, b);
88 #pragma omp barrier
89  m_solver->solve(xe, Be, Nconv1, diff1);
90 #pragma omp barrier
91  fopr->postProp(xq, xe, bo);
92 
93  fopr->set_mode("D");
94  fopr->preProp(Be, bo, xq);
95 #pragma omp barrier
96  m_solver->solve(xe, Be, Nconv2, diff2);
97 #pragma omp barrier
98  fopr->postProp(xq, xe, bo);
99  }
100 
101 
102  //- NB. #mult is doubled for even-odd
103  Nconv = 2 * (Nconv1 + Nconv2);
104 
105  //- rough estimate of diff
106  diff = (diff1 + diff2) / 2.0;
107 }
108 
109 
110 //====================================================================
112 {
113  const int NPE = CommonParameters::NPE();
114  const double eps = CommonParameters::epsilon_criterion();
115 
116  //- NB1 Nin = 2 * Nc * Nd, Nex = 1 for field_F
117  //- NB2 Nvol/2 for eo
118  const int Nin = 2 * CommonParameters::Nc() * CommonParameters::Nd();
119  const int Nvol = CommonParameters::Nvol();
120  const int Nex = 1;
121 
122  const double flop_fopr = m_solver->get_fopr()->flop_count();
123 
124  if (flop_fopr < eps) {
125  vout.crucial(m_vl, "Warning at %s: no fopr->flop_count() is available, setting flop = 0.0.\n", class_name.c_str());
126  return 0.0;
127  }
128 
129  const double flop_axpy = static_cast<double>(Nin * Nex * 2) * (Nvol / 2 * NPE);
130 
131  const double flop_preProp = flop_fopr + flop_axpy;
132  const double flop_solver = m_solver->flop_count();
133  const double flop_postProp = flop_fopr + flop_axpy;
134 
135  const double flop = flop_preProp + 2 * flop_solver + flop_postProp;
136 
137  return flop;
138 }
139 
140 
141 
142 //====================================================================
143 void Fprop_Standard_eo::mult_performance(const std::string mode,
144  const int Nrepeat)
145 {
146  Fopr *fopr = m_solver->get_fopr();
147 
148  int nin = fopr->field_nin();
149  int nvol = fopr->field_nvol();
150  int nex = fopr->field_nex();
151 
152  Field axq(nin, nvol, nex), abq(nin, nvol, nex);
153  abq.set(0.0);
154  abq.set(0, 1.0);
155 
156  unique_ptr<Timer> timer(new Timer);
157 
158  std::string mode_prev = fopr->get_mode();
159 
160  fopr->set_mode(mode);
161 
162  timer->start();
163 
164 #pragma omp parallel
165  {
166  for (int i = 0; i < Nrepeat; ++i) {
167  fopr->mult(axq, abq);
168  fopr->mult(abq, axq);
169  }
170  }
171 
172  timer->stop();
173 
174  double flop_fopr = fopr->flop_count() * 1.e9;
175  double flop_total = flop_fopr * double(2 * Nrepeat);
176 
177  double elapsed_time = timer->elapsed_sec();
178  double flops = flop_total / elapsed_time;
179  double gflops = flops * 1.0e-9;
180 
181  vout.general(m_vl, "\n");
182  vout.general(m_vl, "%s: mult performance:\n", class_name.c_str());
183  vout.general(m_vl, " mult mode = %s\n", mode.c_str());
184  vout.general(m_vl, " Elapsed time = %14.6f sec\n", elapsed_time);
185  vout.general(m_vl, " Flop(Fopr) = %18.0f\n", flop_fopr);
186  vout.general(m_vl, " Flop(total) = %18.0f\n", flop_total);
187  vout.general(m_vl, " Performance = %11.3f GFlops\n", gflops);
188 
189  fopr->set_mode(mode_prev);
190 }
191 
192 
193 //============================================================END=====
AFopr< Field >
Fprop_Standard_eo::set_config
void set_config(Field *)
Definition: fprop_Standard_eo.cpp:20
Field::set
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
AFopr::mult
virtual void mult(AFIELD &, const AFIELD &)
multiplies fermion operator to a given field.
Definition: afopr.h:95
AFopr_eo< Field >
Solver::flop_count
virtual double flop_count()=0
Fprop_Standard_eo::invert_DdagD
void invert_DdagD(Field &, const Field &, int &, double &)
Definition: fprop_Standard_eo.cpp:65
AFopr::field_nex
virtual int field_nex()=0
returns the external degree of freedom of the fermion field.
Fprop_Standard_eo::m_index
Index_eo * m_index
Definition: fprop_Standard_eo.h:47
Field::nex
int nex() const
Definition: field.h:128
Fprop_Standard_eo::class_name
static const std::string class_name
Definition: fprop_Standard_eo.h:41
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
Fprop_Standard_eo::mult_performance
void mult_performance(const std::string mode, const int Nrepeat)
Definition: fprop_Standard_eo.cpp:143
AFopr::set_mode
virtual void set_mode(std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: afopr.h:81
Field::nin
int nin() const
Definition: field.h:126
Timer
Definition: timer.h:31
fprop_Standard_eo.h
Fprop_Standard_eo::m_solver
Solver * m_solver
Definition: fprop_Standard_eo.h:44
AFopr_eo::set_mode
virtual void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: afopr_eo.h:63
AFopr::set_config
virtual void set_config(Field *)=0
sets the gauge configuration.
Solver::solve
virtual void solve(Field &solution, const Field &source, int &Nconv, double &diff)=0
AFopr::get_mode
virtual std::string get_mode() const
returns the current mult mode.
Definition: afopr.h:88
Fprop_Standard_eo::flop_count
double flop_count()
Definition: fprop_Standard_eo.cpp:111
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
timer.h
AFopr::field_nvol
virtual int field_nvol()=0
returns the volume of the fermion field.
Index_eo::convertField
void convertField(Field &eo, const Field &lex)
Definition: index_eo.cpp:90
AFopr::flop_count
virtual double flop_count()
returns the number of floating point operations.
Definition: afopr.h:160
AFopr_eo::preProp
virtual void preProp(AFIELD &, AFIELD &, const AFIELD &)=0
Fprop::m_vl
Bridge::VerboseLevel m_vl
Definition: fprop.h:37
Fprop_Standard_eo::m_Ueo
Field_G * m_Ueo
Definition: fprop_Standard_eo.h:45
Field::nvol
int nvol() const
Definition: field.h:127
CommonParameters::NPE
static int NPE()
Definition: commonParameters.h:101
Solver::get_fopr
virtual Fopr * get_fopr()=0
AFopr_eo::postProp
virtual void postProp(AFIELD &, const AFIELD &, const AFIELD &)=0
CommonParameters::Nd
static int Nd()
Definition: commonParameters.h:116
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Field
Container of Field-type object.
Definition: field.h:46
AFopr::field_nin
virtual int field_nin()=0
returns the on-site degree of freedom of the fermion field.
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Fprop_Standard_eo::invert_D
void invert_D(Field &, const Field &, int &, double &)
Definition: fprop_Standard_eo.cpp:29
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
CommonParameters::epsilon_criterion
static double epsilon_criterion()
Definition: commonParameters.h:119