CHROMA
lwldslash_w_pab.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Wilson Dslash linear operator
3  */
4 
5 #include "chromabase.h"
6 #include "chroma_config.h"
8 
9 #include <wfm.h>
10 
11 namespace Chroma
12 {
13  namespace PABDslashEnv {
14  int refcount = 0;
15  };
16 
17  //! Empty constructor
19 
20  //! Full constructor
22  {
23  create(state);
24  }
25 
26  //! Full constructor with anisotropy
28  const AnisoParam_t& aniso_)
29  {
30  create(state, aniso_);
31  }
32 
33  //! Full constructor with general coefficients
35  const multi1d<Real>& coeffs_)
36  {
37  create(state, coeffs_);
38  }
39 
40 
41  //! Creation routine
43  {
44  multi1d<Real> cf(Nd);
45  cf = 1.0;
46  create(state, cf);
47  }
48 
49  //! Creation routine with anisotropy
51  const AnisoParam_t& anisoParam)
52  {
53  START_CODE();
54 
55  create(state, makeFermCoeffs(anisoParam));
56 
57  END_CODE();
58  }
59 
60  //! Full constructor with general coefficients
62  const multi1d<Real>& coeffs_)
63  {
64  START_CODE();
65 
66  // Save a copy of the aniso params original fields and with aniso folded in
67  coeffs = coeffs_;
68 
69  // Save a copy of the fermbc
70  fbc = state->getFermBC();
71 
72  // Sanity check
73  if (fbc.operator->() == 0)
74  {
75  QDPIO::cerr << "PABWilsonDslash: error: fbc is null" << std::endl;
76  QDP_abort(1);
77  }
78 
79  // Fold in anisotropy
80  multi1d<LatticeColorMatrix> u = state->getLinks();
81 
82  // Rescale the u fields by the anisotropy
83  for(int mu=0; mu < u.size(); ++mu)
84  {
85  u[mu] *= coeffs[mu];
86  }
87 
88  // Rearrange the gauge
89  // Allocate the packed gauge
90  // Now use the QDP allocator system which calls qalloc on QCDOC
91  bool got_fast=true;
92  try {
94  QDP::Allocator::theQDPAllocator::Instance().allocate(
95  Nd*sizeof(PrimitiveSU3Matrix)*Layout::sitesOnNode(),
96  QDP::Allocator::FAST);
97  }
98  catch(std::bad_alloc ) {
99  got_fast = false;
100  }
101 
102  if( got_fast == false ) {
103  try {
105  QDP::Allocator::theQDPAllocator::Instance().allocate(
106  Nd*sizeof(PrimitiveSU3Matrix)*Layout::sitesOnNode(),
108  }
109  catch(std::bad_alloc ) {
110  QDPIO::cerr << "Unable to allocate memory for packed array in lwldslash_w_pab.cc line 65" << std::endl << std::flush;
111  QDP_abort(1);
112  }
113  }
114 
115  // Pack the gauge field.
116  int volume=Layout::sitesOnNode();
117  for(int ix=0; ix < volume; ix++) {
118  for(int mu=0; mu < 4; mu++) {
119  packed_gauge[4*ix + mu] = transpose(u[mu].elem(ix).elem());
120  }
121  }
122 
123  wil_cbsize=Layout::sitesOnNode()/2;
124 
125  // If the refcount is 0 -- Init the Vector (both dslash-es)
126  if ( PABDslashEnv::refcount == 0 ) {
127  // I probably need the local size here...
128  const multi1d<int>& lsize= Layout::subgridLattSize();
129  const multi1d<int>& machsize = Layout::logicalSize();
130 
131  // Set up the wilson thingie
132  for(int i = 0; i < Nd; i++) {
133  wil.local_latt[i] = lsize[i];
134 
135  if( machsize[i] == 1 ) {
136  wil.local_comm[i] = 1;
137 
138  }
139  else {
140  wil.local_comm[i] = 0;
141  }
142  }
143 
144 #ifdef CHROMA_USE_SLOPPY_BAGEL_DSLASH
145  wil.BGL = true;
146  wil.SloppyPrecision = true;
147 #endif
148 
149  // Init the OP
150  wfm_vec_init(&wil);
151 #ifdef CHROMA_WFM_NO_END
152  // Refcount is a lock variable
153  // to control instantiation
155 #endif
156  }
157 
158 #ifndef CHROMA_WFM_NO_END
159  // Always increase the refcount
161 #endif
162 
163  END_CODE();
164  }
165 
166 
168  {
169 
170 #ifndef CHROMA_WFM_NO_END
171  // Only deal with refcount decreases if the refcount is at least 1
172  if( PABDslashEnv::refcount > 0 ) {
173 
174  // Always decrease the refcount
176  if( PABDslashEnv::refcount == 0 ) {
177  // Only call free when refcount ==0
178  wfm_vec_end(&wil);
179  }
180  }
181 #endif
182 
183  QDP::Allocator::theQDPAllocator::Instance().free(packed_gauge);
184  }
185 
186  //! Apply Wilson-Dirac dslash
187  /*! \ingroup linop
188  * Wilson dslash
189 
190  * Arguments:
191  *
192  * \param chi Result (Write)
193  * \param psi Pseudofermion field (Read)
194  * \param isign D'^dag or D' ( MINUS | PLUS ) resp. (Read)
195  * \param cb Checkerboard of OUTPUT std::vector (Read)
196  */
197  void
198  PABWilsonDslash::apply (LatticeFermion& chi, const LatticeFermion& psi,
199  enum PlusMinus isign, int cb) const
200  {
201  START_CODE();
202 
203  /* Pass the right parities.
204  *
205  * SZIN standard is that cb is cb of INPUT
206  * Chroma standard is that the cb is cb of OUTPUT
207  *
208  * Need to invert cb for SZIN style SSE call
209 
210  *
211  *
212  * Pass all the fermion and all the gauge pieces
213  *
214  * NOTE: this breaks usage from SZIN. However, Chroma and SSE dslash can handle
215  * odd subgrid lattice sizes, whereas SZIN cannot. Thus, I must pass all fermion
216  * cbs to support such flexibility.
217  *
218  */
219  /* sse_su3dslash_wilson((SSEREAL *)&(packed_gauge[0]),
220  (SSEREAL *)&(psi.elem(0).elem(0).elem(0).real()),
221  (SSEREAL *)&(chi.elem(0).elem(0).elem(0).real()),
222  (int)isign, (1-cb));
223  */
224 
225  wfm_dslash((Float *)&(chi.elem(wil_cbsize*(cb)).elem(0).elem(0).real()),
226  (Float *)&(packed_gauge[0]),
227  (Float *)&(psi.elem(wil_cbsize*(1-cb)).elem(0).elem(0).real()),
228  1-cb,
229  (isign == (enum PlusMinus)PLUS ? 0 : 1));
230 
231  getFermBC().modifyF(chi, rb[cb]);
232 
233  END_CODE();
234  }
235 
236 }; // End Namespace Chroma
237 
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
~PABWilsonDslash()
No real need for cleanup here.
PABWilsonDslash()
Empty constructor. Must use create later.
void create(Handle< FermState< T, P, Q > > state)
Creation routine.
PrimitiveSU3Matrix * packed_gauge
Handle< FermBC< T, P, Q > > fbc
const FermBC< T, P, Q > & getFermBC() const
Return the fermion BC object for this linear operator.
int mu
Definition: cool.cc:24
void apply(LatticeFermion &chi, const LatticeFermion &psi, enum PlusMinus isign, int cb) const
Apply Wilson-Dirac dslash.
Wilson Dslash linear operator.
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
void transpose(multi2d< LatticeColorVector > &dist_rep, const multi2d< LatticeColorVector > &prop_rep)
Take transpose of a matrix in (explicit) spin space.
int i
Definition: pbg5p_w.cc:55
@ PLUS
Definition: chromabase.h:45
multi1d< LatticeFermion > chi(Ncb)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
PColorMatrix< RComplex< REAL >, Nc > PrimitiveSU3Matrix
START_CODE()
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
FloatingPoint< float > Float
Definition: gtest.h:7350
Parameters for anisotropy.
Definition: aniso_io.h:24