QUDA  v1.1.0
A library for QCD on GPUs
multigrid.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <invert_quda.h>
4 #include <transfer.h>
5 #include <vector>
6 #include <complex_quda.h>
7 
8 // at the moment double-precision multigrid is only enabled when debugging
9 #ifdef HOST_DEBUG
10 //#define GPU_MULTIGRID_DOUBLE
11 #endif
12 
13 namespace quda {
14 
15  // forward declarations
16  class MG;
17  class DiracCoarse;
18 
25  struct MGParam : SolverParam {
26 
30 
32  int level;
33 
35  int Nlevel;
36 
39 
42 
44  int Nvec;
45 
48 
51 
53  MG *fine;
54 
56  std::vector<ColorSpinorField*> &B;
57 
59  int nu_pre;
60 
62  int nu_post;
63 
65  double smoother_tol;
66 
69 
72 
75 
78 
81 
84 
88 
91 
94 
97 
99  char filename[100];
100 
103 
105  bool use_mma;
106 
110  MGParam(QudaMultigridParam &param, std::vector<ColorSpinorField *> &B, DiracMatrix *matResidual,
112  SolverParam(*(param.invert_param)),
113  mg_global(param),
114  level(level),
115  Nlevel(param.n_level),
116  spinBlockSize(param.spin_block_size[level]),
117  Nvec(param.n_vec[level]),
119  B(B),
135  {
136  // set the block size
137  for (int i = 0; i < QUDA_MAX_DIM; i++) geoBlockSize[i] = param.geo_block_size[level][i];
138 
139  // set the smoother relaxation factor
140  omega = param.omega[level];
141  }
142 
143  MGParam(const MGParam &param, std::vector<ColorSpinorField *> &B, DiracMatrix *matResidual, DiracMatrix *matSmooth,
144  DiracMatrix *matSmoothSloppy, int level = 0) :
147  level(level),
149  spinBlockSize(param.mg_global.spin_block_size[level]),
150  Nvec(param.mg_global.n_vec[level]),
153  fine(param.fine),
154  B(B),
170  {
171  // set the block size
172  for (int i = 0; i < QUDA_MAX_DIM; i++) geoBlockSize[i] = param.mg_global.geo_block_size[level][i];
173 
174  // set the smoother relaxation factor
175  omega = param.mg_global.omega[level];
176  }
177  };
178 
182  class MG : public Solver {
183 
184  private:
186  MGParam &param;
187 
189  Transfer *transfer;
190 
192  bool resetTransfer;
193 
195  Solver *presmoother, *postsmoother;
196 
198  TimeProfile &profile_global;
199 
201  TimeProfile profile;
202 
204  char prefix[128];
205 
207  char coarse_prefix[128];
208 
210  MG *coarse;
211 
213  Solver *coarse_solver;
214 
216  MGParam *param_coarse;
217 
219  SolverParam *param_presmooth;
220 
222  SolverParam *param_postsmooth;
223 
225  SolverParam *param_coarse_solver;
226 
228  std::vector<ColorSpinorField*> *B_coarse;
229 
231  ColorSpinorField *r;
232 
234  ColorSpinorField *b_tilde;
235 
237  ColorSpinorField *r_coarse;
238 
240  ColorSpinorField *x_coarse;
241 
243  ColorSpinorField *tmp_coarse;
244 
246  ColorSpinorField *tmp2_coarse;
247 
249  cudaGaugeField *xInvKD;
250 
252  const Dirac *diracResidual;
253 
255  const Dirac *diracSmoother;
256 
258  const Dirac *diracSmootherSloppy;
259 
261  Dirac *diracCoarseResidual;
262 
264  Dirac *diracCoarseSmoother;
265 
267  Dirac *diracCoarseSmootherSloppy;
268 
270  DiracMatrix *matCoarseResidual;
271 
273  DiracMatrix *matCoarseSmoother;
274 
276  DiracMatrix *matCoarseSmootherSloppy;
277 
279  RNG *rng;
280 
285  void pushLevel(int level) const;
286 
291  void popLevel(int level) const;
292 
293 public:
299  MG(MGParam &param, TimeProfile &profile);
300 
305  virtual ~MG();
306 
310  bool hermitian() { return false; };
311 
316  void reset(bool refresh=false);
317 
321  void dumpNullVectors() const;
322 
326  void createSmoother();
327 
331  void destroySmoother();
332 
336  void createCoarseDirac();
337 
341  void createCoarseSolver();
342 
346  void destroyCoarseSolver();
347 
359  void verify(bool recursively = false);
360 
367 
372  void loadVectors(std::vector<ColorSpinorField *> &B);
373 
378  void saveVectors(const std::vector<ColorSpinorField *> &B) const;
379 
385  void generateNullVectors(std::vector<ColorSpinorField*> &B, bool refresh=false);
386 
390  void generateEigenVectors();
391 
396  void buildFreeVectors(std::vector<ColorSpinorField*> &B);
397 
401  double flops() const;
402 
403  };
404 
423  const GaugeField &Y, const GaugeField &X, double kappa, int parity = QUDA_INVALID_PARITY,
424  bool dslash=true, bool clover=true, bool dagger=false, const int *commDim=0,
425  QudaPrecision halo_precision=QUDA_INVALID_PRECISION);
426 
443  void CoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, const cudaGaugeField &gauge,
444  const cudaCloverField *clover, double kappa, double mass, double mu, double mu_factor,
446 
459  void StaggeredCoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, const cudaGaugeField &gauge,
460  const cudaGaugeField *XinvKD, double mass, QudaDiracType dirac, QudaMatPCType matpc);
461 
483  void CoarseCoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, const GaugeField &gauge, const GaugeField &clover,
484  const GaugeField &cloverInv, double kappa, double mass, double mu, double mu_factor,
485  QudaDiracType dirac, QudaMatPCType matpc, bool need_bidirectional, bool use_mma = false);
486 
495  void calculateYhat(GaugeField &Yhat, GaugeField &Xinv, const GaugeField &Y, const GaugeField &X, bool use_mma = false);
496 
507 
511 
512  std::vector<ColorSpinorField*> B;
513 
515 
516  MG *mg;
518 
520 
522  {
523  profile.TPSTART(QUDA_PROFILE_FREE);
524  if (mg) delete mg;
525 
526  if (mgParam) delete mgParam;
527 
528  for (unsigned int i=0; i<B.size(); i++) delete B[i];
529 
530  if (m) delete m;
531  if (mSmooth) delete mSmooth;
532  if (mSmoothSloppy) delete mSmoothSloppy;
533 
534  if (d) delete d;
535  if (dSmooth) delete dSmooth;
537  profile.TPSTOP(QUDA_PROFILE_FREE);
538  }
539  };
540 
541 } // namespace quda
double flops() const
Return the total flops done on this and all coarser levels.
Definition: multigrid.cpp:734
MG(MGParam &param, TimeProfile &profile)
Definition: multigrid.cpp:16
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Definition: multigrid.cpp:1095
void destroySmoother()
Destroy the smoothers.
Definition: multigrid.cpp:274
void createCoarseDirac()
Create the coarse dirac operator.
Definition: multigrid.cpp:362
void createSmoother()
Create the smoothers.
Definition: multigrid.cpp:301
void saveVectors(const std::vector< ColorSpinorField * > &B) const
Save the null space vectors in from file.
Definition: multigrid.cpp:1253
void buildFreeVectors(std::vector< ColorSpinorField * > &B)
Build free-field null-space vectors.
Definition: multigrid.cpp:1478
void createCoarseSolver()
Create the solver wrapper.
Definition: multigrid.cpp:539
void verify(bool recursively=false)
Verify the correctness of the MG method, optionally recursively starting from the top down.
Definition: multigrid.cpp:764
void dumpNullVectors() const
Dump the null-space vectors to disk. Will recurse dumping all levels.
Definition: multigrid.cpp:1275
void loadVectors(std::vector< ColorSpinorField * > &B)
Load the null space vectors in from file.
Definition: multigrid.cpp:1231
virtual ~MG()
Definition: multigrid.cpp:681
void generateEigenVectors()
Generate lowest eigenvectors.
Definition: multigrid.cpp:1653
void destroyCoarseSolver()
Destroy the solver wrapper.
Definition: multigrid.cpp:510
void reset(bool refresh=false)
This method resets the solver, e.g., when a parameter has changed such as the mass.
Definition: multigrid.cpp:126
void generateNullVectors(std::vector< ColorSpinorField * > &B, bool refresh=false)
Generate the null-space vectors.
Definition: multigrid.cpp:1285
bool hermitian()
Definition: multigrid.h:310
Class declaration to initialize and hold CURAND RNG states.
Definition: random_quda.h:23
int commDim(int)
double kappa
double mass
quda::mgarray< int > n_block_ortho
double mu
quda::mgarray< double > mu_factor
bool dagger
GaugeCovDev * dirac
Definition: covdev_test.cpp:42
QudaParity parity
Definition: covdev_test.cpp:40
void matpc(void *outEven, void **gauge, void *inEven, double kappa, QudaMatPCType matpc_type, int dagger_bit, QudaPrecision sPrecision, QudaPrecision gPrecision, double mferm)
enum QudaSolveType_s QudaSolveType
enum QudaPrecision_s QudaPrecision
enum QudaTransferType_s QudaTransferType
@ QUDA_BOOLEAN_TRUE
Definition: enum_quda.h:461
enum QudaMultigridCycleType_s QudaMultigridCycleType
enum QudaDiracType_s QudaDiracType
@ QUDA_INVALID_PARITY
Definition: enum_quda.h:284
enum QudaBoolean_s QudaBoolean
enum QudaSolutionType_s QudaSolutionType
enum QudaInverterType_s QudaInverterType
enum QudaFieldLocation_s QudaFieldLocation
enum QudaMatPCType_s QudaMatPCType
@ QUDA_INVALID_PRECISION
Definition: enum_quda.h:66
void calculateYhat(GaugeField &Yhat, GaugeField &Xinv, const GaugeField &Y, const GaugeField &X, bool use_mma=false)
Calculate preconditioned coarse links and coarse clover inverse field.
void CoarseCoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, const GaugeField &gauge, const GaugeField &clover, const GaugeField &cloverInv, double kappa, double mass, double mu, double mu_factor, QudaDiracType dirac, QudaMatPCType matpc, bool need_bidirectional, bool use_mma=false)
Coarse operator construction from an intermediate-grid operator (Coarse)
void ApplyCoarse(ColorSpinorField &out, const ColorSpinorField &inA, const ColorSpinorField &inB, const GaugeField &Y, const GaugeField &X, double kappa, int parity=QUDA_INVALID_PARITY, bool dslash=true, bool clover=true, bool dagger=false, const int *commDim=0, QudaPrecision halo_precision=QUDA_INVALID_PRECISION)
Apply the coarse dslash stencil. This single driver accounts for all variations with and without the ...
@ QUDA_PROFILE_FREE
Definition: timer.h:111
void StaggeredCoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, const cudaGaugeField &gauge, const cudaGaugeField *XinvKD, double mass, QudaDiracType dirac, QudaMatPCType matpc)
Coarse operator construction from a fine-grid operator (Staggered)
void CoarseOp(GaugeField &Y, GaugeField &X, const Transfer &T, const cudaGaugeField &gauge, const cudaCloverField *clover, double kappa, double mass, double mu, double mu_factor, QudaDiracType dirac, QudaMatPCType matpc)
Coarse operator construction from a fine-grid operator (Wilson / Clover)
QudaGaugeParam param
Definition: pack_test.cpp:18
#define QUDA_MAX_DIM
Maximum number of dimensions supported by QUDA. In practice, no routines make use of more than 5.
DiracMatrix * matResidual
Definition: multigrid.h:74
double smoother_tol
Definition: multigrid.h:65
int spinBlockSize
Definition: multigrid.h:41
MGParam(QudaMultigridParam &param, std::vector< ColorSpinorField * > &B, DiracMatrix *matResidual, DiracMatrix *matSmooth, DiracMatrix *matSmoothSloppy, int level=0)
Definition: multigrid.h:110
std::vector< ColorSpinorField * > & B
Definition: multigrid.h:56
QudaInverterType smoother
Definition: multigrid.h:83
QudaSolutionType coarse_grid_solution_type
Definition: multigrid.h:87
MGParam(const MGParam &param, std::vector< ColorSpinorField * > &B, DiracMatrix *matResidual, DiracMatrix *matSmooth, DiracMatrix *matSmoothSloppy, int level=0)
Definition: multigrid.h:143
DiracMatrix * matSmoothSloppy
Definition: multigrid.h:80
QudaFieldLocation location
Definition: multigrid.h:93
QudaBoolean global_reduction
Definition: multigrid.h:71
QudaMultigridCycleType cycle_type
Definition: multigrid.h:68
int geoBlockSize[QUDA_MAX_DIM]
Definition: multigrid.h:38
QudaMultigridParam & mg_global
Definition: multigrid.h:29
char filename[100]
Definition: multigrid.h:99
QudaSolveType smoother_solve_type
Definition: multigrid.h:90
int NblockOrtho
Definition: multigrid.h:47
DiracMatrix * matSmooth
Definition: multigrid.h:77
QudaTransferType transfer_type
Definition: multigrid.h:102
QudaFieldLocation setup_location
Definition: multigrid.h:96
virtual ~multigrid_solver()
Definition: multigrid.h:521
TimeProfile & profile
Definition: multigrid.h:517
multigrid_solver(QudaMultigridParam &mg_param, TimeProfile &profile)
std::vector< ColorSpinorField * > B
Definition: multigrid.h:512