CHROMA
multi_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 __multi_syssolver_mdagm_cg_h__
7 #define __multi_syssolver_mdagm_cg_h__
8 
9 #include "handle.h"
10 #include "syssolver.h"
11 #include "linearop.h"
16 #include "init/chroma_init.h"
17 
18 namespace Chroma
19 {
20 
21  //! CG2 system solver namespace
22  namespace MdagMMultiSysSolverCGEnv
23  {
24  //! Register the syssolver
25  bool registerAll();
26  }
27 
28 
29  //! Solve a CG2 system. Here, the operator is NOT assumed to be hermitian
30  /*! \ingroup invert
31  */
32  template<typename T>
34  {
35  public:
36  //! Constructor
37  /*!
38  * \param M_ Linear operator ( Read )
39  * \param invParam inverter parameters ( Read )
40  */
42  const MultiSysSolverCGParams& invParam_) :
43  A(A_), invParam(invParam_)
44  {}
45 
46  //! Destructor is automatic
48 
49  //! Return the subset on which the operator acts
50  const Subset& subset() const {return A->subset();}
51 
52  //! Solver the linear system
53  /*!
54  * \param psi solution ( Modify )
55  * \param chi source ( Read )
56  * \return syssolver results
57  */
58  SystemSolverResults_t operator() (multi1d<T>& psi, const multi1d<Real>& shifts, const T& chi) const
59  {
60  START_CODE();
61 
62  multi1d<Real> RsdCG(shifts.size());
63  if (invParam.RsdCG.size() == 1)
64  {
65  RsdCG = invParam.RsdCG[0];
66  }
67  else if (invParam.RsdCG.size() == RsdCG.size())
68  {
70  }
71  else
72  {
73  QDPIO::cerr << "MdagMMultiSysSolverCG: shifts incompatible" << std::endl;
74  QDP_abort(1);
75  }
76 
78  MInvCG2(*A, chi, psi, shifts, RsdCG, invParam.MaxCG, res.n_count);
79 #if 0
80  XMLFileWriter& log = Chroma::getXMLLogInstance();
81  push(log, "MultiCG");
82  write(log, "shifts", shifts);
83  write(log, "RsdCG", RsdCG);
84  write(log, "n_count", res.n_count);
85  Double chinorm=norm2(chi, A->subset());
86  multi1d<Double> r_rel(shifts.size());
87 
88  for(int i=0; i < shifts.size(); i++) {
89  T tmp1,tmp2;
90  (*A)(tmp1, psi[i], PLUS);
91  (*A)(tmp2, tmp1, MINUS); // tmp2 = A^\dagger A psi
92  tmp2[ A->subset() ] += shifts[i]* psi[i]; // tmp2 = ( A^\dagger A + shift_i ) psi
93  T r;
94  r[ A->subset() ] = chi - tmp2;
95  r_rel[i] = sqrt(norm2(r, A->subset())/chinorm );
96  }
97  write(log, "ResidRel", r_rel);
98  pop(log);
99 #endif
100  END_CODE();
101 
102  return res;
103  }
104 
105 
106  private:
107  // Hide default constructor
109 
112  };
113 
114 
115 } // End namespace
116 
117 #endif
118 
Initialization of Chroma.
Class for counted reference semantics.
Definition: handle.h:33
Linear Operator.
Definition: linearop.h:27
Solve a CG2 system. Here, the operator is NOT assumed to be hermitian.
Handle< LinearOperator< T > > A
const Subset & subset() const
Return the subset on which the operator acts.
MdagMMultiSysSolverCG(Handle< LinearOperator< T > > A_, const MultiSysSolverCGParams &invParam_)
Constructor.
~MdagMMultiSysSolverCG()
Destructor is automatic.
SystemSolverResults_t operator()(multi1d< T > &psi, const multi1d< Real > &shifts, const T &chi) const
Solver the linear system.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void MInvCG2(const LinearOperator< LatticeFermionF > &M, const LatticeFermionF &chi, multi1d< LatticeFermionF > &psi, const multi1d< RealF > &shifts, const multi1d< RealF > &RsdCG, int MaxCG, int &n_count)
Definition: minvcg2.cc:376
Class for counted reference semantics.
Linear Operators.
Double tmp2
Definition: mesq.cc:30
Multishift Conjugate-Gradient algorithm for a Linear Operator.
Multishift Conjugate-Gradient algorithm for a Linear Operator.
Params of CG inverter.
Disambiguator for multi-shift MdagM system solvers.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > & RsdCG
Definition: pbg5p_w.cc:30
XMLFileWriter & getXMLLogInstance()
Get xml log instance.
Definition: chroma_init.cc:378
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
pop(xml_out)
START_CODE()
FloatingPoint< double > Double
Definition: gtest.h:7351
SystemSolver disambiguator.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Linear system solvers.