1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-09 23:45:36 +00:00

naik now returns separately

This commit is contained in:
david clarke 2023-10-30 17:40:53 -06:00
parent 3d3376d1a3
commit df9b958c40
3 changed files with 63 additions and 30 deletions

View File

@ -179,11 +179,11 @@ extern GridLogger GridLogSolver;
extern GridLogger GridLogError;
extern GridLogger GridLogWarning;
extern GridLogger GridLogMessage;
extern GridLogger GridLogDebug ;
extern GridLogger GridLogDebug;
extern GridLogger GridLogPerformance;
extern GridLogger GridLogDslash;
extern GridLogger GridLogIterative ;
extern GridLogger GridLogIntegrator ;
extern GridLogger GridLogIterative;
extern GridLogger GridLogIntegrator;
extern GridLogger GridLogHMC;
extern GridLogger GridLogMemory;
extern GridLogger GridLogTracing;
@ -209,7 +209,21 @@ inline void Grid_log(Args&&... args) {
template <typename... Args>
inline void Grid_warn(Args&&... args) {
std::string msg = sjoin(std::forward<Args>(args)...);
std::cout << GridLogWarning << msg << std::endl;
std::cout << "\033[33m" << GridLogWarning << msg << "\033[0m" << std::endl;
}
/*! @brief make error messages work like python print */
template <typename... Args>
inline void Grid_error(Args&&... args) {
std::string msg = sjoin(std::forward<Args>(args)...);
std::cout << "\033[31m" << GridLogError << msg << "\033[0m" << std::endl;
}
/*! @brief make pass messages work like python print */
template <typename... Args>
inline void Grid_pass(Args&&... args) {
std::string msg = sjoin(std::forward<Args>(args)...);
std::cout << "\033[32m" << GridLogMessage << msg << "\033[0m" << std::endl;
}
#define _NBACKTRACE (256)

View File

@ -81,9 +81,9 @@ struct SmearingParameters{
/*! @brief create fat links from link variables */
//template<class GF, class Gimpl>
template<class Gimpl>
class Smear_HISQ_fat : public Gimpl {
class Smear_HISQ : public Gimpl {
// TODO: this needs to be renamed, becaues the Naik guy is not part of the fat smear
private:
GridCartesian* const _grid;
@ -96,7 +96,7 @@ public:
typedef typename Gimpl::GaugeLinkField LF;
// Don't allow default values here.
Smear_HISQ_fat(GridCartesian* grid, Real c1, Real cnaik, Real c3, Real c5, Real c7, Real clp)
Smear_HISQ(GridCartesian* grid, Real c1, Real cnaik, Real c3, Real c5, Real c7, Real clp)
: _grid(grid),
_linkTreatment(c1,cnaik,c3,c5,c7,clp) {
assert(Nc == 3 && "HISQ smearing currently implemented only for Nc==3");
@ -104,16 +104,18 @@ public:
}
// Allow to pass a pointer to a C-style, double array for MILC convenience
Smear_HISQ_fat(GridCartesian* grid, double* coeff)
Smear_HISQ(GridCartesian* grid, double* coeff)
: _grid(grid),
_linkTreatment(coeff[0],coeff[1],coeff[2],coeff[3],coeff[4],coeff[5]) {
assert(Nc == 3 && "HISQ smearing currently implemented only for Nc==3");
assert(Nd == 4 && "HISQ smearing only defined for Nd==4");
}
~Smear_HISQ_fat() {}
~Smear_HISQ() {}
void smear(GF& u_smr, GF& u_thin) const {
// Intent: OUT--u_smr, u_naik
// IN--u_thin
void smear(GF& u_smr, GF& u_naik, GF& u_thin) const {
SmearingParameters lt = this->_linkTreatment;
@ -127,6 +129,7 @@ public:
GF Ughost_3link(Ughost.Grid());
GF Ughost_5linkA(Ughost.Grid());
GF Ughost_5linkB(Ughost.Grid());
GF Ughost_naik(Ughost.Grid());
// mu-nu plane stencil. We allow mu==nu to make indexing the stencil easier,
// but these entries will not be used.
@ -146,6 +149,7 @@ public:
// This is where contributions from the smearing get added together
Ughost_fat=Zero();
Ughost_naik=Zero();
// This loop handles 3-, 5-, and 7-link constructs, minus Lepage and Naik.
for(int mu=0;mu<Nd;mu++) {
@ -156,6 +160,7 @@ public:
autoView(U_3link_v , Ughost_3link , CpuWrite);
autoView(U_5linkA_v, Ughost_5linkA, CpuWrite);
autoView(U_5linkB_v, Ughost_5linkB, CpuWrite);
autoView(U_naik_v , Ughost_naik , CpuWrite);
// TODO: This approach is slightly memory inefficient. It uses 25% extra memory
Ughost_3link =Zero();
@ -169,7 +174,7 @@ public:
U3matrix U0, U1, U2, U3, U4, U5, W;
for(int site=0;site<U_v.size();site++){ // ----------- 3-link
for(int site=0;site<U_v.size();site++){ // ----------- 3-link constructs
for(int nu=0;nu<Nd;nu++) {
if(nu==mu) continue;
int s = stencilIndex(mu,nu);
@ -201,13 +206,12 @@ public:
U_3link_v[site](nu) = W;
U_fat_v[site](mu) = U_fat_v[site](mu) + lt.c_3*W;
// TODO: May need to be shifted by 1?
U0 = coalescedReadGeneralPermute(U_v[x_m_mu](mu),SE5->_permute,Nd);
U1 = coalescedReadGeneralPermute(U_v[x ](mu),SE2->_permute,Nd);
U2 = coalescedReadGeneralPermute(U_v[x_p_mu](mu),SE0->_permute,Nd);
W = U0*U1*U2;
// Add Naik term to smeared field.
U_fat_v[site](mu) = U_fat_v[site](mu) + lt.c_naik*W;
U_naik_v[site](mu) = U_fat_v[site](mu) + lt.c_naik*W;
}
}
@ -290,6 +294,9 @@ public:
// c1, c3, c5, c7 construct contributions
u_smr = Ghost.Extract(Ughost_fat) + lt.c_1*u_thin;
// Naik contribution
u_naik = Ghost.Extract(Ughost_naik);
// Load up U and V std::vectors to access thin and smeared links.
std::vector<LF> U(Nd, u_thin.Grid());
std::vector<LF> V(Nd, u_smr.Grid());

View File

@ -57,6 +57,22 @@ struct ConfParameters: Serializable {
// another : input --> unitarize
//
void testSmear(GridCartesian& GRID, LatticeGaugeFieldD Umu, LatticeGaugeFieldD Usmr, LatticeGaugeFieldD Unaik,
LatticeGaugeFieldD Ucontrol, Real c1, Real cnaik, Real c3, Real c5, Real c7, Real clp) {
Smear_HISQ<PeriodicGimplD> hisq_fat(&GRID,c1,cnaik,c3,c5,c7,clp);
hisq_fat.smear(Usmr, Unaik, Umu);
LatticeGaugeFieldD diff(&GRID);
diff = Ucontrol-Usmr;
auto absDiff = norm2(diff)/norm2(Ucontrol);
if (absDiff < 1e-30) {
Grid_pass(" |Umu-U|/|Umu| = ",absDiff);
} else {
Grid_error(" |Umu-U|/|Umu| = ",absDiff);
}
}
int main (int argc, char** argv) {
// Params for the test.
@ -83,30 +99,26 @@ int main (int argc, char** argv) {
ConfParameters param(Reader);
if(param.benchmark) Grid_log(" Nloop = ",param.Nloop);
// Instantiate the LGF objects holding thin (Umu) and fat (U_smr) links
LGF Umu(&GRID);
LGF U_smr(&GRID);
LGF Umu(&GRID), Usmr(&GRID), Unaik(&GRID), Ucontrol(&GRID);
// Read the configuration into Umu
FieldMetaData header;
NerscIO::readConfiguration(Umu, header, conf_in);
// Smear Umu and store result in U_smr
Smear_HISQ_fat<PeriodicGimplD> hisq_fat(&GRID,1/8.,-1/24.,1/16.,1/64.,1/384.,-1/8.);
hisq_fat.smear(U_smr,Umu);
NerscIO::writeConfiguration(U_smr,conf_out,"HISQ");
// Carry out various tests
NerscIO::readConfiguration(Ucontrol, header, "nersc.l8t4b3360.357lplink.control");
testSmear(GRID,Umu,Usmr,Unaik,Ucontrol,1/8.,0.,1/16.,1/64.,1/384.,-1/8.);
NerscIO::writeConfiguration(Usmr,conf_out,"HISQ");
NerscIO::readConfiguration(Ucontrol, header, "nersc.l8t4b3360.357link.control");
testSmear(GRID,Umu,Usmr,Unaik,Ucontrol,1/8.,0.,1/16.,1/64.,1/384.,0.);
NerscIO::readConfiguration(Ucontrol, header, "nersc.l8t4b3360.35link.control");
testSmear(GRID,Umu,Usmr,Unaik,Ucontrol,1/8.,0.,1/16.,1/64.,0.,0.);
NerscIO::readConfiguration(Ucontrol, header, "nersc.l8t4b3360.3link.control");
testSmear(GRID,Umu,Usmr,Unaik,Ucontrol,1/8.,0.,1/16.,0.,0.,0.);
// Test a C-style instantiation
double path_coeff[6] = {1, 2, 3, 4, 5, 6};
Smear_HISQ_fat<PeriodicGimplD> hisq_fat_Cstyle(&GRID,path_coeff);
// Make sure result doesn't change w.r.t. a trusted lattice
NerscIO::readConfiguration(Umu, header, "nersc.l8t4b3360.357lplink.control");
LGF diff(&GRID);
diff = Umu-U_smr;
auto absDiff = norm2(diff)/norm2(Umu);
Grid_log(" |Umu-U|/|Umu| = ",absDiff);
Smear_HISQ<PeriodicGimplD> hisq_fat_Cstyle(&GRID,path_coeff);
if (param.benchmark) {