QUDA  v1.1.0
A library for QCD on GPUs
invert_quda.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <quda.h>
4 #include <quda_internal.h>
5 #include <dirac_quda.h>
6 #include <color_spinor_field.h>
7 #include <qio_field.h>
8 #include <eigensolve_quda.h>
9 #include <vector>
10 #include <memory>
11 
12 namespace quda {
13 
17  struct SolverParam {
18 
23 
29 
34 
38  void *deflation_op;
39 
50 
52  bool deflate;
53 
56 
59 
62 
64  double delta;
65 
68 
71 
81 
86 
91 
96 
101 
104 
106  int pipeline;
107 
109  double tol;
110 
112  double tol_restart;
113 
115  double tol_hq;
116 
119 
122 
124  double true_res;
125 
127  double true_res_hq;
128 
130  int maxiter;
131 
133  int iter;
134 
137 
140 
143 
146 
149 
152 
156 
159 
161  int num_src;
162 
163  // Multi-shift solver parameters
164 
167 
170 
173 
176 
179 
182 
185 
187  int Nsteps;
188 
190  int Nkrylov;
191 
194 
197 
200 
202  double omega;
203 
206 
209 
211  double ca_lambda_max; // -1 -> power iter generate
212 
215 
217  double secs;
218 
220  double gflops;
221 
222  // Incremental EigCG solver parameters
224  QudaPrecision precision_ritz;//also search space precision
225 
226  int n_ev; // number of eigenvectors produced by EigCG
227  int m;//Dimension of the search space
229  int rhs_idx;
230 
233  double inc_tol;
234  double eigenval_tol;
235 
237 
239 
241 
246 
249 
255  compute_true_res(true),
256  sloppy_converge(false),
258  mg_instance(false)
259  {
260  ;
261  }
262 
274  deflate(param.eig_param != 0),
287  tol(param.tol),
291  sloppy_converge(false),
295  iter(param.iter),
310  omega(param.omega),
315  secs(param.secs),
318  n_ev(param.n_ev),
321  rhs_idx(0),
327  is_preconditioner(false),
328  global_reduction(true),
329  mg_instance(false),
331  {
332  if (deflate) { eig_param = *(static_cast<QudaEigParam *>(param.eig_param)); }
333  for (int i=0; i<num_offset; i++) {
334  offset[i] = param.offset[i];
335  tol_offset[i] = param.tol_offset[i];
336  tol_hq_offset[i] = param.tol_hq_offset[i];
337  }
338 
339  if (param.rhs_idx != 0
340  && (param.inv_type == QUDA_INC_EIGCG_INVERTER || param.inv_type == QUDA_GMRESDR_PROJ_INVERTER)) {
341  rhs_idx = param.rhs_idx;
342  }
343  }
344 
355  delta(param.delta),
363  tol(param.tol),
371  iter(param.iter),
385  omega(param.omega),
390  secs(param.secs),
393  n_ev(param.n_ev),
394  m(param.m),
396  rhs_idx(0),
406  {
407  for (int i=0; i<num_offset; i++) {
408  offset[i] = param.offset[i];
409  tol_offset[i] = param.tol_offset[i];
410  tol_hq_offset[i] = param.tol_hq_offset[i];
411  }
412 
413  if((param.inv_type == QUDA_INC_EIGCG_INVERTER || param.inv_type == QUDA_EIGCG_INVERTER) && m % 16){//current hack for the magma library
414  m = (m / 16) * 16 + 16;
415  warningQuda("\nSwitched eigenvector search dimension to %d\n", m);
416  }
417  if(param.rhs_idx != 0 && (param.inv_type==QUDA_INC_EIGCG_INVERTER || param.inv_type==QUDA_GMRESDR_PROJ_INVERTER)){
418  rhs_idx = param.rhs_idx;
419  }
420  }
421 
423 
429  param.true_res = true_res;
430  param.true_res_hq = true_res_hq;
431  param.iter += iter;
433  param.gflops += gflops;
434  param.secs += secs;
435  if (offset >= 0) {
436  param.true_res_offset[offset] = true_res_offset[offset];
437  param.iter_res_offset[offset] = iter_res_offset[offset];
438  param.true_res_hq_offset[offset] = true_res_hq_offset[offset];
439  } else {
440  for (int i=0; i<num_offset; i++) {
441  param.true_res_offset[i] = true_res_offset[i];
442  param.iter_res_offset[i] = iter_res_offset[i];
443  param.true_res_hq_offset[i] = true_res_hq_offset[i];
444  }
445  }
446  //for incremental eigCG:
447  param.rhs_idx = rhs_idx;
448 
449  param.ca_lambda_min = ca_lambda_min;
450  param.ca_lambda_max = ca_lambda_max;
451 
452  if (deflate) *static_cast<QudaEigParam *>(param.eig_param) = eig_param;
453  }
454 
456  //for incremental eigCG:
457  rhs_idx = param.rhs_idx;
458  }
459 
460  };
461 
462  class Solver {
463 
464  protected:
465  const DiracMatrix &mat;
469 
477  std::vector<ColorSpinorField *> evecs;
478  std::vector<Complex> evals;
480  public:
483  virtual ~Solver();
484 
485  virtual void operator()(ColorSpinorField &out, ColorSpinorField &in) = 0;
486 
487  virtual void blocksolve(ColorSpinorField &out, ColorSpinorField &in);
488 
489  const DiracMatrix &M() { return mat; }
490  const DiracMatrix &Msloppy() { return matSloppy; }
491  const DiracMatrix &Mprecon() { return matPrecon; }
492  const DiracMatrix &Meig() { return matEig; }
493 
497  virtual bool hermitian() = 0;
498 
504 
512  static double stopping(double tol, double b2, QudaResidualType residual_type);
513 
522  bool convergence(double r2, double hq2, double r2_tol, double hq_tol);
523 
532  bool convergenceHQ(double r2, double hq2, double r2_tol, double hq_tol);
533 
541  bool convergenceL2(double r2, double hq2, double r2_tol, double hq_tol);
542 
551  void PrintStats(const char *name, int k, double r2, double b2, double hq2);
552 
564  void PrintSummary(const char *name, int k, double r2, double b2, double r2_tol, double hq_tol);
565 
572 
580  void constructDeflationSpace(const ColorSpinorField &meta, const DiracMatrix &mat);
581 
585  void destroyDeflationSpace();
586 
591 
600  void injectDeflationSpace(std::vector<ColorSpinorField *> &defl_space);
601 
610  void extractDeflationSpace(std::vector<ColorSpinorField *> &defl_space);
611 
615  int deflationSpaceSize() const { return (int)evecs.size(); };
616 
621  void setDeflateCompute(bool flag) { deflate_compute = flag; };
622 
627  void setRecomputeEvals(bool flag) { recompute_evals = flag; };
628 
633  virtual double flops() const { return 0; }
634  };
635 
639  class CG : public Solver {
640 
641  private:
642  // pointers to fields to avoid multiple creation overhead
643  ColorSpinorField *yp, *rp, *rnewp, *pp, *App, *tmpp, *tmp2p, *tmp3p, *rSloppyp, *xSloppyp;
644  std::vector<ColorSpinorField*> p;
645  bool init;
646 
647  public:
650  virtual ~CG();
657  (*this)(out, in, nullptr, 0.0);
658  };
659 
668  void operator()(ColorSpinorField &out, ColorSpinorField &in, ColorSpinorField *p_init, double r2_old_init);
669 
671 
672  virtual bool hermitian() { return true; }
673  };
674 
675  class CGNE : public CG
676  {
677 
678  private:
679  DiracMMdag mmdag;
680  DiracMMdag mmdagSloppy;
681  DiracMMdag mmdagPrecon;
682  DiracMMdag mmdagEig;
683  ColorSpinorField *xp;
684  ColorSpinorField *yp;
685  bool init;
686 
687  public:
690  virtual ~CGNE();
691 
693 
694  virtual bool hermitian() { return false; }
695  };
696 
697  class CGNR : public CG
698  {
699 
700  private:
701  DiracMdagM mdagm;
702  DiracMdagM mdagmSloppy;
703  DiracMdagM mdagmPrecon;
704  DiracMdagM mdagmEig;
705  ColorSpinorField *bp;
706  bool init;
707 
708  public:
711  virtual ~CGNR();
712 
714 
715  virtual bool hermitian() { return false; }
716  };
717 
718  class CG3 : public Solver
719  {
720 
721  private:
722  // pointers to fields to avoid multiple creation overhead
723  ColorSpinorField *yp, *rp, *tmpp, *ArSp, *rSp, *xSp, *xS_oldp, *tmpSp, *rS_oldp, *tmp2Sp;
724  bool init;
725 
726  public:
729  virtual ~CG3();
730 
732 
733  virtual bool hermitian() { return true; }
734  };
735 
736  class CG3NE : public CG3
737  {
738 
739  private:
740  DiracMMdag mmdag;
741  DiracMMdag mmdagSloppy;
742  DiracMMdag mmdagPrecon;
743  ColorSpinorField *xp;
744  ColorSpinorField *yp;
745  bool init;
746 
747  public:
750  virtual ~CG3NE();
751 
753 
754  virtual bool hermitian() { return false; }
755  };
756 
757  class CG3NR : public CG3
758  {
759 
760  private:
761  DiracMdagM mdagm;
762  DiracMdagM mdagmSloppy;
763  DiracMdagM mdagmPrecon;
764  ColorSpinorField *bp;
765  bool init;
766 
767  public:
770  virtual ~CG3NR();
771 
773 
774  virtual bool hermitian() { return false; }
775  };
776 
777  class MPCG : public Solver {
778  private:
779  void computeMatrixPowers(cudaColorSpinorField out[], cudaColorSpinorField &in, int nvec);
780  void computeMatrixPowers(std::vector<cudaColorSpinorField>& out, std::vector<cudaColorSpinorField>& in, int nsteps);
781 
782  public:
784  virtual ~MPCG();
785 
787  virtual bool hermitian() { return true; }
788  };
789 
790 
791  class PreconCG : public Solver {
792  private:
793  Solver *K;
794  SolverParam Kparam; // parameters for preconditioner solve
795 
796  public:
799 
800  virtual ~PreconCG();
801 
803  virtual bool hermitian() { return true; }
804  };
805 
806 
807  class BiCGstab : public Solver {
808 
809  private:
810  // pointers to fields to avoid multiple creation overhead
811  ColorSpinorField *yp, *rp, *pp, *vp, *tmpp, *tp;
812  bool init;
813 
814  public:
817  virtual ~BiCGstab();
818 
820 
821  virtual bool hermitian() { return false; }
822  };
823 
824  class SimpleBiCGstab : public Solver {
825 
826  private:
827 
828  // pointers to fields to avoid multiple creation overhead
829  cudaColorSpinorField *yp, *rp, *pp, *vp, *tmpp, *tp;
830  bool init;
831 
832  public:
834  virtual ~SimpleBiCGstab();
835 
837 
838  virtual bool hermitian() { return false; }
839  };
840 
841  class MPBiCGstab : public Solver {
842 
843  private:
844  void computeMatrixPowers(std::vector<cudaColorSpinorField>& pr, cudaColorSpinorField& p, cudaColorSpinorField& r, int nsteps);
845 
846  public:
848  virtual ~MPBiCGstab();
849 
851 
852  virtual bool hermitian() { return false; }
853  };
854 
855  class BiCGstabL : public Solver {
856 
857  private:
861  int n_krylov; // in the language of BiCGstabL, this is L.
862 
863  // Various coefficients and params needed on each iteration.
864  Complex rho0, rho1, alpha, omega, beta; // Various coefficients for the BiCG part of BiCGstab-L.
865  Complex *gamma, *gamma_prime, *gamma_prime_prime; // Parameters for MR part of BiCGstab-L. (L+1) length.
866  Complex **tau; // Parameters for MR part of BiCGstab-L. Tech. modified Gram-Schmidt coeffs. (L+1)x(L+1) length.
867  double *sigma; // Parameters for MR part of BiCGstab-L. Tech. the normalization part of Gram-Scmidt. (L+1) length.
868 
869  // pointers to fields to avoid multiple creation overhead
870  // full precision fields
871  ColorSpinorField *r_fullp;
872  ColorSpinorField *yp;
873  // sloppy precision fields
874  ColorSpinorField *tempp;
875  std::vector<ColorSpinorField*> r; // Current residual + intermediate residual values, along the MR.
876  std::vector<ColorSpinorField*> u; // Search directions.
877 
878  // Saved, preallocated vectors. (may or may not get used depending on precision.)
879  ColorSpinorField *x_sloppy_saved_p;
880  ColorSpinorField *r0_saved_p;
881  ColorSpinorField *r_sloppy_saved_p;
882 
886  int reliable(double &rNorm, double &maxrx, double &maxrr, const double &r2, const double &delta);
887 
891  void computeTau(Complex **tau, double *sigma, std::vector<ColorSpinorField*> r, int begin, int size, int j);
892  void updateR(Complex **tau, std::vector<ColorSpinorField*> r, int begin, int size, int j);
893  void orthoDir(Complex **tau, double* sigma, std::vector<ColorSpinorField*> r, int j, int pipeline);
894 
895  void updateUend(Complex *gamma, std::vector<ColorSpinorField *> u, int n_krylov);
896  void updateXRend(Complex *gamma, Complex *gamma_prime, Complex *gamma_prime_prime,
897  std::vector<ColorSpinorField *> r, ColorSpinorField &x, int n_krylov);
898 
902  bool init;
903 
904  std::string solver_name; // holds BiCGstab-l, where 'l' literally equals n_krylov.
905 
906  public:
908  virtual ~BiCGstabL();
909 
911 
912  virtual bool hermitian() { return false; }
913  };
914 
915  class GCR : public Solver {
916 
917  private:
918  const DiracMdagM matMdagM; // used by the eigensolver
919 
920  Solver *K;
921  SolverParam Kparam; // parameters for preconditioner solve
922 
926  int n_krylov;
927 
928  Complex *alpha;
929  Complex **beta;
930  double *gamma;
931 
935  bool init;
936 
937  ColorSpinorField *rp;
938  ColorSpinorField *tmpp;
939  ColorSpinorField *tmp_sloppy;
940  ColorSpinorField *r_sloppy;
941 
942  std::vector<ColorSpinorField*> p; // GCR direction vectors
943  std::vector<ColorSpinorField*> Ap; // mat * direction vectors
944 
945  public:
948 
952  GCR(const DiracMatrix &mat, Solver &K, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon,
954  virtual ~GCR();
955 
957 
958  virtual bool hermitian() { return false; }
959  };
960 
961  class MR : public Solver {
962 
963  private:
964  ColorSpinorField *rp;
965  ColorSpinorField *r_sloppy;
966  ColorSpinorField *Arp;
967  ColorSpinorField *tmpp;
968  ColorSpinorField *tmp_sloppy;
969  ColorSpinorField *x_sloppy;
970  bool init;
971 
972  public:
974  virtual ~MR();
975 
977 
978  virtual bool hermitian() { return false; }
979  };
980 
989  class CACG : public Solver {
990 
991  private:
992  bool init;
993 
994  bool lambda_init;
995  QudaCABasis basis;
996 
997  Complex *Q_AQandg; // Fused inner product matrix
998  Complex *Q_AS; // inner product matrix
999  Complex *alpha; // QAQ^{-1} g
1000  Complex *beta; // QAQ^{-1} QpolyS
1001 
1002  ColorSpinorField *rp;
1003  ColorSpinorField *tmpp;
1004  ColorSpinorField *tmpp2;
1005  ColorSpinorField *tmp_sloppy;
1006  ColorSpinorField *tmp_sloppy2;
1007 
1008  std::vector<ColorSpinorField*> S; // residual vectors
1009  std::vector<ColorSpinorField*> AS; // mat * residual vectors. Can be replaced by a single temporary.
1010  std::vector<ColorSpinorField*> Q; // CG direction vectors
1011  std::vector<ColorSpinorField*> Qtmp; // CG direction vectors for pointer swap
1012  std::vector<ColorSpinorField*> AQ; // mat * CG direction vectors.
1013  // it's possible to avoid carrying these
1014  // around, but there's a stability penalty,
1015  // and computing QAQ becomes a pain (though
1016  // it does let you fuse the reductions...)
1017 
1024  void create(ColorSpinorField &b);
1025 
1029  void compute_alpha();
1030 
1034  void compute_beta();
1035 
1039  int reliable(double &rNorm, double &maxrr, int &rUpdate, const double &r2, const double &delta);
1040 
1041  public:
1044  virtual ~CACG();
1045 
1047 
1048  virtual bool hermitian() { return true; }
1049  };
1050 
1051  class CACGNE : public CACG {
1052 
1053  private:
1054  DiracMMdag mmdag;
1055  DiracMMdag mmdagSloppy;
1056  DiracMMdag mmdagPrecon;
1057  DiracMMdag mmdagEig;
1058  ColorSpinorField *xp;
1059  ColorSpinorField *yp;
1060  bool init;
1061 
1062  public:
1065  virtual ~CACGNE();
1066 
1068 
1069  virtual bool hermitian() { return false; }
1070  };
1071 
1072  class CACGNR : public CACG {
1073 
1074  private:
1075  DiracMdagM mdagm;
1076  DiracMdagM mdagmSloppy;
1077  DiracMdagM mdagmPrecon;
1078  DiracMdagM mdagmEig;
1079  ColorSpinorField *bp;
1080  bool init;
1081 
1082  public:
1085  virtual ~CACGNR();
1086 
1088 
1089  virtual bool hermitian() { return false; }
1090  };
1091 
1099  class CAGCR : public Solver {
1100 
1101  private:
1102  const DiracMdagM matMdagM; // used by the eigensolver
1103  bool init;
1104  const bool use_source; // whether we can reuse the source vector
1105 
1106  // Basis. Currently anything except POWER_BASIS causes a warning
1107  // then swap to POWER_BASIS.
1108  QudaCABasis basis;
1109 
1110  Complex *alpha; // Solution coefficient vectors
1111 
1112  ColorSpinorField *rp;
1113  ColorSpinorField *tmpp;
1114  ColorSpinorField *tmp_sloppy;
1115 
1116  std::vector<ColorSpinorField*> p; // GCR direction vectors
1117  std::vector<ColorSpinorField*> q; // mat * direction vectors
1118 
1125  void create(ColorSpinorField &b);
1126 
1134  void solve(Complex *psi_, std::vector<ColorSpinorField*> &q, ColorSpinorField &b);
1135 
1136 public:
1139  virtual ~CAGCR();
1140 
1142 
1143  virtual bool hermitian() { return false; }
1144  };
1145 
1146  // Steepest descent solver used as a preconditioner
1147  class SD : public Solver {
1148  private:
1152  bool init;
1153 
1154  public:
1156  virtual ~SD();
1157 
1159 
1160  virtual bool hermitian() { return false; }
1161  };
1162 
1163  // Extended Steepest Descent solver used for overlapping DD preconditioning
1164  class XSD : public Solver
1165  {
1166  private:
1169  SD *sd; // extended sd is implemented using standard sd
1170  bool init;
1171  int R[4];
1172 
1173  public:
1175  virtual ~XSD();
1176 
1178 
1179  virtual bool hermitian() { return false; }
1180  };
1181 
1183  {
1184 private:
1185  Solver *solver;
1186  const Dirac &dirac;
1187  const char *prefix;
1188 
1189 public:
1190  PreconditionedSolver(Solver &solver, const Dirac &dirac, SolverParam &param, TimeProfile &profile, const char *prefix) :
1191  Solver(solver.M(), solver.Msloppy(), solver.Mprecon(), solver.Meig(), param, profile),
1192  solver(&solver),
1193  dirac(dirac),
1194  prefix(prefix)
1195  {
1196  }
1197 
1198  virtual ~PreconditionedSolver() { delete solver; }
1199 
1201  pushOutputPrefix(prefix);
1202 
1204 
1205  ColorSpinorField *out=nullptr;
1206  ColorSpinorField *in=nullptr;
1207 
1208  if (dirac.hasSpecialMG()) {
1209  dirac.prepareSpecialMG(in, out, x, b, solution_type);
1210  } else {
1211  dirac.prepare(in, out, x, b, solution_type);
1212  }
1213  (*solver)(*out, *in);
1214  if (dirac.hasSpecialMG()) {
1215  dirac.reconstructSpecialMG(x, b, solution_type);
1216  } else {
1217  dirac.reconstruct(x, b, solution_type);
1218  }
1219 
1220  popOutputPrefix();
1221  }
1222 
1227  Solver &ExposeSolver() const { return *solver; }
1228 
1229  virtual bool hermitian() { return solver->hermitian(); }
1230  };
1231 
1233 
1234  protected:
1239 
1240  public:
1242  mat(mat),
1244  param(param),
1245  profile(profile)
1246  {
1247  ;
1248  }
1249  virtual ~MultiShiftSolver() { ; }
1250 
1251  virtual void operator()(std::vector<ColorSpinorField*> out, ColorSpinorField &in) = 0;
1252  bool convergence(const double *r2, const double *r2_tol, int n) const;
1253  };
1254 
1259 
1260  public:
1262  virtual ~MultiShiftCG();
1271  void operator()(std::vector<ColorSpinorField*>x, ColorSpinorField &b, std::vector<ColorSpinorField*> &p, double* r2_old_array );
1272 
1279  void operator()(std::vector<ColorSpinorField*> out, ColorSpinorField &in){
1280  std::unique_ptr<double[]> r2_old(new double[QUDA_MAX_MULTI_SHIFT]);
1281  std::vector<ColorSpinorField*> p;
1282 
1283  (*this)(out, in, p, r2_old.get());
1284 
1285  for (auto &pp : p) delete pp;
1286  }
1287 
1288  };
1289 
1290 
1303  class MinResExt {
1304 
1305  protected:
1307  bool orthogonal;
1308  bool apply_mat;
1309  bool hermitian;
1311 
1320  void solve(Complex *psi_, std::vector<ColorSpinorField*> &p,
1321  std::vector<ColorSpinorField*> &q, ColorSpinorField &b, bool hermitian);
1322 
1323  public:
1331  virtual ~MinResExt();
1332 
1339  std::vector<std::pair<ColorSpinorField*,ColorSpinorField*> > basis);
1340 
1348  std::vector<ColorSpinorField*> p,
1349  std::vector<ColorSpinorField*> q);
1350  };
1351 
1353 
1354  //forward declaration
1355  class EigCGArgs;
1356 
1357  class IncEigCG : public Solver {
1358 
1359  private:
1360  Solver *K;
1361  SolverParam Kparam; // parameters for preconditioner solve
1362 
1363  ColorSpinorFieldSet *Vm; //eigCG search vectors (spinor matrix of size eigen_vector_length x m)
1364 
1365  ColorSpinorField *rp;
1366  ColorSpinorField *yp;
1367  ColorSpinorField* p; // conjugate vector
1368  ColorSpinorField* Ap; // mat * conjugate vector
1369  ColorSpinorField *tmpp;
1370  ColorSpinorField *Az; // mat * conjugate vector from the previous iteration
1371  ColorSpinorField *r_pre;
1372  ColorSpinorField *p_pre;
1373 
1374  EigCGArgs *eigcg_args;
1375 
1376  TimeProfile &profile; // time profile for initCG solver
1377 
1378  bool init;
1379 
1380 public:
1382  TimeProfile &profile);
1383 
1384  virtual ~IncEigCG();
1385 
1392 
1393  void RestartVT(const double beta, const double rho);
1394  void UpdateVm(ColorSpinorField &res, double beta, double sqrtr2);
1395  // EigCG solver:
1397  // InitCG solver:
1399  // Incremental eigCG solver (for eigcg and initcg calls)
1401 
1402  bool hermitian() { return true; } // EigCG is only for Hermitian systems
1403  };
1404 
1405 //forward declaration
1406  class GMResDRArgs;
1407 
1408  class GMResDR : public Solver {
1409 
1410  private:
1411  Solver *K;
1412  SolverParam Kparam; // parameters for preconditioner solve
1413 
1414  ColorSpinorFieldSet *Vm;//arnoldi basis vectors, size (m+1)
1415  ColorSpinorFieldSet *Zm;//arnoldi basis vectors, size (m+1)
1416 
1417  ColorSpinorField *rp;
1418  ColorSpinorField *yp;
1419  ColorSpinorField *tmpp;
1420  ColorSpinorField *r_sloppy;
1421  ColorSpinorField *r_pre;
1422  ColorSpinorField *p_pre;
1423 
1424  TimeProfile &profile; //time profile for initCG solver
1425 
1426  GMResDRArgs *gmresdr_args;
1427 
1428  bool init;
1429 
1430  public:
1432  TimeProfile &profile);
1434  SolverParam &param, TimeProfile &profile);
1435 
1436  virtual ~GMResDR();
1437 
1438  //GMRES-DR solver
1440  //
1441  //GMRESDR method
1442  void RunDeflatedCycles (ColorSpinorField *out, ColorSpinorField *in, const double tol_threshold);
1443  //
1444  int FlexArnoldiProcedure (const int start_idx, const bool do_givens);
1445 
1446  void RestartVZH();
1447 
1448  void UpdateSolution(ColorSpinorField *x, ColorSpinorField *r, bool do_gels);
1449 
1450  bool hermitian() { return false; } // GMRESDR for any linear system
1451  };
1452 
1457  struct deflation_space : public Object {
1458  bool svd;
1459  std::vector<ColorSpinorField *> evecs;
1460  std::vector<Complex> evals;
1461  };
1462 
1463 } // namespace quda
BiCGstab(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
virtual bool hermitian()
Definition: invert_quda.h:821
void operator()(ColorSpinorField &out, ColorSpinorField &in)
virtual bool hermitian()
Definition: invert_quda.h:912
BiCGstabL(const DiracMatrix &mat, const DiracMatrix &matSloppy, SolverParam &param, TimeProfile &profile)
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Communication-avoiding CG solver. This solver does un-preconditioned CG, running in steps of n_krylov...
Definition: invert_quda.h:989
virtual bool hermitian()
Definition: invert_quda.h:1048
virtual ~CACG()
Definition: inv_ca_cg.cpp:33
CACG(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
Definition: inv_ca_cg.cpp:15
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Definition: inv_ca_cg.cpp:464
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Definition: inv_ca_cg.cpp:90
CACGNE(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
Definition: inv_ca_cg.cpp:68
virtual ~CACGNE()
Definition: inv_ca_cg.cpp:81
virtual bool hermitian()
Definition: invert_quda.h:1069
virtual ~CACGNR()
Definition: inv_ca_cg.cpp:170
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Definition: inv_ca_cg.cpp:178
virtual bool hermitian()
Definition: invert_quda.h:1089
CACGNR(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
Definition: inv_ca_cg.cpp:158
Communication-avoiding GCR solver. This solver does un-preconditioned GCR, first building up a polyno...
Definition: invert_quda.h:1099
CAGCR(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
Definition: inv_ca_gcr.cpp:7
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Definition: inv_ca_gcr.cpp:168
virtual bool hermitian()
Definition: invert_quda.h:1143
virtual ~CAGCR()
Definition: inv_ca_gcr.cpp:22
virtual ~CG3()
virtual bool hermitian()
Definition: invert_quda.h:733
CG3(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, SolverParam &param, TimeProfile &profile)
void operator()(ColorSpinorField &out, ColorSpinorField &in)
CG3NE(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, SolverParam &param, TimeProfile &profile)
virtual ~CG3NE()
void operator()(ColorSpinorField &out, ColorSpinorField &in)
virtual bool hermitian()
Definition: invert_quda.h:754
CG3NR(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, SolverParam &param, TimeProfile &profile)
virtual ~CG3NR()
void operator()(ColorSpinorField &out, ColorSpinorField &in)
virtual bool hermitian()
Definition: invert_quda.h:774
Conjugate-Gradient Solver.
Definition: invert_quda.h:639
virtual bool hermitian()
Definition: invert_quda.h:672
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Run CG.
Definition: invert_quda.h:656
void blocksolve(ColorSpinorField &out, ColorSpinorField &in)
CG(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
Definition: inv_cg_quda.cpp:19
virtual ~CG()
Definition: inv_cg_quda.cpp:36
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Run CG.
Definition: inv_cg_quda.cpp:84
CGNE(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
Definition: inv_cg_quda.cpp:62
virtual bool hermitian()
Definition: invert_quda.h:694
virtual ~CGNE()
Definition: inv_cg_quda.cpp:75
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Run CG.
virtual ~CGNR()
virtual bool hermitian()
Definition: invert_quda.h:715
CGNR(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
QudaSiteSubset SiteSubset() const
GCR(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
virtual bool hermitian()
Definition: invert_quda.h:958
void operator()(ColorSpinorField &out, ColorSpinorField &in)
virtual ~GCR()
GMResDR(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, SolverParam &param, TimeProfile &profile)
bool hermitian()
Definition: invert_quda.h:1450
void UpdateSolution(ColorSpinorField *x, ColorSpinorField *r, bool do_gels)
int FlexArnoldiProcedure(const int start_idx, const bool do_givens)
void operator()(ColorSpinorField &out, ColorSpinorField &in)
void RunDeflatedCycles(ColorSpinorField *out, ColorSpinorField *in, const double tol_threshold)
void increment(ColorSpinorField &V, int n_ev)
Expands deflation space.
void operator()(ColorSpinorField &out, ColorSpinorField &in)
int eigCGsolve(ColorSpinorField &out, ColorSpinorField &in)
void UpdateVm(ColorSpinorField &res, double beta, double sqrtr2)
int initCGsolve(ColorSpinorField &out, ColorSpinorField &in)
IncEigCG(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, SolverParam &param, TimeProfile &profile)
void RestartVT(const double beta, const double rho)
virtual bool hermitian()
Definition: invert_quda.h:852
MPBiCGstab(const DiracMatrix &mat, SolverParam &param, TimeProfile &profile)
void operator()(ColorSpinorField &out, ColorSpinorField &in)
void operator()(ColorSpinorField &out, ColorSpinorField &in)
virtual ~MPCG()
virtual bool hermitian()
Definition: invert_quda.h:787
MPCG(const DiracMatrix &mat, SolverParam &param, TimeProfile &profile)
MR(const DiracMatrix &mat, const DiracMatrix &matSloppy, SolverParam &param, TimeProfile &profile)
Definition: inv_mr_quda.cpp:16
virtual ~MR()
Definition: inv_mr_quda.cpp:31
virtual bool hermitian()
Definition: invert_quda.h:978
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Definition: inv_mr_quda.cpp:44
This computes the optimum guess for the system Ax=b in the L2 residual norm. For use in the HMD force...
Definition: invert_quda.h:1303
TimeProfile & profile
whether A is hermitian ot not
Definition: invert_quda.h:1310
bool apply_mat
Whether to construct an orthogonal basis or not.
Definition: invert_quda.h:1308
const DiracMatrix & mat
Definition: invert_quda.h:1306
void operator()(ColorSpinorField &x, ColorSpinorField &b, std::vector< std::pair< ColorSpinorField *, ColorSpinorField * > > basis)
Definition: inv_mre.cpp:169
virtual ~MinResExt()
Definition: inv_mre.cpp:16
bool hermitian
Whether to compute q = Ap or assume it is provided.
Definition: invert_quda.h:1309
MinResExt(const DiracMatrix &mat, bool orthogonal, bool apply_mat, bool hermitian, TimeProfile &profile)
Definition: inv_mre.cpp:7
void solve(Complex *psi_, std::vector< ColorSpinorField * > &p, std::vector< ColorSpinorField * > &q, ColorSpinorField &b, bool hermitian)
Solve the equation A p_k psi_k = q_k psi_k = b by minimizing the residual and using Eigen's SVD algor...
Definition: inv_mre.cpp:22
Multi-Shift Conjugate Gradient Solver.
Definition: invert_quda.h:1258
MultiShiftCG(const DiracMatrix &mat, const DiracMatrix &matSloppy, SolverParam &param, TimeProfile &profile)
void operator()(std::vector< ColorSpinorField * > out, ColorSpinorField &in)
Run multi-shift and return Krylov-space at the end of the solve in p and r2_old_arry.
Definition: invert_quda.h:1279
void operator()(std::vector< ColorSpinorField * >x, ColorSpinorField &b, std::vector< ColorSpinorField * > &p, double *r2_old_array)
Run multi-shift and return Krylov-space at the end of the solve in p and r2_old_arry.
const DiracMatrix & matSloppy
Definition: invert_quda.h:1236
TimeProfile & profile
Definition: invert_quda.h:1238
virtual void operator()(std::vector< ColorSpinorField * > out, ColorSpinorField &in)=0
const DiracMatrix & mat
Definition: invert_quda.h:1235
MultiShiftSolver(const DiracMatrix &mat, const DiracMatrix &matSloppy, SolverParam &param, TimeProfile &profile)
Definition: invert_quda.h:1241
bool convergence(const double *r2, const double *r2_tol, int n) const
Definition: solver.cpp:427
virtual ~PreconCG()
void operator()(ColorSpinorField &out, ColorSpinorField &in)
virtual bool hermitian()
Definition: invert_quda.h:803
PreconCG(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
Solver & ExposeSolver() const
Return reference to the solver. Used when mass/mu rescaling an MG instance.
Definition: invert_quda.h:1227
PreconditionedSolver(Solver &solver, const Dirac &dirac, SolverParam &param, TimeProfile &profile, const char *prefix)
Definition: invert_quda.h:1190
void operator()(ColorSpinorField &x, ColorSpinorField &b)
Definition: invert_quda.h:1200
virtual ~SD()
Definition: inv_sd_quda.cpp:24
virtual bool hermitian()
Definition: invert_quda.h:1160
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
void operator()(ColorSpinorField &out, ColorSpinorField &in)
virtual bool hermitian()
Definition: invert_quda.h:838
SimpleBiCGstab(const DiracMatrix &mat, SolverParam &param, TimeProfile &profile)
bool deflate_init
Definition: invert_quda.h:474
const DiracMatrix & Msloppy()
Definition: invert_quda.h:490
double precisionEpsilon(QudaPrecision prec=QUDA_INVALID_PRECISION) const
Returns the epsilon tolerance for a given precision, by default returns the solver precision.
Definition: solver.cpp:412
void extractDeflationSpace(std::vector< ColorSpinorField * > &defl_space)
Extracts the deflation space from the solver to the vector argument. Note the solver deflation space ...
Definition: solver.cpp:276
const DiracMatrix & M()
Definition: invert_quda.h:489
bool deflate_compute
Definition: invert_quda.h:475
TimeProfile & profile
Definition: invert_quda.h:471
Solver(const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, SolverParam &param, TimeProfile &profile)
Definition: solver.cpp:14
bool convergenceL2(double r2, double hq2, double r2_tol, double hq_tol)
Test for L2 solver convergence – ignore HQ residual.
Definition: solver.cpp:361
virtual void operator()(ColorSpinorField &out, ColorSpinorField &in)=0
const DiracMatrix & Meig()
Definition: invert_quda.h:492
virtual void blocksolve(ColorSpinorField &out, ColorSpinorField &in)
Definition: solver.cpp:302
const DiracMatrix & mat
Definition: invert_quda.h:465
virtual ~Solver()
Definition: solver.cpp:33
bool convergence(double r2, double hq2, double r2_tol, double hq_tol)
Definition: solver.cpp:328
bool recompute_evals
Definition: invert_quda.h:476
std::vector< ColorSpinorField * > evecs
Definition: invert_quda.h:477
bool convergenceHQ(double r2, double hq2, double r2_tol, double hq_tol)
Test for HQ solver convergence – ignore L2 residual.
Definition: solver.cpp:348
virtual double flops() const
Return flops.
Definition: invert_quda.h:633
int deflationSpaceSize() const
Returns the size of deflation space.
Definition: invert_quda.h:615
void destroyDeflationSpace()
Destroy the allocated deflation space.
Definition: solver.cpp:229
void PrintSummary(const char *name, int k, double r2, double b2, double r2_tol, double hq_tol)
Prints out the summary of the solver convergence (requires a verbosity of QUDA_SUMMARIZE)....
Definition: solver.cpp:386
const DiracMatrix & matEig
Definition: invert_quda.h:468
void injectDeflationSpace(std::vector< ColorSpinorField * > &defl_space)
Injects a deflation space into the solver from the vector argument. Note the input space is reduced t...
Definition: solver.cpp:266
SolverParam & param
Definition: invert_quda.h:470
static double stopping(double tol, double b2, QudaResidualType residual_type)
Set the solver L2 stopping condition.
Definition: solver.cpp:311
void setDeflateCompute(bool flag)
Sets the deflation compute boolean.
Definition: invert_quda.h:621
void extendSVDDeflationSpace()
Extends the deflation space to twice its size for SVD deflation.
Definition: solver.cpp:287
std::vector< Complex > evals
Definition: invert_quda.h:478
virtual bool hermitian()=0
void setRecomputeEvals(bool flag)
Sets the recompute evals boolean.
Definition: invert_quda.h:627
EigenSolver * eig_solve
Definition: invert_quda.h:473
void PrintStats(const char *name, int k, double r2, double b2, double hq2)
Prints out the running statistics of the solver (requires a verbosity of QUDA_VERBOSE)
Definition: solver.cpp:373
void constructDeflationSpace(const ColorSpinorField &meta, const DiracMatrix &mat)
Constructs the deflation space and eigensolver.
Definition: solver.cpp:168
const DiracMatrix & matPrecon
Definition: invert_quda.h:467
static Solver * create(SolverParam &param, const DiracMatrix &mat, const DiracMatrix &matSloppy, const DiracMatrix &matPrecon, const DiracMatrix &matEig, TimeProfile &profile)
Solver factory.
Definition: solver.cpp:42
const DiracMatrix & Mprecon()
Definition: invert_quda.h:491
const DiracMatrix & matSloppy
Definition: invert_quda.h:466
XSD(const DiracMatrix &mat, SolverParam &param, TimeProfile &profile)
void operator()(ColorSpinorField &out, ColorSpinorField &in)
virtual bool hermitian()
Definition: invert_quda.h:1179
virtual ~XSD()
void reduceDouble(double &)
double reliable_delta
double tol
quda::mgarray< int > nvec
int max_search_dim
int gcrNkrylov
QudaSolutionType solution_type
int pipeline
QudaPrecision prec
int V
Definition: host_utils.cpp:37
GaugeCovDev * dirac
Definition: covdev_test.cpp:42
enum QudaPrecision_s QudaPrecision
enum QudaUseInitGuess_s QudaUseInitGuess
@ QUDA_SILENT
Definition: enum_quda.h:265
@ QUDA_FULL_SITE_SUBSET
Definition: enum_quda.h:333
enum QudaPreserveSource_s QudaPreserveSource
enum QudaSolutionType_s QudaSolutionType
enum QudaInverterType_s QudaInverterType
enum QudaExtLibType_s QudaExtLibType
enum QudaComputeNullVector_s QudaComputeNullVector
enum QudaResidualType_s QudaResidualType
@ QUDA_GMRESDR_PROJ_INVERTER
Definition: enum_quda.h:119
@ QUDA_INC_EIGCG_INVERTER
Definition: enum_quda.h:117
@ QUDA_EIGCG_INVERTER
Definition: enum_quda.h:116
@ QUDA_PRESERVE_SOURCE_NO
Definition: enum_quda.h:238
@ QUDA_MATPC_SOLUTION
Definition: enum_quda.h:159
@ QUDA_MAT_SOLUTION
Definition: enum_quda.h:157
@ QUDA_INVALID_PRECISION
Definition: enum_quda.h:66
enum QudaCABasis_s QudaCABasis
enum QudaSchwarzType_s QudaSchwarzType
enum QudaVerbosity_s QudaVerbosity
@ QUDA_COMPUTE_NULL_VECTOR_NO
Definition: enum_quda.h:441
QudaPrecision & cuda_prec
Definition: host_utils.cpp:58
QudaPrecision & cuda_prec_sloppy
Definition: host_utils.cpp:59
QudaPrecision & cuda_prec_eigensolver
Definition: host_utils.cpp:62
QudaPrecision & cuda_prec_precondition
Definition: host_utils.cpp:61
QudaPrecision & cuda_prec_refinement_sloppy
Definition: host_utils.cpp:60
QudaPrecision & cuda_prec_ritz
Definition: host_utils.cpp:63
std::complex< double > Complex
Definition: quda_internal.h:86
::std::string string
Definition: gtest-port.h:891
QudaGaugeParam param
Definition: pack_test.cpp:18
Main header file for the QUDA library.
#define QUDA_MAX_MULTI_SHIFT
Maximum number of shifts supported by the multi-shift solver. This number may be changed if need be.
QudaPreserveSource preserve_source
Definition: invert_quda.h:151
void updateRhsIndex(QudaInvertParam &param)
Definition: invert_quda.h:455
QudaCABasis ca_basis
Definition: invert_quda.h:205
QudaPrecision precision
Definition: invert_quda.h:136
QudaComputeNullVector compute_null_vector
Definition: invert_quda.h:61
double iter_res_offset[QUDA_MAX_MULTI_SHIFT]
Definition: invert_quda.h:181
bool is_preconditioner
verbosity to use for preconditioner
Definition: invert_quda.h:238
bool use_sloppy_partial_accumulator
Definition: invert_quda.h:70
QudaSchwarzType schwarz_type
Definition: invert_quda.h:214
double tol_precondition
Definition: invert_quda.h:196
int max_res_increase_total
Definition: invert_quda.h:90
QudaResidualType residual_type
Definition: invert_quda.h:49
bool use_alternative_reliable
Definition: invert_quda.h:67
QudaExtLibType extlib_type
Definition: invert_quda.h:248
QudaPrecision precision_refinement_sloppy
Definition: invert_quda.h:142
double offset[QUDA_MAX_MULTI_SHIFT]
Definition: invert_quda.h:169
SolverParam(const SolverParam &param)
Definition: invert_quda.h:345
double tol_hq_offset[QUDA_MAX_MULTI_SHIFT]
Definition: invert_quda.h:175
QudaPrecision precision_precondition
Definition: invert_quda.h:145
QudaPrecision precision_sloppy
Definition: invert_quda.h:139
bool mg_instance
whether to use a global or local (node) reduction for this solver
Definition: invert_quda.h:245
double tol_offset[QUDA_MAX_MULTI_SHIFT]
Definition: invert_quda.h:172
double true_res_offset[QUDA_MAX_MULTI_SHIFT]
Definition: invert_quda.h:178
int solution_accumulator_pipeline
Definition: invert_quda.h:80
void * preconditioner
Definition: invert_quda.h:33
QudaPrecision precision_eigensolver
Definition: invert_quda.h:148
QudaInverterType inv_type
Definition: invert_quda.h:22
QudaPrecision precision_ritz
Definition: invert_quda.h:224
QudaVerbosity verbosity_precondition
Definition: invert_quda.h:236
QudaEigParam eig_param
Definition: invert_quda.h:55
double true_res_hq_offset[QUDA_MAX_MULTI_SHIFT]
Definition: invert_quda.h:184
QudaUseInitGuess use_init_guess
Definition: invert_quda.h:58
int max_hq_res_restart_total
Definition: invert_quda.h:100
QudaInverterType inv_type_precondition
Definition: invert_quda.h:28
void updateInvertParam(QudaInvertParam &param, int offset=-1)
Definition: invert_quda.h:428
bool global_reduction
whether the solver acting as a preconditioner for another solver
Definition: invert_quda.h:240
SolverParam(const QudaInvertParam &param)
Definition: invert_quda.h:268
This is an object that captures the state required for a deflated solver.
Definition: invert_quda.h:1457
std::vector< ColorSpinorField * > evecs
Definition: invert_quda.h:1459
std::vector< Complex > evals
Definition: invert_quda.h:1460
void popOutputPrefix()
Pop the output prefix restoring the prior one on the stack.
Definition: util_quda.cpp:121
void pushOutputPrefix(const char *prefix)
Push a new output prefix onto the stack.
Definition: util_quda.cpp:105
#define warningQuda(...)
Definition: util_quda.h:132