CHROMA
syssolver_linop_cg_array.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Solve a M*psi=chi linear system by CG2
4  */
5 
6 #ifndef __syssolver_linop_cg_array_h__
7 #define __syssolver_linop_cg_array_h__
8 
9 #include "chroma_config.h"
10 #include "handle.h"
11 #include "syssolver.h"
12 #include "linearop.h"
16 
17 
18 namespace Chroma
19 {
20 
21  //! CG1 system solver namespace
22  namespace LinOpSysSolverCGArrayEnv
23  {
24  //! Register the syssolver
25  bool registerAll();
26  }
27 
28 
29  //! Solve a M*psi=chi linear system by CG2
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 SysSolverCGParams& invParam_) :
43  A(A_), invParam(invParam_)
44  {}
45 
46  //! Destructor is automatic
48 
49  //! Expected length of array index
50  int size() const {return A->size();}
51 
52  //! Return the subset on which the operator acts
53  const Subset& subset() const {return A->subset();}
54 
55  //! Solver the linear system
56  /*!
57  * \param psi solution ( Modify )
58  * \param chi source ( Read )
59  * \return syssolver results
60  */
61  SystemSolverResults_t operator() (multi1d<T>& psi, const multi1d<T>& chi) const
62  {
63  START_CODE();
64 
65  multi1d<T> chi_tmp(size());
66  (*A)(chi_tmp, chi, MINUS);
67 
68  SystemSolverResults_t res; // initialized by a constructor
69  {
70 
71  res = InvCG2(*A, chi_tmp, psi, invParam.RsdCG, invParam.MaxCG);
72 
73 
74 #ifdef CHROMA_DO_ONE_CG_RESTART
75 
76  int n_count = res.n_count;
77 
78  // One automatic restart (if enabled)
80  res.n_count += n_count;
81 #endif
82 
83  }
84 
85  END_CODE();
86 
87  return res;
88  }
89 
90 
91  private:
92  // Hide default constructor
94 
97  };
98 
99 
100 } // End namespace
101 
102 #endif
103 
Class for counted reference semantics.
Definition: handle.h:33
Solve a M*psi=chi linear system by CG2.
LinOpSysSolverCGArray(Handle< LinearOperatorArray< T > > A_, const SysSolverCGParams &invParam_)
Constructor.
SystemSolverResults_t operator()(multi1d< T > &psi, const multi1d< T > &chi) const
Solver the linear system.
int size() const
Expected length of array index.
~LinOpSysSolverCGArray()
Destructor is automatic.
Handle< LinearOperatorArray< T > > A
const Subset & subset() const
Return the subset on which the operator acts.
SystemSolver disambiguator.
Linear Operator to arrays.
Definition: linearop.h:61
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.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
int n_count
Definition: invbicg.cc:78
@ MINUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
START_CODE()
Params for CG inverter.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Linear system solvers.
Solve a CG1 system.
Disambiguator for LinOp system solvers.