CHROMA
syssolver_linop_nef_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 LinOpSysSolverQUDANEFEnv
23  {
24 
25  //! Anonymous namespace
26  namespace
27  {
28  //! Name to be used
29  const std::string name("QUDA_NEF_INVERTER");
30 
31  //! Local registration flag
32  bool registered = false;
33  }
34 
36  const std::string& path,
37  Handle< FermState< LatticeFermion, multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > > state,
38 
40  {
41  return new LinOpSysSolverQUDANEF(A, state,SysSolverQUDANEFParams(xml_in, path));
42  }
43 
44  //! Register all the factories
45  bool registerAll()
46  {
47  bool success = true;
48  if (! registered)
49  {
51  registered = true;
52  }
53  return success;
54  }
55  }
56 
57  SystemSolverResults_t LinOpSysSolverQUDANEF::qudaInvert(const multi1d<T>& chi_s, multi1d<T>& psi_s) const{
58 
59  SystemSolverResults_t ret;
60 
61  //size of field to copy. it is only half the field, since preconditioning is running
62  const multi1d<int>& latdims = Layout::subgridLattSize();
63  int halfsize=latdims[0]*latdims[1]*latdims[2]*latdims[3]/2;
64  int fermsize=halfsize*Nc*Ns*2;
65 
66  REAL* spinorIn = new REAL[quda_inv_param.Ls*fermsize];
67  REAL* spinorOut = new REAL[quda_inv_param.Ls*fermsize];
68  memset(reinterpret_cast<char*>(spinorIn), 0, fermsize*quda_inv_param.Ls*sizeof(REAL));
69  memset(reinterpret_cast<char*>(spinorOut), 0, fermsize*quda_inv_param.Ls*sizeof(REAL));
70 
71  //copy negative parity
72 #ifndef BUILD_QUDA_DEVIFACE_SPINOR
73  for(unsigned int s=0; s<quda_inv_param.Ls; s++){
74  memcpy(reinterpret_cast<char*>(&spinorIn[fermsize*s]),reinterpret_cast<char*>(const_cast<REAL*>(&(chi_s[s].elem(rb[1].start()).elem(0).elem(0).real()))),fermsize*sizeof(REAL));
75  }
76 #else
77  //not yet
78  //for(unsigned int s=0; s<quda_inv_param.Ls; s++){
79  // spinorIn[s]=GetMemoryPtr( chi_s[s].getId() );
80  // spinorOut[s]=GetMemoryPtr( psi_s[s].getId() );
81  //}
82 #endif
83 
84  // Do the solve here
85  StopWatch swatch1;
86  swatch1.reset();
87  swatch1.start();
88  invertQuda(reinterpret_cast<void*>(spinorOut), reinterpret_cast<void*>(spinorIn), (QudaInvertParam*)&quda_inv_param);
89  swatch1.stop();
90 
91  //copy result
92  psi_s.resize(quda_inv_param.Ls);
93  psi_s = zero;
94 
95 #ifndef BUILD_QUDA_DEVIFACE_SPINOR
96  for(unsigned int s=0; s<quda_inv_param.Ls; s++){
97  // memset(reinterpret_cast<char*>(&(psi_s[s].elem(all.start()).elem(0).elem(0).real())),0,fermsize*2*sizeof(REAL));
98  memcpy(reinterpret_cast<char*>(const_cast<REAL*>(&(psi_s[s].elem(rb[1].start()).elem(0).elem(0).real()))),reinterpret_cast<char*>(&spinorOut[fermsize*s]),fermsize*sizeof(REAL));
99  }
100 #else
101  //not yet implemented
102  //for(unsigned int s=0; s<quda_inv_param.Ls; s++){
103  // spinorIn[s]=GetMemoryPtr( chi_s[s].getId() );
104  // spinorOut[s]=GetMemoryPtr( psi_s[s].getId() );
105  //}
106 #endif
107 
108  //clean up
109  delete [] spinorIn;
110  delete [] spinorOut;
111  QDPIO::cout << "Norm2 psi = " << norm2(psi_s, rb[1]) << std::endl;
112 
113  QDPIO::cout << "QUDA_" << solver_string << "_NEF_SOLVER: time=" << quda_inv_param.secs << " s" ;
114  QDPIO::cout << "\tPerformance="<< quda_inv_param.gflops/quda_inv_param.secs<<" GFLOPS" ;
115  QDPIO::cout << "\tTotal Time (incl. load gauge)=" << swatch1.getTimeInSeconds() <<" s"<<std::endl;
116 
117  ret.n_count =quda_inv_param.iter;
118 
119  return ret;
120 
121  }
122 
123 
124 }
Anisotropy parameters.
Support class for fermion actions and linear operators.
Definition: state.h:94
Class for counted reference semantics.
Definition: handle.h:33
Linear Operator to arrays.
Definition: linearop.h:61
static T & Instance()
Definition: singleton.h:432
4D Even Odd preconditioned NEF domain-wall fermion linear operator
Class for counted reference semantics.
static bool registered
Local registration flag.
const std::string name
Name to be used.
LinOpSystemSolverArray< LatticeFermion > * createFerm(XMLReader &xml_in, const std::string &path, Handle< FermState< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > > state, Handle< LinearOperatorArray< LatticeFermion > > A)
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
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
multi1d< LatticeFermion > s(Ncb)
::std::string string
Definition: gtest.h:1979
Periodic ferm state and a creator.
Register linop system solvers that solve M*psi=chi.
Factory for solving M*psi=chi where M is not hermitian or pos. def.
Solve a MdagM*psi=chi linear system by BiCGStab.