Grid 0.7.0
NaiveStaggeredFermionImplementation.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/action/fermion/ImprovedStaggeredFermion.cc
6
7Copyright (C) 2015
8
9Author: Azusa Yamaguchi, Peter Boyle
10
11This program is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2 of the License, or
14(at your option) any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License along
22with this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25See the full license in the file "LICENSE" in the top level distribution
26directory
27*************************************************************************************/
28/* END LEGAL */
29#include <Grid/Grid.h>
30
31#pragma once
32
34
36// Constructor and gauge import
38
39template <class Impl>
41 RealD _mass,
42 RealD _c1, RealD _u0,
43 const ImplParams &p)
44 : Kernels(p),
45 _grid(&Fgrid),
46 _cbgrid(&Hgrid),
48 StencilEven(&Hgrid, npoint, Even, directions, displacements,p), // source is Even
49 StencilOdd(&Hgrid, npoint, Odd, directions, displacements,p), // source is Odd
50 mass(_mass),
51 Umu(&Fgrid),
52 UmuEven(&Hgrid),
53 UmuOdd(&Hgrid),
54 _tmp(&Hgrid)
55{
56 int vol4;
57 int LLs=1;
58 c1=_c1;
59 u0=_u0;
60 vol4= _grid->oSites();
61 Stencil.BuildSurfaceList(LLs,vol4);
62 vol4= _cbgrid->oSites();
63 StencilEven.BuildSurfaceList(LLs,vol4);
64 StencilOdd.BuildSurfaceList(LLs,vol4);
65}
66
67template <class Impl>
69 GridRedBlackCartesian &Hgrid, RealD _mass,
70 RealD _c1, RealD _u0,
71 const ImplParams &p)
72 : NaiveStaggeredFermion(Fgrid,Hgrid,_mass,_c1,_u0,p)
73{
74 ImportGauge(_U);
75}
76
78// Momentum space propagator should be
79// https://arxiv.org/pdf/hep-lat/9712010.pdf
80//
81// mom space action.
82// gamma_mu i ( c1 sin pmu + c2 sin 3 pmu ) + m
83//
84// must track through staggered flavour/spin reduction in literature to
85// turn to free propagator for the one component chi field, a la page 4/5
86// of above link to implmement fourier based solver.
88
89template <class Impl>
95template <class Impl>
97{
98 GaugeLinkField U(GaugeGrid());
99 DoubledGaugeField _UUU(GaugeGrid());
101 // Double Store should take two fields for Naik and one hop separately.
102 // Discard teh Naik as Naive
104 Impl::DoubleStore(GaugeGrid(), _UUU, Umu, _U, _U );
105
107 // Apply scale factors to get the right fermion Kinetic term
108 // Could pass coeffs into the double store to save work.
109 // 0.5 ( U p(x+mu) - Udag(x-mu) p(x-mu) )
111 for (int mu = 0; mu < Nd; mu++) {
112
114 PokeIndex<LorentzIndex>(Umu, U*( 0.5*c1/u0), mu );
115
117 PokeIndex<LorentzIndex>(Umu, U*(-0.5*c1/u0), mu+4);
118
119 }
120
122}
123
125// Implement the interface
127
128template <class Impl>
129void NaiveStaggeredFermion<Impl>::M(const FermionField &in, FermionField &out) {
130 out.Checkerboard() = in.Checkerboard();
131 Dhop(in, out, DaggerNo);
132 axpy(out, mass, in, out);
133}
134
135template <class Impl>
136void NaiveStaggeredFermion<Impl>::Mdag(const FermionField &in, FermionField &out) {
137 out.Checkerboard() = in.Checkerboard();
138 Dhop(in, out, DaggerYes);
139 axpy(out, mass, in, out);
140}
141
142template <class Impl>
143void NaiveStaggeredFermion<Impl>::Meooe(const FermionField &in, FermionField &out) {
144 if (in.Checkerboard() == Odd) {
145 DhopEO(in, out, DaggerNo);
146 } else {
147 DhopOE(in, out, DaggerNo);
148 }
149}
150template <class Impl>
151void NaiveStaggeredFermion<Impl>::MeooeDag(const FermionField &in, FermionField &out) {
152 if (in.Checkerboard() == Odd) {
153 DhopEO(in, out, DaggerYes);
154 } else {
155 DhopOE(in, out, DaggerYes);
156 }
157}
158
159template <class Impl>
160void NaiveStaggeredFermion<Impl>::Mooee(const FermionField &in, FermionField &out) {
161 out.Checkerboard() = in.Checkerboard();
162 typename FermionField::scalar_type scal(mass);
163 out = scal * in;
164}
165
166template <class Impl>
167void NaiveStaggeredFermion<Impl>::MooeeDag(const FermionField &in, FermionField &out) {
168 out.Checkerboard() = in.Checkerboard();
169 Mooee(in, out);
170}
171
172template <class Impl>
173void NaiveStaggeredFermion<Impl>::MooeeInv(const FermionField &in, FermionField &out) {
174 out.Checkerboard() = in.Checkerboard();
175 out = (1.0 / (mass)) * in;
176}
177
178template <class Impl>
179void NaiveStaggeredFermion<Impl>::MooeeInvDag(const FermionField &in, FermionField &out)
180{
181 out.Checkerboard() = in.Checkerboard();
182 MooeeInv(in, out);
183}
184
186// Internal
188
189template <class Impl>
190void NaiveStaggeredFermion<Impl>::DerivInternal(StencilImpl &st, DoubledGaugeField &U,
191 GaugeField & mat,
192 const FermionField &A, const FermionField &B, int dag)
193{
194 assert((dag == DaggerNo) || (dag == DaggerYes));
195
196 Compressor compressor;
197
198 FermionField Btilde(B.Grid());
199 FermionField Atilde(B.Grid());
200 Atilde = A;
201
202 st.HaloExchange(B, compressor);
203
204 for (int mu = 0; mu < Nd; mu++) {
205
207 // Call the single hop
209 autoView( U_v , U, CpuRead);
210 autoView( B_v , B, CpuWrite);
211 autoView( Btilde_v , Btilde, CpuWrite);
212 thread_for(sss,B.Grid()->oSites(),{
213 Kernels::DhopDirKernel(st, U_v, U_v, st.CommBuf(), sss, sss, B_v, Btilde_v, mu,1);
214 });
215
216 assert(0);// need to figure out the force interface with a blasted three link term.
217
218 }
219}
220
221template <class Impl>
222void NaiveStaggeredFermion<Impl>::DhopDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) {
223
224 conformable(U.Grid(), _grid);
225 conformable(U.Grid(), V.Grid());
226 conformable(U.Grid(), mat.Grid());
227
228 mat.Checkerboard() = U.Checkerboard();
229
230 DerivInternal(Stencil, Umu, mat, U, V, dag);
231}
232
233template <class Impl>
234void NaiveStaggeredFermion<Impl>::DhopDerivOE(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) {
235
236 conformable(U.Grid(), _cbgrid);
237 conformable(U.Grid(), V.Grid());
238 conformable(U.Grid(), mat.Grid());
239
240 assert(V.Checkerboard() == Even);
241 assert(U.Checkerboard() == Odd);
242 mat.Checkerboard() = Odd;
243
244 DerivInternal(StencilEven, UmuOdd, mat, U, V, dag);
245}
246
247template <class Impl>
248void NaiveStaggeredFermion<Impl>::DhopDerivEO(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) {
249
250 conformable(U.Grid(), _cbgrid);
251 conformable(U.Grid(), V.Grid());
252 conformable(U.Grid(), mat.Grid());
253
254 assert(V.Checkerboard() == Odd);
255 assert(U.Checkerboard() == Even);
256 mat.Checkerboard() = Even;
257
258 DerivInternal(StencilOdd, UmuEven, mat, U, V, dag);
259}
260
261template <class Impl>
262void NaiveStaggeredFermion<Impl>::Dhop(const FermionField &in, FermionField &out, int dag)
263{
264 conformable(in.Grid(), _grid); // verifies full grid
265 conformable(in.Grid(), out.Grid());
266
267 out.Checkerboard() = in.Checkerboard();
268
269 DhopInternal(Stencil, Umu, in, out, dag);
270}
271
272template <class Impl>
273void NaiveStaggeredFermion<Impl>::DhopOE(const FermionField &in, FermionField &out, int dag)
274{
275 conformable(in.Grid(), _cbgrid); // verifies half grid
276 conformable(in.Grid(), out.Grid()); // drops the cb check
277
278 assert(in.Checkerboard() == Even);
279 out.Checkerboard() = Odd;
280
281 DhopInternal(StencilEven, UmuOdd, in, out, dag);
282}
283
284template <class Impl>
285void NaiveStaggeredFermion<Impl>::DhopEO(const FermionField &in, FermionField &out, int dag)
286{
287 conformable(in.Grid(), _cbgrid); // verifies half grid
288 conformable(in.Grid(), out.Grid()); // drops the cb check
289
290 assert(in.Checkerboard() == Odd);
291 out.Checkerboard() = Even;
292
293 DhopInternal(StencilOdd, UmuEven, in, out, dag);
294}
295
296template <class Impl>
297void NaiveStaggeredFermion<Impl>::Mdir(const FermionField &in, FermionField &out, int dir, int disp)
298{
299 DhopDir(in, out, dir, disp);
300}
301template <class Impl>
302void NaiveStaggeredFermion<Impl>::MdirAll(const FermionField &in, std::vector<FermionField> &out)
303{
304 assert(0); // Not implemented yet
305}
306
307template <class Impl>
308void NaiveStaggeredFermion<Impl>::DhopDir(const FermionField &in, FermionField &out, int dir, int disp)
309{
310
311 Compressor compressor;
312 Stencil.HaloExchange(in, compressor);
313 autoView( Umu_v , Umu, CpuRead);
314 autoView( in_v , in, CpuRead);
315 autoView( out_v , out, CpuWrite);
316 // thread_for( sss, in.Grid()->oSites(),{
317 // Kernels::DhopDirKernel(Stencil, Umu_v, Stencil.CommBuf(), sss, sss, in_v, out_v, dir, disp);
318 // });
319 assert(0);
320};
321
322
323template <class Impl>
325 DoubledGaugeField &U,
326 const FermionField &in,
327 FermionField &out, int dag)
328{
330 DhopInternalOverlappedComms(st,U,in,out,dag);
331 else
332 DhopInternalSerialComms(st,U,in,out,dag);
333}
334template <class Impl>
336 DoubledGaugeField &U,
337 const FermionField &in,
338 FermionField &out, int dag)
339{
340 Compressor compressor;
341 int len = U.Grid()->oSites();
342
343 st.Prepare();
344 st.HaloGather(in,compressor);
345
346 std::vector<std::vector<CommsRequest_t> > requests;
347 st.CommunicateBegin(requests);
348
349 st.CommsMergeSHM(compressor);
350
352 // Removed explicit thread comms
354 {
355 int interior=1;
356 int exterior=0;
357 Kernels::DhopNaive(st,U,in,out,dag,interior,exterior);
358 }
359
360 st.CommunicateComplete(requests);
361
362 // First to enter, last to leave timing
363 st.CommsMerge(compressor);
364
365 {
366 int interior=0;
367 int exterior=1;
368 Kernels::DhopNaive(st,U,in,out,dag,interior,exterior);
369 }
370}
371
372template <class Impl>
374 DoubledGaugeField &U,
375 const FermionField &in,
376 FermionField &out, int dag)
377{
378 assert((dag == DaggerNo) || (dag == DaggerYes));
379
380 Compressor compressor;
381 st.HaloExchange(in, compressor);
382
383 {
384 int interior=1;
385 int exterior=1;
386 Kernels::DhopNaive(st,U,in,out,dag,interior,exterior);
387 }
388};
389
391// Conserved current - not yet implemented.
393template <class Impl>
395 PropagatorField &q_in_2,
396 PropagatorField &q_out,
397 PropagatorField &src,
398 Current curr_type,
399 unsigned int mu)
400{
401 assert(0);
402}
403
404template <class Impl>
406 PropagatorField &q_out,
407 PropagatorField &src,
408 Current curr_type,
409 unsigned int mu,
410 unsigned int tmin,
411 unsigned int tmax,
412 ComplexField &lattice_cmplx)
413{
414 assert(0);
415
416}
417
static const int Even
static const int Odd
B
void axpy(Lattice< vobj > &ret, sobj a, const Lattice< vobj > &x, const Lattice< vobj > &y)
void conformable(const Lattice< obj1 > &lhs, const Lattice< obj2 > &rhs)
void PokeIndex(Lattice< vobj > &lhs, const Lattice< decltype(peekIndex< Index >(vobj(), 0))> &rhs, int i)
auto PeekIndex(const Lattice< vobj > &lhs, int i) -> Lattice< decltype(peekIndex< Index >(vobj(), i))>
void pickCheckerboard(int cb, Lattice< vobj > &half, const Lattice< vobj > &full)
#define autoView(l_v, l, mode)
@ CpuRead
@ CpuWrite
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
static constexpr int DaggerYes
Definition QCD.h:70
static constexpr int Nd
Definition QCD.h:52
static constexpr int DaggerNo
Definition QCD.h:69
double RealD
Definition Simd.h:61
#define thread_for(i, num,...)
Definition Threads.h:60
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
static const std::vector< int > directions
static const std::vector< int > displacements
StaggeredKernels< Impl > Kernels
void DhopInternal(StencilImpl &st, DoubledGaugeField &U, const FermionField &in, FermionField &out, int dag)
void MooeeDag(const FermionField &in, FermionField &out)
void MdirAll(const FermionField &in, std::vector< FermionField > &out)
void Dhop(const FermionField &in, FermionField &out, int dag)
void DhopInternalOverlappedComms(StencilImpl &st, DoubledGaugeField &U, const FermionField &in, FermionField &out, int dag)
void DhopDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag)
void M(const FermionField &in, FermionField &out)
void DhopDerivOE(GaugeField &mat, const FermionField &U, const FermionField &V, int dag)
void SeqConservedCurrent(PropagatorField &q_in, PropagatorField &q_out, PropagatorField &srct, Current curr_type, unsigned int mu, unsigned int tmin, unsigned int tmax, ComplexField &lattice_cmplx)
void DhopOE(const FermionField &in, FermionField &out, int dag)
void DhopEO(const FermionField &in, FermionField &out, int dag)
void DhopDir(const FermionField &in, FermionField &out, int dir, int disp)
NaiveStaggeredFermion(GaugeField &_U, GridCartesian &Fgrid, GridRedBlackCartesian &Hgrid, RealD _mass, RealD _c1, RealD _u0, const ImplParams &p=ImplParams())
void Mdag(const FermionField &in, FermionField &out)
void DhopDerivEO(GaugeField &mat, const FermionField &U, const FermionField &V, int dag)
void MooeeInv(const FermionField &in, FermionField &out)
void MeooeDag(const FermionField &in, FermionField &out)
void MooeeInvDag(const FermionField &in, FermionField &out)
void DhopInternalSerialComms(StencilImpl &st, DoubledGaugeField &U, const FermionField &in, FermionField &out, int dag)
void DerivInternal(StencilImpl &st, DoubledGaugeField &U, GaugeField &mat, const FermionField &A, const FermionField &B, int dag)
void Mooee(const FermionField &in, FermionField &out)
void ContractConservedCurrent(PropagatorField &q_in_1, PropagatorField &q_in_2, PropagatorField &q_out, PropagatorField &src, Current curr_type, unsigned int mu)
void Meooe(const FermionField &in, FermionField &out)
void Mdir(const FermionField &in, FermionField &out, int dir, int disp)
void DhopNaive(StencilImpl &st, DoubledGaugeField &U, const FermionField &in, FermionField &out, int dag, int interior, int exterior)