CHROMA
inv_rel_gmresr_cg.cc
Go to the documentation of this file.
1 #include "chromabase.h"
4 
5 namespace Chroma {
6 
7 
8 template<typename T>
10  const LinearOperator<T>& UnprecMM,
11  const T& b,
12  T& x,
13  const Real& epsilon,
14  const Real& epsilon_prec,
15  int MaxGMRESR,
16  int MaxGMRESRPrec,
17  int& n_count)
18 {
19  const Subset& s= UnprecMM.subset();
20 
21  x[s] = zero;
22  T r;
23  r[s] = b;
24 
25  // Arrays of pointers for C and U, up to the maximum number
26  multi1d<T*> C(MaxGMRESR);
27  multi1d<T*> U(MaxGMRESR);
28  int C_size=0;
29 
30  // Get || r ||
31  Double norm_r = sqrt(norm2(r,s));
32  Double terminate = sqrt(norm2(b,s))*epsilon;
33 
34  int iter=0;
35 
36  int prec_count;
37 
38  // Do the loop
39  while( toBool( norm_r > terminate) && iter < MaxGMRESR ) {
40  // First we have to get a new u std::vector (in U)
41  T* u = new T;
42  (*u)[s] = zero;
43 
44 
45  // Now solve with the preconditioned system to preconditioned accuracy
46  // THis is done with CG
47  // solve MM u = r
48  InvRelCG1(PrecMM, r, *u, epsilon_prec, MaxGMRESRPrec, prec_count);
49 
50  // Get C
51  T* c = new T;
52  (*c)[s] = zero;
53 
54  // Now Apply Matrix A, to u, to precision epsilon || b ||/ || r ||
55  Real inner_tol = terminate / norm_r;
56 
57  // Apply zeta + rho U
58  // First apply U
59  UnprecMM( *c, *u, PLUS, inner_tol);
60 
61 
62  // Now there is some orthogonalisation to do
63  for(int i =0; i < C_size; i++) {
64  Complex beta = innerProduct( *(C[i]), *(c), s );
65  (*c)[s] -= beta*(*(C[i]));
66  (*u)[s] -= beta*(*(U[i]));
67  }
68 
69  // Normalise c
70  Double norm_c = sqrt(norm2( *c, s));
71 
72  (*c)[s] /= norm_c;
73  (*u)[s] /= norm_c;
74 
75  // Hook vectors into the U, C arrays
76  C[C_size] = c;
77  U[C_size] = u;
78  C_size++;
79 
80  Complex alpha = innerProduct( *c, r, s);
81 
82  x[s] += alpha*(*u);
83  r[s] -= alpha*(*c);
84 
85  iter++;
86  norm_r = sqrt(norm2(r,s));
87  QDPIO::cout << "Inv Rel GMRESR: iter "<< iter <<" || r || = " << norm_r << std::endl;
88  }
89 
90  // Cleanup
91  for(int i=0; i < C_size; i++) {
92  delete C[i];
93  delete U[i];
94  }
95 
96  if( iter == MaxGMRESR ) {
97  QDPIO::cout << "Nonconvergence warning " << std::endl;
98  }
99 
100  n_count = iter;
101 }
102 
103 template<>
105  const LinearOperator<LatticeFermion>& UnprecMM,
106  const LatticeFermion& b,
107  LatticeFermion& x,
108  const Real& epsilon,
109  const Real& epsilon_prec,
110  int MaxGMRESR,
111  int MaxGMRESRPrec,
112  int& n_count)
113 {
114  InvRelGMRESR_CG_a(PrecMM, UnprecMM, b, x, epsilon, epsilon_prec, MaxGMRESR, MaxGMRESRPrec, n_count);
115 }
116 
117 } // end namespace Chroma
Primary include file for CHROMA library code.
Linear Operator.
Definition: linearop.h:27
virtual const Subset & subset() const =0
Return the subset on which the operator acts.
void InvRelCG1(const LinearOperator< LatticeFermion > &A, const LatticeFermion &chi, LatticeFermion &psi, const Real &RsdCG, int MaxCG, int &n_count)
Conjugate-Gradient (CGNE) algorithm for a generic Linear Operator.
Definition: inv_rel_cg1.cc:144
Conjugate-Gradient algorithm for a generic Linear Operator.
Relaxed GMRESR algorithm of the Wuppertal Group.
int x
Definition: meslate.cc:34
SpinMatrix C()
C = Gamma(10)
Definition: barspinmat_w.cc:29
int epsilon(int i, int j, int k)
BinaryReturn< C1, C2, FnInnerProduct >::Type_t innerProduct(const QDPSubType< T1, C1 > &s1, const QDPType< T2, C2 > &s2)
static const LatticeInteger & beta(const int dim)
Definition: stag_phases_s.h:47
static const LatticeInteger & alpha(const int dim)
Definition: stag_phases_s.h:43
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
void InvRelGMRESR_CG_a(const LinearOperator< T > &PrecMM, const LinearOperator< T > &UnprecMM, const T &b, T &x, const Real &epsilon, const Real &epsilon_prec, int MaxGMRESR, int MaxGMRESRPrec, int &n_count)
static multi1d< LatticeColorMatrix > u
int n_count
Definition: invbicg.cc:78
Double c
Definition: invbicg.cc:108
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
@ PLUS
Definition: chromabase.h:45
void InvRelGMRESR_CG(const LinearOperator< LatticeFermion > &PrecMM, const LinearOperator< LatticeFermion > &UnprecMM, const LatticeFermion &b, LatticeFermion &x, const Real &epsilon, const Real &epsilon_prec, int MaxGMRESR, int MaxGMRESRPrec, int &n_count)
Complex b
Definition: invbicg.cc:96
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
FloatingPoint< double > Double
Definition: gtest.h:7351
multi1d< LatticeColorMatrix > U