QUDA  v1.1.0
A library for QCD on GPUs
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(mat, mat, mat, mat, param, profile),
19  init(false)
20  {
21 
22  }
23 
26  if(init){
27  delete r;
28  delete Ar;
29  delete y;
30  }
32  }
33 
34 
36  {
38 
39  if(!init){
40  r = new cudaColorSpinorField(b);
41  Ar = new cudaColorSpinorField(b);
42  y = new cudaColorSpinorField(b);
43  init = true;
44  }
45 
46  double b2 = norm2(b);
47 
48  zero(*r), zero(x);
49  double r2 = xmyNorm(b,*r);
50  double alpha=0.;
51  double3 rAr;
52 
53  int k=0;
54  while(k < param.maxiter-1){
55 
56  mat(*Ar, *r, *y);
57  rAr = cDotProductNormA(*r, *Ar);
58  alpha = rAr.z/rAr.x;
59  axpy(alpha, *r, x);
60  axpy(-alpha, *Ar, *r);
61 
62  if(getVerbosity() >= QUDA_VERBOSE){
63  r2 = norm2(*r);
64  printfQuda("Steepest Descent: %d iterations, |r| = %e, |r|/|b| = %e\n", k, sqrt(r2), sqrt(r2/b2));
65  }
66 
67  ++k;
68  }
69 
70 
71  rAr = cDotProductNormA(*r, *Ar);
72  alpha = rAr.z/rAr.x;
73  axpy(alpha, *r, x);
74  if(getVerbosity() >= QUDA_VERBOSE){
75  axpy(-alpha, *Ar, *r);
76  r2 = norm2(*r);
77  printfQuda("Steepest Descent: %d iterations, |r| = %e, |r|/|b| = %e\n", k, sqrt(r2), sqrt(r2/b2));
78  ++k;
79  }
80 
82  // Compute the true residual
83  mat(*r, x, *y);
84  double true_r2 = xmyNorm(b,*r);
85  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));
86  } // >= QUDA_DEBUG_VERBOSITY
87 
89  return;
90  }
91 
92 } // namespace quda
virtual ~SD()
Definition: inv_sd_quda.cpp:24
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Definition: inv_sd_quda.cpp:35
SD(const DiracMatrix &mat, SolverParam &param, TimeProfile &profile)
Definition: inv_sd_quda.cpp:17
TimeProfile & profile
Definition: invert_quda.h:471
const DiracMatrix & mat
Definition: invert_quda.h:465
SolverParam & param
Definition: invert_quda.h:470
void commGlobalReductionSet(bool global_reduce)
void mat(void *out, void **link, void *in, int dagger_bit, int mu, QudaPrecision sPrecision, QudaPrecision gPrecision)
@ QUDA_DEBUG_VERBOSE
Definition: enum_quda.h:268
@ QUDA_VERBOSE
Definition: enum_quda.h:267
void init()
double xmyNorm(ColorSpinorField &x, ColorSpinorField &y)
Definition: blas_quda.h:79
void axpy(double a, ColorSpinorField &x, ColorSpinorField &y)
Definition: blas_quda.h:43
double3 cDotProductNormA(ColorSpinorField &a, ColorSpinorField &b)
double norm2(const CloverField &a, bool inverse=false)
__device__ __host__ void zero(double &a)
Definition: float_vector.h:318
__host__ __device__ ValueType sqrt(ValueType x)
Definition: complex_quda.h:120
@ QUDA_PROFILE_FREE
Definition: timer.h:111
QudaGaugeParam param
Definition: pack_test.cpp:18
bool is_preconditioner
verbosity to use for preconditioner
Definition: invert_quda.h:238
bool global_reduction
whether the solver acting as a preconditioner for another solver
Definition: invert_quda.h:240
#define printfQuda(...)
Definition: util_quda.h:114
QudaVerbosity getVerbosity()
Definition: util_quda.cpp:21