CHROMA
syssolver_mdagm_rel_cg_clover.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Solve a MdagM*psi=chi linear system by BiCGStab
4  */
5 
6 #ifndef __syssolver_mdagm_rel_cg_multiprec_h__
7 #define __syssolver_mdagm_rel_cg_multiprec_h__
8 #include "chroma_config.h"
9 
10 #include "handle.h"
11 #include "state.h"
12 #include "syssolver.h"
13 #include "linearop.h"
14 #include "lmdagm.h"
22 
23 #include <string>
24 
25 namespace Chroma
26 {
27 
28  //! Richardson system solver namespace
29  namespace MdagMSysSolverReliableCGCloverEnv
30  {
31  //! Register the syssolver
32  bool registerAll();
33  }
34 
35 
36 
37  //! Solve a system using Richardson iteration.
38  /*! \ingroup invert
39  *** WARNING THIS SOLVER WORKS FOR CLOVER FERMIONS ONLY ***
40  */
41 
42  class MdagMSysSolverReliableCGClover : public MdagMSystemSolver<LatticeFermion>
43  {
44  public:
45  typedef LatticeFermion T;
46  typedef LatticeColorMatrix U;
47  typedef multi1d<LatticeColorMatrix> Q;
48 
49  typedef LatticeFermionF TF;
50  typedef LatticeColorMatrixF UF;
51  typedef multi1d<LatticeColorMatrixF> QF;
52 
53  typedef LatticeFermionD TD;
54  typedef LatticeColorMatrixD UD;
55  typedef multi1d<LatticeColorMatrixD> QD;
56 
57  //! Constructor
58  /*!
59  * \param M_ Linear operator ( Read )
60  * \param invParam inverter parameters ( Read )
61  */
63  Handle< FermState<T,Q,Q> > state_,
64  const SysSolverReliableCGCloverParams& invParam_) :
65  A(A_), invParam(invParam_)
66  {
67 
68  // Get the Links out of the state and convertto single.
69  QF links_single; links_single.resize(Nd);
70  QD links_double; links_double.resize(Nd);
71 
72  const Q& links = state_->getLinks();
73  for(int mu=0; mu < Nd; mu++) {
74  links_single[mu] = links[mu];
75  links_double[mu] = links[mu];
76  }
77 
78 
79  // Links single hold the possibly stouted links
80  // with gaugeBCs applied...
81  // Now I need to create a single prec state...
82  fstate_single = new PeriodicFermState<TF,QF,QF>(links_single);
83  fstate_double = new PeriodicFermState<TD,QD,QD>(links_double);
84 
85  // Make single precision M
88 
89 
90 
91  }
92 
93  //! Destructor is automatic
95 
96  //! Return the subset on which the operator acts
97  const Subset& subset() const {return A->subset();}
98 
99  //! Solver the linear system
100  /*!
101  * \param psi solution ( Modify )
102  * \param chi source ( Read )
103  * \return syssolver results
104  */
106  {
108 
109  START_CODE();
110  StopWatch swatch;
111  swatch.start();
112  const Subset& s = (*M_double).subset();
113  // T MdagChi;
114 
115  // This is a CGNE. So create new RHS
116  // (*A)(MdagChi, chi, MINUS);
117  // Handle< LinearOperator<T> > MM(new MdagMLinOp<T>(A));
118 
119  TD psi_d; psi_d[s] = psi;
120  TD chi_d; chi_d[s] = chi;
121 
122 
123  // Two Step CG:
124  // Step 1: M^\dagger Y = chi;
125 
126  res=InvCGReliable(*M_double,
127  *M_single,
128  chi_d,
129  psi_d,
131  invParam.Delta,
132  invParam.MaxIter);
133  psi = psi_d;
134 
135  {
136  T r;
137  r[A->subset()]=chi;
138  T tmp,tmp2;
139  // M^\dag M
140  (*A)(tmp, psi, PLUS);
141  (*A)(tmp2,tmp, MINUS);
142  r[A->subset()] -= tmp2;
143  res.resid = sqrt(norm2(r, A->subset()));
144  }
145  QDPIO::cout << "RELIABLE_CG_SOLVER: " << res.n_count << " iterations. Rsd = " << res.resid << " Relative Rsd = " << res.resid/sqrt(norm2(chi,A->subset())) << std::endl;
146 
147 
148  END_CODE();
149  return res;
150  }
151 
152 
153 
154 
155  //! Solve the linear system starting with a chrono guess
156  /*!
157  * \param psi solution (Write)
158  * \param chi source (Read)
159  * \param predictor a chronological predictor (Read)
160  * \return syssolver results
161  */
162 
164  AbsChronologicalPredictor4D<T>& predictor) const
165  {
166 
167  START_CODE();
168 
169  // This solver uses InvCG2, so A is just the matrix.
170  // I need to predict with A^\dagger A
171  {
173  predictor(psi, (*MdagM), chi);
174  }
175  // Do solve
176  SystemSolverResults_t res=(*this)(psi,chi);
177 
178  // Store result
179  predictor.newVector(psi);
180  END_CODE();
181  return res;
182  }
183 
184 
185  private:
186  // Hide default constructor
190 
191  // Created and initialized here.
196  };
197 
198 
199 } // End namespace
200 
201 #endif
202 
Abstract interface for a Chronological Solution predictor.
virtual void newVector(const T &psi)=0
Even-odd preconditioned Clover-Dirac operator.
Even-odd preconditioned Clover-Dirac operator.
Support class for fermion actions and linear operators.
Definition: state.h:94
Class for counted reference semantics.
Definition: handle.h:33
Linear Operator.
Definition: linearop.h:27
M^dag.M linear operator.
Definition: lmdagm.h:22
Solve a system using Richardson iteration.
MdagMSysSolverReliableCGClover(Handle< LinearOperator< T > > A_, Handle< FermState< T, Q, Q > > state_, const SysSolverReliableCGCloverParams &invParam_)
Constructor.
Handle< FermState< TF, QF, QF > > fstate_single
SystemSolverResults_t operator()(T &psi, const T &chi) const
Solver the linear system.
const Subset & subset() const
Return the subset on which the operator acts.
const SysSolverReliableCGCloverParams invParam
SystemSolverResults_t operator()(T &psi, const T &chi, AbsChronologicalPredictor4D< T > &predictor) const
Solve the linear system starting with a chrono guess.
Handle< FermState< TD, QD, QD > > fstate_double
SystemSolver disambiguator.
Periodic version of FermState.
Parameters for Clover fermion action.
int mu
Definition: cool.cc:24
Even-odd preconditioned Clover fermion linear operator.
SystemSolverResults_t InvCGReliable(const LinearOperator< LatticeFermionF > &A, const LatticeFermionF &chi, LatticeFermionF &psi, const Real &RsdCG, const Real &Delta, int MaxCG)
Bi-CG stabilized.
Definition: reliable_cg.cc:193
Class for counted reference semantics.
Linear Operators.
M^dag*M composition of a linear operator.
Nd
Definition: meslate.cc:74
Double tmp2
Definition: mesq.cc:30
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
START_CODE()
multi1d< LatticeFermion > s(Ncb)
Periodic ferm state and a creator.
BiCGStab Solver with reliable updates.
Support class for fermion actions and linear operators.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Linear system solvers.
Disambiguator for MdagM system solvers.
Handle< LinearOperator< T > > MdagM
Factory for producing system solvers for MdagM*psi = chi.