Grid 0.7.0
CompactWilsonCloverFermion.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/CompactWilsonCloverFermion.h
6
7 Copyright (C) 2020 - 2022
8
9 Author: Daniel Richtmann <daniel.richtmann@gmail.com>
10 Author: Nils Meyer <nils.meyer@ur.de>
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 */
29
30#pragma once
31
35
37
38// see Grid/qcd/action/fermion/WilsonCloverFermion.h for description
39//
40// Modifications done here:
41//
42// Original: clover term = 12x12 matrix per site
43//
44// But: Only two diagonal 6x6 hermitian blocks are non-zero (also true for original, verified by running)
45// Sufficient to store/transfer only the real parts of the diagonal and one triangular part
46// 2 * (6 + 15 * 2) = 72 real or 36 complex words to be stored/transfered
47//
48// Here: Above but diagonal as complex numbers, i.e., need to store/transfer
49// 2 * (6 * 2 + 15 * 2) = 84 real or 42 complex words
50//
51// Words per site and improvement compared to original (combined with the input and output spinors):
52//
53// - Original: 2*12 + 12*12 = 168 words -> 1.00 x less
54// - Minimal: 2*12 + 36 = 60 words -> 2.80 x less
55// - Here: 2*12 + 42 = 66 words -> 2.55 x less
56//
57// These improvements directly translate to wall-clock time
58//
59// Data layout:
60//
61// - diagonal and triangle part as separate lattice fields,
62// this was faster than as 1 combined field on all tested machines
63// - diagonal: as expected
64// - triangle: store upper right triangle in row major order
65// - graphical:
66// 0 1 2 3 4
67// 5 6 7 8
68// 9 10 11 = upper right triangle indices
69// 12 13
70// 14
71// 0
72// 1
73// 2
74// 3 = diagonal indices
75// 4
76// 5
77// 0
78// 1 5
79// 2 6 9 = lower left triangle indices
80// 3 7 10 12
81// 4 8 11 13 14
82//
83// Impact on total memory consumption:
84// - Original: (2 * 1 + 8 * 1/2) 12x12 matrices = 6 12x12 matrices = 864 complex words per site
85// - Here: (2 * 1 + 4 * 1/2) diagonal parts = 4 diagonal parts = 24 complex words per site
86// + (2 * 1 + 4 * 1/2) triangle parts = 4 triangle parts = 60 complex words per site
87// = 84 complex words per site
88
89template<class Impl, class CloverHelpers>
91 public WilsonCloverHelpers<Impl>,
92 public CompactWilsonCloverHelpers<Impl> {
94 // Sizes
96
97public:
98
100
102 // Type definitions
104
105public:
106
110
114
116 // Constructors
118
119public:
120
122 GridCartesian& Fgrid,
124 const RealD _mass,
125 const RealD _csw_r = 0.0,
126 const RealD _csw_t = 0.0,
127 const RealD _cF = 1.0,
129 const ImplParams& impl_p = ImplParams());
130
132 // Member functions (implementing interface)
134
135public:
136
137 virtual void Instantiatable() {};
138 int ConstEE() override { return 0; };
139 int isTrivialEE() override { return 0; };
140
141 void Dhop(const FermionField& in, FermionField& out, int dag) override;
142
143 void DhopOE(const FermionField& in, FermionField& out, int dag) override;
144
145 void DhopEO(const FermionField& in, FermionField& out, int dag) override;
146
147 void DhopDir(const FermionField& in, FermionField& out, int dir, int disp) override;
148
149 void DhopDirAll(const FermionField& in, std::vector<FermionField>& out) /* override */;
150
151 void M(const FermionField& in, FermionField& out) override;
152
153 void Mdag(const FermionField& in, FermionField& out) override;
154
155 void Meooe(const FermionField& in, FermionField& out) override;
156
157 void MeooeDag(const FermionField& in, FermionField& out) override;
158
159 void Mooee(const FermionField& in, FermionField& out) override;
160
161 void MooeeDag(const FermionField& in, FermionField& out) override;
162
163 void MooeeInv(const FermionField& in, FermionField& out) override;
164
165 void MooeeInvDag(const FermionField& in, FermionField& out) override;
166
167 void Mdir(const FermionField& in, FermionField& out, int dir, int disp) override;
168
169 void MdirAll(const FermionField& in, std::vector<FermionField>& out) override;
170
171 void MDeriv(GaugeField& force, const FermionField& X, const FermionField& Y, int dag) override;
172
173 void MooDeriv(GaugeField& mat, const FermionField& U, const FermionField& V, int dag) override;
174
175 void MeeDeriv(GaugeField& mat, const FermionField& U, const FermionField& V, int dag) override;
176
178 // Member functions (internals)
180
181 void MooeeInternal(const FermionField& in,
182 FermionField& out,
183 const CloverDiagonalField& diagonal,
184 const CloverTriangleField& triangle);
185
187 // Helpers
189
190 void ImportGauge(const GaugeField& _Umu) override;
191
193 // Helpers
195
196private:
197
198 template<class Field>
199 const MaskField* getCorrectMaskField(const Field &in) const {
200 if(in.Grid()->_isCheckerBoarded) {
201 if(in.Checkerboard() == Odd) {
202 return &this->BoundaryMaskOdd;
203 } else {
204 return &this->BoundaryMaskEven;
205 }
206 } else {
207 return &this->BoundaryMask;
208 }
209 }
210
211 template<class Field>
212 void ApplyBoundaryMask(Field& f) {
213 const MaskField* m = getCorrectMaskField(f); assert(m != nullptr);
214 assert(m != nullptr);
216 }
217
219 // Member Data
221
222public:
223
227
229
230 CloverDiagonalField Diagonal, DiagonalEven, DiagonalOdd;
232
233 CloverTriangleField Triangle, TriangleEven, TriangleOdd;
235
236 FermionField Tmp;
237
239};
240
static const int Odd
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
double RealD
Definition Simd.h:61
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
void Mdag(const FermionField &in, FermionField &out) override
void Mdir(const FermionField &in, FermionField &out, int dir, int disp) override
void MeooeDag(const FermionField &in, FermionField &out) override
void Dhop(const FermionField &in, FermionField &out, int dag) override
void MDeriv(GaugeField &force, const FermionField &X, const FermionField &Y, int dag) override
void MdirAll(const FermionField &in, std::vector< FermionField > &out) override
void DhopEO(const FermionField &in, FermionField &out, int dag) override
void M(const FermionField &in, FermionField &out) override
CompactWilsonCloverHelpers< Impl > CompactHelpers
void MooDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) override
void MooeeInternal(const FermionField &in, FermionField &out, const CloverDiagonalField &diagonal, const CloverTriangleField &triangle)
void MeeDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) override
void DhopDirAll(const FermionField &in, std::vector< FermionField > &out)
WilsonCloverHelpers< Impl > Helpers
void DhopOE(const FermionField &in, FermionField &out, int dag) override
void MooeeInv(const FermionField &in, FermionField &out) override
void MooeeInvDag(const FermionField &in, FermionField &out) override
void Meooe(const FermionField &in, FermionField &out) override
void DhopDir(const FermionField &in, FermionField &out, int dir, int disp) override
void MooeeDag(const FermionField &in, FermionField &out) override
CompactWilsonCloverFermion(GaugeField &_Umu, GridCartesian &Fgrid, GridRedBlackCartesian &Hgrid, const RealD _mass, const RealD _csw_r=0.0, const RealD _csw_t=0.0, const RealD _cF=1.0, const WilsonAnisotropyCoefficients &clover_anisotropy=WilsonAnisotropyCoefficients(), const ImplParams &impl_p=ImplParams())
void Mooee(const FermionField &in, FermionField &out) override
static strong_inline void ApplyBoundaryMask(Field &f, const Mask &m)
WilsonFermion(GaugeField &_Umu, GridCartesian &Fgrid, GridRedBlackCartesian &Hgrid, RealD _mass, const ImplParams &p=ImplParams(), const WilsonAnisotropyCoefficients &anis=WilsonAnisotropyCoefficients())