CHROMA
avp_inverter_interface.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Base class for AVP's DWF solver interface
4  */
5 
6 #ifndef AVP_INVERTER_INTERFACE_H
7 #define AVP_INVERTER_INTERFACE_H
8 
9 #include "chromabase.h"
10 
11 using namespace QDP;
12 
13 namespace Chroma
14 {
15  //! AVP's DWF Solver interface
16  /*!
17  * \ingroup qprop
18  *
19  * @{
20  */
21  namespace AVPSolverFunctions
22  {
23  // Gauge Reader function - user supplied
24  double gaugeReader(const void *OuterGauge,
25  void *env,
26  const int lattice_coord[4],
27  int mu,
28  int row,
29  int col,
30  int reim);
31 
32 
33  // Fermion Reader function - user supplied
34  double fermionReaderRHS(const void *OuterFermion,
35  void *env,
36  const int lattice_coord[5],
37  int color,
38  int spin,
39  int reim);
40 
41  // Fermion Reader function - user supplied
42  double fermionReaderGuess(const void *OuterFermion,
43  void *env,
44  const int lattice_addr[5],
45  int color,
46  int spin,
47  int reim) ;
48 
49 
50  // Fermion Writer function - user supplied
51  void fermionWriterSolver(void *OuterFermion,
52  void *env,
53  const int lattice_addr[5],
54  int color,
55  int spin,
56  int reim,
57  double val);
58 
59 
60  // Fermion Writer function - user supplied
61  void fermionWriterOperator(void *OuterFermion,
62  void *env,
63  const int lattice_addr[5],
64  int color,
65  int spin,
66  int reim,
67  double val);
68 
69  } // namespace AVPSolverFunctions
70 
71  namespace AVPSolver
72  {
73 
74  template< typename U, typename T>
76  {
77  public:
78 
79  // Gauge Field Type
80  typedef U Gauge;
81 
82  // Gauge Fermion Field Type
83  typedef T Fermion;
84 
85 
86  protected:
87 
88  // Here I can wrap AVPs solver stuff
89  virtual Fermion* loadFermionRHS(const void *OuterFermion) const = 0;
90  virtual Fermion* loadFermionGuess(const void *OuterFermion) const = 0;
91  virtual Fermion* allocateFermion(void) const =0 ;
92  virtual void saveFermionSolver(void *OuterFermion,
93  Fermion* CGfermion) const =0;
94 
95  virtual void saveFermionOperator(void *OuterFermion,
96  Fermion* CGfermion) const =0;
97 
98  virtual void deleteFermion(Fermion* ptr) const = 0;
99 
100 
101 
102  virtual int cgInternal(Fermion *psi,
103  double *out_eps,
104  int *out_iter,
105  double M,
106  double m_f,
107  const Fermion *x0,
108  const Fermion *eta,
109  double eps,
110  int min_iter,
111  int max_iter) const = 0;
112 
113 
114 
115 
116 
117 
118  public:
119 
120  // Init the system -- Constructor call?
121  virtual int init(const int lattice[5],
122  void *(*allocator)(size_t size),
123  void (*deallocator)(void *)) = 0;
124 
125  // Finalize - destructor call
126  virtual void fini(void) = 0;
127 
128  virtual void loadGauge(const void *OuterGauge_U,
129  const void *OuterGauge_V) = 0;
130 
131  virtual void deleteGauge(void) = 0;
132 
133 
134  // Call the solver
135  int cgSolver(multi1d<LatticeFermion> &solution, // output
136  double M5, // input
137  double m_f, // input
138  const multi1d<LatticeFermion> &rhs, // input
139  const multi1d<LatticeFermion> &x0, // input
140  double rsd, // input
141  int max_iter, // input
142  double& out_eps, // output
143  int &out_iter ) const // output
144  {
145 
146  StopWatch swatch;
147  swatch.reset();
148  swatch.start();
149  Fermion *eta = loadFermionRHS(&rhs);
150  swatch.stop();
151  QDPIO::cout << "Importing RHS Fermion took: " << swatch.getTimeInSeconds() << " seconds " << std::endl;
152 
153 
154  swatch.reset();
155  swatch.start();
156  Fermion *X0 = loadFermionGuess(&x0);
157  swatch.stop();
158 
159  QDPIO::cout << "Importing Guess took: " << swatch.getTimeInSeconds()
160  << " seconds" << std::endl;
161 
162  Fermion *res = allocateFermion();
163 
164  QDPIO::cout << "Entering CG_DWF solver: rsd = " << rsd
165  << ", max_iterations = " << max_iter
166  << std::endl;
167 
168  double M_0 = -2*M5;
169  out_eps = 0.0;
170  out_iter = 0;
171  int min_iter = 0;
172 
173 
174  swatch.reset();
175  swatch.start();
176 
177 
178  int status = cgInternal(res, &out_eps, &out_iter,
179  M_0, m_f, X0, eta,
180  rsd, min_iter, max_iter);
181 
182  swatch.stop();
183  QDPIO::cout << "CGInternal : status = " << status
184  << ", iterations = " << out_iter
185  << ", resulting epsilon = " << out_eps
186  << std::endl;
187 
188  if (status != 0) {
189 
190  QDPIO::cerr << "DWF_solver: status = " << status
191  << ", iterations = " << out_iter
192  << ", resulting epsilon = " << out_eps
193  << std::endl;
194  QDP_abort(1);
195  }
196 
197  // Flop counting
198  {
199  unsigned long Ls = solution.size();
200  unsigned long Ndiag = (4*Ls+2)*Nc*Ns; /* This is my count with the blas / chiral proj ops */
201  unsigned long NdiagInv = (10*Ls-8)*Nc*Ns;
202  unsigned long Neo = Ls*(1320+24);
203  unsigned long N_mpsi = 2*Ndiag + 2*Neo + Ls*24;
204  unsigned long Nflops_c = (24*Ls + 2*N_mpsi) + (48*Ls); /* constant term */
205  unsigned long Nflops_s = (2*N_mpsi + Ls*(2*48+2*24)); /* slope */
206  unsigned long long Nflops_per_cbsite = Nflops_c + ( out_iter)*Nflops_s;
207  unsigned long long Nflops_total = Nflops_per_cbsite*(Layout::sitesOnNode()/2);
208 
209  /* Flop count for inverter */
210  FlopCounter flopcount;
211  flopcount.reset();
212  flopcount.addFlops(Nflops_total);
213  flopcount.report("CGDWFQpropT", swatch.getTimeInSeconds());
214  }
215 
216  swatch.reset();
217  swatch.start();
218  saveFermionSolver(&solution,res);
219  swatch.stop();
220 
221  QDPIO::cout << "Exporting Solution took: " << swatch.getTimeInSeconds()
222  << " seconds " << std::endl;
223 
224  deleteFermion(res);
225  deleteFermion(X0);
226  deleteFermion(eta);
227  }
228 
229  }; // Class
230  } // AVP Solver Interface
231 
232  /*! @} */ // end of group qprop
233 
234 } // Chroma namepace
235 
236 #endif
Primary include file for CHROMA library code.
virtual void deleteFermion(Fermion *ptr) const =0
virtual int init(const int lattice[5], void *(*allocator)(size_t size), void(*deallocator)(void *))=0
virtual Fermion * allocateFermion(void) const =0
virtual void saveFermionOperator(void *OuterFermion, Fermion *CGfermion) const =0
virtual void saveFermionSolver(void *OuterFermion, Fermion *CGfermion) const =0
int cgSolver(multi1d< LatticeFermion > &solution, double M5, double m_f, const multi1d< LatticeFermion > &rhs, const multi1d< LatticeFermion > &x0, double rsd, int max_iter, double &out_eps, int &out_iter) const
virtual void loadGauge(const void *OuterGauge_U, const void *OuterGauge_V)=0
virtual int cgInternal(Fermion *psi, double *out_eps, int *out_iter, double M, double m_f, const Fermion *x0, const Fermion *eta, double eps, int min_iter, int max_iter) const =0
virtual Fermion * loadFermionGuess(const void *OuterFermion) const =0
virtual Fermion * loadFermionRHS(const void *OuterFermion) const =0
int mu
Definition: cool.cc:24
void fermionWriterOperator(void *OuterFermion, void *env, const int latt_coord[5], int color, int spin, int reim, double val)
double fermionReaderGuess(const void *OuterFermion, void *env, const int latt_coord[5], int color, int spin, int reim)
double gaugeReader(const void *OuterGauge, void *env, const int latt_coord[4], int mu, int row, int col, int reim)
double fermionReaderRHS(const void *OuterFermion, void *env, const int latt_coord[5], int color, int spin, int reim)
void fermionWriterSolver(void *OuterFermion, void *env, const int latt_coord[5], int color, int spin, int reim, double val)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LinOpSysSolverMGProtoClover::T T
LatticeFermion eta
Definition: mespbg5p_w.cc:37
psi
Definition: pade_trln_w.cc:191
multi1d< LatticeColorMatrix > U