CHROMA
syssolver_linop_bicgstab.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Solve a M*psi=chi linear system by BICGSTAB
4  */
5 
6 #ifndef __syssolver_linop_bicgstab_h__
7 #define __syssolver_linop_bicgstab_h__
8 
9 #include "chroma_config.h"
10 #include "handle.h"
11 #include "syssolver.h"
12 #include "linearop.h"
16 
17 namespace Chroma
18 {
19 
20  //! BICGSTAB system solver namespace
21  namespace LinOpSysSolverBiCGStabEnv
22  {
23  //! Register the syssolver
24  bool registerAll();
25  }
26 
27 
28  //! Solve a M*psi=chi linear system by BICGSTAB
29  /*! \ingroup invert
30  */
31  template<typename T>
33  {
34  public:
35  //! Constructor
36  /*!
37  * \param A_ Linear operator ( Read )
38  * \param invParam inverter parameters ( Read )
39  */
41  const SysSolverBiCGStabParams& invParam_) :
42  A(A_), invParam(invParam_)
43  {}
44 
45  //! Destructor is automatic
47 
48  //! Return the subset on which the operator acts
49  const Subset& subset() const {return A->subset();}
50 
51  //! Solver the linear system
52  /*!
53  * \param psi solution ( Modify )
54  * \param chi source ( Read )
55  * \return syssolver results
56  */
58  {
59  START_CODE();
60  StopWatch swatch;
61 
62  SystemSolverResults_t res; // initialized by a constructor
63  swatch.start();
64 
65  // For now solve with PLUS until we add a way to explicitly
66  // ask for MINUS
67  res = InvBiCGStab(*A,
68  chi,
69  psi,
72  PLUS);
73 
74  swatch.stop();
75  double time = swatch.getTimeInSeconds();
76  {
77  T r;
78  r[A->subset()]=chi;
79  T tmp;
80  (*A)(tmp, psi, PLUS);
81  r[A->subset()] -= tmp;
82  res.resid = sqrt(norm2(r, A->subset()));
83  }
84  QDPIO::cout << "BICGSTAB_SOLVER: " << res.n_count << " iterations. Rsd = " << res.resid << " Relative Rsd = " << res.resid/sqrt(norm2(chi,A->subset())) << std::endl;
85  QDPIO::cout << "BICGSTAB_SOLVER_TIME: "<<time<< " sec" << std::endl;
86 
87 
88  END_CODE();
89 
90  return res;
91  }
92 
93 
94  private:
95  // Hide default constructor
97 
100  };
101 
102 } // End namespace
103 
104 #endif
105 
Class for counted reference semantics.
Definition: handle.h:33
Solve a M*psi=chi linear system by BICGSTAB.
~LinOpSysSolverBiCGStab()
Destructor is automatic.
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.
LinOpSysSolverBiCGStab(Handle< LinearOperator< T > > A_, const SysSolverBiCGStabParams &invParam_)
Constructor.
Handle< LinearOperator< T > > A
SystemSolver disambiguator.
Linear Operator.
Definition: linearop.h:27
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
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
LinOpSysSolverMGProtoClover::T T
SystemSolverResults_t InvBiCGStab(const LinearOperator< LatticeFermionF > &A, const LatticeFermionF &chi, LatticeFermionF &psi, const Real &RsdBiCGStab, int MaxBiCGStab, enum PlusMinus isign)
Definition: invbicgstab.cc:222
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
START_CODE()
Params for BiCGStab inverter.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Linear system solvers.
Solve a BICGSTAB system.
Disambiguator for LinOp system solvers.