QUDA  v0.7.0
A library for QCD on GPUs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
inv_sd_quda.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <cstdlib>
3 #include <cmath>
4 
5 #include <quda_internal.h>
6 #include <color_spinor_field.h>
7 #include <blas_quda.h>
8 #include <dslash_quda.h>
9 #include <invert_quda.h>
10 #include <util_quda.h>
11 #include <sys/time.h>
12 
13 #include <face_quda.h>
14 #include <iostream>
15 
16 
17 namespace quda {
18 
20  Solver(param,profile), mat(mat), init(false)
21  {
22 
23  }
24 
27  if(init){
28  delete r;
29  delete Ar;
30  delete y;
31  }
33  }
34 
35 
37  {
38 
39 
40  globalReduce = false;
41  if(!init){
42  r = new cudaColorSpinorField(b);
43  Ar = new cudaColorSpinorField(b);
44  y = new cudaColorSpinorField(b);
45  init = true;
46  }
47 
48  double b2 = norm2(b);
49 
50  zeroCuda(*r), zeroCuda(x);
51  double r2 = xmyNormCuda(b,*r);
52  double alpha=0.;
53  double2 rAr;
54 
55  int k=0;
56  while(k < param.maxiter-1){
57 
58  mat(*Ar, *r, *y);
59  rAr = reDotProductNormACuda(*r, *Ar);
60  alpha = rAr.y/rAr.x;
61  axpyCuda(alpha, *r, x);
62  axpyCuda(-alpha, *Ar, *r);
63 
64  if(getVerbosity() >= QUDA_VERBOSE){
65  r2 = norm2(*r);
66  printfQuda("Steepest Descent: %d iterations, |r| = %e, |r|/|b| = %e\n", k, sqrt(r2), sqrt(r2/b2));
67  }
68 
69  ++k;
70  }
71 
72 
73  rAr = reDotProductNormACuda(*r, *Ar);
74  alpha = rAr.y/rAr.x;
75  axpyCuda(alpha, *r, x);
76  if(getVerbosity() >= QUDA_VERBOSE){
77  axpyCuda(-alpha, *Ar, *r);
78  r2 = norm2(*r);
79  printfQuda("Steepest Descent: %d iterations, |r| = %e, |r|/|b| = %e\n", k, sqrt(r2), sqrt(r2/b2));
80  ++k;
81  }
82 
84  // Compute the true residual
85  mat(*r, x, *y);
86  double true_r2 = xmyNormCuda(b,*r);
87  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));
88  } // >= QUDA_DEBUG_VERBOSITY
89  globalReduce = true;
90  return;
91  }
92 
93 } // namespace quda
QudaVerbosity getVerbosity()
Definition: util_quda.cpp:20
__host__ __device__ ValueType sqrt(ValueType x)
Definition: complex_quda.h:105
void mat(void *out, void **fatlink, void **longlink, void *in, double kappa, int dagger_bit, QudaPrecision sPrecision, QudaPrecision gPrecision)
TimeProfile & profile
Definition: invert_quda.h:224
QudaInverterType inv_type_precondition
Definition: invert_quda.h:24
double2 reDotProductNormACuda(cudaColorSpinorField &a, cudaColorSpinorField &b)
Definition: reduce_quda.cu:297
QudaGaugeParam param
Definition: pack_test.cpp:17
void operator()(cudaColorSpinorField &out, cudaColorSpinorField &in)
Definition: inv_sd_quda.cpp:36
void axpyCuda(const double &a, cudaColorSpinorField &x, cudaColorSpinorField &y)
Definition: blas_quda.cu:115
int x[4]
SD(DiracMatrix &mat, SolverParam &param, TimeProfile &profile)
Definition: inv_sd_quda.cpp:19
virtual ~SD()
Definition: inv_sd_quda.cpp:25
SolverParam & param
Definition: invert_quda.h:223
void Stop(QudaProfileType idx)
#define printfQuda(...)
Definition: util_quda.h:67
void zeroCuda(cudaColorSpinorField &a)
Definition: blas_quda.cu:40
void Start(QudaProfileType idx)
void init(int argc, char **argv)
Definition: dslash_test.cpp:79
double norm2(const ColorSpinorField &)
double xmyNormCuda(cudaColorSpinorField &a, cudaColorSpinorField &b)
Definition: reduce_quda.cu:343
bool globalReduce
Definition: face_buffer.cpp:11