Grid 0.7.0
ImprovedStaggeredFermion5DImplementation.h
Go to the documentation of this file.
1/*************************************************************************************
2
3 Grid physics library, www.github.com/paboyle/Grid
4
5 Source file: ./lib/qcd/action/fermion/ImprovedStaggeredFermion5D.cc
6
7 Copyright (C) 2015
8
9Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
10Author: Peter Boyle <paboyle@ph.ed.ac.uk>
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License along
23 with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25
26 See the full license in the file "LICENSE" in the top level distribution directory
27*************************************************************************************/
28/* END LEGAL */
32
33#pragma once
34
36
37// 5d lattice for DWF.
38template<class Impl>
40 GridRedBlackCartesian &FiveDimRedBlackGrid,
41 GridCartesian &FourDimGrid,
42 GridRedBlackCartesian &FourDimRedBlackGrid,
43 RealD _mass,
44 RealD _c1,RealD _c2, RealD _u0,
45 const ImplParams &p) :
46 Kernels(p),
47 _FiveDimGrid (&FiveDimGrid),
48 _FiveDimRedBlackGrid(&FiveDimRedBlackGrid),
49 _FourDimGrid (&FourDimGrid),
50 _FourDimRedBlackGrid(&FourDimRedBlackGrid),
52 StencilEven(&FiveDimRedBlackGrid,npoint,Even,directions,displacements,p), // source is Even
53 StencilOdd (&FiveDimRedBlackGrid,npoint,Odd ,directions,displacements,p), // source is Odd
54 mass(_mass),
55 c1(_c1),
56 c2(_c2),
57 u0(_u0),
58 Umu(&FourDimGrid),
59 UmuEven(&FourDimRedBlackGrid),
60 UmuOdd (&FourDimRedBlackGrid),
61 UUUmu(&FourDimGrid),
62 UUUmuEven(&FourDimRedBlackGrid),
63 UUUmuOdd(&FourDimRedBlackGrid),
64 _tmp(&FiveDimRedBlackGrid)
65{
66
67 // some assertions
68 assert(FiveDimGrid._ndimension==5);
69 assert(FourDimGrid._ndimension==4);
70 assert(FourDimRedBlackGrid._ndimension==4);
71 assert(FiveDimRedBlackGrid._ndimension==5);
72 assert(FiveDimRedBlackGrid._checker_dim==1); // Don't checker the s direction
73
74 // extent of fifth dim and not spread out
75 Ls=FiveDimGrid._fdimensions[0];
76 assert(FiveDimRedBlackGrid._fdimensions[0]==Ls);
77 assert(FiveDimGrid._processors[0] ==1);
78 assert(FiveDimRedBlackGrid._processors[0] ==1);
79
80 // Other dimensions must match the decomposition of the four-D fields
81 for(int d=0;d<4;d++){
82 assert(FiveDimGrid._processors[d+1] ==FourDimGrid._processors[d]);
83 assert(FiveDimRedBlackGrid._processors[d+1] ==FourDimGrid._processors[d]);
84 assert(FourDimRedBlackGrid._processors[d] ==FourDimGrid._processors[d]);
85
86 assert(FiveDimGrid._fdimensions[d+1] ==FourDimGrid._fdimensions[d]);
87 assert(FiveDimRedBlackGrid._fdimensions[d+1]==FourDimGrid._fdimensions[d]);
88 assert(FourDimRedBlackGrid._fdimensions[d] ==FourDimGrid._fdimensions[d]);
89
90 assert(FiveDimGrid._simd_layout[d+1] ==FourDimGrid._simd_layout[d]);
91 assert(FiveDimRedBlackGrid._simd_layout[d+1]==FourDimGrid._simd_layout[d]);
92 assert(FourDimRedBlackGrid._simd_layout[d] ==FourDimGrid._simd_layout[d]);
93 }
94
95 if (Impl::LsVectorised) {
96
97 int nsimd = Simd::Nsimd();
98
99 // Dimension zero of the five-d is the Ls direction
100 assert(FiveDimGrid._simd_layout[0] ==nsimd);
101 assert(FiveDimRedBlackGrid._simd_layout[0]==nsimd);
102
103 for(int d=0;d<4;d++){
104 assert(FourDimGrid._simd_layout[d]==1);
105 assert(FourDimRedBlackGrid._simd_layout[d]==1);
106 assert(FiveDimRedBlackGrid._simd_layout[d+1]==1);
107 }
108
109 } else {
110
111 // Dimension zero of the five-d is the Ls direction
112 assert(FiveDimRedBlackGrid._simd_layout[0]==1);
113 assert(FiveDimGrid._simd_layout[0] ==1);
114
115 }
116 int LLs = FiveDimGrid._rdimensions[0];
117 int vol4= FourDimGrid.oSites();
118 Stencil.BuildSurfaceList(LLs,vol4);
119
120 vol4=FourDimRedBlackGrid.oSites();
121 StencilEven.BuildSurfaceList(LLs,vol4);
122 StencilOdd.BuildSurfaceList(LLs,vol4);
123}
124template <class Impl>
132template<class Impl>
134 GridCartesian &FiveDimGrid,
135 GridRedBlackCartesian &FiveDimRedBlackGrid,
136 GridCartesian &FourDimGrid,
137 GridRedBlackCartesian &FourDimRedBlackGrid,
138 RealD _mass,
139 RealD _c1,RealD _c2, RealD _u0,
140 const ImplParams &p) :
141 ImprovedStaggeredFermion5D(FiveDimGrid,FiveDimRedBlackGrid,
142 FourDimGrid,FourDimRedBlackGrid,
143 _mass,_c1,_c2,_u0,p)
144{
145 ImportGauge(_Uthin,_Ufat);
146}
147
149// For MILC use; pass three link U's and 1 link U
151template <class Impl>
152void ImprovedStaggeredFermion5D<Impl>::ImportGaugeSimple(const GaugeField &_Utriple,const GaugeField &_Ufat)
153{
155 // Trivial import; phases and fattening and such like preapplied
157 for (int mu = 0; mu < Nd; mu++) {
158
159 auto U = PeekIndex<LorentzIndex>(_Utriple, mu);
160 Impl::InsertGaugeField(UUUmu,U,mu);
161
162 U = adj( Cshift(U, mu, -3));
163 Impl::InsertGaugeField(UUUmu,-U,mu+4);
164
165 U = PeekIndex<LorentzIndex>(_Ufat, mu);
166 Impl::InsertGaugeField(Umu,U,mu);
167
168 U = adj( Cshift(U, mu, -1));
169 Impl::InsertGaugeField(Umu,-U,mu+4);
170
171 }
173}
174template <class Impl>
175void ImprovedStaggeredFermion5D<Impl>::ImportGaugeSimple(const DoubledGaugeField &_UUU,const DoubledGaugeField &_U)
176{
178 // Trivial import; phases and fattening and such like preapplied
180 Umu = _U;
181 UUUmu = _UUU;
183}
184template<class Impl>
185void ImprovedStaggeredFermion5D<Impl>::ImportGauge(const GaugeField &_Uthin,const GaugeField &_Ufat)
186{
188 // Double Store should take two fields for Naik and one hop separately.
190 Impl::DoubleStore(GaugeGrid(), UUUmu, Umu, _Uthin, _Ufat );
191
193 // Apply scale factors to get the right fermion Kinetic term
194 // Could pass coeffs into the double store to save work.
195 // 0.5 ( U p(x+mu) - Udag(x-mu) p(x-mu) )
197 for (int mu = 0; mu < Nd; mu++) {
198
199 auto U = PeekIndex<LorentzIndex>(Umu, mu);
200 PokeIndex<LorentzIndex>(Umu, U*( 0.5*c1/u0), mu );
201
203 PokeIndex<LorentzIndex>(Umu, U*(-0.5*c1/u0), mu+4);
204
206 PokeIndex<LorentzIndex>(UUUmu, U*( 0.5*c2/u0/u0/u0), mu );
207
209 PokeIndex<LorentzIndex>(UUUmu, U*(-0.5*c2/u0/u0/u0), mu+4);
210 }
211
213}
214template<class Impl>
215void ImprovedStaggeredFermion5D<Impl>::DhopDir(const FermionField &in, FermionField &out,int dir5,int disp)
216{
217 int dir = dir5-1; // Maps to the ordering above in "directions" that is passed to stencil
218 // we drop off the innermost fifth dimension
219
220 Compressor compressor;
221 Stencil.HaloExchange(in,compressor);
222 autoView( Umu_v , Umu, CpuRead);
223 autoView( UUUmu_v , UUUmu, CpuRead);
224 autoView( in_v , in, CpuRead);
225 autoView( out_v , out, CpuWrite);
226 thread_for( ss,Umu.Grid()->oSites(),{
227 for(int s=0;s<Ls;s++){
228 int sU=ss;
229 int sF = s+Ls*sU;
230 Kernels::DhopDirKernel(Stencil, Umu_v, UUUmu_v, Stencil.CommBuf(), sF, sU, in_v, out_v, dir, disp);
231 }
232 });
233};
234
235template<class Impl>
237 DoubledGaugeField & U,
238 DoubledGaugeField & UUU,
239 GaugeField &mat,
240 const FermionField &A,
241 const FermionField &B,
242 int dag)
243{
244 // No force terms in multi-rhs solver staggered
245 assert(0);
246}
247
248template<class Impl>
250 const FermionField &A,
251 const FermionField &B,
252 int dag)
253{
254 assert(0);
255}
256
257template<class Impl>
259 const FermionField &A,
260 const FermionField &B,
261 int dag)
262{
263 assert(0);
264}
265
266
267template<class Impl>
269 const FermionField &A,
270 const FermionField &B,
271 int dag)
272{
273 assert(0);
274}
275
276/*CHANGE */
277template<class Impl>
279 DoubledGaugeField & U,DoubledGaugeField & UUU,
280 const FermionField &in, FermionField &out,int dag)
281{
283 DhopInternalOverlappedComms(st,U,UUU,in,out,dag);
284 else
285 DhopInternalSerialComms(st,U,UUU,in,out,dag);
286}
287
288template<class Impl>
290 DoubledGaugeField & U,DoubledGaugeField & UUU,
291 const FermionField &in, FermionField &out,int dag)
292{
293 // assert((dag==DaggerNo) ||(dag==DaggerYes));
294 Compressor compressor;
295
296 int LLs = in.Grid()->_rdimensions[0];
297 int len = U.Grid()->oSites();
298
299 st.Prepare();
300 st.HaloGather(in,compressor);
301
302 std::vector<std::vector<CommsRequest_t> > requests;
303 st.CommunicateBegin(requests);
304
305 // st.HaloExchangeOptGather(in,compressor); // Wilson compressor
306 st.CommsMergeSHM(compressor);// Could do this inside parallel region overlapped with comms
307
309 // Remove explicit thread mapping introduced for OPA reasons.
311 {
312 int interior=1;
313 int exterior=0;
314 Kernels::DhopImproved(st,U,UUU,in,out,dag,interior,exterior);
315 }
316
317 st.CommsMerge(compressor);
318
319 st.CommunicateComplete(requests);
320
321 {
322 int interior=0;
323 int exterior=1;
324 Kernels::DhopImproved(st,U,UUU,in,out,dag,interior,exterior);
325 }
326}
327
328template<class Impl>
330 DoubledGaugeField & U,DoubledGaugeField & UUU,
331 const FermionField &in, FermionField &out,int dag)
332{
333 Compressor compressor;
334 int LLs = in.Grid()->_rdimensions[0];
335
336 st.HaloExchange(in,compressor);
337
338 // Dhop takes the 4d grid from U, and makes a 5d index for fermion
339 {
340 int interior=1;
341 int exterior=1;
342 Kernels::DhopImproved(st,U,UUU,in,out,dag,interior,exterior);
343 }
344}
345/*CHANGE END*/
346
347
348
349template<class Impl>
350void ImprovedStaggeredFermion5D<Impl>::DhopOE(const FermionField &in, FermionField &out,int dag)
351{
352 conformable(in.Grid(),FermionRedBlackGrid()); // verifies half grid
353 conformable(in.Grid(),out.Grid()); // drops the cb check
354
355 assert(in.Checkerboard()==Even);
356 out.Checkerboard() = Odd;
357
359}
360template<class Impl>
361void ImprovedStaggeredFermion5D<Impl>::DhopEO(const FermionField &in, FermionField &out,int dag)
362{
363 conformable(in.Grid(),FermionRedBlackGrid()); // verifies half grid
364 conformable(in.Grid(),out.Grid()); // drops the cb check
365
366 assert(in.Checkerboard()==Odd);
367 out.Checkerboard() = Even;
368
370}
371template<class Impl>
372void ImprovedStaggeredFermion5D<Impl>::Dhop(const FermionField &in, FermionField &out,int dag)
373{
374 conformable(in.Grid(),FermionGrid()); // verifies full grid
375 conformable(in.Grid(),out.Grid());
376
377 out.Checkerboard() = in.Checkerboard();
378
379 DhopInternal(Stencil,Umu,UUUmu,in,out,dag);
380}
381
383// Implement the general interface. Here we use SAME mass on all slices
385template <class Impl>
386void ImprovedStaggeredFermion5D<Impl>::Mdir(const FermionField &in, FermionField &out, int dir, int disp)
387{
388 DhopDir(in, out, dir, disp);
389}
390template <class Impl>
391void ImprovedStaggeredFermion5D<Impl>::MdirAll(const FermionField &in, std::vector<FermionField> &out)
392{
393 assert(0);
394}
395template <class Impl>
396void ImprovedStaggeredFermion5D<Impl>::M(const FermionField &in, FermionField &out)
397{
398 out.Checkerboard() = in.Checkerboard();
399 Dhop(in, out, DaggerNo);
400 axpy(out, mass, in, out);
401}
402
403template <class Impl>
404void ImprovedStaggeredFermion5D<Impl>::Mdag(const FermionField &in, FermionField &out)
405{
406 out.Checkerboard() = in.Checkerboard();
407 Dhop(in, out, DaggerYes);
408 axpy(out, mass, in, out);
409}
410
411template <class Impl>
412void ImprovedStaggeredFermion5D<Impl>::Meooe(const FermionField &in, FermionField &out)
413{
414 if (in.Checkerboard() == Odd) {
415 DhopEO(in, out, DaggerNo);
416 } else {
417 DhopOE(in, out, DaggerNo);
418 }
419}
420template <class Impl>
421void ImprovedStaggeredFermion5D<Impl>::MeooeDag(const FermionField &in, FermionField &out)
422{
423 if (in.Checkerboard() == Odd) {
424 DhopEO(in, out, DaggerYes);
425 } else {
426 DhopOE(in, out, DaggerYes);
427 }
428}
429
430template <class Impl>
431void ImprovedStaggeredFermion5D<Impl>::Mooee(const FermionField &in, FermionField &out)
432{
433 out.Checkerboard() = in.Checkerboard();
434 typename FermionField::scalar_type scal(mass);
435 out = scal * in;
436}
437
438template <class Impl>
439void ImprovedStaggeredFermion5D<Impl>::MooeeDag(const FermionField &in, FermionField &out)
440{
441 out.Checkerboard() = in.Checkerboard();
442 Mooee(in, out);
443}
444
445template <class Impl>
446void ImprovedStaggeredFermion5D<Impl>::MooeeInv(const FermionField &in, FermionField &out)
447{
448 out.Checkerboard() = in.Checkerboard();
449 out = (1.0 / (mass)) * in;
450}
451
452template <class Impl>
453void ImprovedStaggeredFermion5D<Impl>::MooeeInvDag(const FermionField &in,FermionField &out)
454{
455 out.Checkerboard() = in.Checkerboard();
456 MooeeInv(in, out);
457}
458
460// Conserved current - not yet implemented.
462template <class Impl>
464 PropagatorField &q_in_2,
465 PropagatorField &q_out,
466 PropagatorField &src,
467 Current curr_type,
468 unsigned int mu)
469{
470 assert(0);
471}
472
473template <class Impl>
475 PropagatorField &q_out,
476 PropagatorField &src,
477 Current curr_type,
478 unsigned int mu,
479 unsigned int tmin,
480 unsigned int tmax,
481 ComplexField &lattice_cmplx)
482{
483 assert(0);
484
485}
486
488
489
490
static const int Even
static const int Odd
auto Cshift(const Expression &expr, int dim, int shift) -> decltype(closure(expr))
Definition Cshift.h:55
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))>
Lattice< vobj > adj(const Lattice< vobj > &lhs)
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
Coordinate _fdimensions
int oSites(void) const
Coordinate _rdimensions
Coordinate _simd_layout
static const std::vector< int > displacements
static const std::vector< int > directions
void Mdag(const FermionField &in, FermionField &out)
void MdirAll(const FermionField &in, std::vector< FermionField > &out)
void Mooee(const FermionField &in, FermionField &out)
void DhopDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag)
void ImportGauge(const GaugeField &_Uthin)
void DhopOE(const FermionField &in, FermionField &out, int dag)
void DerivInternal(StencilImpl &st, DoubledGaugeField &U, DoubledGaugeField &UUU, GaugeField &mat, const FermionField &A, const FermionField &B, int dag)
void DhopDerivOE(GaugeField &mat, const FermionField &U, const FermionField &V, int dag)
ImprovedStaggeredFermion5D(GaugeField &_Uthin, GaugeField &_Ufat, GridCartesian &FiveDimGrid, GridRedBlackCartesian &FiveDimRedBlackGrid, GridCartesian &FourDimGrid, GridRedBlackCartesian &FourDimRedBlackGrid, double _mass, RealD _c1, RealD _c2, RealD _u0, const ImplParams &p=ImplParams())
void MooeeDag(const FermionField &in, FermionField &out)
void DhopEO(const FermionField &in, FermionField &out, int dag)
void DhopInternalSerialComms(StencilImpl &st, DoubledGaugeField &U, DoubledGaugeField &UUU, const FermionField &in, FermionField &out, int dag)
void M(const FermionField &in, FermionField &out)
void Mdir(const FermionField &in, FermionField &out, int dir, int disp)
void ContractConservedCurrent(PropagatorField &q_in_1, PropagatorField &q_in_2, PropagatorField &q_out, PropagatorField &src, Current curr_type, unsigned int mu)
void DhopInternalOverlappedComms(StencilImpl &st, DoubledGaugeField &U, DoubledGaugeField &UUU, const FermionField &in, FermionField &out, int dag)
void MooeeInvDag(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 Meooe(const FermionField &in, FermionField &out)
void Dhop(const FermionField &in, FermionField &out, int dag)
void DhopDir(const FermionField &in, FermionField &out, int dir, int disp)
void MeooeDag(const FermionField &in, FermionField &out)
void SeqConservedCurrent(PropagatorField &q_in, PropagatorField &q_out, PropagatorField &src, Current curr_type, unsigned int mu, unsigned int tmin, unsigned int tmax, ComplexField &lattice_cmplx)
void DhopInternal(StencilImpl &st, DoubledGaugeField &U, DoubledGaugeField &UUU, const FermionField &in, FermionField &out, int dag)
void ImportGaugeSimple(const GaugeField &_UUU, const GaugeField &_U)
void DhopImproved(StencilImpl &st, DoubledGaugeField &U, DoubledGaugeField &UUU, const FermionField &in, FermionField &out, int dag, int interior, int exterior)