QUDA  1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
inv_sd_quda.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 #include <cmath>
4 #include <iostream>
5 
6 #include <quda_internal.h>
7 #include <color_spinor_field.h>
8 #include <blas_quda.h>
9 #include <dslash_quda.h>
10 #include <invert_quda.h>
11 #include <util_quda.h>
12 
13 namespace quda {
14 
15  using namespace blas;
16 
18  Solver(param,profile), mat(mat), init(false)
19  {
20 
21  }
22 
25  if(init){
26  delete r;
27  delete Ar;
28  delete y;
29  }
31  }
32 
33 
35  {
37 
38  if(!init){
39  r = new cudaColorSpinorField(b);
40  Ar = new cudaColorSpinorField(b);
41  y = new cudaColorSpinorField(b);
42  init = true;
43  }
44 
45  double b2 = norm2(b);
46 
47  zero(*r), zero(x);
48  double r2 = xmyNorm(b,*r);
49  double alpha=0.;
50  double3 rAr;
51 
52  int k=0;
53  while(k < param.maxiter-1){
54 
55  mat(*Ar, *r, *y);
56  rAr = cDotProductNormA(*r, *Ar);
57  alpha = rAr.z/rAr.x;
58  axpy(alpha, *r, x);
59  axpy(-alpha, *Ar, *r);
60 
61  if(getVerbosity() >= QUDA_VERBOSE){
62  r2 = norm2(*r);
63  printfQuda("Steepest Descent: %d iterations, |r| = %e, |r|/|b| = %e\n", k, sqrt(r2), sqrt(r2/b2));
64  }
65 
66  ++k;
67  }
68 
69 
70  rAr = cDotProductNormA(*r, *Ar);
71  alpha = rAr.z/rAr.x;
72  axpy(alpha, *r, x);
73  if(getVerbosity() >= QUDA_VERBOSE){
74  axpy(-alpha, *Ar, *r);
75  r2 = norm2(*r);
76  printfQuda("Steepest Descent: %d iterations, |r| = %e, |r|/|b| = %e\n", k, sqrt(r2), sqrt(r2/b2));
77  ++k;
78  }
79 
81  // Compute the true residual
82  mat(*r, x, *y);
83  double true_r2 = xmyNorm(b,*r);
84  printfQuda("Steepest Descent: %d iterations, accumulated |r| = %e, true |r| = %e, |r|/|b| = %e\n", k, sqrt(r2), sqrt(true_r2), sqrt(true_r2/b2));
85  } // >= QUDA_DEBUG_VERBOSITY
86 
88  return;
89  }
90 
91 } // namespace quda
bool global_reduction
whether the solver acting as a preconditioner for another solver
Definition: invert_quda.h:243
cudaColorSpinorField * r
Definition: invert_quda.h:1039
double3 cDotProductNormA(ColorSpinorField &a, ColorSpinorField &b)
Definition: reduce_quda.cu:778
QudaVerbosity getVerbosity()
Definition: util_quda.cpp:21
void init()
Definition: blas_quda.cu:483
__host__ __device__ ValueType sqrt(ValueType x)
Definition: complex_quda.h:120
TimeProfile & profile
Definition: invert_quda.h:464
double xmyNorm(ColorSpinorField &x, ColorSpinorField &y)
Definition: blas_quda.h:75
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Definition: inv_sd_quda.cpp:34
double norm2(const CloverField &a, bool inverse=false)
QudaGaugeParam param
Definition: pack_test.cpp:17
bool is_preconditioner
verbosity to use for preconditioner
Definition: invert_quda.h:241
cudaColorSpinorField * Ar
Definition: invert_quda.h:1038
cudaColorSpinorField * y
Definition: invert_quda.h:1040
SD(DiracMatrix &mat, SolverParam &param, TimeProfile &profile)
Definition: inv_sd_quda.cpp:17
virtual ~SD()
Definition: inv_sd_quda.cpp:23
SolverParam & param
Definition: invert_quda.h:463
#define printfQuda(...)
Definition: util_quda.h:115
__device__ void axpy(real a, const real *x, Link &y)
void mat(void *out, void **link, void *in, int dagger_bit, int mu, QudaPrecision sPrecision, QudaPrecision gPrecision)
const DiracMatrix & mat
Definition: invert_quda.h:1037
__device__ __host__ void zero(vector_type< scalar, n > &v)
Definition: cub_helper.cuh:54
void commGlobalReductionSet(bool global_reduce)