CHROMA
lwldslash_w_cppd.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Wilson Dslash linear operator
3  */
4 
5 #include "chromabase.h"
7 #include "cpp_dslash.h"
8 #include "cpp_dslash_qdp_packer.h"
9 
10 
11 
12 using namespace CPlusPlusWilsonDslash;
13 
14 namespace Chroma
15 {
16  //! Initialization routine
18  {
19  // Initialize internal structures for DSLASH
20 #if 0
21  QDPIO::cout << "Calling init_sse_su3dslash()... " << std::endl;
22 #endif
23 
24 
25  // Initialize using the total problem size
26  D=new Dslash<double>(Layout::lattSize().slice(),
27  Layout::QDPXX_getSiteCoords,
28  Layout::QDPXX_getLinearSiteIndex,
29  Layout::QDPXX_nodeNumber);
30 
31  }
32 
33 
34  //! Empty constructor
35  CPPWilsonDslashD::CPPWilsonDslashD()
36 #ifndef CHROMA_STATIC_PACKED_GAUGE
37  : packed_gauge(nullptr)
38 #endif
39  {
40 
41  init();
42  }
43 
44  //! Full constructor
45  CPPWilsonDslashD::CPPWilsonDslashD(Handle< FermState<T,P,Q> > state)
46 #ifndef CHROMA_STATIC_PACKED_GAUGE
47  : packed_gauge(nullptr)
48 #endif
49  {
50  init();
51  create(state);
52  }
53 
54  //! Full constructor with anisotropy
55  CPPWilsonDslashD::CPPWilsonDslashD(Handle< FermState<T,P,Q> > state,
56  const AnisoParam_t& aniso_)
57 #ifndef CHROMA_STATIC_PACKED_GAUGE
58  : packed_gauge(nullptr)
59 #endif
60  {
61  init();
62  create(state, aniso_);
63  }
64 
65  //! Full constructor with general coefficients
66  CPPWilsonDslashD::CPPWilsonDslashD(Handle< FermState<T,P,Q> > state,
67  const multi1d<Real>& coeffs_)
68 #ifndef CHROMA_STATIC_PACKED_GAUGE
69  : packed_gauge(nullptr)
70 #endif
71  {
72  init();
73  create(state, coeffs_);
74  }
75 
76  //! Creation routine
77  void CPPWilsonDslashD::create(Handle< FermState<T,P,Q> > state)
78  {
79  multi1d<Real> cf(Nd);
80  cf = 1.0;
81  create(state, cf);
82  }
83 
84  //! Creation routine with anisotropy
85  void CPPWilsonDslashD::create(Handle< FermState<T,P,Q> > state,
86  const AnisoParam_t& anisoParam)
87  {
88  START_CODE();
89 
90  create(state, makeFermCoeffs(anisoParam));
91 
92  END_CODE();
93  }
94 
95  //! Full constructor with general coefficients
96  void CPPWilsonDslashD::create(Handle< FermState<T,P,Q> > state,
97  const multi1d<Real>& coeffs_)
98  {
99  START_CODE();
100 
101  // Save a copy of the aniso params original fields and with aniso folded in
102  coeffs = coeffs_;
103 
104  // Save a copy of the fermbc
105  fbc = state->getFermBC();
106 
107  // Sanity check
108  if (fbc.operator->() == 0)
109  {
110  QDPIO::cerr << "CPPWilsonDslashD: error: fbc is null" << std::endl;
111  QDP_abort(1);
112  }
113 
114  // Fold in anisotropy
115  multi1d<LatticeColorMatrixD> u = state->getLinks();
116 
117  // Rescale the u fields by the anisotropy
118  for(int mu=0; mu < u.size(); ++mu)
119  {
120  u[mu] *= coeffs[mu];
121  }
122 
123  // Pack the gauge fields
124  //packed_gauge.resize( Nd * Layout::sitesOnNode() );
125  // Allocate as a pointer -- In the case of static allocation
126  // Always allocate if null. If the packed gauge is static, it will not be null after the first allocation.
127  if ( packed_gauge == nullptr ) {
128  packed_gauge = (PrimitiveSU3MatrixD*)QDP::Allocator::theQDPAllocator::Instance().allocate( Layout::sitesOnNode()*Nd*sizeof(PrimitiveSU3MatrixD),
130  if( packed_gauge == nullptr ) {
131  QDPIO::cout << "Failed to allocate packed gauge in CPP_Dslash " <<std::endl;
132  QDP_abort(1);
133  }
134  }
135 
136 #if 0
137  QDPIO::cout << "Done " << std::endl << std::flush;
138 
139  QDPIO::cout << "Calling pack_gauge_field..." << std::flush;
140 #endif
141 
142  qdp_pack_gauge(u, packed_gauge);
143 
144 #if 0
145  QDPIO::cout << "Done" << std::endl << std::flush;
146 #endif
147 
148  END_CODE();
149  }
150 
151 
152  CPPWilsonDslashD::~CPPWilsonDslashD()
153  {
154  START_CODE();
155 
156 #ifndef CHROMA_STATIC_PACKED_GAUGE
157  QDP::Allocator::theQDPAllocator::Instance().free(packed_gauge);
158 #endif
159 
160  END_CODE();
161  }
162 
163  //! General Wilson-Dirac dslash
164  /*! \ingroup linop
165  * Wilson dslash
166  *
167  * Arguments:
168  *
169  * \param chi Result (Write)
170  * \param psi Pseudofermion field (Read)
171  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
172  * \param cb Checkerboard of OUTPUT std::vector (Read)
173  */
174  void
175  CPPWilsonDslashD::apply (T& chi, const T& psi,
176  enum PlusMinus isign, int cb) const
177  {
178  START_CODE();
179 
180  /* Pass the right parities.
181  *
182  * SZIN standard is that cb is cb of INPUT
183  * Chroma standard is that the cb is cb of OUTPUT
184  *
185  * Need to invert cb for SZIN style SSE call
186 
187  *
188  *
189  * Pass all the fermion and all the gauge pieces
190  *
191  * NOTE: this breaks usage from SZIN. However, Chroma and SSE dslash can handle
192  * odd subgrid lattice sizes, whereas SZIN cannot. Thus, I must pass all fermion
193  * cbs to support such flexibility.
194  *
195  */
196  int source_cb = 1 - cb;
197  int target_cb = cb;
198  int cbsites = QDP::Layout::sitesOnNode()/2;
199 
200 
201  (*D)((double *)&(chi.elem(all.start()).elem(0).elem(0).real()),
202  (double *)&(psi.elem(all.start()).elem(0).elem(0).real()),
203  (double *)&(packed_gauge[0]),
204  isign,
205  source_cb);
206 
207  // sse_su3dslash_wilson((SSEREAL *)&(packed_gauge[0]),
208  // (SSEREAL *)&(psi.elem(0).elem(0).elem(0).real()),
209  // (SSEREAL *)&(chi.elem(0).elem(0).elem(0).real()),
210  // (int)isign, source_cb);
211 
212  getFermBC().modifyF(chi, QDP::rb[cb]);
213 
214  END_CODE();
215  }
216 
217 } // End Namespace Chroma
218 
Primary include file for CHROMA library code.
#define END_CODE()
Definition: chromabase.h:65
#define START_CODE()
Definition: chromabase.h:64
Support class for fermion actions and linear operators.
Definition: state.h:94
Class for counted reference semantics.
Definition: handle.h:33
int mu
Definition: cool.cc:24
Wilson Dslash linear operator.
Nd
Definition: meslate.cc:74
void init(MesonSpecData_t &data, XMLWriter &xml, const std::string &path, const std::string &id_tag, const Params &params)
Do some initialization.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
int cb
Definition: invbicg.cc:120
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
multi1d< Real > makeFermCoeffs(const AnisoParam_t &aniso)
Make fermion coefficients.
Definition: aniso_io.cc:63
chi
Definition: pade_trln_w.cc:24
psi
Definition: pade_trln_w.cc:191
Parameters for anisotropy.
Definition: aniso_io.h:24