CHROMA
syssolver_linop_clover_mg_proto_qphix_eo.cc
Go to the documentation of this file.
1 /*
2  * syssolver_linop_clover_mg_proto.cc
3  *
4  * Created on: Mar 23, 2017
5  * Author: bjoo
6  */
7 
8 #include "chromabase.h"
9 #include "handle.h"
10 #include "state.h"
13 
14 #include "lattice/qphix/qphix_blas_wrappers.h"
15 
16 
17 using namespace QDP;
18 
19 namespace Chroma
20 {
21  namespace LinOpSysSolverMGProtoQPhiXEOCloverEnv
22  {
23 
24  //! Anonymous namespace
25  namespace
26  {
27  //! Name to be used
28  const std::string name("MG_PROTO_QPHIX_EO_CLOVER_INVERTER");
29 
30  //! Local registration flag
31  bool registered = false;
32  }
33 
34 
35 
36  // Double precision
38  const std::string& path,
39  Handle< FermState< LatticeFermion, multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > > state,
40 
42  {
44  }
45 
46  //! Register all the factories
47  bool registerAll()
48  {
49  bool success = true;
50  if (! registered)
51  {
52 
54  registered = true;
55  }
56  return success;
57  }
58  };
59 
60  // Save me typing, by exposing this file level from here
63 
64 
65  // Constructor
66  LinOpSysSolverMGProtoQPhiXEOClover::LinOpSysSolverMGProtoQPhiXEOClover(Handle< LinearOperator<T> > A_,
67  Handle< FermState<T,Q,Q> > state_,
68  const MGProtoSolverParams& invParam_) :
69  A(A_), state(state_), invParam(invParam_), subspaceId(invParam_.SubspaceId) {
70 
71 
73  if ( ! mg_pointer ) {
74  QDPIO::cout << "EO MG Preconditioner not found in Named Obj. Creating" << std::endl;
75 
76  // Check on the links -- they are ferm state and may already have BC's applied? need to figure that out.
78 
79  // Now get the setup
81  }
82 
83  M_ptr = (mg_pointer->M);
84 
85  // Next step is to create a solver instance:
86  MG::FGMRESParams fine_solve_params;
87  fine_solve_params.MaxIter=invParam.OuterSolverMaxIters;
88  fine_solve_params.RsdTarget=toDouble(invParam.OuterSolverRsdTarget);
89  fine_solve_params.VerboseP =invParam.OuterSolverVerboseP;
90  fine_solve_params.NKrylov = invParam.OuterSolverNKrylov;
91 
92  // Internal one with EO preconditioning
93  using EoFGMRES = const MG::FGMRESSolverQPhiX;
94 
95  eo_solver = std::make_shared<const EoFGMRES>(*M_ptr, fine_solve_params, (mg_pointer->v_cycle).get());
96 
97  wrapped= std::make_shared<UnprecFGMRES>(eo_solver, M_ptr);
98 
99  }
100 
101  // Destructor
103 
104  //! Return the subset on which the operator acts
105  const Subset&
107  {
108  return A->subset();
109  }
110 
113  {
114  QDPIO::cout << "Jolly Greetings from Even-Odd Multigridland" << std::endl;
115  const Subset& s = A->subset();
116  StopWatch swatch;
117  StopWatch swatch2;
118 
119  swatch.reset();
120  swatch.start();
121 
122 
123  QDPIO::cout << "DEBUG: Norm2 Chi Before=" << norm2(chi,s) << std::endl;
124  const LatticeInfo& info = M_ptr->GetInfo();
125  QPhiXSpinor qphix_in(info);
126  QPhiXSpinor qphix_out(info);
127 
128 #if 0
129  // Shorthand for the UnprecWrapper
130  using UnprecFGMRES = MG::UnprecFGMRESSolverQPhiXWrapper;
131 
132  // Internal one with EO preconditioning
133  using EoFGMRES = const MG::FGMRESSolverQPhiX;
134 
135  // std::shared_ptr<const MG::FGMRESSolverQPhiX> fgmres_eo=std::make_shared<const MG::FGMRESSolverQPhiX>(*M_ptr, fine_solve_params, (mg_pointer->v_cycle).get());
136  UnprecFGMRES wrapped(std::make_shared<const EoFGMRES>(*M_ptr, fine_solve_params, (mg_pointer->v_cycle).get()), M_ptr);
137 #endif
138 
139  // Solve the system
140  QDPSpinorToQPhiXSpinor(chi,qphix_in);
141  ZeroVec(qphix_out,SUBSET_ALL);
142 
143  swatch2.reset();
144  swatch2.start();
145  //MG::LinearSolverResults res=(*wrapped)(qphix_out,qphix_in, RELATIVE);
146  MG::LinearSolverResults res=(*eo_solver)(qphix_out,qphix_in, RELATIVE);
147 
148  swatch2.stop();
149 
150  double qphix_out_norm_cb0 = MG::Norm2Vec(qphix_out, SUBSET_EVEN);
151  double qphix_out_norm_cb1 = MG::Norm2Vec(qphix_out, SUBSET_ODD);
152 
153  psi = zero;
154  QPhiXSpinorToQDPSpinor(qphix_out,psi);
155  Double psi_norm_cb0 = norm2(psi,rb[0]);
156  Double psi_norm_cb1 = norm2(psi,rb[1]);
157 
158  Double chi_norm_after = norm2(chi,s);
159  QDPIO::cout << "DEBUG: After solve Norm2 chi = " << chi_norm_after << std::endl;
160  QDPIO::cout << "DEBUG: Norm2 qphix_out_cb_0 = " << qphix_out_norm_cb0 << " Norm psi[0]="<< psi_norm_cb0 << std::endl;
161  QDPIO::cout << "DEBUG: Norm2 qphix_out_cb_1 = " << qphix_out_norm_cb1 << " Norm psi[1]="<< psi_norm_cb1 << std::endl;
162 
163 
164  {
165  // Chroma level check (may be slow)
166  T tmp;
167  tmp = zero;
168  (*A)(tmp, psi, PLUS);
169  tmp[s] -= chi;
170  Double n2 = norm2(tmp,s);
171  Double n2rel = n2 / norm2(chi,s);
172  QDPIO::cout << "MG_PROTO_QPHIX_EO_CLOVER_INVERTER: iters = "<< res.n_count << " rel resid = " << sqrt(n2rel) << std::endl;
173  if( toBool( sqrt(n2rel) > invParam.OuterSolverRsdTarget ) ) {
174  MGSolverException convergence_fail(invParam.CloverParams.Mass,
175  subspaceId,
176  res.n_count,
177  Real(sqrt(n2rel)),
179  throw convergence_fail;
180 
181  }
182  }
183  swatch.stop();
184  QDPIO::cout << "MG_PROTO_QPHIX_EO_CLOVER_INVERTER_TIME: call_time = "<< swatch2.getTimeInSeconds() << " sec. total_time=" << swatch.getTimeInSeconds() << " sec." << std::endl;
185  }
186 };
187 
Primary include file for CHROMA library code.
Support class for fermion actions and linear operators.
Definition: state.h:94
Class for counted reference semantics.
Definition: handle.h:33
SystemSolverResults_t operator()(T &psi, const T &chi) const
Solve It!
const Subset & subset() const
Return the subset on which the operator acts.
std::shared_ptr< MGProtoHelpersQPhiX::MGPreconditionerEO > mg_pointer
std::shared_ptr< MG::QPhiXWilsonCloverEOLinearOperator > M_ptr
static T & Instance()
Definition: singleton.h:432
Class for counted reference semantics.
static bool registered
Local registration flag.
const std::string name
Name to be used.
LinOpSystemSolver< LatticeFermion > * createFerm(XMLReader &xml_in, const std::string &path, Handle< FermState< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > > state, Handle< LinearOperator< LatticeFermion > > A)
shared_ptr< MGPreconditionerEO > getMGPreconditionerEO(const std::string &subspaceId)
void createMGPreconditionerEO(const MGProtoSolverParams &params, const multi1d< LatticeColorMatrix > &u)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
LinOpSysSolverMGProtoClover::Q Q
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
LinOpSysSolverMGProtoClover::T T
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
const MG::FGMRESSolverQPhiX EoFGMRES
A(A, psi, r, Ncb, PLUS)
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
static QOP_info_t info
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > s(Ncb)
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Support class for fermion actions and linear operators.
Chroma::CloverFermActParams CloverParams
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Factory for solving M*psi=chi where M is not hermitian or pos. def.
LatticeFermion T
Definition: t_clover.cc:11
multi1d< LatticeColorMatrix > Q
Definition: t_clover.cc:12