CHROMA
invcg2.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Conjugate-Gradient algorithm for a generic Linear Operator
4  */
5 
6 #ifndef __invcg2__
7 #define __invcg2__
8 
9 #include "linearop.h"
10 #include "syssolver.h"
11 
12 namespace Chroma
13 {
14 
15  //! Conjugate-Gradient (CGNE) algorithm for a generic Linear Operator
16  /*! \ingroup invert
17  * This subroutine uses the Conjugate Gradient (CG) algorithm to find
18  * the solution of the set of linear equations
19  *
20  * Chi = A . Psi
21  *
22  * where A = M^dag . M
23  *
24  * Algorithm:
25 
26  * Psi[0] := initial guess; Linear interpolation (argument)
27  * r[0] := Chi - M^dag . M . Psi[0] ; Initial residual
28  * p[1] := r[0] ; Initial direction
29  * IF |r[0]| <= RsdCG |Chi| THEN RETURN; Converged?
30  * FOR k FROM 1 TO MaxCG DO CG iterations
31  * a[k] := |r[k-1]|**2 / <Mp[k],Mp[k]> ;
32  * Psi[k] += a[k] p[k] ; New solution std::vector
33  * r[k] -= a[k] M^dag . M . p[k] ; New residual
34  * IF |r[k]| <= RsdCG |Chi| THEN RETURN; Converged?
35  * b[k+1] := |r[k]|**2 / |r[k-1]|**2 ;
36  * p[k+1] := r[k] + b[k+1] p[k]; New direction
37  *
38  * Arguments:
39  *
40  * \param M Linear Operator (Read)
41  * \param chi Source (Read)
42  * \param psi Solution (Modify)
43  * \param RsdCG CG residual accuracy (Read)
44  * \param MaxCG Maximum CG iterations (Read)
45  * \param n_count Number of CG iteration (Write)
46  *
47  * Local Variables:
48  *
49  * p Direction std::vector
50  * r Residual std::vector
51  * cp | r[k] |**2
52  * c | r[k-1] |**2
53  * k CG iteration counter
54  * a a[k]
55  * b b[k+1]
56  * d < p[k], A.p[k] >
57  * Mp Temporary for M.p
58  *
59  * Subroutines:
60  * +
61  * A Apply matrix M or M to std::vector
62  *
63  * Operations:
64  *
65  * 2 A + 2 Nc Ns + N_Count ( 2 A + 10 Nc Ns )
66  *
67  * @{
68  */
69 
70  // Single precision
71  SystemSolverResults_t
72  InvCG2(const LinearOperator<LatticeFermionF>& M,
73  const LatticeFermionF& chi,
74  LatticeFermionF& psi,
75  const Real& RsdCG,
76  int MaxCG);
77 
78  // Double precision
79  SystemSolverResults_t
80  InvCG2(const LinearOperator<LatticeFermionD>& M,
81  const LatticeFermionD& chi,
82  LatticeFermionD& psi,
83  const Real& RsdCG,
84  int MaxCG);
85 
86  // Single precision
87  SystemSolverResults_t
88  InvCG2(const LinearOperator<LatticeStaggeredFermionF>& M,
89  const LatticeStaggeredFermionF& chi,
90  LatticeStaggeredFermionF& psi,
91  const Real& RsdCG,
92  int MaxCG);
93 
94  // Double precision
95  SystemSolverResults_t
96  InvCG2(const LinearOperator<LatticeStaggeredFermionD>& M,
97  const LatticeStaggeredFermionD& chi,
98  LatticeStaggeredFermionD& psi,
99  const Real& RsdCG,
100  int MaxCG);
101 
102  /*! @} */ // end of group invert
103 
104 } // end namespace Chroma
105 
106 #endif
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
Linear Operators.
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
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > int MaxCG
Definition: pbg5p_w.cc:32
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
Linear system solvers.