QUDA  v0.5.0
A library for QCD on GPUs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
solver.cpp
Go to the documentation of this file.
1 #include <quda_internal.h>
2 #include <invert_quda.h>
3 
4 namespace quda {
5 
6  static void report(const char *type) {
7  if (getVerbosity() >= QUDA_VERBOSE) printfQuda("Creating a %s solver\n", type);
8  }
9 
10  // solver factory
12  DiracMatrix &matPrecon, TimeProfile &profile)
13  {
14  Solver *solver=0;
15 
16  switch (param.inv_type) {
17  case QUDA_CG_INVERTER:
18  report("CG");
19  solver = new CG(mat, matSloppy, param, profile);
20  break;
22  report("BiCGstab");
23  solver = new BiCGstab(mat, matSloppy, matPrecon, param, profile);
24  break;
25  case QUDA_GCR_INVERTER:
26  report("GCR");
27  solver = new GCR(mat, matSloppy, matPrecon, param, profile);
28  break;
29  case QUDA_MR_INVERTER:
30  report("MR");
31  solver = new MR(mat, param, profile);
32  break;
33  default:
34  errorQuda("Invalid solver type");
35  }
36 
37  return solver;
38  }
39 
40  bool Solver::convergence(const double &r2, const double &hq2, const double &r2_tol,
41  const double &hq_tol) {
42  //printf("converge: L2 %e / %e and HQ %e / %e\n", r2, r2_tol, hq2, hq_tol);
43 
44  // check the heavy quark residual norm if necessary
45  if ( (invParam.residual_type & QUDA_HEAVY_QUARK_RESIDUAL) && (hq2 > hq_tol) )
46  return false;
47 
48  // check the L2 relative residual norm if necessary
49  if ( (invParam.residual_type & QUDA_L2_RELATIVE_RESIDUAL) && (r2 > r2_tol) )
50  return false;
51 
52  return true;
53  }
54 
55  void Solver::PrintStats(const char* name, int k, const double &r2,
56  const double &b2, const double &hq2) {
59  printfQuda("%s: %d iterations, <r,r> = %e, |r|/|b| = %e, heavy-quark residual = %e\n",
60  name, k, r2, sqrt(r2/b2), hq2);
61  } else {
62  printfQuda("%s: %d iterations, <r,r> = %e, |r|/|b| = %e\n",
63  name, k, r2, sqrt(r2/b2));
64  }
65  }
66  }
67 
68  void Solver::PrintSummary(const char *name, int k, const double &r2, const double &b2) {
71  printfQuda("%s: Convergence at %d iterations, L2 relative residual: iterated = %e, true = %e, heavy-quark residual = %e\n", name, k, sqrt(r2/b2), invParam.true_res, invParam.true_res_hq);
72  } else {
73  printfQuda("%s: Convergence at %d iterations, L2 relative residual: iterated = %e, true = %e\n",
74  name, k, sqrt(r2/b2), invParam.true_res);
75  }
76 
77  }
78  }
79 
80 } // namespace quda