CHROMA
syssolver_mdagm_cg.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Solve a MdagM*psi=chi linear system by CG2
4  */
5 
6 #ifndef __syssolver_mdagm_cg_h__
7 #define __syssolver_mdagm_cg_h__
8 #include "chroma_config.h"
9 
10 #include "handle.h"
11 #include "syssolver.h"
12 #include "linearop.h"
13 #include "lmdagm.h"
17 
18 
19 namespace Chroma
20 {
21 
22  //! CG2 system solver namespace
23  namespace MdagMSysSolverCGEnv
24  {
25  //! Register the syssolver
26  bool registerAll();
27  }
28 
29 
30  //! Solve a CG2 system. Here, the operator is NOT assumed to be hermitian
31  /*! \ingroup invert
32  */
33  template<typename T>
35  {
36  public:
37  //! Constructor
38  /*!
39  * \param M_ Linear operator ( Read )
40  * \param invParam inverter parameters ( Read )
41  */
43  const SysSolverCGParams& invParam_) :
44  A(A_), invParam(invParam_)
45  {}
46 
47  //! Destructor is automatic
49 
50  //! Return the subset on which the operator acts
51  const Subset& subset() const {return A->subset();}
52 
53  //! Solver the linear system
54  /*!
55  * \param psi solution ( Modify )
56  * \param chi source ( Read )
57  * \return syssolver results
58  */
60  {
61  START_CODE();
62  StopWatch swatch;
63  swatch.reset(); swatch.start();
64 
65  SystemSolverResults_t res; // initialized by a constructor
66  res = InvCG2(*A, chi, psi, invParam.RsdCG, invParam.MaxCG);
67 
68 #ifdef CHROMA_DO_ONE_CG_RESTART
69  int n_count = res.n_count;
71  res.n_count += n_count;
72 #endif
73  { // Find true residuum
74  T tmp=zero;
75  T r=zero;
76  (*A)(tmp,psi, PLUS);
77  (*A)(r,tmp, MINUS);
78  r[A->subset()] -= chi;
79  res.resid = sqrt(norm2(r,A->subset()));
80  }
81 
82  swatch.stop();
83  QDPIO::cout << "CG_SOLVER: " << res.n_count
84  << " iterations. Rsd = " << res.resid
85  << " Relative Rsd = " << res.resid/sqrt(norm2(chi,A->subset())) << std::endl;
86 
87  double time = swatch.getTimeInSeconds();
88  QDPIO::cout << "CG_SOLVER_TIME: "<<time<< " sec" << std::endl;
89 
90 
91  END_CODE();
92 
93  return res;
94  }
95 
96 
97  //! Solve the linear system starting with a chrono guess
98  /*!
99  * \param psi solution (Write)
100  * \param chi source (Read)
101  * \param predictor a chronological predictor (Read)
102  * \return syssolver results
103  */
104 
106  AbsChronologicalPredictor4D<T>& predictor) const
107  {
108 
109  START_CODE();
110 
111  // This solver uses InvCG2, so A is just the matrix.
112  // I need to predict with A^\dagger A
113  {
115  predictor(psi, (*MdagM), chi);
116  }
117  // Do solve
118  SystemSolverResults_t res=(*this)(psi,chi);
119 
120  // Store result
121  predictor.newVector(psi);
122  END_CODE();
123  return res;
124  }
125 
126  private:
127  // Hide default constructor
129 
132  };
133 
134 
135 } // End namespace
136 
137 #endif
138 
Abstract interface for a Chronological Solution predictor.
virtual void newVector(const T &psi)=0
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 CG2 system. Here, the operator is NOT assumed to be hermitian.
SystemSolverResults_t operator()(T &psi, const T &chi, AbsChronologicalPredictor4D< T > &predictor) const
Solve the linear system starting with a chrono guess.
const Subset & subset() const
Return the subset on which the operator acts.
SystemSolverResults_t operator()(T &psi, const T &chi) const
Solver the linear system.
Handle< LinearOperator< T > > A
MdagMSysSolverCG(Handle< LinearOperator< T > > A_, const SysSolverCGParams &invParam_)
Constructor.
~MdagMSysSolverCG()
Destructor is automatic.
SystemSolver disambiguator.
SystemSolverResults_t InvCG2(const LinearOperator< LatticeFermionF > &M, const LatticeFermionF &chi, LatticeFermionF &psi, const Real &RsdCG, int MaxCG)
Conjugate-Gradient (CGNE) algorithm for a generic Linear Operator.
Definition: invcg2.cc:240
Class for counted reference semantics.
Conjugate-Gradient algorithm for a generic Linear Operator.
Linear Operators.
M^dag*M composition of a linear operator.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
int n_count
Definition: invbicg.cc:78
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
LinOpSysSolverMGProtoClover::T T
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
START_CODE()
Double zero
Definition: invbicg.cc:106
Params for CG inverter.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Linear system solvers.
Solve a CG1 system.
Disambiguator for MdagM system solvers.
Handle< LinearOperator< T > > MdagM