CHROMA
inv_rel_gmresr_sumr.cc
Go to the documentation of this file.
1 #include "chromabase.h"
4 
5 
6 namespace Chroma {
7 
8 template<typename T>
10  const Complex& zeta,
11  const Real& rho,
12  const LinearOperator<T>& UnprecU,
13  const T& b,
14  T& x,
15  const Real& epsilon,
16  const Real& epsilon_prec,
17  int MaxGMRESR,
18  int MaxGMRESRPrec,
19  int& n_count)
20 {
21  const Subset& s= UnprecU.subset();
22 
23  x[s] = zero;
24  T r;
25  r[s] = b;
26 
27  // Arrays of pointers for C and U, up to the maximum number
28  multi1d<T*> C(MaxGMRESR);
29  multi1d<T*> U(MaxGMRESR);
30  int C_size=0;
31 
32  // Get || r ||
33  Double norm_r = sqrt(norm2(r,s));
34  Double terminate = sqrt(norm2(b,s))*epsilon;
35 
36  int iter=0;
37 
38  int prec_count;
39  int prec_count_total = 0;
40 
41  // Do the loop
42  while( toBool( norm_r > terminate) && iter < MaxGMRESR ) {
43  // First we have to get a new u std::vector (in U)
44  T* u = new T;
45 
46 
47  (*u)[s] = zero;
48 
49 
50  // Now solve with the preconditioned system to preconditioned accuracy
51  // THis is done with CGNE
52  // solve A u = r
53  InvRelSUMR(PrecU, r, *u, zeta, rho, epsilon_prec*norm_r, MaxGMRESRPrec, prec_count);
54  prec_count_total += prec_count;
55 
56  // Get C
57  T* c = new T;
58  (*c)[s] = zero;
59 
60  // Now Apply Matrix A, to u, to precision epsilon || b ||/ || r ||
61  Real inner_tol = terminate / norm_r;
62 
63  // Apply zeta + rho U
64  // First apply U
65  UnprecU( *c, *u, PLUS, inner_tol);
66 
67  // Now scale by rho and shift by zeta
68  (*c)[s] *= rho;
69  (*c)[s] += zeta*(*u);
70 
71  // Now there is some orthogonalisation to do
72  for(int i =0; i < C_size; i++) {
73  Complex beta = innerProduct( *(C[i]), *(c), s );
74  (*c)[s] -= beta*(*(C[i]));
75  (*u)[s] -= beta*(*(U[i]));
76  }
77 
78  // Normalise c
79  Double norm_c = sqrt(norm2( *c, s));
80 
81  (*c)[s] /= norm_c;
82  (*u)[s] /= norm_c;
83 
84  // Hook vectors into the U, C arrays
85  C[C_size] = c;
86  U[C_size] = u;
87  C_size++;
88 
89  Complex alpha = innerProduct( *c, r, s);
90 
91  x[s] += alpha*(*u);
92  r[s] -= alpha*(*c);
93 
94  iter++;
95  norm_r = sqrt(norm2(r,s));
96  QDPIO::cout << "Inv Rel GMRESR: iter "<< iter <<" || r || = " << norm_r << std::endl;
97  }
98 
99  // Cleanup
100  for(int i=0; i < C_size; i++) {
101  delete C[i];
102  delete U[i];
103  }
104 
105  if( iter == MaxGMRESR ) {
106  QDPIO::cout << "Nonconvergence warning " << std::endl;
107  }
108 
109  n_count = iter;
110 }
111 
112 template<>
114  const Complex& zeta,
115  const Real& rho,
116  const LinearOperator<LatticeFermion>& UnprecU,
117  const LatticeFermion& b,
118  LatticeFermion& x,
119  const Real& epsilon,
120  const Real& epsilon_prec,
121  int MaxGMRESR,
122  int MaxGMRESRPrec,
123  int& n_count)
124 {
125  InvRelGMRESR_SUMR_a(PrecU, zeta, rho, UnprecU, b, x, epsilon, epsilon_prec, MaxGMRESR, MaxGMRESRPrec, n_count);
126 }
127 
128 } // 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.
Relaxed GMRESR algorithm of the Wuppertal Group.
Conjugate-Gradient algorithm for a generic Linear Operator.
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
static multi1d< LatticeColorMatrix > u
void InvRelGMRESR_SUMR(const LinearOperator< LatticeFermion > &PrecU, const Complex &zeta, const Real &rho, const LinearOperator< LatticeFermion > &UnprecU, const LatticeFermion &b, LatticeFermion &x, const Real &epsilon, const Real &epsilon_prec, int MaxGMRESR, int MaxGMRESRPrec, int &n_count)
int n_count
Definition: invbicg.cc:78
void InvRelSUMR(const LinearOperator< LatticeFermion > &U, const LatticeFermion &b, LatticeFermion &x, const Complex &zeta, const Real &rho, const Real &epsilon, int MaxSUMR, int &n_count)
Double c
Definition: invbicg.cc:108
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
@ PLUS
Definition: chromabase.h:45
Complex b
Definition: invbicg.cc:96
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
void InvRelGMRESR_SUMR_a(const LinearOperator< T > &PrecU, const Complex &zeta, const Real &rho, const LinearOperator< T > &UnprecU, const T &b, T &x, const Real &epsilon, const Real &epsilon_prec, int MaxGMRESR, int MaxGMRESRPrec, int &n_count)
FloatingPoint< double > Double
Definition: gtest.h:7351
multi1d< LatticeColorMatrix > U