CHROMA
syssolver_linop_clover_quda_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Solve a MdagM*psi=chi linear system by CG2
3  */
4 
9 #include "io/aniso_io.h"
10 
11 
12 #include "handle.h"
15 #include "meas/glue/mesplq.h"
16 // QUDA Headers
17 #include <quda.h>
18 // #include <util_quda.h>
19 
20 namespace Chroma
21 {
22  namespace LinOpSysSolverQUDACloverEnv
23  {
24 
25  //! Anonymous namespace
26  namespace
27  {
28  //! Name to be used
29  const std::string name("QUDA_CLOVER_INVERTER");
30 
31  //! Local registration flag
32  bool registered = false;
33  }
34 
35 
36 
38  const std::string& path,
39  Handle< FermState< LatticeFermion, multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > > state,
40 
42  {
43  return new LinOpSysSolverQUDAClover(A, state,SysSolverQUDACloverParams(xml_in, path));
44  }
45 
46  //! Register all the factories
47  bool registerAll()
48  {
49  bool success = true;
50  if (! registered)
51  {
53  registered = true;
54  }
55  return success;
56  }
57  }
58 
59  SystemSolverResults_t
60  LinOpSysSolverQUDAClover::qudaInvert(const CloverTermT<T, U>& clover,
61  const CloverTermT<T, U>& invclov,
62  const T& chi_s,
63  T& psi_s) const{
64 
65  SystemSolverResults_t ret;
66 
67  void *spinorIn;
68  void *spinorOut;
69 
70 #ifdef BUILD_QUDA_DEVIFACE_SPINOR
71  std::vector<QDPCache::ArgKey> ids;
72 #endif
73 
74  // No need to transform source
75 #ifndef BUILD_QUDA_DEVIFACE_SPINOR
76  spinorIn =(void *)&(chi_s.elem(rb[1].start()).elem(0).elem(0).real());
77 #else
78  //spinorIn = GetMemoryPtr( chi_s.);
79  //QDPIO::cout << "MDAGM spinor in = " << spinorIn << "\n";
80  ids.push_back(chi_s.getId());
81 #endif
82 
83 
84 #ifndef BUILD_QUDA_DEVIFACE_SPINOR
85  spinorOut =(void *)&(psi_s.elem(rb[1].start()).elem(0).elem(0).real());
86 #else
87  ids.push_back(psi_s.getId());
88  auto dev_ptr = GetMemoryPtr(ids);
89  spinorIn = dev_ptr[0];
90  spinorOut = dev_ptr[1];
91 
92 #endif
93 
94  // Do the solve here
95  StopWatch swatch1;
96  swatch1.reset();
97  swatch1.start();
98  invertQuda(spinorOut, spinorIn, (QudaInvertParam*)&quda_inv_param);
99  swatch1.stop();
100 
101  QDPIO::cout << "QUDA_"<<solver_string<<"_CLOVER_SOLVER: time="<< quda_inv_param.secs <<" s" ;
102  QDPIO::cout << "\tPerformance="<< quda_inv_param.gflops/quda_inv_param.secs<<" GFLOPS" ;
103  QDPIO::cout << "\tTotal Time (incl. load gauge)=" << swatch1.getTimeInSeconds() <<" s"<<std::endl;
104 
105  ret.n_count =quda_inv_param.iter;
106 
107  return ret;
108 
109  }
110 
111 
112 }
113 
114 
115 
116 // DEAD Test Code
117 #if 0
118  void* spinorIn =(void *)&(mod_chi.elem(rb[1].start()).elem(0).elem(0).real());
119  void* spinorOut =(void *)&(psi_s.elem(rb[0].start()).elem(0).elem(0).real());
120 
121  // OK Here I have a chance to test directly
122  // Even Target Checkerboard, No Dagger
123  psi_s = zero;
124  quda_inv_param.dslash_type = QUDA_CLOVER_WILSON_DSLASH; // Sets Clover Matrix
125  dslashQuda(spinorOut, spinorIn, &quda_inv_param, 0, 0);
126 
127 
128 
129  // Need to create a simple ferm state from the links_single...
130  Handle< FermState<T, Q, Q> > pstate(new PeriodicFermState<TF,QF,QF>(links_orig));
131  const AnisoParam_t& aniso = invParam.CloverParams.anisoParam;
132  QDPWilsonDslashT<T,Q,Q> qdp_dslash(pstate, aniso);
133 
134  T tmp,psi2;
135  tmp=zero;
136  psi2=zero;
137  // qdp_dslash.apply(psi2, mod_chi, PLUS, 0);
138  qdp_dslash.apply(tmp, mod_chi, PLUS, 0);
139  invclov.apply(psi2,tmp, PLUS, 0);
140 
141 
142  T r=zero;
143  r = psi2 - psi_s;
144 
145  QDPIO::cout << "CB=0" << std::endl;
146  QDPIO::cout << "Dslash Test: || r || = " << sqrt(norm2(r,rb[0])) << std::endl;
147  // QDPIO::cout << "Dslash Test: || r ||/|| psi || = " << sqrt(norm2(r,rb[0])/norm2(psi_s, rb[0])) << std::endl;
148 
149  QDPIO::cout << "CB=1: Should be zero" << std::endl;
150  QDPIO::cout << "Dslash Test: || r || = " << sqrt(norm2(r,rb[1])) << std::endl;
151  //QDPIO::cout << "Dslash Test: || r ||/|| psi || = " << sqrt(norm2(r,rb[1])/norm2(psi_s, rb[1])) << std::endl;
152 
153  const int* tab = rb[0].siteTable().slice();
154  for(int i=0; i < rb[0].numSiteTable(); i++) {
155  int j = tab[i];
156  bool printSite=false;
157 
158  for(int spin=0; spin < 4; spin++) {
159  for(int col=0; col < 3; col++) {
160  if( (fabs(r.elem(j).elem(spin).elem(col).real()) > 1.0e-5 )
161  || (fabs(r.elem(j).elem(spin).elem(col).imag()) > 1.0e-5 )) {
162  printSite=true;
163  }
164  }
165  }
166  if( printSite ) {
167 
168  for(int spin=0; spin < 4; spin++) {
169  for(int col=0; col < 3; col++) {
170  QDPIO::cout << "Site= " << j << " Spin= "<< spin << " Col= " << col << " spinor = ( "
171  << psi2.elem(j).elem(spin).elem(col).real() << " , "
172  << psi2.elem(j).elem(spin).elem(col).imag() << " )" << std::endl;
173  }
174  }
175  QDPIO::cout << std::endl;
176  }
177  }
178  QDP_abort(1);
179 #endif
Anisotropy parameters.
Support class for fermion actions and linear operators.
Definition: state.h:94
Class for counted reference semantics.
Definition: handle.h:33
static T & Instance()
Definition: singleton.h:432
Class for counted reference semantics.
unsigned j
Definition: ldumul_w.cc:35
unsigned i
Definition: ldumul_w.cc:34
Wilson Dslash linear operator.
Double tmp
Definition: meslate.cc:60
static bool registered
Local registration flag.
const std::string name
Name to be used.
bool registerAll()
Register all the factories.
LinOpSystemSolver< LatticeFermion > * createFerm(XMLReader &xml_in, const std::string &path, Handle< FermState< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > > state, Handle< LinearOperator< LatticeFermion > > A)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
@ PLUS
Definition: chromabase.h:45
A(A, psi, r, Ncb, PLUS)
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
multi1d< LatticeFermion > r(Ncb)
Periodic ferm state and a creator.
Register linop system solvers that solve M*psi=chi.
Solve a MdagM*psi=chi linear system by BiCGStab.
Factory for solving M*psi=chi where M is not hermitian or pos. def.
LatticeFermion T
Definition: t_clover.cc:11