From a04eb7df5d53e72ce501d5e13c8ef051d3a28442 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Fri, 24 Mar 2017 12:43:28 +0900 Subject: [PATCH 001/174] Starting Clover term --- .vscode/settings.json | 3 + lib/qcd/action/fermion/WilsonCloverFermion.cc | 98 +++++++++++++++++++ lib/qcd/action/fermion/WilsonCloverFermion.h | 76 ++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 lib/qcd/action/fermion/WilsonCloverFermion.cc create mode 100644 lib/qcd/action/fermion/WilsonCloverFermion.h diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..20af2f68 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +// Place your settings in this file to overwrite default and user settings. +{ +} \ No newline at end of file diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc new file mode 100644 index 00000000..1d59474e --- /dev/null +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -0,0 +1,98 @@ + /************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./lib/qcd/action/fermion/WilsonTMFermion.cc + + Copyright (C) 2015 + +Author: paboyle + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ + /* END LEGAL */ +#include + +namespace Grid { +namespace QCD { + + /* + * BF sequence + * + void bfmbase::MooeeInv(Fermion_t psi, + Fermion_t chi, + int dag, int cb) + + double m = this->mass; + double tm = this->twistedmass; + double mtil = 4.0+this->mass; + + double sq = mtil*mtil + tm*tm; + + double a = mtil/sq; + double b = -tm /sq; + if(dag) b=-b; + axpibg5x(chi,psi,a,b); + + void bfmbase::Mooee(Fermion_t psi, + Fermion_t chi, + int dag,int cb) + double a = 4.0+this->mass; + double b = this->twistedmass; + if(dag) b=-b; + axpibg5x(chi,psi,a,b); + */ + + template + void WilsonTMFermion::Mooee(const FermionField &in, FermionField &out) { + RealD a = 4.0+this->mass; + RealD b = this->mu; + out.checkerboard = in.checkerboard; + axpibg5x(out,in,a,b); + } + template + void WilsonTMFermion::MooeeDag(const FermionField &in, FermionField &out) { + RealD a = 4.0+this->mass; + RealD b = -this->mu; + out.checkerboard = in.checkerboard; + axpibg5x(out,in,a,b); + } + template + void WilsonTMFermion::MooeeInv(const FermionField &in, FermionField &out) { + RealD m = this->mass; + RealD tm = this->mu; + RealD mtil = 4.0+this->mass; + RealD sq = mtil*mtil+tm*tm; + RealD a = mtil/sq; + RealD b = -tm /sq; + axpibg5x(out,in,a,b); + } + template + void WilsonTMFermion::MooeeInvDag(const FermionField &in, FermionField &out) { + RealD m = this->mass; + RealD tm = this->mu; + RealD mtil = 4.0+this->mass; + RealD sq = mtil*mtil+tm*tm; + RealD a = mtil/sq; + RealD b = tm /sq; + axpibg5x(out,in,a,b); + } + + FermOpTemplateInstantiate(WilsonTMFermion); + +} +} diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h new file mode 100644 index 00000000..5901cb2f --- /dev/null +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -0,0 +1,76 @@ + /************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./lib/qcd/action/fermion/WilsonTMFermion.h + + Copyright (C) 2015 + +Author: paboyle + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ + /* END LEGAL */ +#ifndef GRID_QCD_WILSON_TM_FERMION_H +#define GRID_QCD_WILSON_TM_FERMION_H + +#include + +namespace Grid { + + namespace QCD { + + template + class WilsonTMFermion : public WilsonFermion + { + public: + INHERIT_IMPL_TYPES(Impl); + public: + + virtual void Instantiatable(void) {}; + // Constructors + WilsonTMFermion(GaugeField &_Umu, + GridCartesian &Fgrid, + GridRedBlackCartesian &Hgrid, + RealD _mass, + RealD _mu, + const ImplParams &p= ImplParams() + ) : + WilsonFermion(_Umu, + Fgrid, + Hgrid, + _mass,p) + + { + mu = _mu; + } + + + // allow override for twisted mass and clover + virtual void Mooee(const FermionField &in, FermionField &out) ; + virtual void MooeeDag(const FermionField &in, FermionField &out) ; + virtual void MooeeInv(const FermionField &in, FermionField &out) ; + virtual void MooeeInvDag(const FermionField &in, FermionField &out) ; + + private: + RealD mu; // TwistedMass parameter + + }; + +}} + +#endif From 5fdc05782b4578b21ba66421ec58753c32ec9350 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 27 Mar 2017 10:54:16 +0900 Subject: [PATCH 002/174] More in the clover fermion class --- lib/qcd/action/fermion/WilsonCloverFermion.h | 81 +++++++++----------- lib/qcd/action/fermion/WilsonFermion.h | 4 +- 2 files changed, 40 insertions(+), 45 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index 5901cb2f..41131e5d 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -1,12 +1,13 @@ - /************************************************************************************* +/************************************************************************************* - Grid physics library, www.github.com/paboyle/Grid + Grid physics library, www.github.com/paboyle/Grid Source file: ./lib/qcd/action/fermion/WilsonTMFermion.h - Copyright (C) 2015 + Copyright (C) 2017 Author: paboyle +Author: Guido Cossu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,53 +25,47 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ - /* END LEGAL */ -#ifndef GRID_QCD_WILSON_TM_FERMION_H -#define GRID_QCD_WILSON_TM_FERMION_H +/* END LEGAL */ +#ifndef GRID_QCD_WILSON_CLOVER_FERMION_H +#define GRID_QCD_WILSON_CLOVER_FERMION_H #include namespace Grid { +namespace QCD { - namespace QCD { +template +class WilsonCloverFermion : public WilsonFermion { +public: + INHERIT_IMPL_TYPES(Impl); - template - class WilsonTMFermion : public WilsonFermion - { - public: - INHERIT_IMPL_TYPES(Impl); - public: +public: + virtual void Instantiatable(void){}; + // Constructors + WilsonCloverFermion(GaugeField &_Umu, GridCartesian &Fgrid, + GridRedBlackCartesian &Hgrid, + RealD _mass, + RealD _csw, + const ImplParams &p = ImplParams()) : WilsonFermion(_Umu, + Fgrid, + Hgrid, + _mass, p) + { + csw = _csw; + } - virtual void Instantiatable(void) {}; - // Constructors - WilsonTMFermion(GaugeField &_Umu, - GridCartesian &Fgrid, - GridRedBlackCartesian &Hgrid, - RealD _mass, - RealD _mu, - const ImplParams &p= ImplParams() - ) : - WilsonFermion(_Umu, - Fgrid, - Hgrid, - _mass,p) + virtual RealD M(const FermionField& in, FermionField& out); + virtual RealD Mdag(const FermionField& in, FermionField& out); - { - mu = _mu; - } + virtual void Mooee(const FermionField &in, FermionField &out); + virtual void MooeeDag(const FermionField &in, FermionField &out); + virtual void MooeeInv(const FermionField &in, FermionField &out); + virtual void MooeeInvDag(const FermionField &in, FermionField &out); +private: + RealD csw; // Clover coefficient +}; +} +} - // allow override for twisted mass and clover - virtual void Mooee(const FermionField &in, FermionField &out) ; - virtual void MooeeDag(const FermionField &in, FermionField &out) ; - virtual void MooeeInv(const FermionField &in, FermionField &out) ; - virtual void MooeeInvDag(const FermionField &in, FermionField &out) ; - - private: - RealD mu; // TwistedMass parameter - - }; - -}} - -#endif +#endif // GRID_QCD_WILSON_CLOVER_FERMION_H diff --git a/lib/qcd/action/fermion/WilsonFermion.h b/lib/qcd/action/fermion/WilsonFermion.h index 933be732..50f4f884 100644 --- a/lib/qcd/action/fermion/WilsonFermion.h +++ b/lib/qcd/action/fermion/WilsonFermion.h @@ -65,8 +65,8 @@ class WilsonFermion : public WilsonKernels, public WilsonFermionStatic { // override multiply; cut number routines if pass dagger argument // and also make interface more uniformly consistent ////////////////////////////////////////////////////////////////// - RealD M(const FermionField &in, FermionField &out); - RealD Mdag(const FermionField &in, FermionField &out); + virtual RealD M(const FermionField &in, FermionField &out); + virtual RealD Mdag(const FermionField &in, FermionField &out); ///////////////////////////////////////////////////////// // half checkerboard operations From fff484eca5a88b01c61b1a638faf75d4b00e5304 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 27 Mar 2017 15:12:57 +0900 Subject: [PATCH 003/174] Populating Clover fermions methods --- lib/qcd/action/Actions.h | 11 +- lib/qcd/action/fermion/WilsonCloverFermion.cc | 134 ++++++++++-------- lib/qcd/action/fermion/WilsonCloverFermion.h | 28 +++- 3 files changed, 103 insertions(+), 70 deletions(-) diff --git a/lib/qcd/action/Actions.h b/lib/qcd/action/Actions.h index 4a30f8c3..b825ac49 100644 --- a/lib/qcd/action/Actions.h +++ b/lib/qcd/action/Actions.h @@ -142,11 +142,10 @@ typedef SymanzikGaugeAction ConjugateSymanzikGaugeAction //////////////////////////////////////////// #include // 4d wilson like -#include // 4d wilson like +#include // 4d wilson like +#include // 4d wilson like #include // 5d base used by all 5d overlap types -//#include - #include // Cayley types #include #include @@ -188,10 +187,16 @@ typedef WilsonFermion WilsonTwoIndexSymmetricFermi typedef WilsonFermion WilsonTwoIndexSymmetricFermionF; typedef WilsonFermion WilsonTwoIndexSymmetricFermionD; +// Twisted mass fermion typedef WilsonTMFermion WilsonTMFermionR; typedef WilsonTMFermion WilsonTMFermionF; typedef WilsonTMFermion WilsonTMFermionD; +// Clover fermions +typedef WilsonCloverFermion WilsonCloverFermionR; +typedef WilsonCloverFermion WilsonCloverFermionF; +typedef WilsonCloverFermion WilsonCloverFermionD; + typedef DomainWallFermion DomainWallFermionR; typedef DomainWallFermion DomainWallFermionF; typedef DomainWallFermion DomainWallFermionD; diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 1d59474e..0cc82f62 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -1,12 +1,13 @@ - /************************************************************************************* +/************************************************************************************* - Grid physics library, www.github.com/paboyle/Grid + Grid physics library, www.github.com/paboyle/Grid - Source file: ./lib/qcd/action/fermion/WilsonTMFermion.cc + Source file: ./lib/qcd/action/fermion/WilsonCloverFermion.cc - Copyright (C) 2015 + Copyright (C) 2017 -Author: paboyle + Author: paboyle + Author: Guido Cossu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,75 +25,82 @@ Author: paboyle See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ - /* END LEGAL */ +/* END LEGAL */ #include +#include namespace Grid { namespace QCD { - /* - * BF sequence - * - void bfmbase::MooeeInv(Fermion_t psi, - Fermion_t chi, - int dag, int cb) + template + void WilsonCloverFermion::AddCloverTerm(const FermionField& in, + FermionField& out){ + FermionField tmp(out._grid); + tmp = zero; + // the product sigma_munu Fmunu is hermitian + tmp += Bx*(Gamma(Gamma::Algebra::SigmaYZ)*in); + tmp += By*(Gamma(Gamma::Algebra::MinusSigmaXZ)*in); + tmp += Bz*(Gamma(Gamma::Algebra::SigmaXY)*in); + tmp += Ex*(Gamma(Gamma::Algebra::MinusSigmaXT)*in); + tmp += Ey*(Gamma(Gamma::Algebra::MinusSigmaYT)*in); + tmp += Ez*(Gamma(Gamma::Algebra::MinusSigmaZT)*in); + out += tmp*csw; // check signs - double m = this->mass; - double tm = this->twistedmass; - double mtil = 4.0+this->mass; + } - double sq = mtil*mtil + tm*tm; - double a = mtil/sq; - double b = -tm /sq; - if(dag) b=-b; - axpibg5x(chi,psi,a,b); - - void bfmbase::Mooee(Fermion_t psi, - Fermion_t chi, - int dag,int cb) - double a = 4.0+this->mass; - double b = this->twistedmass; - if(dag) b=-b; - axpibg5x(chi,psi,a,b); - */ - - template - void WilsonTMFermion::Mooee(const FermionField &in, FermionField &out) { - RealD a = 4.0+this->mass; - RealD b = this->mu; + template + RealD WilsonCloverFermion::M(const FermionField& in, FermionField& out) { + // Wilson term out.checkerboard = in.checkerboard; - axpibg5x(out,in,a,b); - } - template - void WilsonTMFermion::MooeeDag(const FermionField &in, FermionField &out) { - RealD a = 4.0+this->mass; - RealD b = -this->mu; - out.checkerboard = in.checkerboard; - axpibg5x(out,in,a,b); - } - template - void WilsonTMFermion::MooeeInv(const FermionField &in, FermionField &out) { - RealD m = this->mass; - RealD tm = this->mu; - RealD mtil = 4.0+this->mass; - RealD sq = mtil*mtil+tm*tm; - RealD a = mtil/sq; - RealD b = -tm /sq; - axpibg5x(out,in,a,b); - } - template - void WilsonTMFermion::MooeeInvDag(const FermionField &in, FermionField &out) { - RealD m = this->mass; - RealD tm = this->mu; - RealD mtil = 4.0+this->mass; - RealD sq = mtil*mtil+tm*tm; - RealD a = mtil/sq; - RealD b = tm /sq; - axpibg5x(out,in,a,b); + this->Dhop(in, out, DaggerNo); + // Clover term + // apply the sigma and Fmunu + AddCloverTerm(in, out); + // overall factor + return axpy_norm(out, 4 + this->mass, in, out); } - FermOpTemplateInstantiate(WilsonTMFermion); + template + RealD WilsonCloverFermion::Mdag(const FermionField& in, FermionField& out) { + // Wilson term + out.checkerboard = in.checkerboard; + this->Dhop(in, out, DaggerYes); + // Clover term + // apply the sigma and Fmunu + AddCloverTerm(in, out); + return axpy_norm(out, 4 + this->mass, in, out); + } + + template + void WilsonCloverFermion::ImportGauge(const GaugeField& _Umu) { + this->ImportGauge(_Umu); + // Compute the field strength terms + + // Invert the Moo, Mee terms (?) + } + + + template + void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out) { + out.checkerboard = in.checkerboard; + + } + + template + void WilsonCloverFermion::MooeeDag(const FermionField &in, FermionField &out) { + assert(0); // not implemented yet + } + template + void WilsonCloverFermion::MooeeInv(const FermionField &in, FermionField &out) { + assert(0); // not implemented yet + } + template + void WilsonCloverFermion::MooeeInvDag(const FermionField &in, FermionField &out) { + assert(0); // not implemented yet + } + + FermOpTemplateInstantiate(WilsonCloverFermion); } } diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index 41131e5d..d3785cac 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -2,12 +2,12 @@ Grid physics library, www.github.com/paboyle/Grid - Source file: ./lib/qcd/action/fermion/WilsonTMFermion.h + Source file: ./lib/qcd/action/fermion/WilsonCloverFermion.h Copyright (C) 2017 -Author: paboyle -Author: Guido Cossu + Author: paboyle + Author: Guido Cossu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,6 +40,8 @@ public: INHERIT_IMPL_TYPES(Impl); public: + typedef WilsonFermion WilsonBase; + virtual void Instantiatable(void){}; // Constructors WilsonCloverFermion(GaugeField &_Umu, GridCartesian &Fgrid, @@ -49,9 +51,17 @@ public: const ImplParams &p = ImplParams()) : WilsonFermion(_Umu, Fgrid, Hgrid, - _mass, p) + _mass, p), + Bx(_Umu._grid), + By(_Umu._grid), + Bz(_Umu._grid), + Ex(_Umu._grid), + Ey(_Umu._grid), + Ez(_Umu._grid) { csw = _csw; + assert(Nd == 4); // require 4 dimensions + } virtual RealD M(const FermionField& in, FermionField& out); @@ -62,8 +72,18 @@ public: virtual void MooeeInv(const FermionField &in, FermionField &out); virtual void MooeeInvDag(const FermionField &in, FermionField &out); + void ImportGauge(const GaugeField &_Umu); private: + // here fixing the 4 dimensions, make it more general? + + // Field strengths + GaugeLinkField Bx, By, Bz, Ex, Ey, Ez; + RealD csw; // Clover coefficient + + + // Methods + void AddCloverTerm(const FermionField& in, FermionField& out); }; } } From 5e549ebd8b645ba6b7c39548b1ded42b629c6011 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 27 Mar 2017 16:43:15 +0900 Subject: [PATCH 004/174] Adding force terms --- lib/qcd/QCD.h | 6 ++- lib/qcd/action/fermion/WilsonCloverFermion.cc | 29 ++++++++++- lib/qcd/action/fermion/WilsonCloverFermion.h | 6 ++- lib/qcd/utils/WilsonLoops.h | 50 +++++++++++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/lib/qcd/QCD.h b/lib/qcd/QCD.h index f434bdd9..1c24ecdd 100644 --- a/lib/qcd/QCD.h +++ b/lib/qcd/QCD.h @@ -35,7 +35,11 @@ namespace Grid{ namespace QCD { - + static const int Xdir = 0; + static const int Ydir = 1; + static const int Zdir = 2; + static const int Tdir = 3; + static const int Xp = 0; static const int Yp = 1; static const int Zp = 2; diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 0cc82f62..b94c72c0 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -76,6 +76,12 @@ namespace QCD { void WilsonCloverFermion::ImportGauge(const GaugeField& _Umu) { this->ImportGauge(_Umu); // Compute the field strength terms + WilsonLoops::FieldStrength(Bx, _Umu, Ydir, Zdir); + WilsonLoops::FieldStrength(By, _Umu, Zdir, Xdir); + WilsonLoops::FieldStrength(Bz, _Umu, Xdir, Ydir); + WilsonLoops::FieldStrength(Ex, _Umu, Tdir, Xdir); + WilsonLoops::FieldStrength(Ey, _Umu, Tdir, Ydir); + WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); // Invert the Moo, Mee terms (?) } @@ -84,7 +90,7 @@ namespace QCD { template void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out) { out.checkerboard = in.checkerboard; - + assert(0); // to be completed } template @@ -100,6 +106,27 @@ namespace QCD { assert(0); // not implemented yet } + // Derivative parts + template + void WilsonCloverFermion::MDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ + GaugeField tmp(mat._grid); + this->DhopDeriv(mat, U, V, dag); + MooDeriv(tmp, U, V, dag); + mat += tmp; + } + + // Derivative parts + template + void WilsonCloverFermion::MooDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ + assert(0); // not implemented yet + } + + // Derivative parts + template + void WilsonCloverFermion::MeeDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ + assert(0); // not implemented yet + } + FermOpTemplateInstantiate(WilsonCloverFermion); } diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index d3785cac..e942de1f 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -61,7 +61,6 @@ public: { csw = _csw; assert(Nd == 4); // require 4 dimensions - } virtual RealD M(const FermionField& in, FermionField& out); @@ -72,6 +71,11 @@ public: virtual void MooeeInv(const FermionField &in, FermionField &out); virtual void MooeeInvDag(const FermionField &in, FermionField &out); + virtual void MDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag); + virtual void MooDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag); + virtual void MeeDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag); + + void ImportGauge(const GaugeField &_Umu); private: // here fixing the 4 dimensions, make it more general? diff --git a/lib/qcd/utils/WilsonLoops.h b/lib/qcd/utils/WilsonLoops.h index 03d45c07..ca2b2b8d 100644 --- a/lib/qcd/utils/WilsonLoops.h +++ b/lib/qcd/utils/WilsonLoops.h @@ -256,6 +256,56 @@ public: } } + //////////////////////////////////////////////////////////////////////// + // the sum over all staples on each site in direction mu,nu, lower part + //////////////////////////////////////////////////////////////////////// + static void StapleLower(GaugeMat &staple, const GaugeLorentz &Umu, int mu, + int nu) { + if (nu != mu) { + GridBase *grid = Umu._grid; + + std::vector U(Nd, grid); + for (int d = 0; d < Nd; d++) { + U[d] = PeekIndex(Umu, d);// some redundant copies + } + + // mu + // ^ + // |__> nu + + // __ + // | + // |__ + // + // + staple = Gimpl::ShiftStaple( + Gimpl::CovShiftBackward(U[nu], nu, + Gimpl::CovShiftBackward(U[mu], mu, U[nu])), + mu); + } + } + + ////////////////////////////////////////////////////// + // Field Strength + ////////////////////////////////////////////////////// + static void FieldStrength(GaugeMat &FS, const GaugeLorentz &Umu, int mu, int nu){ + // Fmn +--<--+ Ut +--<--+ + // | | | | + // (x)+-->--+ +-->--+(x) + // | | | | + // +--<--+ +--<--+ + + GaugeMat Vup(Umu._grid), Vdn(Umu._grid); + StapleUpper(Vup, Umu, mu, nu);// coalesce these two (up low) + StapleLower(Vdn, Umu, mu, nu); + GaugeMat v = adj(Vup) - adj(Vdn); + GaugeMat u = PeekIndex(Umu, mu); // some redundant copies + GaugeMat vu = v*u; + FS = 0.25*Ta(u*v - Cshift(vu, mu, +1)); + } + + + ////////////////////////////////////////////////////// // Similar to above for rectangle is required ////////////////////////////////////////////////////// From 3750b9ffeefb31e8bfb9b30b2266b83acdc7d4ff Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 27 Mar 2017 16:53:32 +0900 Subject: [PATCH 005/174] Deleting MPI test for OSX in Travis --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ae3efda8..055adee1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -102,5 +102,3 @@ script: - ../configure --enable-precision=single --enable-simd=SSE4 --enable-comms=mpi-auto - make -j4 - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mpirun.openmpi -n 2 ./benchmarks/Benchmark_dwf --threads 1 --mpi 2.1.1.1; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mpirun -n 2 ./benchmarks/Benchmark_dwf --threads 1 --mpi 2.1.1.1; fi - From 1ed69816b9ecb9838c0a9d613e08fc2fc042afa2 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Thu, 30 Mar 2017 11:14:27 +0100 Subject: [PATCH 006/174] First steps for the force term --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 13 ++++++++++++- lib/qcd/utils/WilsonLoops.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index b94c72c0..7e51dcfe 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -82,8 +82,10 @@ namespace QCD { WilsonLoops::FieldStrength(Ex, _Umu, Tdir, Xdir); WilsonLoops::FieldStrength(Ey, _Umu, Tdir, Ydir); WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); + // Save the contracted term with sigma + // into a dense matrix site by site - // Invert the Moo, Mee terms (?) + // Invert the Moo, Mee terms (using Eigen) } @@ -110,6 +112,14 @@ namespace QCD { template void WilsonCloverFermion::MDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ GaugeField tmp(mat._grid); + + conformable(U._grid, _grid); + conformable(U._grid, V._grid); + conformable(U._grid, mat._grid); + + mat.checkerboard = U.checkerboard; + tmp.checkerboard = U.checkerboard; + this->DhopDeriv(mat, U, V, dag); MooDeriv(tmp, U, V, dag); mat += tmp; @@ -118,6 +128,7 @@ namespace QCD { // Derivative parts template void WilsonCloverFermion::MooDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ + assert(0); // not implemented yet } diff --git a/lib/qcd/utils/WilsonLoops.h b/lib/qcd/utils/WilsonLoops.h index ca2b2b8d..1984d2b8 100644 --- a/lib/qcd/utils/WilsonLoops.h +++ b/lib/qcd/utils/WilsonLoops.h @@ -301,7 +301,7 @@ public: GaugeMat v = adj(Vup) - adj(Vdn); GaugeMat u = PeekIndex(Umu, mu); // some redundant copies GaugeMat vu = v*u; - FS = 0.25*Ta(u*v - Cshift(vu, mu, +1)); + FS = 0.25*Ta(u*v + Cshift(vu, mu, +1));// need jsut the antihermite part } From b8ae787b5e3e50646085b5ea0dc74dd825dd9489 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Thu, 30 Mar 2017 11:33:15 +0100 Subject: [PATCH 007/174] Correcting a simple typo --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 1 - lib/qcd/utils/WilsonLoops.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 7e51dcfe..5d5d6622 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -113,7 +113,6 @@ namespace QCD { void WilsonCloverFermion::MDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ GaugeField tmp(mat._grid); - conformable(U._grid, _grid); conformable(U._grid, V._grid); conformable(U._grid, mat._grid); diff --git a/lib/qcd/utils/WilsonLoops.h b/lib/qcd/utils/WilsonLoops.h index 1984d2b8..143b283a 100644 --- a/lib/qcd/utils/WilsonLoops.h +++ b/lib/qcd/utils/WilsonLoops.h @@ -301,7 +301,7 @@ public: GaugeMat v = adj(Vup) - adj(Vdn); GaugeMat u = PeekIndex(Umu, mu); // some redundant copies GaugeMat vu = v*u; - FS = 0.25*Ta(u*v + Cshift(vu, mu, +1));// need jsut the antihermite part + FS = 0.25*Ta(u*v + Cshift(vu, mu, +1)); } From 6fd82228bfcc949e60ba229600d44c251caffd38 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Wed, 5 Apr 2017 10:51:44 +0100 Subject: [PATCH 008/174] Working on the derivative --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 5d5d6622..e588de42 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -127,7 +127,7 @@ namespace QCD { // Derivative parts template void WilsonCloverFermion::MooDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ - + // Compute the 8 terms of the derivative assert(0); // not implemented yet } From ac1253bb764fe3424f1afa87dea4ed349ef24dd9 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Mon, 10 Apr 2017 17:42:55 +0100 Subject: [PATCH 009/174] Corrected solver in rare kaon test --- tests/hadrons/Test_hadrons_rarekaon.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/hadrons/Test_hadrons_rarekaon.cc b/tests/hadrons/Test_hadrons_rarekaon.cc index 26622525..7c76312d 100644 --- a/tests/hadrons/Test_hadrons_rarekaon.cc +++ b/tests/hadrons/Test_hadrons_rarekaon.cc @@ -109,11 +109,10 @@ int main(int argc, char *argv[]) application.createModule("DWF_" + flavour[i], actionPar); // solvers - // RBPrecCG -> CG MSolver::CG::Par solverPar; solverPar.action = "DWF_" + flavour[i]; solverPar.residual = 1.0e-8; - application.createModule(solvers[i], + application.createModule(solvers[i], solverPar); } From af2d6ce2e08d54ea7a46e5eeb56e0374905d9343 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 10 Mar 2017 14:59:11 +0000 Subject: [PATCH 010/174] Encapsulated 4D->5D and 5D->4D conversions in separate functions & added corresponding tests. --- extras/Hadrons/Modules/Quark.hpp | 32 ++++-- tests/hadrons/Test_hadrons_quark.cc | 156 ++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+), 9 deletions(-) create mode 100644 tests/hadrons/Test_hadrons_quark.cc diff --git a/extras/Hadrons/Modules/Quark.hpp b/extras/Hadrons/Modules/Quark.hpp index be7426ab..c08e0192 100644 --- a/extras/Hadrons/Modules/Quark.hpp +++ b/extras/Hadrons/Modules/Quark.hpp @@ -36,6 +36,27 @@ See the full license in the file "LICENSE" in the top level distribution directo BEGIN_HADRONS_NAMESPACE +/****************************************************************************** + * 5D -> 4D and 4D -> 5D conversions. * + ******************************************************************************/ +template // Note that 5D object is modified. +inline void make_4D(Lattice &in_5d, Lattice &out_4d, int Ls) +{ + axpby_ssp_pminus(in_5d, 0., in_5d, 1., in_5d, 0, 0); + axpby_ssp_pplus(in_5d, 1., in_5d, 1., in_5d, 0, Ls-1); + ExtractSlice(out_4d, in_5d, 0, 0); +} + +template +inline void make_5D(const Lattice &in_4d, Lattice &out_5d, int Ls) +{ + out_5d = zero; + InsertSlice(in_4d, out_5d, 0, 0); + InsertSlice(in_4d, out_5d, Ls-1, 0); + axpby_ssp_pplus(out_5d, 0., out_5d, 1., out_5d, 0, 0); + axpby_ssp_pminus(out_5d, 0., out_5d, 1., out_5d, Ls-1, Ls-1); +} + /****************************************************************************** * TQuark * ******************************************************************************/ @@ -143,12 +164,8 @@ void TQuark::execute(void) } else { - source = zero; PropToFerm(tmp, fullSrc, s, c); - InsertSlice(tmp, source, 0, 0); - InsertSlice(tmp, source, Ls_-1, 0); - axpby_ssp_pplus(source, 0., source, 1., source, 0, 0); - axpby_ssp_pminus(source, 0., source, 1., source, Ls_-1, Ls_-1); + make_5D(tmp, source, Ls_); } } // source conversion for 5D sources @@ -171,10 +188,7 @@ void TQuark::execute(void) { PropagatorField &p4d = *env().template getObject(getName()); - - axpby_ssp_pminus(sol, 0., sol, 1., sol, 0, 0); - axpby_ssp_pplus(sol, 1., sol, 1., sol, 0, Ls_-1); - ExtractSlice(tmp, sol, 0, 0); + make_4D(sol, tmp, Ls_); FermToProp(p4d, tmp, s, c); } } diff --git a/tests/hadrons/Test_hadrons_quark.cc b/tests/hadrons/Test_hadrons_quark.cc new file mode 100644 index 00000000..6a142ff6 --- /dev/null +++ b/tests/hadrons/Test_hadrons_quark.cc @@ -0,0 +1,156 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: tests/hadrons/Test_hadrons_quark.cc + + Copyright (C) 2017 + + Author: Andrew Lawson + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution + directory. + *******************************************************************************/ + +#include "Test_hadrons.hpp" +#include + +using namespace Grid; +using namespace QCD; +using namespace Hadrons; + +/******************************************************************************* + * Unit test functions within Quark module. + ******************************************************************************/ + +// Alternative 4D & 5D projections +template +inline void make_4D_with_gammas(Lattice &in_5d, Lattice &out_4d, int Ls) +{ + GridBase *_grid(out_4d._grid); + Lattice tmp(_grid); + Gamma G5(Gamma::Algebra::Gamma5); + + ExtractSlice(tmp, in_5d, 0, 0); + out_4d = 0.5 * (tmp - G5*tmp); + ExtractSlice(tmp, in_5d, Ls - 1, 0); + out_4d += 0.5 * (tmp + G5*tmp); +} + +template +inline void make_5D_with_gammas(Lattice &in_4d, Lattice &out_5d, int Ls) +{ + out_5d = zero; + Gamma G5(Gamma::Algebra::Gamma5); + GridBase *_grid(in_4d._grid); + Lattice tmp(_grid); + + tmp = 0.5 * (in_4d + G5*in_4d); + InsertSlice(tmp, out_5d, 0, 0); + tmp = 0.5 * (in_4d - G5*in_4d); + InsertSlice(tmp, out_5d, Ls - 1, 0); +} + +int main(int argc, char **argv) +{ + /*************************************************************************** + * Initialisation. + **************************************************************************/ + Grid_init(&argc, &argv); + + std::vector latt_size = GridDefaultLatt(); + std::vector simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); + std::vector mpi_layout = GridDefaultMpi(); + + const int Ls = 8; + + GridCartesian UGrid(latt_size,simd_layout,mpi_layout); + GridCartesian *FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls, &UGrid); + GridSerialRNG sRNG; + GridParallelRNG pRNG(&UGrid); + + std::vector seeds4({1,2,3,4}); + std::vector seeds5({5,6,7,8}); + GridParallelRNG rng4(&UGrid); + GridParallelRNG rng5(FGrid); + rng4.SeedFixedIntegers(seeds4); + rng5.SeedFixedIntegers(seeds5); + + /*************************************************************************** + * Build a 4D random source, and convert it to 5D. + **************************************************************************/ + LatticeFermion test4(&UGrid); + LatticeFermion test5(FGrid); + LatticeFermion check5(FGrid); + + gaussian(rng4, test4); + make_5D(test4, test5, Ls); + make_5D_with_gammas(test4, check5, Ls); + test5 -= check5; + std::cout << "4D -> 5D comparison, diff = " << Grid::sqrt(norm2(test5)) << std::endl; + + /*************************************************************************** + * Build a 5D random source, and project down to 4D. + **************************************************************************/ + LatticeFermion check4(&UGrid); + gaussian(rng5, test5); + check5 = test5; + + make_4D(test5, test4, Ls); + make_4D_with_gammas(check5, check4, Ls); + test4 -= check4; + std::cout << "5D -> 4D comparison, diff = " << Grid::sqrt(norm2(test4)) << std::endl; + + /*************************************************************************** + * Convert a propagator to a fermion & back. + **************************************************************************/ + LatticeFermion ferm(&UGrid); + LatticePropagator prop(&UGrid), ref(&UGrid); + gaussian(rng4, prop); + + // Define variables for sanity checking a single site. + typename SpinColourVector::scalar_object fermSite; + typename SpinColourMatrix::scalar_object propSite; + std::vector site(Nd, 0); + + for (int s = 0; s < Ns; ++s) + for (int c = 0; c < Nc; ++c) + { + ref = prop; + PropToFerm(ferm, prop, s, c); + FermToProp(prop, ferm, s, c); + + std::cout << "Spin = " << s << ", Colour = " << c << std::endl; + ref -= prop; + std::cout << "Prop->Ferm->Prop test, diff = " << Grid::sqrt(norm2(ref)) << std::endl; + + peekSite(fermSite, ferm, site); + peekSite(propSite, prop, site); + for (int s2 = 0; s2 < Ns; ++s2) + for (int c2 = 0; c2 < Nc; ++c2) + { + //if (propSite()(s2, s)(c2, c) != fermSite()(s2)(c2)) + //{ + std::cout << propSite()(s2, s)(c2, c) << " != " + << fermSite()(s2)(c2) << " for spin = " << s2 + << ", col = " << c2 << std::endl; + //} + } + } + + Grid_finalize(); + return EXIT_SUCCESS; +} From c382c351a5d088f6af5734ab5dbc11aec53e3cf4 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 10 Mar 2017 15:05:59 +0000 Subject: [PATCH 011/174] Quark test output correction. --- tests/hadrons/Test_hadrons_quark.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/hadrons/Test_hadrons_quark.cc b/tests/hadrons/Test_hadrons_quark.cc index 6a142ff6..5b9d0ce1 100644 --- a/tests/hadrons/Test_hadrons_quark.cc +++ b/tests/hadrons/Test_hadrons_quark.cc @@ -142,12 +142,12 @@ int main(int argc, char **argv) for (int s2 = 0; s2 < Ns; ++s2) for (int c2 = 0; c2 < Nc; ++c2) { - //if (propSite()(s2, s)(c2, c) != fermSite()(s2)(c2)) - //{ + if (propSite()(s2, s)(c2, c) != fermSite()(s2)(c2)) + { std::cout << propSite()(s2, s)(c2, c) << " != " << fermSite()(s2)(c2) << " for spin = " << s2 << ", col = " << c2 << std::endl; - //} + } } } From b69499630276813e217ac211e765d13c9a4e16a0 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Fri, 14 Apr 2017 13:30:14 +0100 Subject: [PATCH 012/174] adding comments --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index e588de42..c7fd211d 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -128,6 +128,17 @@ namespace QCD { template void WilsonCloverFermion::MooDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ // Compute the 8 terms of the derivative + + // Pseudocode + // Using Chroma as a template + + // for loop on mu and nu, but upper matrix + // take the outer product factor * U x (sigma_mu_nu V) + + // derivative of loops + // end of loop + + assert(0); // not implemented yet } From 1425afc72feae364a2629f30eb6c34783d6374eb Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Tue, 25 Apr 2017 17:26:56 +0100 Subject: [PATCH 013/174] Rare Kaon test fix --- tests/hadrons/Test_hadrons_rarekaon.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/hadrons/Test_hadrons_rarekaon.cc b/tests/hadrons/Test_hadrons_rarekaon.cc index 7c76312d..9d35c1bc 100644 --- a/tests/hadrons/Test_hadrons_rarekaon.cc +++ b/tests/hadrons/Test_hadrons_rarekaon.cc @@ -109,7 +109,7 @@ int main(int argc, char *argv[]) application.createModule("DWF_" + flavour[i], actionPar); // solvers - MSolver::CG::Par solverPar; + MSolver::RBPrecCG::Par solverPar; solverPar.action = "DWF_" + flavour[i]; solverPar.residual = 1.0e-8; application.createModule(solvers[i], From 44260643f6b2d61d8ea6a2543c67e08a76dab748 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Tue, 25 Apr 2017 18:00:24 +0100 Subject: [PATCH 014/174] First conserved current implementation for Wilson fermions only. Not implemented for Gparity or 5D-vectorised Wilson fermions. --- lib/qcd/QCD.h | 8 ++ lib/qcd/action/fermion/FermionOperator.h | 15 ++++ .../fermion/ImprovedStaggeredFermion.cc | 25 ++++++ .../action/fermion/ImprovedStaggeredFermion.h | 16 ++++ .../fermion/ImprovedStaggeredFermion5D.cc | 24 +++++ .../fermion/ImprovedStaggeredFermion5D.h | 15 ++++ lib/qcd/action/fermion/WilsonFermion.cc | 47 ++++++++++ lib/qcd/action/fermion/WilsonFermion.h | 16 ++++ lib/qcd/action/fermion/WilsonFermion5D.cc | 77 ++++++++++++++++ lib/qcd/action/fermion/WilsonFermion5D.h | 15 ++++ lib/qcd/action/fermion/WilsonKernels.cc | 89 +++++++++++++++++++ lib/qcd/action/fermion/WilsonKernels.h | 18 ++++ 12 files changed, 365 insertions(+) diff --git a/lib/qcd/QCD.h b/lib/qcd/QCD.h index 6e6144da..c66c7b13 100644 --- a/lib/qcd/QCD.h +++ b/lib/qcd/QCD.h @@ -489,6 +489,14 @@ namespace QCD { return traceIndex(lhs); } + ////////////////////////////////////////// + // Current types + ////////////////////////////////////////// + GRID_SERIALIZABLE_ENUM(Current, undef, + Vector, 0, + Axial, 1, + Tadpole, 2); + } //namespace QCD } // Grid diff --git a/lib/qcd/action/fermion/FermionOperator.h b/lib/qcd/action/fermion/FermionOperator.h index 676a0e83..144b70f6 100644 --- a/lib/qcd/action/fermion/FermionOperator.h +++ b/lib/qcd/action/fermion/FermionOperator.h @@ -112,6 +112,21 @@ namespace Grid { /////////////////////////////////////////////// virtual void ImportGauge(const GaugeField & _U)=0; + ////////////////////////////////////////////////////////////////////// + // Conserved currents, either contract at sink or insert sequentially. + ////////////////////////////////////////////////////////////////////// + virtual void ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + Current curr_type, + unsigned int mu)=0; + virtual void SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + Current curr_type, + unsigned int mu, + std::vector mom, + unsigned int tmin, + unsigned int tmax)=0; }; } diff --git a/lib/qcd/action/fermion/ImprovedStaggeredFermion.cc b/lib/qcd/action/fermion/ImprovedStaggeredFermion.cc index 2ba4f4af..ef8c79bd 100644 --- a/lib/qcd/action/fermion/ImprovedStaggeredFermion.cc +++ b/lib/qcd/action/fermion/ImprovedStaggeredFermion.cc @@ -395,6 +395,31 @@ void ImprovedStaggeredFermion::DhopInternal(StencilImpl &st, LebesgueOrder } }; +//////////////////////////////////////////////////////// +// Conserved current - not yet implemented. +//////////////////////////////////////////////////////// +template +void ImprovedStaggeredFermion::ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + Current curr_type, + unsigned int mu) +{ + assert(0); +} + +template +void ImprovedStaggeredFermion::SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + Current curr_type, + unsigned int mu, + std::vector mom, + unsigned int tmin, + unsigned int tmax) +{ + assert(0); +} + FermOpStaggeredTemplateInstantiate(ImprovedStaggeredFermion); //AdjointFermOpTemplateInstantiate(ImprovedStaggeredFermion); diff --git a/lib/qcd/action/fermion/ImprovedStaggeredFermion.h b/lib/qcd/action/fermion/ImprovedStaggeredFermion.h index 7d1f2996..9d5270c6 100644 --- a/lib/qcd/action/fermion/ImprovedStaggeredFermion.h +++ b/lib/qcd/action/fermion/ImprovedStaggeredFermion.h @@ -157,6 +157,22 @@ class ImprovedStaggeredFermion : public StaggeredKernels, public ImprovedS LebesgueOrder Lebesgue; LebesgueOrder LebesgueEvenOdd; + + /////////////////////////////////////////////////////////////// + // Conserved current utilities + /////////////////////////////////////////////////////////////// + void ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + Current curr_type, + unsigned int mu); + void SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + Current curr_type, + unsigned int mu, + std::vector mom, + unsigned int tmin, + unsigned int tmax); }; typedef ImprovedStaggeredFermion ImprovedStaggeredFermionF; diff --git a/lib/qcd/action/fermion/ImprovedStaggeredFermion5D.cc b/lib/qcd/action/fermion/ImprovedStaggeredFermion5D.cc index 61a3c559..293077f7 100644 --- a/lib/qcd/action/fermion/ImprovedStaggeredFermion5D.cc +++ b/lib/qcd/action/fermion/ImprovedStaggeredFermion5D.cc @@ -345,6 +345,30 @@ void ImprovedStaggeredFermion5D::MooeeInvDag(const FermionField &in, MooeeInv(in, out); } +//////////////////////////////////////////////////////// +// Conserved current - not yet implemented. +//////////////////////////////////////////////////////// +template +void ImprovedStaggeredFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + Current curr_type, + unsigned int mu) +{ + assert(0); +} + +template +void ImprovedStaggeredFermion5D::SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + Current curr_type, + unsigned int mu, + std::vector mom, + unsigned int tmin, + unsigned int tmax) +{ + assert(0); +} FermOpStaggeredTemplateInstantiate(ImprovedStaggeredFermion5D); FermOpStaggeredVec5dTemplateInstantiate(ImprovedStaggeredFermion5D); diff --git a/lib/qcd/action/fermion/ImprovedStaggeredFermion5D.h b/lib/qcd/action/fermion/ImprovedStaggeredFermion5D.h index 4961da49..1c540892 100644 --- a/lib/qcd/action/fermion/ImprovedStaggeredFermion5D.h +++ b/lib/qcd/action/fermion/ImprovedStaggeredFermion5D.h @@ -160,6 +160,21 @@ namespace QCD { // Comms buffer std::vector > comm_buf; + /////////////////////////////////////////////////////////////// + // Conserved current utilities + /////////////////////////////////////////////////////////////// + void ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + Current curr_type, + unsigned int mu); + void SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + Current curr_type, + unsigned int mu, + std::vector mom, + unsigned int tmin, + unsigned int tmax); }; }} diff --git a/lib/qcd/action/fermion/WilsonFermion.cc b/lib/qcd/action/fermion/WilsonFermion.cc index 32083d5e..839f5215 100644 --- a/lib/qcd/action/fermion/WilsonFermion.cc +++ b/lib/qcd/action/fermion/WilsonFermion.cc @@ -347,6 +347,53 @@ void WilsonFermion::DhopInternal(StencilImpl &st, LebesgueOrder &lo, } }; +/******************************************************************************* + * Conserved current utilities for Wilson fermions, for contracting propagators + * to make a conserved current sink or inserting the conserved current + * sequentially. + ******************************************************************************/ +template +void WilsonFermion::ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + Current curr_type, + unsigned int mu) +{ + Gamma g5(Gamma::Algebra::Gamma5); + conformable(_grid, q_in_1._grid); + conformable(_grid, q_in_2._grid); + conformable(_grid, q_out._grid); + Kernels::ContractConservedCurrentInternal(q_in_1, q_in_2, q_out, + Umu, curr_type, mu); +} + +template +void WilsonFermion::SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + Current curr_type, + unsigned int mu, + std::vector mom, + unsigned int tmin, + unsigned int tmax) +{ + conformable(_grid, q_in._grid); + conformable(_grid, q_out._grid); + Lattice> ph(_grid), coor(_grid); + Complex i(0.0,1.0); + + // Momentum projection + ph = zero; + for(unsigned int mu = 0; mu < Nd - 1; mu++) + { + LatticeCoordinate(coor, mu); + ph = ph + mom[mu]*coor*((1./(_grid->_fdimensions[mu]))); + } + ph = exp((Real)(2*M_PI)*i*ph); + + Kernels::SeqConservedCurrentInternal(q_in, q_out, Umu, curr_type, mu, ph, + tmin, tmax); +} + FermOpTemplateInstantiate(WilsonFermion); AdjointFermOpTemplateInstantiate(WilsonFermion); TwoIndexFermOpTemplateInstantiate(WilsonFermion); diff --git a/lib/qcd/action/fermion/WilsonFermion.h b/lib/qcd/action/fermion/WilsonFermion.h index 933be732..feba40ed 100644 --- a/lib/qcd/action/fermion/WilsonFermion.h +++ b/lib/qcd/action/fermion/WilsonFermion.h @@ -146,6 +146,22 @@ class WilsonFermion : public WilsonKernels, public WilsonFermionStatic { LebesgueOrder Lebesgue; LebesgueOrder LebesgueEvenOdd; + + /////////////////////////////////////////////////////////////// + // Conserved current utilities + /////////////////////////////////////////////////////////////// + void ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + Current curr_type, + unsigned int mu); + void SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + Current curr_type, + unsigned int mu, + std::vector mom, + unsigned int tmin, + unsigned int tmax); }; typedef WilsonFermion WilsonFermionF; diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index 88bc425a..d0d3d055 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -679,6 +679,83 @@ void WilsonFermion5D::MomentumSpacePropagatorHw(FermionField &out,const Fe } +/******************************************************************************* + * Conserved current utilities for Wilson fermions, for contracting propagators + * to make a conserved current sink or inserting the conserved current + * sequentially. + ******************************************************************************/ +template +void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + Current curr_type, + unsigned int mu) +{ + conformable(q_in_1._grid, FermionGrid()); + conformable(q_in_1._grid, q_in_2._grid); + conformable(_FourDimGrid, q_out._grid); + + PropagatorField q1_s(_FourDimGrid); + PropagatorField q2_s(_FourDimGrid); + PropagatorField tmp(_FourDimGrid); + + // Contract across 5th dimension. + q_out = zero; + for (int s = 0; s < Ls; ++s) + { + ExtractSlice(q1_s, q_in_1, 0, s); + ExtractSlice(q2_s, q_in_2, 0, Ls - s - 1); + Kernels::ContractConservedCurrentInternal(q1_s, q2_s, tmp, Umu, curr_type, mu); + + // Axial current sign + Real G_s = (curr_type == Current::Axial) ? ((s < Ls/2) ? -1. : 1.) : 1.; + q_out += G_s*tmp; + } +} + + +template +void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + Current curr_type, + unsigned int mu, + std::vector mom, + unsigned int tmin, + unsigned int tmax) +{ + conformable(q_in._grid, FermionGrid()); + conformable(q_in._grid, q_out._grid); + Lattice> ph(_FourDimGrid), coor(_FourDimGrid); + Complex i(0.0, 1.0); + + // Momentum projection + ph = zero; + for(unsigned int nu = 0; nu < Nd - 1; nu++) + { + LatticeCoordinate(coor, nu); + ph = ph + mom[nu]*coor*((1./(_FourDimGrid->_fdimensions[nu]))); + } + ph = exp((Real)(2*M_PI)*i*ph); + + // Sequential insertion + Kernels::SeqConservedCurrentInternal(q_in, q_out, Umu, curr_type, + mu, ph, tmin, tmax); + + // Axial current sign. + if (curr_type == Current::Axial) + { + SitePropagator result; + parallel_for(int sU = 0; sU < Umu._grid->oSites(); sU++) + { + int sF = sU * Ls; + for (int s = 0; s < Ls/2; s++) + { + vstream(q_out._odata[sF], -q_out._odata[sF]); + sF++; + } + } + } +} FermOpTemplateInstantiate(WilsonFermion5D); GparityFermOpTemplateInstantiate(WilsonFermion5D); diff --git a/lib/qcd/action/fermion/WilsonFermion5D.h b/lib/qcd/action/fermion/WilsonFermion5D.h index e87e927e..d66f4a1d 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.h +++ b/lib/qcd/action/fermion/WilsonFermion5D.h @@ -214,6 +214,21 @@ namespace QCD { // Comms buffer std::vector > comm_buf; + /////////////////////////////////////////////////////////////// + // Conserved current utilities + /////////////////////////////////////////////////////////////// + void ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + Current curr_type, + unsigned int mu); + void SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + Current curr_type, + unsigned int mu, + std::vector mom, + unsigned int tmin, + unsigned int tmax); }; }} diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index 6e72e089..fbf8dc00 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -567,6 +567,95 @@ void WilsonKernels::DhopDir( StencilImpl &st, DoubledGaugeField &U,SiteHal vstream(out._odata[sF], result); } +/******************************************************************************* + * Conserved current utilities for Wilson fermions, for contracting propagators + * to make a conserved current sink or inserting the conserved current + * sequentially. Common to both 4D and 5D. + ******************************************************************************/ +#define WilsonCurrentFwd(expr, mu) (0.5*(Gamma::gmu[mu]*expr - expr)) +#define WilsonCurrentBwd(expr, mu) (0.5*(Gamma::gmu[mu]*expr + expr)) + +template +void WilsonKernels::ContractConservedCurrentInternal(const PropagatorField &q_in_1, + const PropagatorField &q_in_2, + PropagatorField &q_out, + DoubledGaugeField &U, + Current curr_type, + unsigned int mu) +{ + Gamma g5(Gamma::Algebra::Gamma5); + PropagatorField tmp(q_out._grid); + GaugeLinkField Umu(U._grid); + Umu = PeekIndex(U, mu); + + tmp = this->CovShiftForward(Umu, mu, q_in_1); + q_out = (g5*adj(q_in_2)*g5)*WilsonCurrentFwd(tmp, mu); + + tmp = adj(Umu)*q_in_1; + q_out += (g5*adj(this->CovShiftForward(Umu, mu, q_in_2))*g5)*WilsonCurrentBwd(q_in_1, mu); +} + + +template +void WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_in, + PropagatorField &q_out, + DoubledGaugeField &U, + Current curr_type, + unsigned int mu, + Lattice> &ph, + unsigned int tmin, + unsigned int tmax) +{ + int tshift = (mu == Nd - 1) ? 1 : 0; + Real G_T = (curr_type == Current::Tadpole) ? -1. : 1.; + PropagatorField tmp(q_in._grid); + GaugeLinkField Umu(U._grid); + Umu = PeekIndex(U, mu); + Lattice> t(q_in._grid); + + tmp = this->CovShiftForward(Umu, mu, q_in)*ph; + where((t >= tmin) and (t <= tmax), tmp, 0.*tmp); + q_out = G_T*WilsonCurrentFwd(tmp, mu); + + tmp = q_in*ph; + tmp = this->CovShiftBackward(Umu, mu, tmp); + where((t >= tmin + tshift) and (t <= tmax + tshift), tmp, 0.*tmp); + q_out += WilsonCurrentBwd(tmp, mu); +} + + +// GParity, (Z)DomainWallVec5D -> require special implementation +#define NO_CURR(Impl) \ +template <> void \ +WilsonKernels::ContractConservedCurrentInternal(const PropagatorField &q_in_1, \ + const PropagatorField &q_in_2, \ + PropagatorField &q_out, \ + DoubledGaugeField &U, \ + Current curr_type, \ + unsigned int mu) \ +{ \ + assert(0); \ +} \ +template <> void \ +WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_in, \ + PropagatorField &q_out, \ + DoubledGaugeField &U, \ + Current curr_type, \ + unsigned int mu, \ + Lattice> &ph, \ + unsigned int tmin, \ + unsigned int tmax) \ +{ \ + assert(0); \ +} + +NO_CURR(GparityWilsonImplF); +NO_CURR(GparityWilsonImplD); +NO_CURR(DomainWallVec5dImplF); +NO_CURR(DomainWallVec5dImplD); +NO_CURR(ZDomainWallVec5dImplF); +NO_CURR(ZDomainWallVec5dImplD); + FermOpTemplateInstantiate(WilsonKernels); AdjointFermOpTemplateInstantiate(WilsonKernels); TwoIndexFermOpTemplateInstantiate(WilsonKernels); diff --git a/lib/qcd/action/fermion/WilsonKernels.h b/lib/qcd/action/fermion/WilsonKernels.h index 20ee87f2..34820274 100644 --- a/lib/qcd/action/fermion/WilsonKernels.h +++ b/lib/qcd/action/fermion/WilsonKernels.h @@ -166,6 +166,24 @@ public: void DhopDir(StencilImpl &st, DoubledGaugeField &U,SiteHalfSpinor * buf, int sF, int sU, const FermionField &in, FermionField &out, int dirdisp, int gamma); + ////////////////////////////////////////////////////////////////////////////// + // Utilities for inserting Wilson conserved current. + ////////////////////////////////////////////////////////////////////////////// + void ContractConservedCurrentInternal(const PropagatorField &q_in_1, + const PropagatorField &q_in_2, + PropagatorField &q_out, + DoubledGaugeField &U, + Current curr_type, + unsigned int mu); + void SeqConservedCurrentInternal(const PropagatorField &q_in, + PropagatorField &q_out, + DoubledGaugeField &U, + Current curr_type, + unsigned int mu, + Lattice> &ph, + unsigned int tmin, + unsigned int tmax); + private: // Specialised variants void GenericDhopSite(StencilImpl &st, LebesgueOrder &lo, DoubledGaugeField &U, SiteHalfSpinor * buf, From dc5a6404eadc237985a1b4ffac7b8a51760e6bc4 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Tue, 25 Apr 2017 22:08:33 +0100 Subject: [PATCH 015/174] Hadrons: modules for testing conserved current contractions and sequential insertion. --- extras/Hadrons/Modules.hpp | 3 + .../Modules/MContraction/WardIdentity.hpp | 151 ++++++++++++++++++ .../Modules/MContraction/WardIdentitySeq.hpp | 117 ++++++++++++++ .../Hadrons/Modules/MSource/SeqConserved.hpp | 129 +++++++++++++++ extras/Hadrons/modules.inc | 3 + 5 files changed, 403 insertions(+) create mode 100644 extras/Hadrons/Modules/MContraction/WardIdentity.hpp create mode 100644 extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp create mode 100644 extras/Hadrons/Modules/MSource/SeqConserved.hpp diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 05ad1697..67762246 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -32,6 +32,8 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include +#include +#include #include #include #include @@ -42,6 +44,7 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include +#include #include #include #include diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp new file mode 100644 index 00000000..39221148 --- /dev/null +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -0,0 +1,151 @@ +#ifndef Hadrons_WardIdentity_hpp_ +#define Hadrons_WardIdentity_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* + Ward Identity contractions + ----------------------------- + + * options: + - q: propagator, 5D if available (string) + - q4d: 4D propagator, duplicate of q if q is not 5D (string) + - action: action module used for propagator solution (string) + - mass: mass of quark (double) +*/ + +/****************************************************************************** + * WardIdentity * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MContraction) + +class WardIdentityPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(WardIdentityPar, + std::string, q, + std::string, q4d, + std::string, action, + double, mass); +}; + +template +class TWardIdentity: public Module +{ +public: + TYPE_ALIASES(FImpl,); +public: + // constructor + TWardIdentity(const std::string name); + // destructor + virtual ~TWardIdentity(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +private: + unsigned int Ls_; +}; + +MODULE_REGISTER_NS(WardIdentity, TWardIdentity, MContraction); + +/****************************************************************************** + * TWardIdentity implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TWardIdentity::TWardIdentity(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TWardIdentity::getInput(void) +{ + std::vector in = {par().q, par().q4d, par().action}; + + return in; +} + +template +std::vector TWardIdentity::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TWardIdentity::setup(void) +{ + Ls_ = env().getObjectLs(par().q); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TWardIdentity::execute(void) +{ + LOG(Message) << "Performing Ward Identity checks for quark '" << par().q + << "'." << std::endl; + + PropagatorField psi(env().getGrid()), tmp(env().getGrid()); + PropagatorField q = *env().template getObject(par().q); + PropagatorField q4d = *env().template getObject(par().q4d); + FMat &act = *(env().template getObject(par().action)); + Gamma g5(Gamma::Algebra::Gamma5); + LatticeComplex PP(env().getGrid()), PA(env().getGrid()), + c(env().getGrid()), PJ5q(env().getGrid()), + vector_WI(env().getGrid()), defect(env().getGrid()); + c = zero; PJ5q = zero; vector_WI = zero; defect = zero; + std::vector Vmu(Nd, c); + std::vector Amu(Nd, c); + + // Get PP, PA, V_mu, A_mu for 4D. + PP = trace(adj(q4d)*q4d); + PA = trace(adj(q4d)*g5*q4d); + for (unsigned int mu = 0; mu < Nd; ++mu) + { + act.ContractConservedCurrent(q, q, tmp, Current::Vector, mu); + Vmu[mu] = trace(g5*tmp); + act.ContractConservedCurrent(q, q, tmp, Current::Axial, mu); + Amu[mu] = trace(g5*tmp); + } + + // Get PJ5q for 5D (zero for 4D). + if (Ls_ > 1) + { + ExtractSlice(psi, q, 0, Ls_/2 - 1); + psi = 0.5 * (psi + g5*psi); + ExtractSlice(tmp, q, 0, Ls_/2); + psi += 0.5 * (tmp - g5*tmp); + PJ5q = trace(adj(psi)*psi); + } + + // Test ward identities, D_mu V_mu = 0; D_mu A_mu = 2m + 2 PJ5q + for (unsigned int mu = 0; mu < Nd; ++mu) + { + vector_WI += Vmu[mu] - Cshift(Vmu[mu], mu, -1); + defect += Amu[mu] - Cshift(Amu[mu], mu, -1); + } + defect -= 2.*PJ5q; + defect -= 2.*(par().mass)*PP; + + LOG(Message) << "Vector Ward Identity check Delta_mu V_mu = " + << norm2(vector_WI) << std::endl; + LOG(Message) << "Axial Ward Identity defect Delta_mu A_mu = " + << norm2(defect) << std::endl; +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_WardIdentity_hpp_ diff --git a/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp b/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp new file mode 100644 index 00000000..3e72c11e --- /dev/null +++ b/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp @@ -0,0 +1,117 @@ +#ifndef Hadrons_WardIdentitySeq_hpp_ +#define Hadrons_WardIdentitySeq_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* + Ward Identity contractions using sequential propagators. + ----------------------------- + + * options: + - q_x: propagator, mu = x current insertion (string). + - q_y: propagator, mu = y current insertion (string). + - q_z: propagator, mu = z current insertion (string). + - q_t: propagator, mu = t current insertion (string). +*/ + +/****************************************************************************** + * WardIdentitySeq * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MContraction) + +class WardIdentitySeqPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(WardIdentitySeqPar, + std::string, q_x, + std::string, q_y, + std::string, q_z, + std::string, q_t); +}; + +template +class TWardIdentitySeq: public Module +{ +public: + TYPE_ALIASES(FImpl,); +public: + // constructor + TWardIdentitySeq(const std::string name); + // destructor + virtual ~TWardIdentitySeq(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_NS(WardIdentitySeq, TWardIdentitySeq, MContraction); + +/****************************************************************************** + * TWardIdentitySeq implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TWardIdentitySeq::TWardIdentitySeq(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TWardIdentitySeq::getInput(void) +{ + std::vector in = {par().q_x, par().q_y, par().q_z, par().q_t}; + + return in; +} + +template +std::vector TWardIdentitySeq::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TWardIdentitySeq::setup(void) +{ + +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TWardIdentitySeq::execute(void) +{ + LatticeComplex vector_WI(env().getGrid()), c(env().getGrid()); + PropagatorField q_x = *env().template getObject(par().q_x); + PropagatorField q_y = *env().template getObject(par().q_y); + PropagatorField q_z = *env().template getObject(par().q_z); + PropagatorField q_t = *env().template getObject(par().q_t); + PropagatorField *q[Nd] = {&q_x, &q_y, &q_z, &q_t}; + Gamma g5(Gamma::Algebra::Gamma5); + + // Check D_mu V_mu = 0 + for (unsigned int mu = 0; mu < Nd; ++mu) + { + c = trace(g5*(*q[mu])); + vector_WI += c - Cshift(c, mu, -1); + } + + LOG(Message) << "Ward Identity checks for sequential vector current " + << "insertion = " << norm2(vector_WI) << std::endl; +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_WardIdentitySeq_hpp_ diff --git a/extras/Hadrons/Modules/MSource/SeqConserved.hpp b/extras/Hadrons/Modules/MSource/SeqConserved.hpp new file mode 100644 index 00000000..7d4974f4 --- /dev/null +++ b/extras/Hadrons/Modules/MSource/SeqConserved.hpp @@ -0,0 +1,129 @@ +#ifndef Hadrons_SeqConserved_hpp_ +#define Hadrons_SeqConserved_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* + + Sequential source + ----------------------------- + * src_x = q_x * theta(x_3 - tA) * theta(tB - x_3) * J_mu * exp(i x.mom) + + * options: + - q: input propagator (string) + - action: fermion action used for propagator q (string) + - tA: begin timeslice (integer) + - tB: end timesilce (integer) + - curr_type: type of conserved current to insert (Current) + - mu: Lorentz index of current to insert (integer) + - mom: momentum insertion, space-separated float sequence (e.g ".1 .2 1. 0.") + + */ + +/****************************************************************************** + * SeqConserved * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MSource) + +class SeqConservedPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(SeqConservedPar, + std::string, q, + std::string, action, + unsigned int, tA, + unsigned int, tB, + Current, curr_type, + unsigned int, mu, + std::string, mom); +}; + +template +class TSeqConserved: public Module +{ +public: + TYPE_ALIASES(FImpl,); +public: + // constructor + TSeqConserved(const std::string name); + // destructor + virtual ~TSeqConserved(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_NS(SeqConserved, TSeqConserved, MSource); + +/****************************************************************************** + * TSeqConserved implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TSeqConserved::TSeqConserved(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TSeqConserved::getInput(void) +{ + std::vector in; + + return in; +} + +template +std::vector TSeqConserved::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TSeqConserved::setup(void) +{ + +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TSeqConserved::execute(void) +{ + if (par().tA == par().tB) + { + LOG(Message) << "Generating sequential source with conserved " + << par().curr_type << " current insertion (mu = " + << par().mu << ") at " << "t = " << par().tA << std::endl; + } + else + { + LOG(Message) << "Generating sequential source with conserved " + << par().curr_type << " current insertion (mu = " + << par().mu << ") for " << par().tA << " <= t <= " + << par().tB << std::endl; + } + PropagatorField &src = *env().template createLattice(getName()); + PropagatorField &q = *env().template getObject(par().q); + FMat &mat = *(env().template getObject(par().action)); + + std::vector mom = strToVec(par().mom); + mat.SeqConservedCurrent(q, src, par().curr_type, par().mu, + mom, par().tA, par().tB); +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_SeqConserved_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index af291631..32655c3b 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -13,6 +13,8 @@ modules_hpp =\ Modules/MContraction/DiscLoop.hpp \ Modules/MContraction/Gamma3pt.hpp \ Modules/MContraction/Meson.hpp \ + Modules/MContraction/WardIdentity.hpp \ + Modules/MContraction/WardIdentitySeq.hpp \ Modules/MContraction/WeakHamiltonian.hpp \ Modules/MContraction/WeakHamiltonianEye.hpp \ Modules/MContraction/WeakHamiltonianNonEye.hpp \ @@ -23,6 +25,7 @@ modules_hpp =\ Modules/MLoop/NoiseLoop.hpp \ Modules/MSolver/RBPrecCG.hpp \ Modules/MSource/Point.hpp \ + Modules/MSource/SeqConserved.hpp \ Modules/MSource/SeqGamma.hpp \ Modules/MSource/Wall.hpp \ Modules/MSource/Z2.hpp \ From 159770e21ba2515d145bb331305593474ce33b01 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Wed, 26 Apr 2017 09:32:57 +0100 Subject: [PATCH 016/174] Legal Banners added --- .../Modules/MContraction/WardIdentity.hpp | 28 +++++++++++++++++++ .../Modules/MContraction/WardIdentitySeq.hpp | 28 +++++++++++++++++++ .../Hadrons/Modules/MSource/SeqConserved.hpp | 28 +++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index 39221148..355126da 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -1,3 +1,31 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MContraction/WardIdentity.hpp + +Copyright (C) 2017 + +Author: Andrew Lawson + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + #ifndef Hadrons_WardIdentity_hpp_ #define Hadrons_WardIdentity_hpp_ diff --git a/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp b/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp index 3e72c11e..31409925 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp @@ -1,3 +1,31 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp + +Copyright (C) 2017 + +Author: Andrew Lawson + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + #ifndef Hadrons_WardIdentitySeq_hpp_ #define Hadrons_WardIdentitySeq_hpp_ diff --git a/extras/Hadrons/Modules/MSource/SeqConserved.hpp b/extras/Hadrons/Modules/MSource/SeqConserved.hpp index 7d4974f4..ccfb68f4 100644 --- a/extras/Hadrons/Modules/MSource/SeqConserved.hpp +++ b/extras/Hadrons/Modules/MSource/SeqConserved.hpp @@ -1,3 +1,31 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MContraction/SeqConserved.hpp + +Copyright (C) 2017 + +Author: Andrew Lawson + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + #ifndef Hadrons_SeqConserved_hpp_ #define Hadrons_SeqConserved_hpp_ From a39daecb62a0bf8a128f4650d311badaa1659fda Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Wed, 26 Apr 2017 12:39:07 +0100 Subject: [PATCH 017/174] Removed make_5D const declaration to avoid compilation error --- extras/Hadrons/Modules/Quark.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/Hadrons/Modules/Quark.hpp b/extras/Hadrons/Modules/Quark.hpp index c08e0192..fff34edf 100644 --- a/extras/Hadrons/Modules/Quark.hpp +++ b/extras/Hadrons/Modules/Quark.hpp @@ -48,7 +48,7 @@ inline void make_4D(Lattice &in_5d, Lattice &out_4d, int Ls) } template -inline void make_5D(const Lattice &in_4d, Lattice &out_5d, int Ls) +inline void make_5D(Lattice &in_4d, Lattice &out_5d, int Ls) { out_5d = zero; InsertSlice(in_4d, out_5d, 0, 0); From 6299dd35f57b03131447d70f7b8e7f002dc4cdf9 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Wed, 26 Apr 2017 12:41:39 +0100 Subject: [PATCH 018/174] Hadrons: Added test of conserved current code. Tests Ward identities for conserved vector and partially conserved axial currents. --- .../hadrons/Test_hadrons_conserved_current.cc | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 tests/hadrons/Test_hadrons_conserved_current.cc diff --git a/tests/hadrons/Test_hadrons_conserved_current.cc b/tests/hadrons/Test_hadrons_conserved_current.cc new file mode 100644 index 00000000..df774ac0 --- /dev/null +++ b/tests/hadrons/Test_hadrons_conserved_current.cc @@ -0,0 +1,127 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: tests/hadrons/Test_hadrons_conserved_current.cc + + Copyright (C) 2017 + + Author: Andrew Lawson + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution + directory. + *******************************************************************************/ + +#include "Test_hadrons.hpp" + +using namespace Grid; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + // initialization ////////////////////////////////////////////////////////// + Grid_init(&argc, &argv); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); + LOG(Message) << "Grid initialized" << std::endl; + + // run setup /////////////////////////////////////////////////////////////// + Application application; + unsigned int nt = GridDefaultLatt()[Tp]; + double mass = 0.04; + + // global parameters + Application::GlobalPar globalPar; + globalPar.trajCounter.start = 1500; + globalPar.trajCounter.end = 1520; + globalPar.trajCounter.step = 20; + globalPar.seed = "1 2 3 4"; + globalPar.genetic.maxGen = 1000; + globalPar.genetic.maxCstGen = 200; + globalPar.genetic.popSize = 20; + globalPar.genetic.mutationRate = .1; + application.setPar(globalPar); + + // gauge field + application.createModule("gauge"); + + // action + std::string actionName = "DWF"; + MAction::DWF::Par actionPar; + actionPar.gauge = "gauge"; + actionPar.Ls = 12; + actionPar.M5 = 1.8; + actionPar.mass = mass; + application.createModule(actionName, actionPar); + + // solver + std::string solverName = "CG"; + MSolver::RBPrecCG::Par solverPar; + solverPar.action = actionName; + solverPar.residual = 1.0e-8; + application.createModule(solverName, + solverPar); + + // Conserved current sink contractions: use a single point propagator. + std::string pointProp = "q_0"; + std::string pos = "0 0 0 0"; + std::string modName = "Ward Identity Test"; + MAKE_POINT_PROP(pos, pointProp, solverName); + if (!(Environment::getInstance().hasModule(modName))) + { + MContraction::WardIdentity::Par wiPar; + wiPar.q = pointProp + "_5d"; + wiPar.q4d = pointProp; + wiPar.action = actionName; + wiPar.mass = mass; + application.createModule(modName, wiPar); + } + + // Conserved current contractions with sequential insertion of vector + // current. + std::string q_x = "q_x"; + std::string q_y = "q_y"; + std::string q_z = "q_z"; + std::string q_t = "q_t"; + std::string mom = ZERO_MOM; + modName = "Sequential Ward Identity Test"; + MAKE_SEQUENTIAL_PROP(nt/2, pointProp, mom, q_x, solverName); + MAKE_SEQUENTIAL_PROP(nt/2, pointProp, mom, q_y, solverName); + MAKE_SEQUENTIAL_PROP(nt/2, pointProp, mom, q_z, solverName); + MAKE_SEQUENTIAL_PROP(nt/2, pointProp, mom, q_t, solverName); + if (!(Environment::getInstance().hasModule(modName))) + { + MContraction::WardIdentitySeq::Par wiPar; + wiPar.q_x = q_x; + wiPar.q_y = q_y; + wiPar.q_z = q_z; + wiPar.q_t = q_t; + application.createModule(modName, wiPar); + } + + // execution + application.saveParameterFile("ConservedCurrentTest.xml"); + application.run(); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} \ No newline at end of file From d2003f24f49b68f49fd0cb5764ef32f6ef4cd498 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Wed, 26 Apr 2017 17:25:28 +0100 Subject: [PATCH 019/174] Corrected incorrect usage of ExtractSlice for conserved current code. --- extras/Hadrons/Modules/MContraction/WardIdentity.hpp | 4 ++-- lib/qcd/action/fermion/WilsonFermion5D.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index 355126da..41d8c6d1 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -150,9 +150,9 @@ void TWardIdentity::execute(void) // Get PJ5q for 5D (zero for 4D). if (Ls_ > 1) { - ExtractSlice(psi, q, 0, Ls_/2 - 1); + ExtractSlice(psi, q, Ls_/2 - 1, 0); psi = 0.5 * (psi + g5*psi); - ExtractSlice(tmp, q, 0, Ls_/2); + ExtractSlice(tmp, q, Ls_/2, 0); psi += 0.5 * (tmp - g5*tmp); PJ5q = trace(adj(psi)*psi); } diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index d0d3d055..99ff0dc1 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -703,8 +703,8 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, q_out = zero; for (int s = 0; s < Ls; ++s) { - ExtractSlice(q1_s, q_in_1, 0, s); - ExtractSlice(q2_s, q_in_2, 0, Ls - s - 1); + ExtractSlice(q1_s, q_in_1, s, 0); + ExtractSlice(q2_s, q_in_2, Ls - s - 1, 0); Kernels::ContractConservedCurrentInternal(q1_s, q2_s, tmp, Umu, curr_type, mu); // Axial current sign From a6ccbbe1080f8c7d2bd193e08ad38b97d0f5af1d Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 28 Apr 2017 10:43:47 +0100 Subject: [PATCH 020/174] Conserved current sequential source now registered properly and fixed module inputs. --- extras/Hadrons/Modules/MSource/SeqConserved.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extras/Hadrons/Modules/MSource/SeqConserved.hpp b/extras/Hadrons/Modules/MSource/SeqConserved.hpp index ccfb68f4..6e5fb197 100644 --- a/extras/Hadrons/Modules/MSource/SeqConserved.hpp +++ b/extras/Hadrons/Modules/MSource/SeqConserved.hpp @@ -104,7 +104,7 @@ TSeqConserved::TSeqConserved(const std::string name) template std::vector TSeqConserved::getInput(void) { - std::vector in; + std::vector in = {par().q, par().action}; return in; } @@ -121,7 +121,8 @@ std::vector TSeqConserved::getOutput(void) template void TSeqConserved::setup(void) { - + auto Ls_ = env().getObjectLs(par().action); + env().template registerLattice(getName(), Ls_); } // execution /////////////////////////////////////////////////////////////////// From 5553b8d2b86a1fa4b44a304e4fab9ab3e8001f16 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Fri, 28 Apr 2017 15:23:34 +0100 Subject: [PATCH 021/174] Clover term compiles, not tested --- lib/qcd/action/fermion/Fermion.h | 2 +- lib/qcd/action/fermion/WilsonCloverFermion.cc | 144 ++++++---- lib/qcd/action/fermion/WilsonCloverFermion.h | 59 ++-- tests/core/Test_wilson_clover.cc | 251 ++++++++++++++++++ 4 files changed, 383 insertions(+), 73 deletions(-) create mode 100644 tests/core/Test_wilson_clover.cc diff --git a/lib/qcd/action/fermion/Fermion.h b/lib/qcd/action/fermion/Fermion.h index 2eaf42fa..9d999c6d 100644 --- a/lib/qcd/action/fermion/Fermion.h +++ b/lib/qcd/action/fermion/Fermion.h @@ -49,7 +49,7 @@ Author: Peter Boyle #include // 4d wilson like #include // 4d wilson like -#include // 4d wilson like +#include // 4d wilson clover fermions #include // 5d base used by all 5d overlap types #include diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index c7fd211d..ebea565b 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -27,28 +27,35 @@ *************************************************************************************/ /* END LEGAL */ #include +#include #include namespace Grid { namespace QCD { - template - void WilsonCloverFermion::AddCloverTerm(const FermionField& in, - FermionField& out){ - FermionField tmp(out._grid); - tmp = zero; - // the product sigma_munu Fmunu is hermitian - tmp += Bx*(Gamma(Gamma::Algebra::SigmaYZ)*in); - tmp += By*(Gamma(Gamma::Algebra::MinusSigmaXZ)*in); - tmp += Bz*(Gamma(Gamma::Algebra::SigmaXY)*in); - tmp += Ex*(Gamma(Gamma::Algebra::MinusSigmaXT)*in); - tmp += Ey*(Gamma(Gamma::Algebra::MinusSigmaYT)*in); - tmp += Ez*(Gamma(Gamma::Algebra::MinusSigmaZT)*in); - out += tmp*csw; // check signs - - } +//WilsonLoop::CloverPlaquette +///////////////////////////////////////////////////// +//// Clover plaquette combination in mu,nu plane with Double Stored U +//////////////////////////////////////////////////// +//static void CloverPlaquette(GaugeMat &Q, const std::vector &U, +// const int mu, const int nu){ +// Q = zero; +// Q += Gimpl::CovShiftBackward( +// U[mu], mu, Gimpl::CovShiftBackward( +// U[nu], nu, Gimpl::CovShiftForward(U[mu], mu, U[nu] ))); +// Q += Gimpl::CovShiftForward( +// U[mu], mu, Gimpl::CovShiftForward( +// U[nu], nu, Gimpl::CovShiftBackward(U[mu], mu, U[nu+Nd] ))); +// Q += Gimpl::CovShiftBackward( +// U[nu], nu, Gimpl::CovShiftForward( +// U[mu], mu, Gimpl::CovShiftForward(U[nu], nu, U[mu+Nd] ))); +// Q += Gimpl::CovShiftForward( +// U[mu], mu, Gimpl::CovShiftBackward( +// U[nu], nu, Gimpl::CovShiftBackward(U[mu], mu, U[nu] ))); +// } +// *NOT* EO template RealD WilsonCloverFermion::M(const FermionField& in, FermionField& out) { // Wilson term @@ -56,7 +63,7 @@ namespace QCD { this->Dhop(in, out, DaggerNo); // Clover term // apply the sigma and Fmunu - AddCloverTerm(in, out); + Mooee(in, out); // overall factor return axpy_norm(out, 4 + this->mass, in, out); } @@ -68,13 +75,16 @@ namespace QCD { this->Dhop(in, out, DaggerYes); // Clover term // apply the sigma and Fmunu - AddCloverTerm(in, out); + MooeeDag(in, out); return axpy_norm(out, 4 + this->mass, in, out); } template void WilsonCloverFermion::ImportGauge(const GaugeField& _Umu) { this->ImportGauge(_Umu); + GridBase* grid = _Umu._grid; + assert(Nd==4); //only works in 4 dim + typename Impl::GaugeLinkField Bx(grid), By(grid), Bz(grid), Ex(grid), Ey(grid), Ez(grid); // Compute the field strength terms WilsonLoops::FieldStrength(Bx, _Umu, Ydir, Zdir); WilsonLoops::FieldStrength(By, _Umu, Zdir, Xdir); @@ -82,31 +92,77 @@ namespace QCD { WilsonLoops::FieldStrength(Ex, _Umu, Tdir, Xdir); WilsonLoops::FieldStrength(Ey, _Umu, Tdir, Ydir); WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); - // Save the contracted term with sigma - // into a dense matrix site by site - // Invert the Moo, Mee terms (using Eigen) + // Compute the Clover Operator acting on Colour and Spin + CloverTerm = fillClover(Bx)*(Gamma(Gamma::Algebra::SigmaYZ)); + CloverTerm += fillClover(By)*(Gamma(Gamma::Algebra::MinusSigmaXZ)); + CloverTerm += fillClover(Bz)*(Gamma(Gamma::Algebra::SigmaXY)); + CloverTerm += fillClover(Ex)*(Gamma(Gamma::Algebra::MinusSigmaXT)); + CloverTerm += fillClover(Ey)*(Gamma(Gamma::Algebra::MinusSigmaYT)); + CloverTerm += fillClover(Ez)*(Gamma(Gamma::Algebra::MinusSigmaZT)); + CloverTerm *= csw; + + + int lvol = _Umu._grid->lSites(); + int DimRep = Impl::Dimension; + + Eigen::MatrixXcd EigenCloverOp = Eigen::MatrixXcd::Zero(Ns*DimRep,Ns*DimRep); + Eigen::MatrixXcd EigenInvCloverOp = Eigen::MatrixXcd::Zero(Ns*DimRep,Ns*DimRep); + + std::vector lcoor; + typename SiteCloverType::scalar_object Qx = zero, Qxinv = zero; + + for (int site = 0; site < lvol; site++){ + grid->LocalIndexToLocalCoor(site,lcoor); + EigenCloverOp=Eigen::MatrixXcd::Zero(Ns*DimRep,Ns*DimRep); + peekLocalSite(Qx,CloverTerm,lcoor); + Qxinv = zero; + for(int j = 0; j < Ns; j++) + for (int k = 0; k < Ns; k++) + for(int a = 0; a < DimRep; a++) + for(int b = 0; b < DimRep; b++) + EigenCloverOp(a+j*DimRep,b+k*DimRep) = Qx()(j,k)(a,b); + + EigenInvCloverOp = EigenCloverOp.inverse(); + for(int j = 0; j < Ns; j++) + for (int k = 0; k < Ns; k++) + for(int a = 0; a < DimRep; a++) + for(int b = 0; b < DimRep; b++) + Qxinv()(j,k)(a,b) = EigenInvCloverOp(a+j*DimRep,b+k*DimRep); + + pokeLocalSite(Qxinv,CloverTermInv,lcoor); + } + } + + template + void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out){ + this -> MooeeInternal(in, out, DaggerNo, InverseNo); + } + + template + void WilsonCloverFermion::MooeeDag(const FermionField &in, FermionField &out){ + this -> MooeeInternal(in, out, DaggerNo, InverseYes); + } + + template + void WilsonCloverFermion::MooeeInv(const FermionField &in, FermionField &out){ + this -> MooeeInternal(in, out, DaggerNo, InverseYes); + } + + template + void WilsonCloverFermion::MooeeInvDag(const FermionField &in, FermionField &out){ + this -> MooeeInternal(in, out, DaggerNo, InverseYes); } template - void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out) { - out.checkerboard = in.checkerboard; - assert(0); // to be completed - } + void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionField &out, int dag, int inv){ + out.checkerboard = in.checkerboard; + CloverFieldType *Clover; - template - void WilsonCloverFermion::MooeeDag(const FermionField &in, FermionField &out) { - assert(0); // not implemented yet - } - template - void WilsonCloverFermion::MooeeInv(const FermionField &in, FermionField &out) { - assert(0); // not implemented yet - } - template - void WilsonCloverFermion::MooeeInvDag(const FermionField &in, FermionField &out) { - assert(0); // not implemented yet - } + Clover = (inv) ? &CloverTermInv : &CloverTerm; + if(dag){ out = adj(*Clover)*in;} else {out = *Clover*in;} + } // MooeeInternal // Derivative parts template @@ -128,17 +184,6 @@ namespace QCD { template void WilsonCloverFermion::MooDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ // Compute the 8 terms of the derivative - - // Pseudocode - // Using Chroma as a template - - // for loop on mu and nu, but upper matrix - // take the outer product factor * U x (sigma_mu_nu V) - - // derivative of loops - // end of loop - - assert(0); // not implemented yet } @@ -148,7 +193,10 @@ namespace QCD { assert(0); // not implemented yet } - FermOpTemplateInstantiate(WilsonCloverFermion); +FermOpTemplateInstantiate(WilsonCloverFermion); // now only for the fundamental representation +//AdjointFermOpTemplateInstantiate(WilsonCloverFermion); +//TwoIndexFermOpTemplateInstantiate(WilsonCloverFermion); +//GparityFermOpTemplateInstantiate(WilsonCloverFermion); } } diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index e942de1f..0fa0d57d 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -31,14 +31,20 @@ #include -namespace Grid { -namespace QCD { +namespace Grid +{ +namespace QCD +{ template -class WilsonCloverFermion : public WilsonFermion { +class WilsonCloverFermion : public WilsonFermion +{ public: + // Types definitions INHERIT_IMPL_TYPES(Impl); - + template using iImplClover = iScalar, Ns> >; + typedef iImplClover SiteCloverType; + typedef Lattice CloverFieldType; public: typedef WilsonFermion WilsonBase; @@ -51,43 +57,48 @@ public: const ImplParams &p = ImplParams()) : WilsonFermion(_Umu, Fgrid, Hgrid, - _mass, p), - Bx(_Umu._grid), - By(_Umu._grid), - Bz(_Umu._grid), - Ex(_Umu._grid), - Ey(_Umu._grid), - Ez(_Umu._grid) + _mass, p), + CloverTerm(&Fgrid), + CloverTermInv(&Fgrid) { csw = _csw; assert(Nd == 4); // require 4 dimensions } - virtual RealD M(const FermionField& in, FermionField& out); - virtual RealD Mdag(const FermionField& in, FermionField& out); + virtual RealD M(const FermionField &in, FermionField &out); + virtual RealD Mdag(const FermionField &in, FermionField &out); virtual void Mooee(const FermionField &in, FermionField &out); virtual void MooeeDag(const FermionField &in, FermionField &out); virtual void MooeeInv(const FermionField &in, FermionField &out); virtual void MooeeInvDag(const FermionField &in, FermionField &out); + virtual void MooeeInternal(const FermionField &in, FermionField &out, int dag, int inv); - virtual void MDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag); - virtual void MooDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag); - virtual void MeeDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag); - + virtual void MDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag); + virtual void MooDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag); + virtual void MeeDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag); void ImportGauge(const GaugeField &_Umu); + private: // here fixing the 4 dimensions, make it more general? - // Field strengths - GaugeLinkField Bx, By, Bz, Ex, Ey, Ez; + RealD csw; // Clover coefficient + CloverFieldType CloverTerm, CloverTermInv; // Clover term + // eventually these two can be compressed into 6x6 blocks instead of the 12x12 + // using the DeGrand-Rossi basis for the gamma matrices - RealD csw; // Clover coefficient - - - // Methods - void AddCloverTerm(const FermionField& in, FermionField& out); + CloverFieldType fillClover(const GaugeLinkField& F){ + CloverFieldType T(F._grid); + PARALLEL_FOR_LOOP + for (int i = 0; i < CloverTerm._grid->oSites(); i++){ + for (int s1 = 0; s1 < Nc; s1++) + for (int s2 = 0; s2 < Nc; s2++) + T._odata[i]()(s1,s2) = F._odata[i]()(); + } + return T; + } + }; } } diff --git a/tests/core/Test_wilson_clover.cc b/tests/core/Test_wilson_clover.cc new file mode 100644 index 00000000..08516d80 --- /dev/null +++ b/tests/core/Test_wilson_clover.cc @@ -0,0 +1,251 @@ + /************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./benchmarks/Benchmark_wilson.cc + + Copyright (C) 2015 + + Author: Guido Cossu + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ + /* END LEGAL */ +#include + +using namespace std; +using namespace Grid; +using namespace Grid::QCD; + +int main (int argc, char ** argv) +{ + Grid_init(&argc,&argv); + + std::vector latt_size = GridDefaultLatt(); + std::vector simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); + std::vector mpi_layout = GridDefaultMpi(); + GridCartesian Grid(latt_size,simd_layout,mpi_layout); + GridRedBlackCartesian RBGrid(latt_size,simd_layout,mpi_layout); + + int threads = GridThread::GetThreads(); + std::cout< seeds({1,2,3,4}); + GridParallelRNG pRNG(&Grid); + pRNG.SeedFixedIntegers(seeds); + // pRNG.SeedFixedIntegers(std::vector({45,12,81,9}); + + typedef typename WilsonCloverFermionR::FermionField FermionField; + typename WilsonCloverFermionR::ImplParams params; + + FermionField src (&Grid); random(pRNG,src); + FermionField result(&Grid); result=zero; + FermionField ref(&Grid); ref=zero; + FermionField tmp(&Grid); tmp=zero; + FermionField err(&Grid); tmp=zero; + FermionField phi (&Grid); random(pRNG,phi); + FermionField chi (&Grid); random(pRNG,chi); + LatticeGaugeField Umu(&Grid); SU3::HotConfiguration(pRNG,Umu); + std::vector U(4,&Grid); + + + double volume=1; + for(int mu=0;mu(Umu,mu); + /* Debug force unit + U[mu] = 1.0; + PokeIndex(Umu,U[mu],mu); + */ + } + + ref = zero; + + RealD mass=0.1; + RealD csw = 1.0; + + { // Simple clover implementation + + // ref = ref + mass * src; + } + + WilsonCloverFermionR Dwc(Umu,Grid,RBGrid,mass,csw,params); + + + std::cout< * = < chi | Deo^dag| phi> "< HermOpEO(Dwc); + HermOpEO.MpcDagMpc(chi_e,dchi_e,t1,t2); + HermOpEO.MpcDagMpc(chi_o,dchi_o,t1,t2); + + HermOpEO.MpcDagMpc(phi_e,dphi_e,t1,t2); + HermOpEO.MpcDagMpc(phi_o,dphi_o,t1,t2); + + pDce = innerProduct(phi_e,dchi_e); + pDco = innerProduct(phi_o,dchi_o); + cDpe = innerProduct(chi_e,dphi_e); + cDpo = innerProduct(chi_o,dphi_o); + + std::cout< Date: Fri, 28 Apr 2017 15:27:49 +0100 Subject: [PATCH 022/174] SitePropagator redefined to be a scalar object in TYPE_ALIASES. --- extras/Hadrons/Global.hpp | 14 +++++++------- extras/Hadrons/Modules/MSource/Point.hpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 3e11ddf8..ebf93283 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -60,13 +60,13 @@ BEGIN_HADRONS_NAMESPACE // type aliases #define TYPE_ALIASES(FImpl, suffix)\ -typedef FermionOperator FMat##suffix; \ -typedef typename FImpl::FermionField FermionField##suffix; \ -typedef typename FImpl::PropagatorField PropagatorField##suffix; \ -typedef typename FImpl::SitePropagator SitePropagator##suffix; \ -typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix;\ -typedef std::function SolverFn##suffix; +typedef FermionOperator FMat##suffix; \ +typedef typename FImpl::FermionField FermionField##suffix; \ +typedef typename FImpl::PropagatorField PropagatorField##suffix; \ +typedef typename FImpl::SitePropagator::scalar_object SitePropagator##suffix; \ +typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix;\ +typedef std::function SolverFn##suffix; // logger class HadronsLogger: public Logger diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index a0ecbc2a..36e1cc5b 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -118,7 +118,7 @@ template void TPoint::execute(void) { std::vector position = strToVec(par().position); - typename SitePropagator::scalar_object id; + SitePropagator id; LOG(Message) << "Creating point source at position [" << par().position << "]" << std::endl; From 99a73f4287cf0eb595595851b0330e4c0e7c9dc1 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Fri, 28 Apr 2017 15:51:05 +0100 Subject: [PATCH 023/174] Correcting the M and Mdag in the clover term --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 277 +++++++++--------- 1 file changed, 146 insertions(+), 131 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index ebea565b..3ab481ce 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -30,13 +30,15 @@ #include #include -namespace Grid { -namespace QCD { +namespace Grid +{ +namespace QCD +{ -//WilsonLoop::CloverPlaquette -///////////////////////////////////////////////////// -//// Clover plaquette combination in mu,nu plane with Double Stored U -//////////////////////////////////////////////////// +//WilsonLoop::CloverPlaquette +///////////////////////////////////////////////////// +//// Clover plaquette combination in mu,nu plane with Double Stored U +//////////////////////////////////////////////////// //static void CloverPlaquette(GaugeMat &Q, const std::vector &U, // const int mu, const int nu){ // Q = zero; @@ -54,149 +56,162 @@ namespace QCD { // U[nu], nu, Gimpl::CovShiftBackward(U[mu], mu, U[nu] ))); // } +// *NOT* EO +template +RealD WilsonCloverFermion::M(const FermionField &in, FermionField &out) +{ + // Wilson term + out.checkerboard = in.checkerboard; + this->Dhop(in, out, DaggerNo); + // Clover term + // apply the sigma and Fmunu + FermionField temp(out._grid); + Mooee(in, temp); + // overall factor + out += temp; + return axpy_norm(out, 4 + this->mass, in, out); +} -// *NOT* EO - template - RealD WilsonCloverFermion::M(const FermionField& in, FermionField& out) { - // Wilson term - out.checkerboard = in.checkerboard; - this->Dhop(in, out, DaggerNo); - // Clover term - // apply the sigma and Fmunu - Mooee(in, out); - // overall factor - return axpy_norm(out, 4 + this->mass, in, out); +template +RealD WilsonCloverFermion::Mdag(const FermionField &in, FermionField &out) +{ + // Wilson term + out.checkerboard = in.checkerboard; + this->Dhop(in, out, DaggerYes); + // Clover term + // apply the sigma and Fmunu + FermionField temp(out._grid); + MooeeDag(in, temp); + out+=temp; + return axpy_norm(out, 4 + this->mass, in, out); +} + +template +void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) +{ + this->ImportGauge(_Umu); + GridBase *grid = _Umu._grid; + assert(Nd == 4); // only works in 4 dim + typename Impl::GaugeLinkField Bx(grid), By(grid), Bz(grid), Ex(grid), Ey(grid), Ez(grid); + + // Compute the field strength terms + WilsonLoops::FieldStrength(Bx, _Umu, Ydir, Zdir); + WilsonLoops::FieldStrength(By, _Umu, Zdir, Xdir); + WilsonLoops::FieldStrength(Bz, _Umu, Xdir, Ydir); + WilsonLoops::FieldStrength(Ex, _Umu, Tdir, Xdir); + WilsonLoops::FieldStrength(Ey, _Umu, Tdir, Ydir); + WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); + + // Compute the Clover Operator acting on Colour and Spin + CloverTerm = fillClover(Bx) * (Gamma(Gamma::Algebra::SigmaYZ)); + CloverTerm += fillClover(By) * (Gamma(Gamma::Algebra::MinusSigmaXZ)); + CloverTerm += fillClover(Bz) * (Gamma(Gamma::Algebra::SigmaXY)); + CloverTerm += fillClover(Ex) * (Gamma(Gamma::Algebra::MinusSigmaXT)); + CloverTerm += fillClover(Ey) * (Gamma(Gamma::Algebra::MinusSigmaYT)); + CloverTerm += fillClover(Ez) * (Gamma(Gamma::Algebra::MinusSigmaZT)); + CloverTerm *= csw; + + int lvol = _Umu._grid->lSites(); + int DimRep = Impl::Dimension; + + Eigen::MatrixXcd EigenCloverOp = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep); + Eigen::MatrixXcd EigenInvCloverOp = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep); + + std::vector lcoor; + typename SiteCloverType::scalar_object Qx = zero, Qxinv = zero; + + for (int site = 0; site < lvol; site++) + { + grid->LocalIndexToLocalCoor(site, lcoor); + EigenCloverOp = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep); + peekLocalSite(Qx, CloverTerm, lcoor); + Qxinv = zero; + for (int j = 0; j < Ns; j++) + for (int k = 0; k < Ns; k++) + for (int a = 0; a < DimRep; a++) + for (int b = 0; b < DimRep; b++) + EigenCloverOp(a + j * DimRep, b + k * DimRep) = Qx()(j, k)(a, b); + + EigenInvCloverOp = EigenCloverOp.inverse(); + for (int j = 0; j < Ns; j++) + for (int k = 0; k < Ns; k++) + for (int a = 0; a < DimRep; a++) + for (int b = 0; b < DimRep; b++) + Qxinv()(j, k)(a, b) = EigenInvCloverOp(a + j * DimRep, b + k * DimRep); + + pokeLocalSite(Qxinv, CloverTermInv, lcoor); } +} - template - RealD WilsonCloverFermion::Mdag(const FermionField& in, FermionField& out) { - // Wilson term - out.checkerboard = in.checkerboard; - this->Dhop(in, out, DaggerYes); - // Clover term - // apply the sigma and Fmunu - MooeeDag(in, out); - return axpy_norm(out, 4 + this->mass, in, out); - } +template +void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out) +{ + this->MooeeInternal(in, out, DaggerNo, InverseNo); +} - template - void WilsonCloverFermion::ImportGauge(const GaugeField& _Umu) { - this->ImportGauge(_Umu); - GridBase* grid = _Umu._grid; - assert(Nd==4); //only works in 4 dim - typename Impl::GaugeLinkField Bx(grid), By(grid), Bz(grid), Ex(grid), Ey(grid), Ez(grid); - // Compute the field strength terms - WilsonLoops::FieldStrength(Bx, _Umu, Ydir, Zdir); - WilsonLoops::FieldStrength(By, _Umu, Zdir, Xdir); - WilsonLoops::FieldStrength(Bz, _Umu, Xdir, Ydir); - WilsonLoops::FieldStrength(Ex, _Umu, Tdir, Xdir); - WilsonLoops::FieldStrength(Ey, _Umu, Tdir, Ydir); - WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); +template +void WilsonCloverFermion::MooeeDag(const FermionField &in, FermionField &out) +{ + this->MooeeInternal(in, out, DaggerNo, InverseYes); +} - // Compute the Clover Operator acting on Colour and Spin - CloverTerm = fillClover(Bx)*(Gamma(Gamma::Algebra::SigmaYZ)); - CloverTerm += fillClover(By)*(Gamma(Gamma::Algebra::MinusSigmaXZ)); - CloverTerm += fillClover(Bz)*(Gamma(Gamma::Algebra::SigmaXY)); - CloverTerm += fillClover(Ex)*(Gamma(Gamma::Algebra::MinusSigmaXT)); - CloverTerm += fillClover(Ey)*(Gamma(Gamma::Algebra::MinusSigmaYT)); - CloverTerm += fillClover(Ez)*(Gamma(Gamma::Algebra::MinusSigmaZT)); - CloverTerm *= csw; +template +void WilsonCloverFermion::MooeeInv(const FermionField &in, FermionField &out) +{ + this->MooeeInternal(in, out, DaggerNo, InverseYes); +} +template +void WilsonCloverFermion::MooeeInvDag(const FermionField &in, FermionField &out) +{ + this->MooeeInternal(in, out, DaggerNo, InverseYes); +} - int lvol = _Umu._grid->lSites(); - int DimRep = Impl::Dimension; +template +void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionField &out, int dag, int inv) +{ + out.checkerboard = in.checkerboard; + CloverFieldType *Clover; - Eigen::MatrixXcd EigenCloverOp = Eigen::MatrixXcd::Zero(Ns*DimRep,Ns*DimRep); - Eigen::MatrixXcd EigenInvCloverOp = Eigen::MatrixXcd::Zero(Ns*DimRep,Ns*DimRep); - - std::vector lcoor; - typename SiteCloverType::scalar_object Qx = zero, Qxinv = zero; + Clover = (inv) ? &CloverTermInv : &CloverTerm; + if (dag){ out = adj(*Clover) * in;} else { out = *Clover * in;} +} // MooeeInternal - for (int site = 0; site < lvol; site++){ - grid->LocalIndexToLocalCoor(site,lcoor); - EigenCloverOp=Eigen::MatrixXcd::Zero(Ns*DimRep,Ns*DimRep); - peekLocalSite(Qx,CloverTerm,lcoor); - Qxinv = zero; - for(int j = 0; j < Ns; j++) - for (int k = 0; k < Ns; k++) - for(int a = 0; a < DimRep; a++) - for(int b = 0; b < DimRep; b++) - EigenCloverOp(a+j*DimRep,b+k*DimRep) = Qx()(j,k)(a,b); +// Derivative parts +template +void WilsonCloverFermion::MDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) +{ + GaugeField tmp(mat._grid); - EigenInvCloverOp = EigenCloverOp.inverse(); - for(int j = 0; j < Ns; j++) - for (int k = 0; k < Ns; k++) - for(int a = 0; a < DimRep; a++) - for(int b = 0; b < DimRep; b++) - Qxinv()(j,k)(a,b) = EigenInvCloverOp(a+j*DimRep,b+k*DimRep); + conformable(U._grid, V._grid); + conformable(U._grid, mat._grid); - pokeLocalSite(Qxinv,CloverTermInv,lcoor); - } - } + mat.checkerboard = U.checkerboard; + tmp.checkerboard = U.checkerboard; - template - void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out){ - this -> MooeeInternal(in, out, DaggerNo, InverseNo); - } + this->DhopDeriv(mat, U, V, dag); + MooDeriv(tmp, U, V, dag); + mat += tmp; +} - template - void WilsonCloverFermion::MooeeDag(const FermionField &in, FermionField &out){ - this -> MooeeInternal(in, out, DaggerNo, InverseYes); - } +// Derivative parts +template +void WilsonCloverFermion::MooDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) +{ + // Compute the 8 terms of the derivative + assert(0); // not implemented yet +} - template - void WilsonCloverFermion::MooeeInv(const FermionField &in, FermionField &out){ - this -> MooeeInternal(in, out, DaggerNo, InverseYes); - } - - template - void WilsonCloverFermion::MooeeInvDag(const FermionField &in, FermionField &out){ - this -> MooeeInternal(in, out, DaggerNo, InverseYes); - } - - - template - void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionField &out, int dag, int inv){ - out.checkerboard = in.checkerboard; - CloverFieldType *Clover; - - Clover = (inv) ? &CloverTermInv : &CloverTerm; - if(dag){ out = adj(*Clover)*in;} else {out = *Clover*in;} - } // MooeeInternal - - // Derivative parts - template - void WilsonCloverFermion::MDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ - GaugeField tmp(mat._grid); - - conformable(U._grid, V._grid); - conformable(U._grid, mat._grid); - - mat.checkerboard = U.checkerboard; - tmp.checkerboard = U.checkerboard; - - this->DhopDeriv(mat, U, V, dag); - MooDeriv(tmp, U, V, dag); - mat += tmp; - } - - // Derivative parts - template - void WilsonCloverFermion::MooDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ - // Compute the 8 terms of the derivative - assert(0); // not implemented yet - } - - // Derivative parts - template - void WilsonCloverFermion::MeeDeriv(GaugeField&mat, const FermionField&U, const FermionField&V, int dag){ - assert(0); // not implemented yet - } +// Derivative parts +template +void WilsonCloverFermion::MeeDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) +{ + assert(0); // not implemented yet +} FermOpTemplateInstantiate(WilsonCloverFermion); // now only for the fundamental representation //AdjointFermOpTemplateInstantiate(WilsonCloverFermion); //TwoIndexFermOpTemplateInstantiate(WilsonCloverFermion); //GparityFermOpTemplateInstantiate(WilsonCloverFermion); - } } From b9356d38662144acfa5b3f1d5184123b9769598d Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 28 Apr 2017 16:46:40 +0100 Subject: [PATCH 024/174] Added more complete test of sequential insertion of conserved current. --- extras/Hadrons/Modules.hpp | 1 + .../Modules/MUtilities/TestSeqConserved.hpp | 166 ++++++++++++++++++ extras/Hadrons/modules.inc | 1 + 3 files changed, 168 insertions(+) create mode 100644 extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 67762246..0286333c 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -48,4 +48,5 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include +#include #include diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp new file mode 100644 index 00000000..0730b8ed --- /dev/null +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -0,0 +1,166 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp + +Copyright (C) 2017 + +Author: Andrew Lawson + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#ifndef Hadrons_TestSeqConserved_hpp_ +#define Hadrons_TestSeqConserved_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/* + Ward Identity contractions using sequential propagators. + ----------------------------- + + * options: + - q: point source propagator, 5D if available (string) + - q4d: 4D point source propagator, duplicate of q if q is 4D (string) + - qSeq: result of sequential insertion of conserved current using q (string) + - action: action used for computation of q (string) + - origin: string giving point source origin of q (string) + - t_J: time at which sequential current is inserted (int) + - mu: Lorentz index of current inserted (int) + - curr: current type, e.g. vector/axial (Current) +*/ + +/****************************************************************************** + * TestSeqConserved * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MUtilities) + +class TestSeqConservedPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(TestSeqConservedPar, + std::string, q, + std::string, q4d, + std::string, qSeq, + std::string, action, + std::string, origin, + unsigned int, t_J, + unsigned int, mu, + Current, curr); +}; + +template +class TTestSeqConserved: public Module +{ +public: + TYPE_ALIASES(FImpl,); +public: + // constructor + TTestSeqConserved(const std::string name); + // destructor + virtual ~TTestSeqConserved(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_NS(TestSeqConserved, TTestSeqConserved, MUtilities); + +/****************************************************************************** + * TTestSeqConserved implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TTestSeqConserved::TTestSeqConserved(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TTestSeqConserved::getInput(void) +{ + std::vector in = {par().q, par().q4d, + par().qSeq, par().action}; + + return in; +} + +template +std::vector TTestSeqConserved::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TTestSeqConserved::setup(void) +{ + +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TTestSeqConserved::execute(void) +{ + PropagatorField tmp(env().getGrid()); + PropagatorField &q = *env().template getObject(par().q); + PropagatorField &q4d = *env().template getObject(par().q4d); + PropagatorField &qSeq = *env().template getObject(par().qSeq); + FMat &act = *(env().template getObject(par().action)); + Gamma g5(Gamma::Algebra::Gamma5); + SitePropagator qSite; + LatticeComplex c(env().getGrid()); + Complex seq_res, check_res; + std::vector check_buf; + + // Check sequential insertion of current gives same result as conserved + // current sink upon contraction. Assume q uses a point source. + std::vector siteCoord; + siteCoord = strToVec(par().origin); + peekSite(qSite, q, siteCoord); + seq_res = trace(g5*qSite); + + act.ContractConservedCurrent(q, q, tmp, par().curr, par().mu); + c = trace(tmp); + sliceSum(c, check_buf, Tp); + check_res = TensorRemove(check_buf[par().t_J]); + + // Check difference = 0 + check_res -= seq_res; + + LOG(Message) << "Consistency check for sequential conserved " + << par().curr << " current insertion = " << abs(check_res) + << std::endl; +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_TestSeqConserved_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 32655c3b..4ab51ce0 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -29,5 +29,6 @@ modules_hpp =\ Modules/MSource/SeqGamma.hpp \ Modules/MSource/Wall.hpp \ Modules/MSource/Z2.hpp \ + Modules/MUtilities/TestSeqConserved.hpp \ Modules/Quark.hpp From db14fb30df901c5e6bb445a2c59a55bf28ac75d5 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 28 Apr 2017 16:48:00 +0100 Subject: [PATCH 025/174] Hadrons: overhaul of conserved current test --- tests/hadrons/Test_hadrons.hpp | 125 +++++++++++++++++- .../hadrons/Test_hadrons_conserved_current.cc | 54 ++++---- 2 files changed, 145 insertions(+), 34 deletions(-) diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index 26d02a5c..c4dcedaf 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -40,6 +40,7 @@ using namespace Hadrons; #define LABEL_3PT(s, t1, t2) ADD_INDEX(INIT_INDEX(s, t1), t2) #define LABEL_4PT(s, t1, t2, t3) ADD_INDEX(ADD_INDEX(INIT_INDEX(s, t1), t2), t3) #define LABEL_4PT_NOISE(s, t1, t2, t3, nn) ADD_INDEX(ADD_INDEX(ADD_INDEX(INIT_INDEX(s, t1), t2), t3), nn) +#define LABEL_5D(s) s + "_5d"; // Wall source/sink macros #define NAME_3MOM_WALL_SOURCE(t, mom) ("wall_" + std::to_string(t) + "_" + mom) @@ -123,6 +124,44 @@ inline void makeSequentialSource(Application &application, std::string srcName, } } +/******************************************************************************* + * Name: makeConservedSequentialSource + * Purpose: Construct sequential source with conserved current insertion and + * add to application module. + * Parameters: application - main application that stores modules. + * srcName - name of source module to create. + * qSrc - Input quark for sequential inversion. + * actionName - action corresponding to quark. + * tS - sequential source timeslice. + * curr - conserved current type to insert. + * mu - Lorentz index of current to insert. + * mom - momentum insertion (default is zero). + * Returns: None. + ******************************************************************************/ +inline void makeConservedSequentialSource(Application &application, + std::string &srcName, + std::string &qSrc, + std::string &actionName, + unsigned int tS, + Current curr, + unsigned int mu, + std::string mom = ZERO_MOM) +{ + // If the source already exists, don't make the module again. + if (!(Environment::getInstance().hasModule(srcName))) + { + MSource::SeqConserved::Par seqPar; + seqPar.q = qSrc; + seqPar.action = actionName; + seqPar.tA = tS; + seqPar.tB = tS; + seqPar.curr_type = curr; + seqPar.mu = mu; + seqPar.mom = mom; + application.createModule(srcName, seqPar); + } +} + /******************************************************************************* * Name: makeWallSource * Purpose: Construct wall source and add to application module. @@ -132,7 +171,7 @@ inline void makeSequentialSource(Application &application, std::string srcName, * mom - momentum insertion (default is zero). * Returns: None. ******************************************************************************/ -inline void makeWallSource(Application &application, std::string srcName, +inline void makeWallSource(Application &application, std::string &srcName, unsigned int tW, std::string mom = ZERO_MOM) { // If the source already exists, don't make the module again. @@ -154,8 +193,8 @@ inline void makeWallSource(Application &application, std::string srcName, * mom - momentum insertion (default is zero). * Returns: None. ******************************************************************************/ -inline void makeWallSink(Application &application, std::string propName, - std::string wallName, std::string mom = ZERO_MOM) +inline void makeWallSink(Application &application, std::string &propName, + std::string &wallName, std::string mom = ZERO_MOM) { // If the propagator has already been smeared, don't smear it again. // Temporarily removed, strategy for sink smearing likely to change. @@ -365,4 +404,82 @@ inline void discLoopContraction(Application &application, discPar.gamma = gamma; application.createModule(modName, discPar); } - } +} + +/******************************************************************************* + * Name: makeWITest + * Purpose: Create module to test Ward Identities for conserved current + * contractions and add to application module. + * Parameters: application - main application that stores modules. + * modName - name of module to create. + * propName - 4D quark propagator. + * actionName - action used to compute quark propagator. + * mass - mass of quark. + * Ls - length of 5th dimension (default = 1). + * Returns: None. + ******************************************************************************/ +inline void makeWITest(Application &application, std::string &modName, + std::string &propName, std::string &actionName, + double mass, unsigned int Ls = 1) +{ + if (!(Environment::getInstance().hasModule(modName))) + { + MContraction::WardIdentity::Par wiPar; + if (Ls > 1) + { + wiPar.q = LABEL_5D(propName); + } + else + { + wiPar.q = propName; + } + wiPar.q4d = propName; + wiPar.action = actionName; + wiPar.mass = mass; + application.createModule(modName, wiPar); + } +} + +/******************************************************************************* + * Name: makeSeqTest + * Purpose: Create module to test sequential insertion of conserved current + * and add to application module. + * Parameters: application - main application that stores modules. + * modName - name of module to create. + * propName - 4D quark propagator. + * seqProp - 4D quark propagator with sequential insertion of + * conserved current. + * actionName - action used to compute quark propagators. + * t_J - time at which sequential current is inserted. + * mu - Lorentz index of sequential current. + * curr - type of conserved current inserted. + * Ls - length of 5th dimension (default = 1). + * Returns: None. + ******************************************************************************/ +inline void makeSeqTest(Application &application, std::string &modName, + std::string &propName, std::string &seqName, + std::string &actionName, std::string &origin, + unsigned int t_J, unsigned int mu, Current curr, + unsigned int Ls = 1) +{ + if (!(Environment::getInstance().hasModule(modName))) + { + MUtilities::TestSeqConserved::Par seqPar; + if (Ls > 1) + { + seqPar.q = LABEL_5D(propName); + } + else + { + seqPar.q = propName; + } + seqPar.q4d = propName; + seqPar.qSeq = seqName; + seqPar.action = actionName; + seqPar.origin = origin; + seqPar.t_J = t_J; + seqPar.mu = mu; + seqPar.curr = curr; + application.createModule(modName, seqPar); + } +} diff --git a/tests/hadrons/Test_hadrons_conserved_current.cc b/tests/hadrons/Test_hadrons_conserved_current.cc index df774ac0..a11a3530 100644 --- a/tests/hadrons/Test_hadrons_conserved_current.cc +++ b/tests/hadrons/Test_hadrons_conserved_current.cc @@ -45,6 +45,7 @@ int main(int argc, char *argv[]) Application application; unsigned int nt = GridDefaultLatt()[Tp]; double mass = 0.04; + unsigned int Ls = 12; // global parameters Application::GlobalPar globalPar; @@ -65,7 +66,7 @@ int main(int argc, char *argv[]) std::string actionName = "DWF"; MAction::DWF::Par actionPar; actionPar.gauge = "gauge"; - actionPar.Ls = 12; + actionPar.Ls = Ls; actionPar.M5 = 1.8; actionPar.mass = mass; application.createModule(actionName, actionPar); @@ -83,37 +84,30 @@ int main(int argc, char *argv[]) std::string pos = "0 0 0 0"; std::string modName = "Ward Identity Test"; MAKE_POINT_PROP(pos, pointProp, solverName); - if (!(Environment::getInstance().hasModule(modName))) - { - MContraction::WardIdentity::Par wiPar; - wiPar.q = pointProp + "_5d"; - wiPar.q4d = pointProp; - wiPar.action = actionName; - wiPar.mass = mass; - application.createModule(modName, wiPar); - } + makeWITest(application, modName, pointProp, actionName, mass, Ls); - // Conserved current contractions with sequential insertion of vector + // Conserved current contractions with sequential insertion of vector/axial // current. - std::string q_x = "q_x"; - std::string q_y = "q_y"; - std::string q_z = "q_z"; - std::string q_t = "q_t"; - std::string mom = ZERO_MOM; - modName = "Sequential Ward Identity Test"; - MAKE_SEQUENTIAL_PROP(nt/2, pointProp, mom, q_x, solverName); - MAKE_SEQUENTIAL_PROP(nt/2, pointProp, mom, q_y, solverName); - MAKE_SEQUENTIAL_PROP(nt/2, pointProp, mom, q_z, solverName); - MAKE_SEQUENTIAL_PROP(nt/2, pointProp, mom, q_t, solverName); - if (!(Environment::getInstance().hasModule(modName))) - { - MContraction::WardIdentitySeq::Par wiPar; - wiPar.q_x = q_x; - wiPar.q_y = q_y; - wiPar.q_z = q_z; - wiPar.q_t = q_t; - application.createModule(modName, wiPar); - } + std::string mom = ZERO_MOM; + unsigned int t_J = nt/2; + std::string seqPropA = ADD_INDEX(pointProp + "_seq_A", t_J); + std::string seqPropV = ADD_INDEX(pointProp + "_seq_V", t_J); + std::string seqSrcA = seqPropA + "_src"; + std::string seqSrcV = seqPropV + "_src"; + std::string point5d = LABEL_5D(pointProp); + makeConservedSequentialSource(application, seqSrcA, point5d, + actionName, t_J, Current::Axial, Tp, mom); + makePropagator(application, seqPropA, seqSrcA, solverName); + makeConservedSequentialSource(application, seqSrcV, point5d, + actionName, t_J, Current::Vector, Tp, mom); + makePropagator(application, seqPropV, seqSrcV, solverName); + + std::string modNameA = "Axial Sequential Test"; + std::string modNameV = "Vector Sequential Test"; + makeSeqTest(application, modNameA, pointProp, seqPropA, + actionName, pos, t_J, Tp, Current::Axial, Ls); + makeSeqTest(application, modNameV, pointProp, seqPropV, + actionName, pos, t_J, Tp, Current::Vector, Ls); // execution application.saveParameterFile("ConservedCurrentTest.xml"); From 51d84ec057a80b9898369c7181dacce9979a945d Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 28 Apr 2017 16:49:14 +0100 Subject: [PATCH 026/174] Bugfixes in Wilson 5D sequential conserved current insertion --- lib/qcd/action/fermion/WilsonFermion5D.cc | 24 ++++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index 99ff0dc1..bae5ae70 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -726,6 +726,8 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, conformable(q_in._grid, FermionGrid()); conformable(q_in._grid, q_out._grid); Lattice> ph(_FourDimGrid), coor(_FourDimGrid); + PropagatorField q_in_s(_FourDimGrid); + PropagatorField q_out_s(_FourDimGrid); Complex i(0.0, 1.0); // Momentum projection @@ -737,23 +739,17 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, } ph = exp((Real)(2*M_PI)*i*ph); - // Sequential insertion - Kernels::SeqConservedCurrentInternal(q_in, q_out, Umu, curr_type, - mu, ph, tmin, tmax); - - // Axial current sign. - if (curr_type == Current::Axial) + // Sequential insertion across 5th dimension + for (int s = 0; s < Ls; s++) { - SitePropagator result; - parallel_for(int sU = 0; sU < Umu._grid->oSites(); sU++) + ExtractSlice(q_in_s, q_in, s, 0); + Kernels::SeqConservedCurrentInternal(q_in_s, q_out_s, Umu, curr_type, + mu, ph, tmin, tmax); + if ((curr_type == Current::Axial) && (s < Ls/2)) { - int sF = sU * Ls; - for (int s = 0; s < Ls/2; s++) - { - vstream(q_out._odata[sF], -q_out._odata[sF]); - sF++; - } + q_out_s = -q_out_s; } + InsertSlice(q_out_s, q_out, s, 0); } } From 49331a3e72b6b644cd48424b8566440a7338fa64 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 28 Apr 2017 16:50:17 +0100 Subject: [PATCH 027/174] Minor improvements to Ward Identity checks --- .../Hadrons/Modules/MContraction/WardIdentity.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index 41d8c6d1..d312bd4d 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -115,6 +115,10 @@ template void TWardIdentity::setup(void) { Ls_ = env().getObjectLs(par().q); + if (Ls_ != env().getObjectLs(par().action)) + { + HADRON_ERROR("Ls mismatch between quark action and propagator"); + } } // execution /////////////////////////////////////////////////////////////////// @@ -125,8 +129,8 @@ void TWardIdentity::execute(void) << "'." << std::endl; PropagatorField psi(env().getGrid()), tmp(env().getGrid()); - PropagatorField q = *env().template getObject(par().q); - PropagatorField q4d = *env().template getObject(par().q4d); + PropagatorField &q = *env().template getObject(par().q); + PropagatorField &q4d = *env().template getObject(par().q4d); FMat &act = *(env().template getObject(par().action)); Gamma g5(Gamma::Algebra::Gamma5); LatticeComplex PP(env().getGrid()), PA(env().getGrid()), @@ -142,7 +146,7 @@ void TWardIdentity::execute(void) for (unsigned int mu = 0; mu < Nd; ++mu) { act.ContractConservedCurrent(q, q, tmp, Current::Vector, mu); - Vmu[mu] = trace(g5*tmp); + Vmu[mu] = trace(tmp); act.ContractConservedCurrent(q, q, tmp, Current::Axial, mu); Amu[mu] = trace(g5*tmp); } @@ -170,6 +174,9 @@ void TWardIdentity::execute(void) << norm2(vector_WI) << std::endl; LOG(Message) << "Axial Ward Identity defect Delta_mu A_mu = " << norm2(defect) << std::endl; + LOG(Message) << "norm2(PP) = " << norm2(PP) << std::endl; + LOG(Message) << "norm2(PA) = " << norm2(PA) << std::endl; + LOG(Message) << "norm2(PJ5q) = " << norm2(PJ5q) << std::endl; } END_MODULE_NAMESPACE From 62a64d9108cf260cb0f5d3dd18aa0695568cc432 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 1 May 2017 11:06:21 +0100 Subject: [PATCH 028/174] EO support, wip --- .vscode/settings.json | 38 +++++++++++++++++++ lib/qcd/action/fermion/WilsonCloverFermion.cc | 15 +++++++- lib/qcd/action/fermion/WilsonCloverFermion.h | 8 +++- tests/core/Test_wilson_clover.cc | 3 +- 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 20af2f68..dd8f0473 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,41 @@ // Place your settings in this file to overwrite default and user settings. { + "files.associations": { + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "chrono": "cpp", + "codecvt": "cpp", + "condition_variable": "cpp", + "cstdint": "cpp", + "exception": "cpp", + "slist": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "limits": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "ratio": "cpp", + "stdexcept": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "utility": "cpp" + } } \ No newline at end of file diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 3ab481ce..e1900830 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -91,7 +91,6 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) { this->ImportGauge(_Umu); GridBase *grid = _Umu._grid; - assert(Nd == 4); // only works in 4 dim typename Impl::GaugeLinkField Bx(grid), By(grid), Bz(grid), Ex(grid), Ey(grid), Ez(grid); // Compute the field strength terms @@ -140,6 +139,11 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) Qxinv()(j, k)(a, b) = EigenInvCloverOp(a + j * DimRep, b + k * DimRep); pokeLocalSite(Qxinv, CloverTermInv, lcoor); + // Separate the even and odd parts. + pickCheckerboard(Even, CloverTermEven, CloverTerm); + pickCheckerboard( Odd, CloverTermOdd, CloverTerm); + pickCheckerboard(Even, CloverTermInvEven, CloverTermInv); + pickCheckerboard( Odd, CloverTermInvOdd, CloverTermInv); } } @@ -172,8 +176,15 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie { out.checkerboard = in.checkerboard; CloverFieldType *Clover; + if (in.checkerboard == Odd){ + std::cout << "Calling clover term Odd" << std::endl; + Clover = (inv) ? &CloverTermInvOdd : &CloverTermOdd; + } + if (in.checkerboard == Even){ + std::cout << "Calling clover term Even" << std::endl; + Clover = (inv) ? &CloverTermInvEven : &CloverTermEven; + } - Clover = (inv) ? &CloverTermInv : &CloverTerm; if (dag){ out = adj(*Clover) * in;} else { out = *Clover * in;} } // MooeeInternal diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index 0fa0d57d..c9e7be39 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -59,7 +59,11 @@ public: Hgrid, _mass, p), CloverTerm(&Fgrid), - CloverTermInv(&Fgrid) + CloverTermInv(&Fgrid), + CloverTermEven(&Hgrid), + CloverTermOdd(&Hgrid), + CloverTermInvEven(&Hgrid), + CloverTermInvOdd(&Hgrid) { csw = _csw; assert(Nd == 4); // require 4 dimensions @@ -85,6 +89,8 @@ private: RealD csw; // Clover coefficient CloverFieldType CloverTerm, CloverTermInv; // Clover term + CloverFieldType CloverTermEven, CloverTermOdd; + CloverFieldType CloverTermInvEven, CloverTermInvOdd; // Clover term // eventually these two can be compressed into 6x6 blocks instead of the 12x12 // using the DeGrand-Rossi basis for the gamma matrices diff --git a/tests/core/Test_wilson_clover.cc b/tests/core/Test_wilson_clover.cc index 08516d80..3df69e3b 100644 --- a/tests/core/Test_wilson_clover.cc +++ b/tests/core/Test_wilson_clover.cc @@ -191,8 +191,9 @@ int main (int argc, char ** argv) Dwc.MooeeInv(src_e,phi_e); Dwc.Mooee(chi_o,src_o); +exit(1); Dwc.MooeeInv(src_o,phi_o); - + setCheckerboard(phi,phi_e); setCheckerboard(phi,phi_o); From 77e0af9c2eca8ce816b6c6a54bc2d0edef26e213 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 5 May 2017 12:27:50 +0100 Subject: [PATCH 029/174] Compilation fix after merge - conserved current code not yet operational for vectorised 5D or Gparity Impl. --- lib/qcd/action/fermion/WilsonKernels.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index 5deec27c..8dc6bd8c 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -365,10 +365,16 @@ WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_in, NO_CURR(GparityWilsonImplF); NO_CURR(GparityWilsonImplD); +NO_CURR(GparityWilsonImplFH); +NO_CURR(GparityWilsonImplDF); NO_CURR(DomainWallVec5dImplF); NO_CURR(DomainWallVec5dImplD); +NO_CURR(DomainWallVec5dImplFH); +NO_CURR(DomainWallVec5dImplDF); NO_CURR(ZDomainWallVec5dImplF); NO_CURR(ZDomainWallVec5dImplD); +NO_CURR(ZDomainWallVec5dImplFH); +NO_CURR(ZDomainWallVec5dImplDF); FermOpTemplateInstantiate(WilsonKernels); AdjointFermOpTemplateInstantiate(WilsonKernels); From d44cc204d166e19c0198ab9176061d3d8595930a Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 12 May 2017 14:58:17 +0100 Subject: [PATCH 030/174] Added test module for sequential gamma matrix insertion --- extras/Hadrons/Modules.hpp | 1 + .../Modules/MUtilities/TestSeqGamma.hpp | 119 ++++++++++++++++++ extras/Hadrons/modules.inc | 1 + 3 files changed, 121 insertions(+) create mode 100644 extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 0286333c..dd6a6010 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -49,4 +49,5 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include +#include #include diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp new file mode 100644 index 00000000..b3e99617 --- /dev/null +++ b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp @@ -0,0 +1,119 @@ +#ifndef Hadrons_TestSeqGamma_hpp_ +#define Hadrons_TestSeqGamma_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * TestSeqGamma * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MUtilities) + +class TestSeqGammaPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(TestSeqGammaPar, + std::string, q, + std::string, qSeq, + std::string, origin, + Gamma::Algebra, gamma, + unsigned int, t_g); +}; + +template +class TTestSeqGamma: public Module +{ +public: + TYPE_ALIASES(FImpl,); +public: + // constructor + TTestSeqGamma(const std::string name); + // destructor + virtual ~TTestSeqGamma(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_NS(TestSeqGamma, TTestSeqGamma, MUtilities); + +/****************************************************************************** + * TTestSeqGamma implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TTestSeqGamma::TTestSeqGamma(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TTestSeqGamma::getInput(void) +{ + std::vector in = {par().q, par().qSeq}; + + return in; +} + +template +std::vector TTestSeqGamma::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TTestSeqGamma::setup(void) +{ + +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TTestSeqGamma::execute(void) +{ + PropagatorField &q = *env().template getObject(par().q); + PropagatorField &qSeq = *env().template getObject(par().qSeq); + LatticeComplex c(env().getGrid()); + Gamma g5(Gamma::Algebra::Gamma5); + Gamma g(par().gamma); + SitePropagator qSite; + Complex test, check; + std::vector check_buf; + + // Check sequential insertion of gamma matrix gives same result as + // insertion of gamma at sink upon contraction. Assume q uses a point + // source. + std::vector siteCoord; + siteCoord = strToVec(par().origin); + peekSite(qSite, qSeq, siteCoord); + test = trace(g*qSite); + + c = trace(adj(g)*g5*adj(q)*g5*g*q); + sliceSum(c, check_buf, Tp); + check = TensorRemove(check_buf[par().t_g]); + + LOG(Message) << "Seq Result = " << abs(test) << std::endl; + LOG(Message) << "Reference = " << abs(check) << std::endl; + + // Check difference = 0 + check -= test; + + LOG(Message) << "Consistency check for sequential " << par().gamma + << " insertion = " << abs(check) << std::endl; +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_TestSeqGamma_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 4ab51ce0..0364502a 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -30,5 +30,6 @@ modules_hpp =\ Modules/MSource/Wall.hpp \ Modules/MSource/Z2.hpp \ Modules/MUtilities/TestSeqConserved.hpp \ + Modules/MUtilities/TestSeqGamma.hpp \ Modules/Quark.hpp From 98f610ce5384f75883d7e4a31be54e55c6251410 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 12 May 2017 16:15:26 +0100 Subject: [PATCH 031/174] Reduced code duplication in hadron tests --- tests/hadrons/Test_hadrons.hpp | 96 ++++++++++++++++++++++++++ tests/hadrons/Test_hadrons_rarekaon.cc | 41 +++-------- 2 files changed, 107 insertions(+), 30 deletions(-) diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index c4dcedaf..c0a596b5 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -33,6 +33,30 @@ using namespace Hadrons; /******************************************************************************* * Macros to reduce code duplication. ******************************************************************************/ +// Common initialisation +#define HADRONS_DEFAULT_INIT \ + Grid_init(&argc, &argv); \ + HadronsLogError.Active(GridLogError.isActive()); \ + HadronsLogWarning.Active(GridLogWarning.isActive()); \ + HadronsLogMessage.Active(GridLogMessage.isActive()); \ + HadronsLogIterative.Active(GridLogIterative.isActive()); \ + HadronsLogDebug.Active(GridLogDebug.isActive()); \ + LOG(Message) << "Grid initialized" << std::endl; + +#define HADRONS_DEFAULT_GLOBALS(application) \ +{ \ + Application::GlobalPar globalPar; \ + globalPar.trajCounter.start = 1500; \ + globalPar.trajCounter.end = 1520; \ + globalPar.trajCounter.step = 20; \ + globalPar.seed = "1 2 3 4"; \ + globalPar.genetic.maxGen = 1000; \ + globalPar.genetic.maxCstGen = 200; \ + globalPar.genetic.popSize = 20; \ + globalPar.genetic.mutationRate = .1; \ + application.setPar(globalPar); \ +} + // Useful definitions #define ZERO_MOM "0. 0. 0. 0." #define INIT_INDEX(s, n) (std::string(s) + "_" + std::to_string(n)) @@ -73,10 +97,82 @@ using namespace Hadrons; makePropagator(application, propName, srcName, solver);\ } +/******************************************************************************* + * Action setups. + ******************************************************************************/ + +/******************************************************************************* + * Name: makeWilsonAction + * Parameters: application - main application that stores modules. + * actionName - name of action module to create. + * gaugeField - gauge field module. + * mass - quark mass. + * Returns: None. + ******************************************************************************/ +inline void makeWilsonAction(Application &application, std::string actionName, + std::string &gaugeField, double mass) +{ + if (!(Environment::getInstance().hasModule(actionName))) + { + MAction::Wilson::Par actionPar; + actionPar.gauge = gaugeField; + actionPar.mass = mass; + application.createModule(actionName, actionPar); + } +} + +/******************************************************************************* + * Name: makeDWFAction + * Parameters: application - main application that stores modules. + * actionName - name of action module to create. + * gaugeField - gauge field module. + * mass - quark mass. + * M5 - domain wall height. + * Ls - fifth dimension extent. + * Returns: None. + ******************************************************************************/ +inline void makeDWFAction(Application &application, std::string actionName, + std::string &gaugeField, double mass, double M5, + unsigned int Ls) +{ + if (!(Environment::getInstance().hasModule(actionName))) + { + MAction::DWF::Par actionPar; + actionPar.gauge = gaugeField; + actionPar.Ls = Ls; + actionPar.M5 = M5; + actionPar.mass = mass; + application.createModule(actionName, actionPar); + } +} + /******************************************************************************* * Functions for propagator construction. ******************************************************************************/ +/******************************************************************************* + * Name: makeRBPrecCGSolver + * Purpose: Make RBPrecCG solver module for specified action. + * Parameters: application - main application that stores modules. + * solverName - name of solver module to create. + * actionName - action module corresponding to propagators to be + * computed. + * residual - CG target residual. + * Returns: None. + ******************************************************************************/ +inline void makeRBPrecCGSolver(Application &application, std::string &solverName, + std::string &actionName, double residual = 1e-8) +{ + if (!(Environment::getInstance().hasModule(solverName))) + { + MSolver::RBPrecCG::Par solverPar; + solverPar.action = actionName; + solverPar.residual = residual; + application.createModule(solverName, + solverPar); + } +} + /******************************************************************************* * Name: makePointSource * Purpose: Construct point source and add to application module. diff --git a/tests/hadrons/Test_hadrons_rarekaon.cc b/tests/hadrons/Test_hadrons_rarekaon.cc index 9d35c1bc..1b5a45d9 100644 --- a/tests/hadrons/Test_hadrons_rarekaon.cc +++ b/tests/hadrons/Test_hadrons_rarekaon.cc @@ -51,13 +51,7 @@ int main(int argc, char *argv[]) configStem = argv[1]; // initialization ////////////////////////////////////////////////////////// - Grid_init(&argc, &argv); - HadronsLogError.Active(GridLogError.isActive()); - HadronsLogWarning.Active(GridLogWarning.isActive()); - HadronsLogMessage.Active(GridLogMessage.isActive()); - HadronsLogIterative.Active(GridLogIterative.isActive()); - HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << std::endl; + HADRONS_DEFAULT_INIT; // run setup /////////////////////////////////////////////////////////////// Application application; @@ -74,46 +68,33 @@ int main(int argc, char *argv[]) unsigned int n_noise = 1; unsigned int nt = 32; bool do_disconnected(false); + Gamma::Algebra gT = Gamma::Algebra::GammaT; + unsigned int Ls = 16; + double M5 = 1.8; // Global parameters. - Application::GlobalPar globalPar; - globalPar.trajCounter.start = 1500; - globalPar.trajCounter.end = 1520; - globalPar.trajCounter.step = 20; - globalPar.seed = "1 2 3 4"; - globalPar.genetic.maxGen = 1000; - globalPar.genetic.maxCstGen = 200; - globalPar.genetic.popSize = 20; - globalPar.genetic.mutationRate = .1; - application.setPar(globalPar); + HADRONS_DEFAULT_GLOBALS(application); // gauge field + std::string gaugeField = "gauge"; if (configStem == "None") { - application.createModule("gauge"); + application.createModule(gaugeField); } else { MGauge::Load::Par gaugePar; gaugePar.file = configStem; - application.createModule("gauge", gaugePar); + application.createModule(gaugeField, gaugePar); } for (unsigned int i = 0; i < flavour.size(); ++i) { // actions - MAction::DWF::Par actionPar; - actionPar.gauge = "gauge"; - actionPar.Ls = 16; - actionPar.M5 = 1.8; - actionPar.mass = mass[i]; - application.createModule("DWF_" + flavour[i], actionPar); + std::string actionName = "DWF_" + flavour[i]; + makeDWFAction(application, actionName, gaugeField, mass[i], M5, Ls); // solvers - MSolver::RBPrecCG::Par solverPar; - solverPar.action = "DWF_" + flavour[i]; - solverPar.residual = 1.0e-8; - application.createModule(solvers[i], - solverPar); + makeRBPrecCGSolver(application, solvers[i], actionName); } // Create noise propagators for loops. From c2010f21aba12b3f2fd7166211b6c3243b428ed9 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 12 May 2017 16:23:01 +0100 Subject: [PATCH 032/174] Added sequential propagator test for gamma matrix insertion --- tests/hadrons/Test_hadrons.hpp | 42 ++++++++++-- tests/hadrons/Test_hadrons_rarekaon.cc | 10 +-- tests/hadrons/Test_hadrons_seq_gamma.cc | 89 +++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 tests/hadrons/Test_hadrons_seq_gamma.cc diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index c0a596b5..61e90bac 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -82,11 +82,11 @@ using namespace Hadrons; MAKE_3MOM_WALL_PROP(tW, ZERO_MOM, propName, solver) // Sequential source macros -#define MAKE_SEQUENTIAL_PROP(tS, qSrc, mom, propName, solver)\ +#define MAKE_SEQUENTIAL_PROP(tS, qSrc, mom, seqPropName, solver, gamma)\ {\ - std::string srcName = ADD_INDEX(qSrc + "_seq", tS);\ - makeSequentialSource(application, srcName, qSrc, tS, mom);\ - makePropagator(application, propName, srcName, solver);\ + std::string srcName = seqPropName + "_src";\ + makeSequentialSource(application, srcName, qSrc, tS, gamma, mom);\ + makePropagator(application, seqPropName, srcName, solver);\ } // Point source macros @@ -205,6 +205,7 @@ inline void makePointSource(Application &application, std::string srcName, ******************************************************************************/ inline void makeSequentialSource(Application &application, std::string srcName, std::string qSrc, unsigned int tS, + Gamma::Algebra gamma = Gamma::Algebra::GammaT, std::string mom = ZERO_MOM) { // If the source already exists, don't make the module again. @@ -215,7 +216,7 @@ inline void makeSequentialSource(Application &application, std::string srcName, seqPar.tA = tS; seqPar.tB = tS; seqPar.mom = mom; - seqPar.gamma = Gamma::Algebra::GammaT; + seqPar.gamma = gamma; application.createModule(srcName, seqPar); } } @@ -579,3 +580,34 @@ inline void makeSeqTest(Application &application, std::string &modName, application.createModule(modName, seqPar); } } + +/******************************************************************************* + * Name: makeSeqGamComparison + * Purpose: Create module to compare sequential insertion of gamma matrix + * against sink contraction and add to application module. + * Parameters: application - main application that stores modules. + * modName - name of module to create. + * propName - 4D quark propagator. + * seqProp - 4D quark propagator with sequential insertion of + * gamma matrix. + * gamma - Inserted gamma matrix. + * t_g - time at which gamma matrix is inserted + * sequentially. + * Returns: None. + ******************************************************************************/ +inline void makeSeqGamComparison(Application &application, std::string &modName, + std::string &propName, std::string &seqProp, + std::string &origin, Gamma::Algebra gamma, + unsigned int t_g) +{ + if (!(Environment::getInstance().hasModule(modName))) + { + MUtilities::TestSeqGamma::Par seqPar; + seqPar.q = propName; + seqPar.qSeq = seqProp; + seqPar.origin = origin; + seqPar.t_g = t_g; + seqPar.gamma = gamma; + application.createModule(modName, seqPar); + } +} diff --git a/tests/hadrons/Test_hadrons_rarekaon.cc b/tests/hadrons/Test_hadrons_rarekaon.cc index 1b5a45d9..3a642f24 100644 --- a/tests/hadrons/Test_hadrons_rarekaon.cc +++ b/tests/hadrons/Test_hadrons_rarekaon.cc @@ -212,10 +212,10 @@ int main(int argc, char *argv[]) std::string q_KsCs_mq = LABEL_3PT("Q_KsCs_mq", tK, tJ); std::string q_pilCl_q = LABEL_3PT("Q_pilCl_q", tpi, tJ); std::string q_pilCl_mq = LABEL_3PT("Q_pilCl_mq", tpi, tJ); - MAKE_SEQUENTIAL_PROP(tJ, q_Kl_0, qmom, q_KlCl_q, solvers[light]); - MAKE_SEQUENTIAL_PROP(tJ, q_Ks_k, mqmom, q_KsCs_mq, solvers[strange]); - MAKE_SEQUENTIAL_PROP(tJ, q_pil_p, qmom, q_pilCl_q, solvers[light]); - MAKE_SEQUENTIAL_PROP(tJ, q_pil_0, mqmom, q_pilCl_mq, solvers[light]); + MAKE_SEQUENTIAL_PROP(tJ, q_Kl_0, qmom, q_KlCl_q, solvers[light], gT); + MAKE_SEQUENTIAL_PROP(tJ, q_Ks_k, mqmom, q_KsCs_mq, solvers[strange], gT); + MAKE_SEQUENTIAL_PROP(tJ, q_pil_p, qmom, q_pilCl_q, solvers[light], gT); + MAKE_SEQUENTIAL_PROP(tJ, q_pil_0, mqmom, q_pilCl_mq, solvers[light], gT); /******************************************************************* * CONTRACTIONS: pi and K 3pt contractions with current insertion. @@ -271,7 +271,7 @@ int main(int argc, char *argv[]) std::string loop_qCq = LABEL_3PT(loop_stem + flavour[f], tJ, nn); std::string loop_qCq_res = loop_qCq + "_res"; MAKE_SEQUENTIAL_PROP(tJ, noiseRes[f][nn], qmom, - loop_qCq_res, solvers[f]); + loop_qCq_res, solvers[f], gT); makeLoop(application, loop_qCq, eta, loop_qCq_res); /******************************************************* diff --git a/tests/hadrons/Test_hadrons_seq_gamma.cc b/tests/hadrons/Test_hadrons_seq_gamma.cc new file mode 100644 index 00000000..22c35ecb --- /dev/null +++ b/tests/hadrons/Test_hadrons_seq_gamma.cc @@ -0,0 +1,89 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: tests/hadrons/Test_hadrons_seq_gamma.cc + + Copyright (C) 2017 + + Author: Andrew Lawson + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution + directory. + *******************************************************************************/ + +#include "Test_hadrons.hpp" + +using namespace Grid; +using namespace QCD; +using namespace Hadrons; + +/******************************************************************************* + * Consistency test for sequential gamma insertion. + ******************************************************************************/ + +int main(int argc, char *argv[]) +{ + // initialization ////////////////////////////////////////////////////////// + HADRONS_DEFAULT_INIT; + + // run setup /////////////////////////////////////////////////////////////// + Application application; + unsigned int nt = GridDefaultLatt()[Tp]; + unsigned int tS = nt / 2; + unsigned int Ls = 12; + double mass = 0.04; + double M5 = 1.8; + + // global parameters + HADRONS_DEFAULT_GLOBALS(application); + + // gauge field + std::string gaugeField = "gauge"; + application.createModule(gaugeField); + + // action + std::string actionName = "DWF"; + makeDWFAction(application, actionName, gaugeField, mass, M5, Ls); + + // solver + std::string solverName = "CG"; + makeRBPrecCGSolver(application, solverName, actionName); + + // test sequential propagator, with g5 insertion. + Gamma::Algebra g = Gamma::Algebra::Gamma5; + std::string pointProp = "q_0"; + std::string point5d = LABEL_5D(pointProp); + std::string origin = "0 0 0 0"; + MAKE_POINT_PROP(origin, pointProp, solverName); + + std::string seqProp = ADD_INDEX(pointProp + "_seqg5", tS); + std::string seqSrc = seqProp + "_src"; + MAKE_SEQUENTIAL_PROP(tS, pointProp, ZERO_MOM, seqProp, solverName, g); + + std::string modName = "Test g5 sequential insertion"; + makeSeqGamComparison(application, modName, pointProp, seqProp, origin, g, tS); + + // execution + application.saveParameterFile("SeqGamma5Test.xml"); + application.run(); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} \ No newline at end of file From 34332fe3934754025446cec92b6c099c6828df9f Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 12 May 2017 16:30:43 +0100 Subject: [PATCH 033/174] Improvement to sequential conserved current insertion tests --- .../Modules/MUtilities/TestSeqConserved.hpp | 45 +++-- tests/hadrons/Test_hadrons.hpp | 31 ++-- .../hadrons/Test_hadrons_conserved_current.cc | 156 +++++++++++------- 3 files changed, 131 insertions(+), 101 deletions(-) diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp index 0730b8ed..3ae1b8b0 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -41,7 +41,6 @@ BEGIN_HADRONS_NAMESPACE * options: - q: point source propagator, 5D if available (string) - - q4d: 4D point source propagator, duplicate of q if q is 4D (string) - qSeq: result of sequential insertion of conserved current using q (string) - action: action used for computation of q (string) - origin: string giving point source origin of q (string) @@ -60,7 +59,6 @@ class TestSeqConservedPar: Serializable public: GRID_SERIALIZABLE_CLASS_MEMBERS(TestSeqConservedPar, std::string, q, - std::string, q4d, std::string, qSeq, std::string, action, std::string, origin, @@ -103,8 +101,7 @@ TTestSeqConserved::TTestSeqConserved(const std::string name) template std::vector TTestSeqConserved::getInput(void) { - std::vector in = {par().q, par().q4d, - par().qSeq, par().action}; + std::vector in = {par().q, par().qSeq, par().action}; return in; } @@ -121,7 +118,11 @@ std::vector TTestSeqConserved::getOutput(void) template void TTestSeqConserved::setup(void) { - + auto Ls = env().getObjectLs(par().q); + if (Ls != env().getObjectLs(par().action)) + { + HADRON_ERROR("Ls mismatch between quark action and propagator"); + } } // execution /////////////////////////////////////////////////////////////////// @@ -130,33 +131,43 @@ void TTestSeqConserved::execute(void) { PropagatorField tmp(env().getGrid()); PropagatorField &q = *env().template getObject(par().q); - PropagatorField &q4d = *env().template getObject(par().q4d); PropagatorField &qSeq = *env().template getObject(par().qSeq); FMat &act = *(env().template getObject(par().action)); Gamma g5(Gamma::Algebra::Gamma5); + Gamma::Algebra gA = (par().curr == Current::Axial) ? + Gamma::Algebra::Gamma5 : + Gamma::Algebra::Identity; + Gamma g(gA); SitePropagator qSite; - LatticeComplex c(env().getGrid()); - Complex seq_res, check_res; - std::vector check_buf; + Complex test_S, test_V, check_S, check_V; + std::vector check_buf; // Check sequential insertion of current gives same result as conserved // current sink upon contraction. Assume q uses a point source. std::vector siteCoord; siteCoord = strToVec(par().origin); - peekSite(qSite, q, siteCoord); - seq_res = trace(g5*qSite); + peekSite(qSite, qSeq, siteCoord); + test_S = trace(qSite*g); + test_V = trace(qSite*g*Gamma::gmu[par().mu]); act.ContractConservedCurrent(q, q, tmp, par().curr, par().mu); - c = trace(tmp); - sliceSum(c, check_buf, Tp); - check_res = TensorRemove(check_buf[par().t_J]); + sliceSum(tmp, check_buf, Tp); + check_S = TensorRemove(trace(check_buf[par().t_J]*g)); + check_V = TensorRemove(trace(check_buf[par().t_J]*g*Gamma::gmu[par().mu])); + + LOG(Message) << "Test S = " << abs(test_S) << std::endl; + LOG(Message) << "Test V = " << abs(test_V) << std::endl; + LOG(Message) << "Check S = " << abs(check_S) << std::endl; + LOG(Message) << "Check V = " << abs(check_V) << std::endl; // Check difference = 0 - check_res -= seq_res; + check_S -= test_S; + check_V -= test_V; LOG(Message) << "Consistency check for sequential conserved " - << par().curr << " current insertion = " << abs(check_res) - << std::endl; + << par().curr << " current insertion: " << std::endl; + LOG(Message) << "Check S = " << abs(check_S) << std::endl; + LOG(Message) << "Check V = " << abs(check_V) << std::endl; } END_MODULE_NAMESPACE diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index 61e90bac..1b038388 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -538,39 +538,30 @@ inline void makeWITest(Application &application, std::string &modName, } /******************************************************************************* - * Name: makeSeqTest - * Purpose: Create module to test sequential insertion of conserved current - * and add to application module. + * Name: makeSeqCurrComparison + * Purpose: Create module to compare sequential insertion of conserved current + * against sink contraction and add to application module. * Parameters: application - main application that stores modules. * modName - name of module to create. - * propName - 4D quark propagator. - * seqProp - 4D quark propagator with sequential insertion of + * propName - quark propagator (point source), 5D if available. + * seqName - 4D quark propagator with sequential insertion of * conserved current. * actionName - action used to compute quark propagators. + * origin - origin of point source propagator. * t_J - time at which sequential current is inserted. * mu - Lorentz index of sequential current. * curr - type of conserved current inserted. - * Ls - length of 5th dimension (default = 1). * Returns: None. ******************************************************************************/ -inline void makeSeqTest(Application &application, std::string &modName, - std::string &propName, std::string &seqName, - std::string &actionName, std::string &origin, - unsigned int t_J, unsigned int mu, Current curr, - unsigned int Ls = 1) +inline void makeSeqCurrComparison(Application &application, std::string &modName, + std::string &propName, std::string &seqName, + std::string &actionName, std::string &origin, + unsigned int t_J, unsigned int mu, Current curr) { if (!(Environment::getInstance().hasModule(modName))) { MUtilities::TestSeqConserved::Par seqPar; - if (Ls > 1) - { - seqPar.q = LABEL_5D(propName); - } - else - { - seqPar.q = propName; - } - seqPar.q4d = propName; + seqPar.q = propName; seqPar.qSeq = seqName; seqPar.action = actionName; seqPar.origin = origin; diff --git a/tests/hadrons/Test_hadrons_conserved_current.cc b/tests/hadrons/Test_hadrons_conserved_current.cc index a11a3530..080fef73 100644 --- a/tests/hadrons/Test_hadrons_conserved_current.cc +++ b/tests/hadrons/Test_hadrons_conserved_current.cc @@ -30,84 +30,112 @@ using namespace Grid; using namespace Hadrons; +inline void setupSeqCurrTests(Application &application, std::string modStem, + std::string &pointProp, std::string &seqStem, + std::string &actionName, std::string &solverName, + std::string &origin, Current curr, + unsigned int t_J, unsigned int mu, + unsigned int Ls = 1) +{ + std::string modName = ADD_INDEX(modStem, mu); + std::string seqProp = ADD_INDEX(seqStem, mu); + std::string seqSrc = seqProp + "_src"; + + // 5D actions require 5D propagator as input for conserved current + // insertions. + std::string propIn; + if (Ls > 1) + { + propIn = LABEL_5D(pointProp); + } + else + { + propIn = pointProp; + } + + makeConservedSequentialSource(application, seqSrc, propIn, + actionName, t_J, curr, mu); + makePropagator(application, seqProp, seqSrc, solverName); + makeSeqCurrComparison(application, modName, propIn, seqProp, + actionName, origin, t_J, mu, curr); +} + +inline void setupWardIdentityTests(Application &application, + std::string &actionName, + double mass, + unsigned int Ls = 1, + bool perform_axial_tests = false) +{ + // solver + std::string solverName = actionName + "_CG"; + makeRBPrecCGSolver(application, solverName, actionName); + + unsigned int nt = GridDefaultLatt()[Tp]; + unsigned int t_J = nt/2; + + /*************************************************************************** + * Conserved current sink contractions: use a single point propagator for + * the Ward Identity test. + **************************************************************************/ + std::string pointProp = actionName + "_q_0"; + std::string origin = "0 0 0 0"; + std::string modName = actionName + " Ward Identity Test"; + MAKE_POINT_PROP(origin, pointProp, solverName); + makeWITest(application, modName, pointProp, actionName, mass, Ls); + + /*************************************************************************** + * Conserved current tests with sequential insertion of vector/axial + * current. If above Ward Identity passes, sufficient to test sequential + * insertion of conserved current agrees with contracted version. + **************************************************************************/ + // Compare sequential insertion to contraction. Should be enough to perform + // for time and one space component. + std::string seqStem = ADD_INDEX(pointProp + "seq_V", t_J); + std::string modStem = actionName + " Vector Sequential Test mu"; + setupSeqCurrTests(application, modStem, pointProp, seqStem, actionName, + solverName, origin, Current::Vector, t_J, Tp, Ls); + setupSeqCurrTests(application, modStem, pointProp, seqStem, actionName, + solverName, origin, Current::Vector, t_J, Xp, Ls); + + // Perform axial tests only if partially-conserved axial current exists for + // the action. + if (perform_axial_tests) + { + seqStem = ADD_INDEX(pointProp + "seq_A", t_J); + modStem = actionName + " Axial Sequential Test mu"; + setupSeqCurrTests(application, modStem, pointProp, seqStem, actionName, + solverName, origin, Current::Axial, t_J, Tp, Ls); + setupSeqCurrTests(application, modStem, pointProp, seqStem, actionName, + solverName, origin, Current::Axial, t_J, Xp, Ls); + } +} + int main(int argc, char *argv[]) { // initialization ////////////////////////////////////////////////////////// - Grid_init(&argc, &argv); - HadronsLogError.Active(GridLogError.isActive()); - HadronsLogWarning.Active(GridLogWarning.isActive()); - HadronsLogMessage.Active(GridLogMessage.isActive()); - HadronsLogIterative.Active(GridLogIterative.isActive()); - HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << std::endl; - + HADRONS_DEFAULT_INIT; + // run setup /////////////////////////////////////////////////////////////// Application application; - unsigned int nt = GridDefaultLatt()[Tp]; double mass = 0.04; + double M5 = 1.8; unsigned int Ls = 12; // global parameters - Application::GlobalPar globalPar; - globalPar.trajCounter.start = 1500; - globalPar.trajCounter.end = 1520; - globalPar.trajCounter.step = 20; - globalPar.seed = "1 2 3 4"; - globalPar.genetic.maxGen = 1000; - globalPar.genetic.maxCstGen = 200; - globalPar.genetic.popSize = 20; - globalPar.genetic.mutationRate = .1; - application.setPar(globalPar); + HADRONS_DEFAULT_GLOBALS(application); // gauge field - application.createModule("gauge"); + std::string gaugeField = "gauge"; + application.createModule(gaugeField); - // action + // Setup each action and the conserved current tests relevant to it. std::string actionName = "DWF"; - MAction::DWF::Par actionPar; - actionPar.gauge = "gauge"; - actionPar.Ls = Ls; - actionPar.M5 = 1.8; - actionPar.mass = mass; - application.createModule(actionName, actionPar); + makeDWFAction(application, actionName, gaugeField, mass, M5, Ls); + setupWardIdentityTests(application, actionName, mass, Ls, true); - // solver - std::string solverName = "CG"; - MSolver::RBPrecCG::Par solverPar; - solverPar.action = actionName; - solverPar.residual = 1.0e-8; - application.createModule(solverName, - solverPar); - - // Conserved current sink contractions: use a single point propagator. - std::string pointProp = "q_0"; - std::string pos = "0 0 0 0"; - std::string modName = "Ward Identity Test"; - MAKE_POINT_PROP(pos, pointProp, solverName); - makeWITest(application, modName, pointProp, actionName, mass, Ls); - - // Conserved current contractions with sequential insertion of vector/axial - // current. - std::string mom = ZERO_MOM; - unsigned int t_J = nt/2; - std::string seqPropA = ADD_INDEX(pointProp + "_seq_A", t_J); - std::string seqPropV = ADD_INDEX(pointProp + "_seq_V", t_J); - std::string seqSrcA = seqPropA + "_src"; - std::string seqSrcV = seqPropV + "_src"; - std::string point5d = LABEL_5D(pointProp); - makeConservedSequentialSource(application, seqSrcA, point5d, - actionName, t_J, Current::Axial, Tp, mom); - makePropagator(application, seqPropA, seqSrcA, solverName); - makeConservedSequentialSource(application, seqSrcV, point5d, - actionName, t_J, Current::Vector, Tp, mom); - makePropagator(application, seqPropV, seqSrcV, solverName); - - std::string modNameA = "Axial Sequential Test"; - std::string modNameV = "Vector Sequential Test"; - makeSeqTest(application, modNameA, pointProp, seqPropA, - actionName, pos, t_J, Tp, Current::Axial, Ls); - makeSeqTest(application, modNameV, pointProp, seqPropV, - actionName, pos, t_J, Tp, Current::Vector, Ls); + actionName = "Wilson"; + makeWilsonAction(application, actionName, gaugeField, mass); + setupWardIdentityTests(application, actionName, mass); // execution application.saveParameterFile("ConservedCurrentTest.xml"); From 08b314fd0fadd012492710bf57fd17b37ea9cf54 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Thu, 18 May 2017 13:16:14 +0100 Subject: [PATCH 034/174] Hadrons: conserved current test fixes. Axial current tests now also optional. --- .../Modules/MContraction/WardIdentity.hpp | 106 ++++++++++-------- tests/hadrons/Test_hadrons.hpp | 13 ++- .../hadrons/Test_hadrons_conserved_current.cc | 3 +- 3 files changed, 69 insertions(+), 53 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index d312bd4d..fa51ce95 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -40,10 +40,10 @@ BEGIN_HADRONS_NAMESPACE ----------------------------- * options: - - q: propagator, 5D if available (string) - - q4d: 4D propagator, duplicate of q if q is not 5D (string) - - action: action module used for propagator solution (string) - - mass: mass of quark (double) + - q: propagator, 5D if available (string) + - action: action module used for propagator solution (string) + - mass: mass of quark (double) + - test_axial: whether or not to test PCAC relation. */ /****************************************************************************** @@ -56,9 +56,9 @@ class WardIdentityPar: Serializable public: GRID_SERIALIZABLE_CLASS_MEMBERS(WardIdentityPar, std::string, q, - std::string, q4d, std::string, action, - double, mass); + double, mass, + bool, test_axial); }; template @@ -97,7 +97,7 @@ TWardIdentity::TWardIdentity(const std::string name) template std::vector TWardIdentity::getInput(void) { - std::vector in = {par().q, par().q4d, par().action}; + std::vector in = {par().q, par().action}; return in; } @@ -128,55 +128,69 @@ void TWardIdentity::execute(void) LOG(Message) << "Performing Ward Identity checks for quark '" << par().q << "'." << std::endl; - PropagatorField psi(env().getGrid()), tmp(env().getGrid()); + PropagatorField psi(env().getGrid()), tmp(env().getGrid()), + vector_WI(env().getGrid()); PropagatorField &q = *env().template getObject(par().q); - PropagatorField &q4d = *env().template getObject(par().q4d); FMat &act = *(env().template getObject(par().action)); Gamma g5(Gamma::Algebra::Gamma5); - LatticeComplex PP(env().getGrid()), PA(env().getGrid()), - c(env().getGrid()), PJ5q(env().getGrid()), - vector_WI(env().getGrid()), defect(env().getGrid()); - c = zero; PJ5q = zero; vector_WI = zero; defect = zero; - std::vector Vmu(Nd, c); - std::vector Amu(Nd, c); - - // Get PP, PA, V_mu, A_mu for 4D. - PP = trace(adj(q4d)*q4d); - PA = trace(adj(q4d)*g5*q4d); + + // Compute D_mu V_mu, D here is backward derivative. + vector_WI = zero; for (unsigned int mu = 0; mu < Nd; ++mu) { act.ContractConservedCurrent(q, q, tmp, Current::Vector, mu); - Vmu[mu] = trace(tmp); - act.ContractConservedCurrent(q, q, tmp, Current::Axial, mu); - Amu[mu] = trace(g5*tmp); + tmp -= Cshift(tmp, mu, -1); + vector_WI += tmp; } - // Get PJ5q for 5D (zero for 4D). - if (Ls_ > 1) - { - ExtractSlice(psi, q, Ls_/2 - 1, 0); - psi = 0.5 * (psi + g5*psi); - ExtractSlice(tmp, q, Ls_/2, 0); - psi += 0.5 * (tmp - g5*tmp); - PJ5q = trace(adj(psi)*psi); - } - - // Test ward identities, D_mu V_mu = 0; D_mu A_mu = 2m + 2 PJ5q - for (unsigned int mu = 0; mu < Nd; ++mu) - { - vector_WI += Vmu[mu] - Cshift(Vmu[mu], mu, -1); - defect += Amu[mu] - Cshift(Amu[mu], mu, -1); - } - defect -= 2.*PJ5q; - defect -= 2.*(par().mass)*PP; - LOG(Message) << "Vector Ward Identity check Delta_mu V_mu = " << norm2(vector_WI) << std::endl; - LOG(Message) << "Axial Ward Identity defect Delta_mu A_mu = " - << norm2(defect) << std::endl; - LOG(Message) << "norm2(PP) = " << norm2(PP) << std::endl; - LOG(Message) << "norm2(PA) = " << norm2(PA) << std::endl; - LOG(Message) << "norm2(PJ5q) = " << norm2(PJ5q) << std::endl; + + if (par().test_axial) + { + LatticeComplex PP(env().getGrid()), axial_defect(env().getGrid()), + PJ5q(env().getGrid()); + + // Compute D_mu A_mu, D is backwards derivative. + axial_defect = zero; + for (unsigned int mu = 0; mu < Nd; ++mu) + { + act.ContractConservedCurrent(q, q, tmp, Current::Axial, mu); + tmp -= Cshift(tmp, mu, -1); + axial_defect += trace(g5*tmp); + } + + // Get PJ5q for 5D (zero for 4D) and PP. + PJ5q = zero; + if (Ls_ > 1) + { + // PP + ExtractSlice(tmp, q, 0, 0); + psi = (tmp - g5*tmp); + ExtractSlice(tmp, q, Ls_ - 1, 0); + psi += (tmp + g5*tmp); + PP = trace(adj(psi)*psi); + + // P5Jq + ExtractSlice(tmp, q, Ls_/2 - 1, 0); + psi = 0.5 * (tmp + g5*tmp); + ExtractSlice(tmp, q, Ls_/2, 0); + psi += 0.5 * (tmp - g5*tmp); + PJ5q = trace(adj(psi)*psi); + } + else + { + PP = trace(adj(q)*q); + } + + // Test ward identities, D_mu V_mu = 0; D_mu A_mu = 2m + 2 PJ5q + axial_defect -= 2.*PJ5q; + axial_defect -= 2.*(par().mass)*PP; + LOG(Message) << "Axial Ward Identity defect Delta_mu A_mu = " + << norm2(axial_defect) << std::endl; + LOG(Message) << "norm2(PP) = " << norm2(PP) << std::endl; + LOG(Message) << "norm2(PJ5q) = " << norm2(PJ5q) << std::endl; + } } END_MODULE_NAMESPACE diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index 1b038388..6dbe3425 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -513,26 +513,27 @@ inline void discLoopContraction(Application &application, * actionName - action used to compute quark propagator. * mass - mass of quark. * Ls - length of 5th dimension (default = 1). + * test_axial - whether or not to check PCAC relation. * Returns: None. ******************************************************************************/ inline void makeWITest(Application &application, std::string &modName, std::string &propName, std::string &actionName, - double mass, unsigned int Ls = 1) + double mass, unsigned int Ls = 1, bool test_axial = false) { if (!(Environment::getInstance().hasModule(modName))) { MContraction::WardIdentity::Par wiPar; if (Ls > 1) { - wiPar.q = LABEL_5D(propName); + wiPar.q = LABEL_5D(propName); } else { - wiPar.q = propName; + wiPar.q = propName; } - wiPar.q4d = propName; - wiPar.action = actionName; - wiPar.mass = mass; + wiPar.action = actionName; + wiPar.mass = mass; + wiPar.test_axial = test_axial; application.createModule(modName, wiPar); } } diff --git a/tests/hadrons/Test_hadrons_conserved_current.cc b/tests/hadrons/Test_hadrons_conserved_current.cc index 080fef73..37ef30d9 100644 --- a/tests/hadrons/Test_hadrons_conserved_current.cc +++ b/tests/hadrons/Test_hadrons_conserved_current.cc @@ -81,7 +81,8 @@ inline void setupWardIdentityTests(Application &application, std::string origin = "0 0 0 0"; std::string modName = actionName + " Ward Identity Test"; MAKE_POINT_PROP(origin, pointProp, solverName); - makeWITest(application, modName, pointProp, actionName, mass, Ls); + makeWITest(application, modName, pointProp, actionName, mass, Ls, + perform_axial_tests); /*************************************************************************** * Conserved current tests with sequential insertion of vector/axial From eec79e0a1e8cdaf58c55547d520e2b9e9a894898 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Mon, 5 Jun 2017 11:55:41 +0100 Subject: [PATCH 035/174] Ward Identity test improvements and conserved current bug fixes --- .../Modules/MContraction/WardIdentity.hpp | 35 ++++++++++++------- lib/qcd/action/fermion/WilsonFermion5D.cc | 10 ++++-- lib/qcd/action/fermion/WilsonKernels.cc | 21 +++++------ 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index fa51ce95..7fc7d15d 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -143,6 +143,7 @@ void TWardIdentity::execute(void) vector_WI += tmp; } + // Test ward identity D_mu V_mu = 0; LOG(Message) << "Vector Ward Identity check Delta_mu V_mu = " << norm2(vector_WI) << std::endl; @@ -150,28 +151,29 @@ void TWardIdentity::execute(void) { LatticeComplex PP(env().getGrid()), axial_defect(env().getGrid()), PJ5q(env().getGrid()); + std::vector axial_buf; - // Compute D_mu A_mu, D is backwards derivative. + // Compute , D is backwards derivative. axial_defect = zero; for (unsigned int mu = 0; mu < Nd; ++mu) { act.ContractConservedCurrent(q, q, tmp, Current::Axial, mu); tmp -= Cshift(tmp, mu, -1); - axial_defect += trace(g5*tmp); + axial_defect += 2.*trace(g5*tmp); } - // Get PJ5q for 5D (zero for 4D) and PP. + // Get for 5D (zero for 4D) and . PJ5q = zero; if (Ls_ > 1) { - // PP + // ExtractSlice(tmp, q, 0, 0); - psi = (tmp - g5*tmp); + psi = 0.5 * (tmp - g5*tmp); ExtractSlice(tmp, q, Ls_ - 1, 0); - psi += (tmp + g5*tmp); + psi += 0.5 * (tmp + g5*tmp); PP = trace(adj(psi)*psi); - // P5Jq + // ExtractSlice(tmp, q, Ls_/2 - 1, 0); psi = 0.5 * (tmp + g5*tmp); ExtractSlice(tmp, q, Ls_/2, 0); @@ -183,13 +185,22 @@ void TWardIdentity::execute(void) PP = trace(adj(q)*q); } - // Test ward identities, D_mu V_mu = 0; D_mu A_mu = 2m + 2 PJ5q - axial_defect -= 2.*PJ5q; - axial_defect -= 2.*(par().mass)*PP; + // Test ward identity = 2m + 2 + LOG(Message) << "|D_mu A_mu|^2 = " << norm2(axial_defect) << std::endl; + LOG(Message) << "|PP|^2 = " << norm2(PP) << std::endl; + LOG(Message) << "|PJ5q|^2 = " << norm2(PJ5q) << std::endl; LOG(Message) << "Axial Ward Identity defect Delta_mu A_mu = " << norm2(axial_defect) << std::endl; - LOG(Message) << "norm2(PP) = " << norm2(PP) << std::endl; - LOG(Message) << "norm2(PJ5q) = " << norm2(PJ5q) << std::endl; + + // Axial defect by timeslice. + axial_defect -= 2.*(par().mass*PP + PJ5q); + LOG(Message) << "Check Axial defect by timeslice" << std::endl; + sliceSum(axial_defect, axial_buf, Tp); + for (int t = 0; t < axial_buf.size(); ++t) + { + LOG(Message) << "t = " << t << ": " + << TensorRemove(axial_buf[t]) << std::endl; + } } } diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index f616a080..3bbc03b4 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -700,8 +700,14 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, Kernels::ContractConservedCurrentInternal(q1_s, q2_s, tmp, Umu, curr_type, mu); // Axial current sign - Real G_s = (curr_type == Current::Axial) ? ((s < Ls/2) ? -1. : 1.) : 1.; - q_out += G_s*tmp; + if ((curr_type == Current::Axial) && (s < (Ls / 2))) + { + q_out -= tmp; + } + else + { + q_out += tmp; + } } } diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index 8dc6bd8c..802c0940 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -286,8 +286,9 @@ void WilsonKernels::DhopDir( StencilImpl &st, DoubledGaugeField &U,SiteHal * to make a conserved current sink or inserting the conserved current * sequentially. Common to both 4D and 5D. ******************************************************************************/ -#define WilsonCurrentFwd(expr, mu) (0.5*(Gamma::gmu[mu]*expr - expr)) -#define WilsonCurrentBwd(expr, mu) (0.5*(Gamma::gmu[mu]*expr + expr)) +// N.B. Functions below assume a -1/2 factor within U. +#define WilsonCurrentFwd(expr, mu) ((expr - Gamma::gmu[mu]*expr)) +#define WilsonCurrentBwd(expr, mu) ((expr + Gamma::gmu[mu]*expr)) template void WilsonKernels::ContractConservedCurrentInternal(const PropagatorField &q_in_1, @@ -300,13 +301,13 @@ void WilsonKernels::ContractConservedCurrentInternal(const PropagatorField Gamma g5(Gamma::Algebra::Gamma5); PropagatorField tmp(q_out._grid); GaugeLinkField Umu(U._grid); - Umu = PeekIndex(U, mu); + Umu = PeekIndex(U, mu); tmp = this->CovShiftForward(Umu, mu, q_in_1); q_out = (g5*adj(q_in_2)*g5)*WilsonCurrentFwd(tmp, mu); - tmp = adj(Umu)*q_in_1; - q_out += (g5*adj(this->CovShiftForward(Umu, mu, q_in_2))*g5)*WilsonCurrentBwd(q_in_1, mu); + tmp = this->CovShiftForward(Umu, mu, q_in_2); + q_out -= (g5*adj(tmp)*g5)*WilsonCurrentBwd(q_in_1, mu); } @@ -320,21 +321,21 @@ void WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_i unsigned int tmin, unsigned int tmax) { - int tshift = (mu == Nd - 1) ? 1 : 0; + int tshift = (mu == Tp) ? 1 : 0; Real G_T = (curr_type == Current::Tadpole) ? -1. : 1.; PropagatorField tmp(q_in._grid); GaugeLinkField Umu(U._grid); - Umu = PeekIndex(U, mu); + Umu = PeekIndex(U, mu); Lattice> t(q_in._grid); tmp = this->CovShiftForward(Umu, mu, q_in)*ph; - where((t >= tmin) and (t <= tmax), tmp, 0.*tmp); + tmp = where((t >= tmin) and (t <= tmax), tmp, 0.*tmp); q_out = G_T*WilsonCurrentFwd(tmp, mu); tmp = q_in*ph; tmp = this->CovShiftBackward(Umu, mu, tmp); - where((t >= tmin + tshift) and (t <= tmax + tshift), tmp, 0.*tmp); - q_out += WilsonCurrentBwd(tmp, mu); + tmp = where((t >= tmin + tshift) and (t <= tmax + tshift), tmp, 0.*tmp); + q_out -= WilsonCurrentBwd(tmp, mu); } From 622a21bec673ccf3a3b895584678afacd1f59c4b Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Mon, 5 Jun 2017 15:55:32 +0100 Subject: [PATCH 036/174] Improvements to sequential conserved current test and small bugfix. --- .../Modules/MUtilities/TestSeqConserved.hpp | 18 ++++++++++++------ lib/qcd/action/fermion/WilsonKernels.cc | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp index 3ae1b8b0..eccb00cc 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -140,7 +140,8 @@ void TTestSeqConserved::execute(void) Gamma g(gA); SitePropagator qSite; Complex test_S, test_V, check_S, check_V; - std::vector check_buf; + std::vector check_buf; + LatticeComplex c(env().getGrid()); // Check sequential insertion of current gives same result as conserved // current sink upon contraction. Assume q uses a point source. @@ -151,9 +152,14 @@ void TTestSeqConserved::execute(void) test_V = trace(qSite*g*Gamma::gmu[par().mu]); act.ContractConservedCurrent(q, q, tmp, par().curr, par().mu); - sliceSum(tmp, check_buf, Tp); - check_S = TensorRemove(trace(check_buf[par().t_J]*g)); - check_V = TensorRemove(trace(check_buf[par().t_J]*g*Gamma::gmu[par().mu])); + + c = trace(tmp*g); + sliceSum(c, check_buf, Tp); + check_S = TensorRemove(check_buf[par().t_J]); + + c = trace(tmp*g*Gamma::gmu[par().mu]); + sliceSum(c, check_buf, Tp); + check_V = TensorRemove(check_buf[par().t_J]); LOG(Message) << "Test S = " << abs(test_S) << std::endl; LOG(Message) << "Test V = " << abs(test_V) << std::endl; @@ -166,8 +172,8 @@ void TTestSeqConserved::execute(void) LOG(Message) << "Consistency check for sequential conserved " << par().curr << " current insertion: " << std::endl; - LOG(Message) << "Check S = " << abs(check_S) << std::endl; - LOG(Message) << "Check V = " << abs(check_V) << std::endl; + LOG(Message) << "Diff S = " << abs(check_S) << std::endl; + LOG(Message) << "Diff V = " << abs(check_V) << std::endl; } END_MODULE_NAMESPACE diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index 802c0940..8d5406f4 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -327,6 +327,7 @@ void WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_i GaugeLinkField Umu(U._grid); Umu = PeekIndex(U, mu); Lattice> t(q_in._grid); + LatticeCoordinate(t, mu); tmp = this->CovShiftForward(Umu, mu, q_in)*ph; tmp = where((t >= tmin) and (t <= tmax), tmp, 0.*tmp); From c504b4dbad611b8f36599fb5d6202a85b465134d Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Mon, 5 Jun 2017 15:56:43 +0100 Subject: [PATCH 037/174] Code cleaning --- extras/Hadrons/Modules/MContraction/WardIdentity.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index 7fc7d15d..fb2ea173 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -128,12 +128,11 @@ void TWardIdentity::execute(void) LOG(Message) << "Performing Ward Identity checks for quark '" << par().q << "'." << std::endl; - PropagatorField psi(env().getGrid()), tmp(env().getGrid()), - vector_WI(env().getGrid()); + PropagatorField tmp(env().getGrid()), vector_WI(env().getGrid()); PropagatorField &q = *env().template getObject(par().q); FMat &act = *(env().template getObject(par().action)); Gamma g5(Gamma::Algebra::Gamma5); - + // Compute D_mu V_mu, D here is backward derivative. vector_WI = zero; for (unsigned int mu = 0; mu < Nd; ++mu) @@ -149,6 +148,7 @@ void TWardIdentity::execute(void) if (par().test_axial) { + PropagatorField psi(env().getGrid()); LatticeComplex PP(env().getGrid()), axial_defect(env().getGrid()), PJ5q(env().getGrid()); std::vector axial_buf; @@ -159,7 +159,7 @@ void TWardIdentity::execute(void) { act.ContractConservedCurrent(q, q, tmp, Current::Axial, mu); tmp -= Cshift(tmp, mu, -1); - axial_defect += 2.*trace(g5*tmp); + axial_defect += trace(g5*tmp); } // Get for 5D (zero for 4D) and . @@ -191,7 +191,7 @@ void TWardIdentity::execute(void) LOG(Message) << "|PJ5q|^2 = " << norm2(PJ5q) << std::endl; LOG(Message) << "Axial Ward Identity defect Delta_mu A_mu = " << norm2(axial_defect) << std::endl; - + // Axial defect by timeslice. axial_defect -= 2.*(par().mass*PP + PJ5q); LOG(Message) << "Check Axial defect by timeslice" << std::endl; From e5c8b7369e2cb259379d987260cf21f2b96e404f Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Tue, 6 Jun 2017 14:19:10 +0100 Subject: [PATCH 038/174] Boundary condition option in quark actions for hadrons tests. --- tests/hadrons/Test_hadrons.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index 6dbe3425..a554425d 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -107,16 +107,20 @@ using namespace Hadrons; * actionName - name of action module to create. * gaugeField - gauge field module. * mass - quark mass. + * boundary - fermion boundary conditions (default to periodic + * space, antiperiodic time). * Returns: None. ******************************************************************************/ inline void makeWilsonAction(Application &application, std::string actionName, - std::string &gaugeField, double mass) + std::string &gaugeField, double mass, + std::string boundary = "1 1 1 -1") { if (!(Environment::getInstance().hasModule(actionName))) { MAction::Wilson::Par actionPar; actionPar.gauge = gaugeField; actionPar.mass = mass; + actionPar.boundary = boundary; application.createModule(actionName, actionPar); } } @@ -129,11 +133,13 @@ inline void makeWilsonAction(Application &application, std::string actionName, * mass - quark mass. * M5 - domain wall height. * Ls - fifth dimension extent. + * boundary - fermion boundary conditions (default to periodic + * space, antiperiodic time). * Returns: None. ******************************************************************************/ inline void makeDWFAction(Application &application, std::string actionName, std::string &gaugeField, double mass, double M5, - unsigned int Ls) + unsigned int Ls, std::string boundary = "1 1 1 -1") { if (!(Environment::getInstance().hasModule(actionName))) { @@ -142,6 +148,7 @@ inline void makeDWFAction(Application &application, std::string actionName, actionPar.Ls = Ls; actionPar.M5 = M5; actionPar.mass = mass; + actionPar.boundary = boundary; application.createModule(actionName, actionPar); } } From 8d442b502dc59f7fe4407b02142677299ac63740 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Tue, 6 Jun 2017 17:06:40 +0100 Subject: [PATCH 039/174] Sequential current fix for spacial indices. --- lib/qcd/action/fermion/WilsonKernels.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index 8d5406f4..62ae93fa 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -327,7 +327,7 @@ void WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_i GaugeLinkField Umu(U._grid); Umu = PeekIndex(U, mu); Lattice> t(q_in._grid); - LatticeCoordinate(t, mu); + LatticeCoordinate(t, Tp); tmp = this->CovShiftForward(Umu, mu, q_in)*ph; tmp = where((t >= tmin) and (t <= tmax), tmp, 0.*tmp); From 60f11bfd72f2c74cfdb0b91eaa9f44d80dd9946c Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Wed, 7 Jun 2017 12:34:47 +0100 Subject: [PATCH 040/174] Removed redundant test module --- extras/Hadrons/Modules.hpp | 1 - .../Modules/MContraction/WardIdentitySeq.hpp | 145 ------------------ extras/Hadrons/modules.inc | 1 - 3 files changed, 147 deletions(-) delete mode 100644 extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index dd6a6010..53ec346c 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -33,7 +33,6 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include -#include #include #include #include diff --git a/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp b/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp deleted file mode 100644 index 31409925..00000000 --- a/extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp +++ /dev/null @@ -1,145 +0,0 @@ -/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: extras/Hadrons/Modules/MContraction/WardIdentitySeq.hpp - -Copyright (C) 2017 - -Author: Andrew Lawson - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ - -#ifndef Hadrons_WardIdentitySeq_hpp_ -#define Hadrons_WardIdentitySeq_hpp_ - -#include -#include -#include - -BEGIN_HADRONS_NAMESPACE - -/* - Ward Identity contractions using sequential propagators. - ----------------------------- - - * options: - - q_x: propagator, mu = x current insertion (string). - - q_y: propagator, mu = y current insertion (string). - - q_z: propagator, mu = z current insertion (string). - - q_t: propagator, mu = t current insertion (string). -*/ - -/****************************************************************************** - * WardIdentitySeq * - ******************************************************************************/ -BEGIN_MODULE_NAMESPACE(MContraction) - -class WardIdentitySeqPar: Serializable -{ -public: - GRID_SERIALIZABLE_CLASS_MEMBERS(WardIdentitySeqPar, - std::string, q_x, - std::string, q_y, - std::string, q_z, - std::string, q_t); -}; - -template -class TWardIdentitySeq: public Module -{ -public: - TYPE_ALIASES(FImpl,); -public: - // constructor - TWardIdentitySeq(const std::string name); - // destructor - virtual ~TWardIdentitySeq(void) = default; - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); -}; - -MODULE_REGISTER_NS(WardIdentitySeq, TWardIdentitySeq, MContraction); - -/****************************************************************************** - * TWardIdentitySeq implementation * - ******************************************************************************/ -// constructor ///////////////////////////////////////////////////////////////// -template -TWardIdentitySeq::TWardIdentitySeq(const std::string name) -: Module(name) -{} - -// dependencies/products /////////////////////////////////////////////////////// -template -std::vector TWardIdentitySeq::getInput(void) -{ - std::vector in = {par().q_x, par().q_y, par().q_z, par().q_t}; - - return in; -} - -template -std::vector TWardIdentitySeq::getOutput(void) -{ - std::vector out = {getName()}; - - return out; -} - -// setup /////////////////////////////////////////////////////////////////////// -template -void TWardIdentitySeq::setup(void) -{ - -} - -// execution /////////////////////////////////////////////////////////////////// -template -void TWardIdentitySeq::execute(void) -{ - LatticeComplex vector_WI(env().getGrid()), c(env().getGrid()); - PropagatorField q_x = *env().template getObject(par().q_x); - PropagatorField q_y = *env().template getObject(par().q_y); - PropagatorField q_z = *env().template getObject(par().q_z); - PropagatorField q_t = *env().template getObject(par().q_t); - PropagatorField *q[Nd] = {&q_x, &q_y, &q_z, &q_t}; - Gamma g5(Gamma::Algebra::Gamma5); - - // Check D_mu V_mu = 0 - for (unsigned int mu = 0; mu < Nd; ++mu) - { - c = trace(g5*(*q[mu])); - vector_WI += c - Cshift(c, mu, -1); - } - - LOG(Message) << "Ward Identity checks for sequential vector current " - << "insertion = " << norm2(vector_WI) << std::endl; -} - -END_MODULE_NAMESPACE - -END_HADRONS_NAMESPACE - -#endif // Hadrons_WardIdentitySeq_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 0364502a..b57aa577 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -14,7 +14,6 @@ modules_hpp =\ Modules/MContraction/Gamma3pt.hpp \ Modules/MContraction/Meson.hpp \ Modules/MContraction/WardIdentity.hpp \ - Modules/MContraction/WardIdentitySeq.hpp \ Modules/MContraction/WeakHamiltonian.hpp \ Modules/MContraction/WeakHamiltonianEye.hpp \ Modules/MContraction/WeakHamiltonianNonEye.hpp \ From b8e45ae490729a9ed79983974e1eeec1778a1e8d Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Wed, 7 Jun 2017 16:26:22 +0100 Subject: [PATCH 041/174] Fixed remaining fermion type aliases after merge. --- extras/Hadrons/Modules/MContraction/WardIdentity.hpp | 2 +- extras/Hadrons/Modules/MSource/SeqConserved.hpp | 2 +- extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp | 2 +- extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index fb2ea173..82b0317a 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -65,7 +65,7 @@ template class TWardIdentity: public Module { public: - TYPE_ALIASES(FImpl,); + FERM_TYPE_ALIASES(FImpl,); public: // constructor TWardIdentity(const std::string name); diff --git a/extras/Hadrons/Modules/MSource/SeqConserved.hpp b/extras/Hadrons/Modules/MSource/SeqConserved.hpp index 6e5fb197..67086f11 100644 --- a/extras/Hadrons/Modules/MSource/SeqConserved.hpp +++ b/extras/Hadrons/Modules/MSource/SeqConserved.hpp @@ -74,7 +74,7 @@ template class TSeqConserved: public Module { public: - TYPE_ALIASES(FImpl,); + FERM_TYPE_ALIASES(FImpl,); public: // constructor TSeqConserved(const std::string name); diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp index eccb00cc..faebab0a 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -71,7 +71,7 @@ template class TTestSeqConserved: public Module { public: - TYPE_ALIASES(FImpl,); + FERM_TYPE_ALIASES(FImpl,); public: // constructor TTestSeqConserved(const std::string name); diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp index b3e99617..1b057c29 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp @@ -27,7 +27,7 @@ template class TTestSeqGamma: public Module { public: - TYPE_ALIASES(FImpl,); + FERM_TYPE_ALIASES(FImpl,); public: // constructor TTestSeqGamma(const std::string name); From 2d433ba30720f621b4d0a1bae91434aa4a42fe36 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Mon, 12 Jun 2017 10:32:14 +0100 Subject: [PATCH 042/174] Changed header include guards to match new convention --- extras/Hadrons/Modules/MContraction/WardIdentity.hpp | 4 ++-- extras/Hadrons/Modules/MSource/SeqConserved.hpp | 4 ++-- extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp | 4 ++-- extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index 82b0317a..8a56e0eb 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -26,8 +26,8 @@ See the full license in the file "LICENSE" in the top level distribution directo *************************************************************************************/ /* END LEGAL */ -#ifndef Hadrons_WardIdentity_hpp_ -#define Hadrons_WardIdentity_hpp_ +#ifndef Hadrons_MContraction_WardIdentity_hpp_ +#define Hadrons_MContraction_WardIdentity_hpp_ #include #include diff --git a/extras/Hadrons/Modules/MSource/SeqConserved.hpp b/extras/Hadrons/Modules/MSource/SeqConserved.hpp index 67086f11..86a7dfb9 100644 --- a/extras/Hadrons/Modules/MSource/SeqConserved.hpp +++ b/extras/Hadrons/Modules/MSource/SeqConserved.hpp @@ -26,8 +26,8 @@ See the full license in the file "LICENSE" in the top level distribution directo *************************************************************************************/ /* END LEGAL */ -#ifndef Hadrons_SeqConserved_hpp_ -#define Hadrons_SeqConserved_hpp_ +#ifndef Hadrons_MSource_SeqConserved_hpp_ +#define Hadrons_MSource_SeqConserved_hpp_ #include #include diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp index faebab0a..b085eb8c 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -26,8 +26,8 @@ See the full license in the file "LICENSE" in the top level distribution directo *************************************************************************************/ /* END LEGAL */ -#ifndef Hadrons_TestSeqConserved_hpp_ -#define Hadrons_TestSeqConserved_hpp_ +#ifndef Hadrons_MUtilities_TestSeqConserved_hpp_ +#define Hadrons_MUtilities_TestSeqConserved_hpp_ #include #include diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp index 1b057c29..3dbd7d63 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp @@ -1,5 +1,5 @@ -#ifndef Hadrons_TestSeqGamma_hpp_ -#define Hadrons_TestSeqGamma_hpp_ +#ifndef Hadrons_MUtilities_TestSeqGamma_hpp_ +#define Hadrons_MUtilities_TestSeqGamma_hpp_ #include #include From 5633a2db20e99cec2b5f11906632beb20eaadb31 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Mon, 12 Jun 2017 10:41:02 +0100 Subject: [PATCH 043/174] Faster implementation of conserved current site contraction. Added 5D vectorised support, but not G-parity. --- lib/qcd/action/fermion/FermionOperatorImpl.h | 29 ++++- lib/qcd/action/fermion/WilsonFermion.cc | 20 ++- lib/qcd/action/fermion/WilsonFermion5D.cc | 48 ++++--- lib/qcd/action/fermion/WilsonKernels.cc | 124 +++++++++++++++---- lib/qcd/action/fermion/WilsonKernels.h | 26 +++- 5 files changed, 198 insertions(+), 49 deletions(-) diff --git a/lib/qcd/action/fermion/FermionOperatorImpl.h b/lib/qcd/action/fermion/FermionOperatorImpl.h index 20458b6d..f330fb0d 100644 --- a/lib/qcd/action/fermion/FermionOperatorImpl.h +++ b/lib/qcd/action/fermion/FermionOperatorImpl.h @@ -212,6 +212,13 @@ namespace QCD { StencilImpl &St) { mult(&phi(), &U(mu), &chi()); } + + inline void multLinkProp(SitePropagator &phi, + const SiteDoubledGaugeField &U, + const SitePropagator &chi, + int mu) { + mult(&phi(), &U(mu), &chi()); + } template inline void loadLinkElement(Simd ®, ref &memory) { @@ -340,7 +347,20 @@ class DomainWallVec5dImpl : public PeriodicGaugeImpl< GaugeImplTypes< S,Nrepres } mult(&phi(), &UU(), &chi()); } - + + inline void multLinkProp(SitePropagator &phi, + const SiteDoubledGaugeField &U, + const SitePropagator &chi, + int mu) { + SiteGaugeLink UU; + for (int i = 0; i < Nrepresentation; i++) { + for (int j = 0; j < Nrepresentation; j++) { + vsplat(UU()()(i, j), U(mu)()(i, j)); + } + } + mult(&phi(), &UU(), &chi()); + } + inline void DoubleStore(GridBase *GaugeGrid, DoubledGaugeField &Uds,const GaugeField &Umu) { SiteScalarGaugeField ScalarUmu; @@ -538,6 +558,13 @@ class GparityWilsonImpl : public ConjugateGaugeImpl::ContractConservedCurrent(PropagatorField &q_in_1, conformable(_grid, q_in_1._grid); conformable(_grid, q_in_2._grid); conformable(_grid, q_out._grid); - Kernels::ContractConservedCurrentInternal(q_in_1, q_in_2, q_out, - Umu, curr_type, mu); + PropagatorField tmp(_grid); + q_out = zero; + + // Forward, need q1(x + mu), q2(x) + tmp = Cshift(q_in_1, mu, 1); + parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) + { + Kernels::ContractConservedCurrentSiteFwd(tmp, q_in_2, q_out, Umu, + mu, sU, sU, sU, sU); + } + + // Backward, need q1(x), q2(x + mu) + tmp = Cshift(q_in_2, mu, 1); + parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) + { + Kernels::ContractConservedCurrentSiteBwd(q_in_1, tmp, q_out, Umu, + mu, sU, sU, sU, sU); + } } template diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index 3bbc03b4..b69a18ba 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -687,26 +687,44 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, conformable(q_in_1._grid, q_in_2._grid); conformable(_FourDimGrid, q_out._grid); - PropagatorField q1_s(_FourDimGrid); - PropagatorField q2_s(_FourDimGrid); - PropagatorField tmp(_FourDimGrid); - - // Contract across 5th dimension. + PropagatorField tmp(FermionGrid()); q_out = zero; - for (int s = 0; s < Ls; ++s) - { - ExtractSlice(q1_s, q_in_1, s, 0); - ExtractSlice(q2_s, q_in_2, Ls - s - 1, 0); - Kernels::ContractConservedCurrentInternal(q1_s, q2_s, tmp, Umu, curr_type, mu); - // Axial current sign - if ((curr_type == Current::Axial) && (s < (Ls / 2))) + // Forward, need q1(x + mu, s), q2(x, Ls - 1 - s). 5D lattice so shift + // 4D coordinate mu by one. + tmp = Cshift(q_in_1, mu + 1, 1); + parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) + { + unsigned int sF1 = sU * Ls; + unsigned int sF2 = (sU + 1) * Ls - 1; + for (int s = 0; s < Ls; ++s) { - q_out -= tmp; + bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ + true : false; + Kernels::ContractConservedCurrentSiteFwd(tmp, q_in_2, q_out, Umu, + mu, sF1, sF2, sU, sU, + axial_sign); + sF1++; + sF2--; } - else + } + + // Backward, need q1(x, s), q2(x + mu, Ls - 1 - s). 5D lattice so shift + // 4D coordinate mu by one. + tmp = Cshift(q_in_2, mu + 1, 1); + parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) + { + unsigned int sF1 = sU * Ls; + unsigned int sF2 = (sU + 1) * Ls - 1; + for (int s = 0; s < Ls; ++s) { - q_out += tmp; + bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ + true : false; + Kernels::ContractConservedCurrentSiteBwd(q_in_1, tmp, q_out, Umu, + mu, sF1, sF2, sU, sU, + axial_sign); + sF1++; + sF2--; } } } diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index 62ae93fa..c519dc56 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -290,26 +290,110 @@ void WilsonKernels::DhopDir( StencilImpl &st, DoubledGaugeField &U,SiteHal #define WilsonCurrentFwd(expr, mu) ((expr - Gamma::gmu[mu]*expr)) #define WilsonCurrentBwd(expr, mu) ((expr + Gamma::gmu[mu]*expr)) +/******************************************************************************* + * Name: ContractConservedCurrentSiteFwd + * Operation: (1/2) * q2[x] * U(x) * (g[mu] - 1) * q1[x + mu] + * Notes: - DoubledGaugeField U assumed to contain -1/2 factor. + * - Pass in q_in_1 shifted in +ve mu direction. + ******************************************************************************/ template -void WilsonKernels::ContractConservedCurrentInternal(const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, - DoubledGaugeField &U, - Current curr_type, - unsigned int mu) +void WilsonKernels::ContractConservedCurrentSiteFwd( + const PropagatorField &q_in_1, + const PropagatorField &q_in_2, + PropagatorField &q_out, + DoubledGaugeField &U, + unsigned int mu, + unsigned int sF_in_1, + unsigned int sF_in_2, + unsigned int sF_out, + unsigned int sU, + bool switch_sign) { + SitePropagator result, tmp; Gamma g5(Gamma::Algebra::Gamma5); - PropagatorField tmp(q_out._grid); - GaugeLinkField Umu(U._grid); - Umu = PeekIndex(U, mu); - - tmp = this->CovShiftForward(Umu, mu, q_in_1); - q_out = (g5*adj(q_in_2)*g5)*WilsonCurrentFwd(tmp, mu); - - tmp = this->CovShiftForward(Umu, mu, q_in_2); - q_out -= (g5*adj(tmp)*g5)*WilsonCurrentBwd(q_in_1, mu); + multLinkProp(tmp, U._odata[sU], q_in_1._odata[sF_in_1], mu); + result = g5 * adj(q_in_2._odata[sF_in_2]) * g5 * WilsonCurrentFwd(tmp, mu); + if (switch_sign) + { + q_out._odata[sF_out] -= result; + } + else + { + q_out._odata[sF_out] += result; + } } +/******************************************************************************* + * Name: ContractConservedCurrentSiteBwd + * Operation: (1/2) * q2[x + mu] * U^dag(x) * (g[mu] + 1) * q1[x] + * Notes: - DoubledGaugeField U assumed to contain -1/2 factor. + * - Pass in q_in_2 shifted in +ve mu direction. + ******************************************************************************/ +template +void WilsonKernels::ContractConservedCurrentSiteBwd( + const PropagatorField &q_in_1, + const PropagatorField &q_in_2, + PropagatorField &q_out, + DoubledGaugeField &U, + unsigned int mu, + unsigned int sF_in_1, + unsigned int sF_in_2, + unsigned int sF_out, + unsigned int sU, + bool switch_sign) +{ + SitePropagator result, tmp; + Gamma g5(Gamma::Algebra::Gamma5); + multLinkProp(tmp, U._odata[sU], q_in_1._odata[sF_in_1], mu + Nd); + result = g5 * adj(q_in_2._odata[sF_in_2]) * g5 * WilsonCurrentBwd(tmp, mu); + if (switch_sign) + { + q_out._odata[sF_out] += result; + } + else + { + q_out._odata[sF_out] -= result; + } +} + +// G-parity requires more specialised implementation. +#define NO_CURR_SITE(Impl) \ +template <> \ +void WilsonKernels::ContractConservedCurrentSiteFwd( \ + const PropagatorField &q_in_1, \ + const PropagatorField &q_in_2, \ + PropagatorField &q_out, \ + DoubledGaugeField &U, \ + unsigned int mu, \ + unsigned int sF_in_1, \ + unsigned int sF_in_2, \ + unsigned int sF_out, \ + unsigned int sU, \ + bool switch_sign) \ +{ \ + assert(0); \ +} \ +template <> \ +void WilsonKernels::ContractConservedCurrentSiteBwd( \ + const PropagatorField &q_in_1, \ + const PropagatorField &q_in_2, \ + PropagatorField &q_out, \ + DoubledGaugeField &U, \ + unsigned int mu, \ + unsigned int sF_in_1, \ + unsigned int sF_in_2, \ + unsigned int sF_out, \ + unsigned int sU, \ + bool switch_sign) \ +{ \ + assert(0); \ +} + +NO_CURR_SITE(GparityWilsonImplF); +NO_CURR_SITE(GparityWilsonImplD); +NO_CURR_SITE(GparityWilsonImplFH); +NO_CURR_SITE(GparityWilsonImplDF); + template void WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_in, @@ -342,16 +426,6 @@ void WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_i // GParity, (Z)DomainWallVec5D -> require special implementation #define NO_CURR(Impl) \ -template <> void \ -WilsonKernels::ContractConservedCurrentInternal(const PropagatorField &q_in_1, \ - const PropagatorField &q_in_2, \ - PropagatorField &q_out, \ - DoubledGaugeField &U, \ - Current curr_type, \ - unsigned int mu) \ -{ \ - assert(0); \ -} \ template <> void \ WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_in, \ PropagatorField &q_out, \ diff --git a/lib/qcd/action/fermion/WilsonKernels.h b/lib/qcd/action/fermion/WilsonKernels.h index 25c956ef..95155ccc 100644 --- a/lib/qcd/action/fermion/WilsonKernels.h +++ b/lib/qcd/action/fermion/WilsonKernels.h @@ -183,12 +183,26 @@ public: ////////////////////////////////////////////////////////////////////////////// // Utilities for inserting Wilson conserved current. ////////////////////////////////////////////////////////////////////////////// - void ContractConservedCurrentInternal(const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, - DoubledGaugeField &U, - Current curr_type, - unsigned int mu); + void ContractConservedCurrentSiteFwd(const PropagatorField &q_in_1, + const PropagatorField &q_in_2, + PropagatorField &q_out, + DoubledGaugeField &U, + unsigned int mu, + unsigned int sF_in_1, + unsigned int sF_in_2, + unsigned int sF_out, + unsigned int sU, + bool switch_sign = false); + void ContractConservedCurrentSiteBwd(const PropagatorField &q_in_1, + const PropagatorField &q_in_2, + PropagatorField &q_out, + DoubledGaugeField &U, + unsigned int mu, + unsigned int sF_in_1, + unsigned int sF_in_2, + unsigned int sF_out, + unsigned int sU, + bool switch_sign = false); void SeqConservedCurrentInternal(const PropagatorField &q_in, PropagatorField &q_out, DoubledGaugeField &U, From 41af8c12d70145320a1f2fd924464802f26cffff Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 16 Jun 2017 16:38:59 +0100 Subject: [PATCH 044/174] Code cleaning for conserved current contractions. Will now be easier to implement mobius conserved current. --- lib/qcd/action/fermion/WilsonFermion.cc | 26 ++++---- lib/qcd/action/fermion/WilsonFermion5D.cc | 40 ++++--------- lib/qcd/action/fermion/WilsonKernels.cc | 72 ++++++++++------------- lib/qcd/action/fermion/WilsonKernels.h | 22 +++---- 4 files changed, 64 insertions(+), 96 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonFermion.cc b/lib/qcd/action/fermion/WilsonFermion.cc index 28842cdd..eff7d958 100644 --- a/lib/qcd/action/fermion/WilsonFermion.cc +++ b/lib/qcd/action/fermion/WilsonFermion.cc @@ -361,23 +361,23 @@ void WilsonFermion::ContractConservedCurrent(PropagatorField &q_in_1, conformable(_grid, q_in_1._grid); conformable(_grid, q_in_2._grid); conformable(_grid, q_out._grid); - PropagatorField tmp(_grid); + PropagatorField tmp1(_grid), tmp2(_grid); q_out = zero; - // Forward, need q1(x + mu), q2(x) - tmp = Cshift(q_in_1, mu, 1); + // Forward, need q1(x + mu), q2(x). Backward, need q1(x), q2(x + mu). + // Inefficient comms method but not performance critical. + tmp1 = Cshift(q_in_1, mu, 1); + tmp2 = Cshift(q_in_2, mu, 1); parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) { - Kernels::ContractConservedCurrentSiteFwd(tmp, q_in_2, q_out, Umu, - mu, sU, sU, sU, sU); - } - - // Backward, need q1(x), q2(x + mu) - tmp = Cshift(q_in_2, mu, 1); - parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) - { - Kernels::ContractConservedCurrentSiteBwd(q_in_1, tmp, q_out, Umu, - mu, sU, sU, sU, sU); + Kernels::ContractConservedCurrentSiteFwd(tmp1._odata[sU], + q_in_2._odata[sU], + q_out._odata[sU], + Umu, sU, mu); + Kernels::ContractConservedCurrentSiteBwd(q_in_1._odata[sU], + tmp2._odata[sU], + q_out._odata[sU], + Umu, sU, mu); } } diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index b69a18ba..76218098 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -686,13 +686,13 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, conformable(q_in_1._grid, FermionGrid()); conformable(q_in_1._grid, q_in_2._grid); conformable(_FourDimGrid, q_out._grid); - - PropagatorField tmp(FermionGrid()); + PropagatorField tmp1(FermionGrid()), tmp2(FermionGrid()); q_out = zero; - // Forward, need q1(x + mu, s), q2(x, Ls - 1 - s). 5D lattice so shift - // 4D coordinate mu by one. - tmp = Cshift(q_in_1, mu + 1, 1); + // Forward, need q1(x + mu, s), q2(x, Ls - 1 - s). Backward, need q1(x, s), + // q2(x + mu, Ls - 1 - s). 5D lattice so shift 4D coordinate mu by one. + tmp1 = Cshift(q_in_1, mu + 1, 1); + tmp2 = Cshift(q_in_2, mu + 1, 1); parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) { unsigned int sF1 = sU * Ls; @@ -701,28 +701,14 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, { bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ true : false; - Kernels::ContractConservedCurrentSiteFwd(tmp, q_in_2, q_out, Umu, - mu, sF1, sF2, sU, sU, - axial_sign); - sF1++; - sF2--; - } - } - - // Backward, need q1(x, s), q2(x + mu, Ls - 1 - s). 5D lattice so shift - // 4D coordinate mu by one. - tmp = Cshift(q_in_2, mu + 1, 1); - parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) - { - unsigned int sF1 = sU * Ls; - unsigned int sF2 = (sU + 1) * Ls - 1; - for (int s = 0; s < Ls; ++s) - { - bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ - true : false; - Kernels::ContractConservedCurrentSiteBwd(q_in_1, tmp, q_out, Umu, - mu, sF1, sF2, sU, sU, - axial_sign); + Kernels::ContractConservedCurrentSiteFwd(tmp1._odata[sF1], + q_in_2._odata[sF2], + q_out._odata[sU], + Umu, sU, mu, axial_sign); + Kernels::ContractConservedCurrentSiteBwd(q_in_1._odata[sF1], + tmp2._odata[sF2], + q_out._odata[sU], + Umu, sU, mu, axial_sign); sF1++; sF2--; } diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index c519dc56..6b193766 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -298,28 +298,25 @@ void WilsonKernels::DhopDir( StencilImpl &st, DoubledGaugeField &U,SiteHal ******************************************************************************/ template void WilsonKernels::ContractConservedCurrentSiteFwd( - const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, + const SitePropagator &q_in_1, + const SitePropagator &q_in_2, + SitePropagator &q_out, DoubledGaugeField &U, - unsigned int mu, - unsigned int sF_in_1, - unsigned int sF_in_2, - unsigned int sF_out, unsigned int sU, + unsigned int mu, bool switch_sign) { SitePropagator result, tmp; Gamma g5(Gamma::Algebra::Gamma5); - multLinkProp(tmp, U._odata[sU], q_in_1._odata[sF_in_1], mu); - result = g5 * adj(q_in_2._odata[sF_in_2]) * g5 * WilsonCurrentFwd(tmp, mu); + Impl::multLinkProp(tmp, U._odata[sU], q_in_1, mu); + result = g5 * adj(q_in_2) * g5 * WilsonCurrentFwd(tmp, mu); if (switch_sign) { - q_out._odata[sF_out] -= result; + q_out -= result; } else { - q_out._odata[sF_out] += result; + q_out += result; } } @@ -331,28 +328,25 @@ void WilsonKernels::ContractConservedCurrentSiteFwd( ******************************************************************************/ template void WilsonKernels::ContractConservedCurrentSiteBwd( - const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, + const SitePropagator &q_in_1, + const SitePropagator &q_in_2, + SitePropagator &q_out, DoubledGaugeField &U, - unsigned int mu, - unsigned int sF_in_1, - unsigned int sF_in_2, - unsigned int sF_out, unsigned int sU, + unsigned int mu, bool switch_sign) { SitePropagator result, tmp; Gamma g5(Gamma::Algebra::Gamma5); - multLinkProp(tmp, U._odata[sU], q_in_1._odata[sF_in_1], mu + Nd); - result = g5 * adj(q_in_2._odata[sF_in_2]) * g5 * WilsonCurrentBwd(tmp, mu); + Impl::multLinkProp(tmp, U._odata[sU], q_in_1, mu + Nd); + result = g5 * adj(q_in_2) * g5 * WilsonCurrentBwd(tmp, mu); if (switch_sign) { - q_out._odata[sF_out] += result; + q_out += result; } else { - q_out._odata[sF_out] -= result; + q_out -= result; } } @@ -360,31 +354,25 @@ void WilsonKernels::ContractConservedCurrentSiteBwd( #define NO_CURR_SITE(Impl) \ template <> \ void WilsonKernels::ContractConservedCurrentSiteFwd( \ - const PropagatorField &q_in_1, \ - const PropagatorField &q_in_2, \ - PropagatorField &q_out, \ - DoubledGaugeField &U, \ - unsigned int mu, \ - unsigned int sF_in_1, \ - unsigned int sF_in_2, \ - unsigned int sF_out, \ - unsigned int sU, \ - bool switch_sign) \ + const SitePropagator &q_in_1, \ + const SitePropagator &q_in_2, \ + SitePropagator &q_out, \ + DoubledGaugeField &U, \ + unsigned int sU, \ + unsigned int mu, \ + bool switch_sign) \ { \ assert(0); \ } \ template <> \ void WilsonKernels::ContractConservedCurrentSiteBwd( \ - const PropagatorField &q_in_1, \ - const PropagatorField &q_in_2, \ - PropagatorField &q_out, \ - DoubledGaugeField &U, \ - unsigned int mu, \ - unsigned int sF_in_1, \ - unsigned int sF_in_2, \ - unsigned int sF_out, \ - unsigned int sU, \ - bool switch_sign) \ + const SitePropagator &q_in_1, \ + const SitePropagator &q_in_2, \ + SitePropagator &q_out, \ + DoubledGaugeField &U, \ + unsigned int mu, \ + unsigned int sU, \ + bool switch_sign) \ { \ assert(0); \ } diff --git a/lib/qcd/action/fermion/WilsonKernels.h b/lib/qcd/action/fermion/WilsonKernels.h index 95155ccc..0294c740 100644 --- a/lib/qcd/action/fermion/WilsonKernels.h +++ b/lib/qcd/action/fermion/WilsonKernels.h @@ -183,25 +183,19 @@ public: ////////////////////////////////////////////////////////////////////////////// // Utilities for inserting Wilson conserved current. ////////////////////////////////////////////////////////////////////////////// - void ContractConservedCurrentSiteFwd(const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, + void ContractConservedCurrentSiteFwd(const SitePropagator &q_in_1, + const SitePropagator &q_in_2, + SitePropagator &q_out, DoubledGaugeField &U, - unsigned int mu, - unsigned int sF_in_1, - unsigned int sF_in_2, - unsigned int sF_out, unsigned int sU, + unsigned int mu, bool switch_sign = false); - void ContractConservedCurrentSiteBwd(const PropagatorField &q_in_1, - const PropagatorField &q_in_2, - PropagatorField &q_out, + void ContractConservedCurrentSiteBwd(const SitePropagator &q_in_1, + const SitePropagator &q_in_2, + SitePropagator &q_out, DoubledGaugeField &U, - unsigned int mu, - unsigned int sF_in_1, - unsigned int sF_in_2, - unsigned int sF_out, unsigned int sU, + unsigned int mu, bool switch_sign = false); void SeqConservedCurrentInternal(const PropagatorField &q_in, PropagatorField &q_out, From 1bd311ba9ccd8506d13064cb6f6829515a0f0240 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Fri, 16 Jun 2017 16:43:15 +0100 Subject: [PATCH 045/174] Faster sequential conserved current implementation, now compatible with 5D vectorisation & G-parity. --- lib/qcd/action/fermion/WilsonFermion.cc | 41 ++++++++- lib/qcd/action/fermion/WilsonFermion5D.cc | 68 +++++++++++--- lib/qcd/action/fermion/WilsonKernels.cc | 105 ++++++++++++---------- lib/qcd/action/fermion/WilsonKernels.h | 22 +++-- 4 files changed, 164 insertions(+), 72 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonFermion.cc b/lib/qcd/action/fermion/WilsonFermion.cc index eff7d958..b986edd7 100644 --- a/lib/qcd/action/fermion/WilsonFermion.cc +++ b/lib/qcd/action/fermion/WilsonFermion.cc @@ -394,6 +394,8 @@ void WilsonFermion::SeqConservedCurrent(PropagatorField &q_in, conformable(_grid, q_out._grid); Lattice> ph(_grid), coor(_grid); Complex i(0.0,1.0); + PropagatorField tmpFwd(_grid), tmpBwd(_grid), tmp(_grid); + int tshift = (mu == Tp) ? 1 : 0; // Momentum projection ph = zero; @@ -404,8 +406,43 @@ void WilsonFermion::SeqConservedCurrent(PropagatorField &q_in, } ph = exp((Real)(2*M_PI)*i*ph); - Kernels::SeqConservedCurrentInternal(q_in, q_out, Umu, curr_type, mu, ph, - tmin, tmax); + q_out = zero; + LatticeInteger coords(_grid); + LatticeCoordinate(coords, Tp); + + // Need q(x + mu) and q(x - mu). + tmp = Cshift(q_in, mu, 1); + tmpFwd = tmp*ph; + tmp = ph*q_in; + tmpBwd = Cshift(tmp, mu, -1); + + parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) + { + // Compute the sequential conserved current insertion only if our simd + // object contains a timeslice we need. + vInteger t_mask = ((coords._odata[sU] >= tmin) && + (coords._odata[sU] <= tmax)); + Integer timeSlices = Reduce(t_mask); + + if (timeSlices > 0) + { + Kernels::SeqConservedCurrentSiteFwd(tmpFwd._odata[sU], + q_out._odata[sU], + Umu, sU, mu, t_mask); + } + + // Repeat for backward direction. + t_mask = ((coords._odata[sU] >= (tmin + tshift)) && + (coords._odata[sU] <= (tmax + tshift))); + timeSlices = Reduce(t_mask); + + if (timeSlices > 0) + { + Kernels::SeqConservedCurrentSiteBwd(tmpBwd._odata[sU], + q_out._odata[sU], + Umu, sU, mu, t_mask); + } + } } FermOpTemplateInstantiate(WilsonFermion); diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index 76218098..5daed3de 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -727,31 +727,73 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, { conformable(q_in._grid, FermionGrid()); conformable(q_in._grid, q_out._grid); - Lattice> ph(_FourDimGrid), coor(_FourDimGrid); - PropagatorField q_in_s(_FourDimGrid); - PropagatorField q_out_s(_FourDimGrid); + Lattice> ph(FermionGrid()), coor(FermionGrid()); + PropagatorField tmpFwd(FermionGrid()), tmpBwd(FermionGrid()), + tmp(FermionGrid()); Complex i(0.0, 1.0); + int tshift = (mu == Tp) ? 1 : 0; - // Momentum projection + // Momentum projection. ph = zero; for(unsigned int nu = 0; nu < Nd - 1; nu++) { - LatticeCoordinate(coor, nu); + // Shift coordinate lattice index by 1 to account for 5th dimension. + LatticeCoordinate(coor, nu + 1); ph = ph + mom[nu]*coor*((1./(_FourDimGrid->_fdimensions[nu]))); } ph = exp((Real)(2*M_PI)*i*ph); - // Sequential insertion across 5th dimension - for (int s = 0; s < Ls; s++) + q_out = zero; + LatticeInteger coords(_FourDimGrid); + LatticeCoordinate(coords, Tp); + + // Need q(x + mu, s) and q(x - mu, s). 5D lattice so shift 4D coordinate mu + // by one. + tmp = Cshift(q_in, mu + 1, 1); + tmpFwd = tmp*ph; + tmp = ph*q_in; + tmpBwd = Cshift(tmp, mu + 1, -1); + + parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) { - ExtractSlice(q_in_s, q_in, s, 0); - Kernels::SeqConservedCurrentInternal(q_in_s, q_out_s, Umu, curr_type, - mu, ph, tmin, tmax); - if ((curr_type == Current::Axial) && (s < Ls/2)) + // Compute the sequential conserved current insertion only if our simd + // object contains a timeslice we need. + vInteger t_mask = ((coords._odata[sU] >= tmin) && + (coords._odata[sU] <= tmax)); + Integer timeSlices = Reduce(t_mask); + + if (timeSlices > 0) { - q_out_s = -q_out_s; + unsigned int sF = sU * Ls; + for (unsigned int s = 0; s < Ls; ++s) + { + bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ + true : false; + Kernels::SeqConservedCurrentSiteFwd(tmpFwd._odata[sF], + q_out._odata[sF], Umu, sU, + mu, t_mask, axial_sign); + ++sF; + } + } + + // Repeat for backward direction. + t_mask = ((coords._odata[sU] >= (tmin + tshift)) && + (coords._odata[sU] <= (tmax + tshift))); + timeSlices = Reduce(t_mask); + + if (timeSlices > 0) + { + unsigned int sF = sU * Ls; + for (unsigned int s = 0; s < Ls; ++s) + { + bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ + true : false; + Kernels::SeqConservedCurrentSiteBwd(tmpBwd._odata[sF], + q_out._odata[sF], Umu, sU, + mu, t_mask, axial_sign); + ++sF; + } } - InsertSlice(q_out_s, q_out, s, 0); } } diff --git a/lib/qcd/action/fermion/WilsonKernels.cc b/lib/qcd/action/fermion/WilsonKernels.cc index 6b193766..dc66db23 100644 --- a/lib/qcd/action/fermion/WilsonKernels.cc +++ b/lib/qcd/action/fermion/WilsonKernels.cc @@ -383,63 +383,70 @@ NO_CURR_SITE(GparityWilsonImplFH); NO_CURR_SITE(GparityWilsonImplDF); -template -void WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_in, - PropagatorField &q_out, - DoubledGaugeField &U, - Current curr_type, - unsigned int mu, - Lattice> &ph, - unsigned int tmin, - unsigned int tmax) +/******************************************************************************* + * Name: SeqConservedCurrentSiteFwd + * Operation: (1/2) * U(x) * (g[mu] - 1) * q[x + mu] + * Notes: - DoubledGaugeField U assumed to contain -1/2 factor. + * - Pass in q_in shifted in +ve mu direction. + ******************************************************************************/ +template +void WilsonKernels::SeqConservedCurrentSiteFwd(const SitePropagator &q_in, + SitePropagator &q_out, + DoubledGaugeField &U, + unsigned int sU, + unsigned int mu, + vInteger t_mask, + bool switch_sign) { - int tshift = (mu == Tp) ? 1 : 0; - Real G_T = (curr_type == Current::Tadpole) ? -1. : 1.; - PropagatorField tmp(q_in._grid); - GaugeLinkField Umu(U._grid); - Umu = PeekIndex(U, mu); - Lattice> t(q_in._grid); - LatticeCoordinate(t, Tp); + SitePropagator result; + Impl::multLinkProp(result, U._odata[sU], q_in, mu); + result = WilsonCurrentFwd(result, mu); - tmp = this->CovShiftForward(Umu, mu, q_in)*ph; - tmp = where((t >= tmin) and (t <= tmax), tmp, 0.*tmp); - q_out = G_T*WilsonCurrentFwd(tmp, mu); + // Zero any unwanted timeslice entries. + result = predicatedWhere(t_mask, result, 0.*result); - tmp = q_in*ph; - tmp = this->CovShiftBackward(Umu, mu, tmp); - tmp = where((t >= tmin + tshift) and (t <= tmax + tshift), tmp, 0.*tmp); - q_out -= WilsonCurrentBwd(tmp, mu); + if (switch_sign) + { + q_out -= result; + } + else + { + q_out += result; + } } +/******************************************************************************* + * Name: SeqConservedCurrentSiteFwd + * Operation: (1/2) * U^dag(x) * (g[mu] + 1) * q[x - mu] + * Notes: - DoubledGaugeField U assumed to contain -1/2 factor. + * - Pass in q_in shifted in -ve mu direction. + ******************************************************************************/ +template +void WilsonKernels::SeqConservedCurrentSiteBwd(const SitePropagator &q_in, + SitePropagator &q_out, + DoubledGaugeField &U, + unsigned int sU, + unsigned int mu, + vInteger t_mask, + bool switch_sign) +{ + SitePropagator result; + Impl::multLinkProp(result, U._odata[sU], q_in, mu + Nd); + result = WilsonCurrentBwd(result, mu); -// GParity, (Z)DomainWallVec5D -> require special implementation -#define NO_CURR(Impl) \ -template <> void \ -WilsonKernels::SeqConservedCurrentInternal(const PropagatorField &q_in, \ - PropagatorField &q_out, \ - DoubledGaugeField &U, \ - Current curr_type, \ - unsigned int mu, \ - Lattice> &ph, \ - unsigned int tmin, \ - unsigned int tmax) \ -{ \ - assert(0); \ + // Zero any unwanted timeslice entries. + result = predicatedWhere(t_mask, result, 0.*result); + + if (switch_sign) + { + q_out += result; + } + else + { + q_out -= result; + } } -NO_CURR(GparityWilsonImplF); -NO_CURR(GparityWilsonImplD); -NO_CURR(GparityWilsonImplFH); -NO_CURR(GparityWilsonImplDF); -NO_CURR(DomainWallVec5dImplF); -NO_CURR(DomainWallVec5dImplD); -NO_CURR(DomainWallVec5dImplFH); -NO_CURR(DomainWallVec5dImplDF); -NO_CURR(ZDomainWallVec5dImplF); -NO_CURR(ZDomainWallVec5dImplD); -NO_CURR(ZDomainWallVec5dImplFH); -NO_CURR(ZDomainWallVec5dImplDF); - FermOpTemplateInstantiate(WilsonKernels); AdjointFermOpTemplateInstantiate(WilsonKernels); TwoIndexFermOpTemplateInstantiate(WilsonKernels); diff --git a/lib/qcd/action/fermion/WilsonKernels.h b/lib/qcd/action/fermion/WilsonKernels.h index 0294c740..ed8d6be9 100644 --- a/lib/qcd/action/fermion/WilsonKernels.h +++ b/lib/qcd/action/fermion/WilsonKernels.h @@ -197,14 +197,20 @@ public: unsigned int sU, unsigned int mu, bool switch_sign = false); - void SeqConservedCurrentInternal(const PropagatorField &q_in, - PropagatorField &q_out, - DoubledGaugeField &U, - Current curr_type, - unsigned int mu, - Lattice> &ph, - unsigned int tmin, - unsigned int tmax); + void SeqConservedCurrentSiteFwd(const SitePropagator &q_in, + SitePropagator &q_out, + DoubledGaugeField &U, + unsigned int sU, + unsigned int mu, + vInteger t_mask, + bool switch_sign = false); + void SeqConservedCurrentSiteBwd(const SitePropagator &q_in, + SitePropagator &q_out, + DoubledGaugeField &U, + unsigned int sU, + unsigned int mu, + vInteger t_mask, + bool switch_sign = false); private: // Specialised variants From 863bb2ad1007d7a00c8aedac932571d56d64a75f Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Thu, 22 Jun 2017 16:02:15 +0200 Subject: [PATCH 046/174] Moving overly-specialised code out of Grid --- tests/hadrons/Test_hadrons_rarekaon.cc | 321 ------------------------- 1 file changed, 321 deletions(-) delete mode 100644 tests/hadrons/Test_hadrons_rarekaon.cc diff --git a/tests/hadrons/Test_hadrons_rarekaon.cc b/tests/hadrons/Test_hadrons_rarekaon.cc deleted file mode 100644 index a85beead..00000000 --- a/tests/hadrons/Test_hadrons_rarekaon.cc +++ /dev/null @@ -1,321 +0,0 @@ -/******************************************************************************* - Grid physics library, www.github.com/paboyle/Grid - - Source file: tests/hadrons/Test_hadrons_rarekaon.cc - - Copyright (C) 2017 - - Author: Andrew Lawson - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - See the full license in the file "LICENSE" in the top level distribution - directory. - *******************************************************************************/ - -#include "Test_hadrons.hpp" - -using namespace Grid; -using namespace Hadrons; - -enum quarks -{ - light = 0, - strange = 1, - charm = 2 -}; - -int main(int argc, char *argv[]) -{ - // parse command line ////////////////////////////////////////////////////// - std::string configStem; - - if (argc < 2) - { - std::cerr << "usage: " << argv[0] << " [Grid options]"; - std::cerr << std::endl; - std::exit(EXIT_FAILURE); - } - configStem = argv[1]; - - // initialization ////////////////////////////////////////////////////////// - HADRONS_DEFAULT_INIT; - - // run setup /////////////////////////////////////////////////////////////// - Application application; - std::vector mass = {.01, .04, .2}; - std::vector flavour = {"l", "s", "c"}; - std::vector solvers = {"CG_l", "CG_s", "CG_c"}; - std::string kmom = "0. 0. 0. 0."; - std::string pmom = "1. 0. 0. 0."; - std::string qmom = "-1. 0. 0. 0."; - std::string mqmom = "1. 0. 0. 0."; - std::vector tKs = {0}; - unsigned int dt_pi = 16; - std::vector tJs = {8}; - unsigned int n_noise = 1; - unsigned int nt = 32; - bool do_disconnected(false); - Gamma::Algebra gT = Gamma::Algebra::GammaT; - unsigned int Ls = 16; - double M5 = 1.8; - - // Global parameters. - HADRONS_DEFAULT_GLOBALS(application); - - // gauge field - std::string gaugeField = "gauge"; - if (configStem == "None") - { - application.createModule(gaugeField); - } - else - { - MGauge::Load::Par gaugePar; - gaugePar.file = configStem; - application.createModule(gaugeField, gaugePar); - } - - // set fermion boundary conditions to be periodic space, antiperiodic time. - std::string boundary = "1 1 1 -1"; - - for (unsigned int i = 0; i < flavour.size(); ++i) - { - // actions - std::string actionName = "DWF_" + flavour[i]; - makeDWFAction(application, actionName, gaugeField, mass[i], M5, Ls); - - // solvers - makeRBPrecCGSolver(application, solvers[i], actionName); - } - - // Create noise propagators for loops. - std::vector noiseSrcs; - std::vector> noiseRes; - std::vector> noiseProps; - if (n_noise > 0) - { - MSource::Z2::Par noisePar; - noisePar.tA = 0; - noisePar.tB = nt - 1; - std::string loop_stem = "loop_"; - - noiseRes.resize(flavour.size()); - noiseProps.resize(flavour.size()); - for (unsigned int nn = 0; nn < n_noise; ++nn) - { - std::string eta = INIT_INDEX("noise", nn); - application.createModule(eta, noisePar); - noiseSrcs.push_back(eta); - - for (unsigned int f = 0; f < flavour.size(); ++f) - { - std::string loop_prop = INIT_INDEX(loop_stem + flavour[f], nn); - std::string loop_res = loop_prop + "_res"; - makePropagator(application, loop_res, eta, solvers[f]); - makeLoop(application, loop_prop, eta, loop_res); - noiseRes[f].push_back(loop_res); - noiseProps[f].push_back(loop_prop); - } - } - } - - // Translate rare kaon decay across specified timeslices. - for (unsigned int i = 0; i < tKs.size(); ++i) - { - // Zero-momentum wall source propagators for kaon and pion. - unsigned int tK = tKs[i]; - unsigned int tpi = (tK + dt_pi) % nt; - std::string q_Kl_0 = INIT_INDEX("Q_l_0", tK); - std::string q_pil_0 = INIT_INDEX("Q_l_0", tpi); - MAKE_WALL_PROP(tK, q_Kl_0, solvers[light]); - MAKE_WALL_PROP(tpi, q_pil_0, solvers[light]); - - // Wall sources for kaon and pion with momentum insertion. If either - // p or k are zero, or p = k, re-use the existing name to avoid - // duplicating a propagator. - std::string q_Ks_k = INIT_INDEX("Q_Ks_k", tK); - std::string q_Ks_p = INIT_INDEX((kmom == pmom) ? "Q_Ks_k" : "Q_Ks_p", tK); - std::string q_pil_k = INIT_INDEX((kmom == ZERO_MOM) ? "Q_l_0" : "Q_l_k", tpi); - std::string q_pil_p = INIT_INDEX((pmom == kmom) ? q_pil_k : ((pmom == ZERO_MOM) ? "Q_l_0" : "Q_l_p"), tpi); - MAKE_3MOM_WALL_PROP(tK, kmom, q_Ks_k, solvers[strange]); - MAKE_3MOM_WALL_PROP(tK, pmom, q_Ks_p, solvers[strange]); - MAKE_3MOM_WALL_PROP(tpi, kmom, q_pil_k, solvers[light]); - MAKE_3MOM_WALL_PROP(tpi, pmom, q_pil_p, solvers[light]); - - /*********************************************************************** - * CONTRACTIONS: pi and K 2pt contractions with mom = p, k. - **********************************************************************/ - // Wall-Point - std::string PW_K_k = INIT_INDEX("PW_K_k", tK); - std::string PW_K_p = INIT_INDEX("PW_K_p", tK); - std::string PW_pi_k = INIT_INDEX("PW_pi_k", tpi); - std::string PW_pi_p = INIT_INDEX("PW_pi_p", tpi); - mesonContraction(application, 2, q_Kl_0, q_Ks_k, PW_K_k, kmom); - mesonContraction(application, 2, q_Kl_0, q_Ks_p, PW_K_p, pmom); - mesonContraction(application, 2, q_pil_k, q_pil_0, PW_pi_k, kmom); - mesonContraction(application, 2, q_pil_p, q_pil_0, PW_pi_p, pmom); - // Wall-Wall, to be done - requires modification of meson module. - - /*********************************************************************** - * CONTRACTIONS: 3pt Weak Hamiltonian, C & W (non-Eye type) classes. - **********************************************************************/ - std::string HW_CW_k = LABEL_3PT("HW_CW_k", tK, tpi); - std::string HW_CW_p = LABEL_3PT("HW_CW_p", tK, tpi); - weakContractionNonEye(application, 3, q_Kl_0, q_Ks_k, q_pil_k, q_pil_0, HW_CW_k); - weakContractionNonEye(application, 3, q_Kl_0, q_Ks_p, q_pil_p, q_pil_0, HW_CW_p); - - /*********************************************************************** - * CONTRACTIONS: 3pt sd insertion. - **********************************************************************/ - // Note: eventually will use wall sink smeared q_Kl_0 instead. - std::string sd_k = LABEL_3PT("sd_k", tK, tpi); - std::string sd_p = LABEL_3PT("sd_p", tK, tpi); - gamma3ptContraction(application, 3, q_Kl_0, q_Ks_k, q_pil_k, sd_k); - gamma3ptContraction(application, 3, q_Kl_0, q_Ks_p, q_pil_p, sd_p); - - for (unsigned int nn = 0; nn < n_noise; ++nn) - { - /******************************************************************* - * CONTRACTIONS: 3pt Weak Hamiltonian, S and E (Eye type) classes. - ******************************************************************/ - // Note: eventually will use wall sink smeared q_Kl_0 instead. - for (unsigned int f = 0; f < flavour.size(); ++f) - { - if ((f != strange) || do_disconnected) - { - std::string HW_SE_k = LABEL_3PT("HW_SE_k_" + flavour[f], tK, tpi); - std::string HW_SE_p = LABEL_3PT("HW_SE_p_" + flavour[f], tK, tpi); - std::string loop_q = noiseProps[f][nn]; - weakContractionEye(application, 3, q_Kl_0, q_Ks_k, q_pil_k, loop_q, HW_CW_k); - weakContractionEye(application, 3, q_Kl_0, q_Ks_p, q_pil_p, loop_q, HW_CW_p); - } - } - } - - // Perform separate contractions for each t_J position. - for (unsigned int j = 0; j < tJs.size(); ++j) - { - // Sequential sources for current insertions. Local for now, - // gamma_0 only. - unsigned int tJ = (tJs[j] + tK) % nt; - MSource::SeqGamma::Par seqPar; - std::string q_KlCl_q = LABEL_3PT("Q_KlCl_q", tK, tJ); - std::string q_KsCs_mq = LABEL_3PT("Q_KsCs_mq", tK, tJ); - std::string q_pilCl_q = LABEL_3PT("Q_pilCl_q", tpi, tJ); - std::string q_pilCl_mq = LABEL_3PT("Q_pilCl_mq", tpi, tJ); - MAKE_SEQUENTIAL_PROP(tJ, q_Kl_0, qmom, q_KlCl_q, solvers[light], gT); - MAKE_SEQUENTIAL_PROP(tJ, q_Ks_k, mqmom, q_KsCs_mq, solvers[strange], gT); - MAKE_SEQUENTIAL_PROP(tJ, q_pil_p, qmom, q_pilCl_q, solvers[light], gT); - MAKE_SEQUENTIAL_PROP(tJ, q_pil_0, mqmom, q_pilCl_mq, solvers[light], gT); - - /******************************************************************* - * CONTRACTIONS: pi and K 3pt contractions with current insertion. - ******************************************************************/ - // Wall-Point - std::string C_PW_Kl = LABEL_3PT("C_PW_Kl", tK, tJ); - std::string C_PW_Ksb = LABEL_3PT("C_PW_Ksb", tK, tJ); - std::string C_PW_pilb = LABEL_3PT("C_PW_pilb", tK, tJ); - std::string C_PW_pil = LABEL_3PT("C_PW_pil", tK, tJ); - mesonContraction(application, 3, q_KlCl_q, q_Ks_k, C_PW_Kl, pmom); - mesonContraction(application, 3, q_Kl_0, q_KsCs_mq, C_PW_Ksb, pmom); - mesonContraction(application, 3, q_pil_0, q_pilCl_q, C_PW_pilb, kmom); - mesonContraction(application, 3, q_pilCl_mq, q_pil_p, C_PW_pil, kmom); - // Wall-Wall, to be done. - - /******************************************************************* - * CONTRACTIONS: 4pt contractions, C & W classes. - ******************************************************************/ - std::string CW_Kl = LABEL_4PT("CW_Kl", tK, tJ, tpi); - std::string CW_Ksb = LABEL_4PT("CW_Ksb", tK, tJ, tpi); - std::string CW_pilb = LABEL_4PT("CW_pilb", tK, tJ, tpi); - std::string CW_pil = LABEL_4PT("CW_pil", tK, tJ, tpi); - weakContractionNonEye(application, 4, q_KlCl_q, q_Ks_k, q_pil_p, q_pil_0, CW_Kl); - weakContractionNonEye(application, 4, q_Kl_0, q_KsCs_mq, q_pil_p, q_pil_0, CW_Ksb); - weakContractionNonEye(application, 4, q_Kl_0, q_Ks_k, q_pilCl_q, q_pil_0, CW_pilb); - weakContractionNonEye(application, 4, q_Kl_0, q_Ks_k, q_pil_p, q_pilCl_mq, CW_pil); - - /******************************************************************* - * CONTRACTIONS: 4pt contractions, sd insertions. - ******************************************************************/ - // Note: eventually will use wall sink smeared q_Kl_0/q_KlCl_q instead. - std::string sd_Kl = LABEL_4PT("sd_Kl", tK, tJ, tpi); - std::string sd_Ksb = LABEL_4PT("sd_Ksb", tK, tJ, tpi); - std::string sd_pilb = LABEL_4PT("sd_pilb", tK, tJ, tpi); - gamma3ptContraction(application, 4, q_KlCl_q, q_Ks_k, q_pil_p, sd_Kl); - gamma3ptContraction(application, 4, q_Kl_0, q_KsCs_mq, q_pil_p, sd_Ksb); - gamma3ptContraction(application, 4, q_Kl_0, q_Ks_k, q_pilCl_q, sd_pilb); - - // Sequential sources for each noise propagator. - for (unsigned int nn = 0; nn < n_noise; ++nn) - { - std::string loop_stem = "loop_"; - - // Contraction required for each quark flavour - alternatively - // drop the strange loop if not performing disconnected - // contractions or neglecting H_W operators Q_3 -> Q_10. - for (unsigned int f = 0; f < flavour.size(); ++f) - { - if ((f != strange) || do_disconnected) - { - std::string eta = noiseSrcs[nn]; - std::string loop_q = noiseProps[f][nn]; - std::string loop_qCq = LABEL_3PT(loop_stem + flavour[f], tJ, nn); - std::string loop_qCq_res = loop_qCq + "_res"; - MAKE_SEQUENTIAL_PROP(tJ, noiseRes[f][nn], qmom, - loop_qCq_res, solvers[f], gT); - makeLoop(application, loop_qCq, eta, loop_qCq_res); - - /******************************************************* - * CONTRACTIONS: 4pt contractions, S & E classes. - ******************************************************/ - // Note: eventually will use wall sink smeared q_Kl_0/q_KlCl_q instead. - std::string SE_Kl = LABEL_4PT_NOISE("SE_Kl", tK, tJ, tpi, nn); - std::string SE_Ksb = LABEL_4PT_NOISE("SE_Ksb", tK, tJ, tpi, nn); - std::string SE_pilb = LABEL_4PT_NOISE("SE_pilb", tK, tJ, tpi, nn); - std::string SE_loop = LABEL_4PT_NOISE("SE_loop", tK, tJ, tpi, nn); - weakContractionEye(application, 4, q_KlCl_q, q_Ks_k, q_pil_p, loop_q, SE_Kl); - weakContractionEye(application, 4, q_Kl_0, q_KsCs_mq, q_pil_p, loop_q, SE_Ksb); - weakContractionEye(application, 4, q_Kl_0, q_Ks_k, q_pilCl_q, loop_q, SE_pilb); - weakContractionEye(application, 4, q_Kl_0, q_Ks_k, q_pil_p, loop_qCq, SE_loop); - - /******************************************************* - * CONTRACTIONS: 4pt contractions, pi0 disconnected - * loop. - ******************************************************/ - std::string disc0 = LABEL_4PT_NOISE("disc0", tK, tJ, tpi, nn); - disc0Contraction(application, q_Kl_0, q_Ks_k, q_pilCl_q, loop_q, disc0); - - /******************************************************* - * CONTRACTIONS: Disconnected loop. - ******************************************************/ - std::string discLoop = "disc_" + loop_qCq; - discLoopContraction(application, loop_qCq, discLoop); - } - } - } - } - } - // execution - std::string par_file_name = "rarekaon_000_100_tK0_tpi16_tJ8_noloop_mc0.2.xml"; - application.saveParameterFile(par_file_name); - application.run(); - - // epilogue - LOG(Message) << "Grid is finalizing now" << std::endl; - Grid_finalize(); - - return EXIT_SUCCESS; -} From 18211eb5b13fa2738061b4c48a7518c7368c2645 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Thu, 22 Jun 2017 16:03:59 +0200 Subject: [PATCH 047/174] Hadrons: Fixed test to use new implementation of meson module. --- tests/hadrons/Test_hadrons.hpp | 20 ++++++----- tests/hadrons/Test_hadrons_meson_3pt.cc | 47 ++++++++++--------------- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index a554425d..3492816d 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -71,6 +71,9 @@ using namespace Hadrons; #define NAME_WALL_SOURCE(t) NAME_3MOM_WALL_SOURCE(t, ZERO_MOM) #define NAME_POINT_SOURCE(pos) ("point_" + pos) +// Meson module "gammas" special values +#define ALL_GAMMAS "all" + #define MAKE_3MOM_WALL_PROP(tW, mom, propName, solver)\ {\ std::string srcName = NAME_3MOM_WALL_SOURCE(tW, mom);\ @@ -364,28 +367,27 @@ inline void makeLoop(Application &application, std::string &propName, * Name: mesonContraction * Purpose: Create meson contraction module and add to application module. * Parameters: application - main application that stores modules. - * npt - specify n-point correlator (for labelling). + * modName - unique module name. + * output - name of output files. * q1 - quark propagator 1. * q2 - quark propagator 2. - * label - unique label to construct module name. - * mom - momentum to project (default is zero) + * sink - sink smearing module. * gammas - gamma insertions at source and sink. * Returns: None. ******************************************************************************/ -inline void mesonContraction(Application &application, unsigned int npt, +inline void mesonContraction(Application &application, + std::string &modName, std::string &output, std::string &q1, std::string &q2, - std::string &label, - std::string mom = ZERO_MOM, + std::string &sink, std::string gammas = "") { - std::string modName = std::to_string(npt) + "pt_" + label; if (!(Environment::getInstance().hasModule(modName))) { MContraction::Meson::Par mesPar; - mesPar.output = std::to_string(npt) + "pt/" + label; + mesPar.output = output; mesPar.q1 = q1; mesPar.q2 = q2; - mesPar.mom = mom; + mesPar.sink = sink; mesPar.gammas = gammas; application.createModule(modName, mesPar); } diff --git a/tests/hadrons/Test_hadrons_meson_3pt.cc b/tests/hadrons/Test_hadrons_meson_3pt.cc index 7e487153..1cbb866d 100644 --- a/tests/hadrons/Test_hadrons_meson_3pt.cc +++ b/tests/hadrons/Test_hadrons_meson_3pt.cc @@ -25,7 +25,7 @@ directory. *******************************************************************************/ -#include +#include "Test_hadrons.hpp" using namespace Grid; using namespace Hadrons; @@ -127,43 +127,34 @@ int main(int argc, char *argv[]) } } + // Point sink. + std::string sink = "sink"; + MSink::Point::Par sinkPar; + sinkPar.mom = ZERO_MOM; + application.createModule(sink, sinkPar); + // contractions MContraction::Meson::Par mesPar; for (unsigned int i = 0; i < flavour.size(); ++i) for (unsigned int j = i; j < flavour.size(); ++j) { - mesPar.output = "mesons/Z2_" + flavour[i] + flavour[j]; - mesPar.q1 = qName[i]; - mesPar.q2 = qName[j]; - mesPar.gammas = "all"; - mesPar.mom = "0. 0. 0. 0."; - application.createModule("meson_Z2_" - + std::to_string(t) - + "_" - + flavour[i] - + flavour[j], - mesPar); + std::string modName = "meson_Z2_" + std::to_string(t) + "_" + \ + flavour[i] + flavour[j]; + std::string output = "mesons/Z2_" + flavour[i] + flavour[j]; + mesonContraction(application, modName, output, qName[i], qName[j], + sink, ALL_GAMMAS); } for (unsigned int i = 0; i < flavour.size(); ++i) for (unsigned int j = 0; j < flavour.size(); ++j) for (unsigned int mu = 0; mu < Nd; ++mu) { - MContraction::Meson::Par mesPar; - - mesPar.output = "3pt/Z2_" + flavour[i] + flavour[j] + "_" - + std::to_string(mu); - mesPar.q1 = qName[i]; - mesPar.q2 = seqName[j][mu]; - mesPar.gammas = "all"; - mesPar.mom = "0. 0. 0. 0."; - application.createModule("3pt_Z2_" - + std::to_string(t) - + "_" - + flavour[i] - + flavour[j] - + "_" - + std::to_string(mu), - mesPar); + std::string modName = "3pt_Z2_" + std::to_string(t) + "_" + \ + flavour[i] + flavour[j] + "_" + \ + std::to_string(mu); + std::string output = "3pt/Z2_" + flavour[i] + \ + flavour[j] + "_" + std::to_string(mu); + mesonContraction(application, modName, output, + qName[i], seqName[j][mu], sink, ALL_GAMMAS); } } From 7a3bd5c66c3e1f125801f17fcb0b3b4f1de5d274 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Thu, 22 Jun 2017 16:06:15 +0200 Subject: [PATCH 048/174] Hadrons: new conserved current contraction test (for regression testing) --- .../Test_hadrons_meson_conserved_3pt.cc | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 tests/hadrons/Test_hadrons_meson_conserved_3pt.cc diff --git a/tests/hadrons/Test_hadrons_meson_conserved_3pt.cc b/tests/hadrons/Test_hadrons_meson_conserved_3pt.cc new file mode 100644 index 00000000..c9aeb2cc --- /dev/null +++ b/tests/hadrons/Test_hadrons_meson_conserved_3pt.cc @@ -0,0 +1,115 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: tests/hadrons/Test_hadrons_meson_conserved_3pt.cc + + Copyright (C) 2017 + + Author: Andrew Lawson + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution + directory. + *******************************************************************************/ + +#include "Test_hadrons.hpp" + +using namespace Grid; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + // initialization ////////////////////////////////////////////////////////// + HADRONS_DEFAULT_INIT; + + // run setup /////////////////////////////////////////////////////////////// + Application application; + + // actions parameters + double mass = 0.04; + unsigned int Ls = 16; + double M5 = 1.8; + + // kinematics + unsigned int nt = GridDefaultLatt()[Tp]; + unsigned int tSrc = 0; + unsigned int tJ = nt / 4; + std::string kmom = "0. 0. 0. 0."; + std::string pmom = "1. 0. 0. 0."; + + // Global parameters. + HADRONS_DEFAULT_GLOBALS(application); + + // Unit gauge field. + std::string gaugeField = "Unit gauge"; + application.createModule(gaugeField); + + // DWF action + std::string actionName = "DWF"; + makeDWFAction(application, actionName, gaugeField, mass, M5, Ls); + + // Solver + std::string solver = "CG"; + makeRBPrecCGSolver(application, solver, actionName); + + // main test body ////////////////////////////////////////////////////////// + // Point sink modules. + std::string sink_0 = "sink_0"; + std::string sink_p = "sink_p"; + MSink::Point::Par sinkPar; + sinkPar.mom = kmom; + application.createModule(sink_0, sinkPar); + sinkPar.mom = pmom; + application.createModule(sink_p, sinkPar); + + // 2pt pion contraction, zero momentum. + std::string q_0 = "Q_0"; + MAKE_WALL_PROP(tSrc, q_0, solver); + std::string modName = INIT_INDEX("2pt_pion_WP", tSrc); + std::string output = "2pt/pion_WP_0"; + mesonContraction(application, modName, output, q_0, q_0, sink_0); + + // 2pt pion contraction, with momentum p. + std::string q_p = "Q_p"; + MAKE_3MOM_WALL_PROP(tSrc, pmom, q_p, solver); + modName = INIT_INDEX("2pt_pion_WP_p", tSrc); + output = "2pt/pion_WP_p"; + mesonContraction(application, modName, output, q_0, q_p, sink_p); + + // 3pt pion(0) -> pion(p), with sequentially inserted vector current in + // time direction. + std::string qSeq = q_0 + INIT_INDEX("_seq_Vc3", tJ); + std::string q5d = LABEL_5D(q_0); // Need 5D prop for DWF conserved current. + std::string srcName = qSeq + "_src"; + modName = LABEL_3PT("3pt_pion_Vc3", tSrc, tJ); + output = "3pt/pion_Vc3_p"; + makeConservedSequentialSource(application, srcName, q5d, actionName, + tJ, Current::Vector, Tp, pmom); + makePropagator(application, qSeq, srcName, solver); + mesonContraction(application, modName, output, q_0, qSeq, sink_p); + + std::string par_file_name = "conserved_3pt.xml"; + application.saveParameterFile(par_file_name); + application.run(); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} + + \ No newline at end of file From dc6b2d30d2dea8ede405aef3f1a753eb7f5127f1 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Thu, 22 Jun 2017 16:09:45 +0200 Subject: [PATCH 049/174] Documentation fix --- extras/Hadrons/Modules/MContraction/Meson.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 7810326a..b71f7c08 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -51,8 +51,7 @@ BEGIN_HADRONS_NAMESPACE in a sequence (e.g. ""). Special values: "all" - perform all possible contractions. - - mom: momentum insertion, space-separated float sequence (e.g ".1 .2 1. 0."), - given as multiples of (2*pi) / L. + - sink: module to compute the sink to use in contraction (string). */ /****************************************************************************** From 08b0e472aa46eb0cef6ad00eaab46cce35357781 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Thu, 22 Jun 2017 16:34:33 +0200 Subject: [PATCH 050/174] Fixed hadrons tests after merge --- tests/hadrons/Test_hadrons.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index 3492816d..6ea51d72 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -329,10 +329,10 @@ inline void makePropagator(Application &application, std::string &propName, // If the propagator already exists, don't make the module again. if (!(Environment::getInstance().hasModule(propName))) { - Quark::Par quarkPar; + MFermion::GaugeProp::Par quarkPar; quarkPar.source = srcName; quarkPar.solver = solver; - application.createModule(propName, quarkPar); + application.createModule(propName, quarkPar); } } From 852ade029a64c6376d391205e607ae655c6d1c80 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Sun, 16 Jul 2017 13:41:47 +0100 Subject: [PATCH 051/174] Hadrons: Added module to sink a propagator --- extras/Hadrons/Modules.hpp | 1 + extras/Hadrons/Modules/MSink/Smear.hpp | 99 ++++++++++++++++++++++++++ extras/Hadrons/modules.inc | 1 + 3 files changed, 101 insertions(+) create mode 100644 extras/Hadrons/Modules/MSink/Smear.hpp diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 6e1b8823..d0d0d80d 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/extras/Hadrons/Modules/MSink/Smear.hpp b/extras/Hadrons/Modules/MSink/Smear.hpp new file mode 100644 index 00000000..9327001f --- /dev/null +++ b/extras/Hadrons/Modules/MSink/Smear.hpp @@ -0,0 +1,99 @@ +#ifndef Hadrons_MSink_Smear_hpp_ +#define Hadrons_MSink_Smear_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Smear * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MSink) + +class SmearPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(SmearPar, + std::string, q, + std::string, sink); +}; + +template +class TSmear: public Module +{ +public: + FERM_TYPE_ALIASES(FImpl,); + SINK_TYPE_ALIASES(); +public: + // constructor + TSmear(const std::string name); + // destructor + virtual ~TSmear(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_NS(Smear, TSmear, MSink); + +/****************************************************************************** + * TSmear implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TSmear::TSmear(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TSmear::getInput(void) +{ + std::vector in = {par().q, par().sink}; + + return in; +} + +template +std::vector TSmear::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TSmear::setup(void) +{ + unsigned int nt = env().getDim(Tp); + unsigned int size = nt * sizeof(SitePropagator); + env().registerObject(getName(), size); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TSmear::execute(void) +{ + LOG(Message) << "Sink smearing propagator '" << par().q + << "' using sink function '" << par().sink << "'." + << std::endl; + + SinkFn &sink = *env().template getObject(par().sink); + PropagatorField &q = *env().template getObject(par().q); + SlicedPropagator *out = new SlicedPropagator(env().getDim(Tp)); + *out = sink(q); + env().setObject(getName(), out); +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MSink_Smear_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 91d0bbe1..fbbb2eb9 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -31,6 +31,7 @@ modules_hpp =\ Modules/MScalar/FreeProp.hpp \ Modules/MScalar/Scalar.hpp \ Modules/MSink/Point.hpp \ + Modules/MSink/Smear.hpp \ Modules/MSolver/RBPrecCG.hpp \ Modules/MSource/Point.hpp \ Modules/MSource/SeqConserved.hpp \ From 6293d438cd6ff2201300298ba29b985962991202 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Sun, 16 Jul 2017 13:43:25 +0100 Subject: [PATCH 052/174] Hadrons: sink smearing compatibility for 3pt contraction modules. --- .../Hadrons/Modules/MContraction/Gamma3pt.hpp | 22 +++++++++++++--- .../Modules/MContraction/WeakHamiltonian.hpp | 1 + .../MContraction/WeakHamiltonianEye.cc | 25 +++++++++++-------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp index 7f643d49..162ab786 100644 --- a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp +++ b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp @@ -51,6 +51,14 @@ BEGIN_HADRONS_NAMESPACE * q1 * * trace(g5*q1*adj(q2)*g5*gamma*q3) + * + * options: + * - q1: sink smeared propagator, source at i + * - q2: propagator, source at i + * - q3: propagator, source at f + * - gamma: gamma matrix to insert + * - tSnk: sink position for propagator q1. + * */ /****************************************************************************** @@ -66,6 +74,7 @@ public: std::string, q2, std::string, q3, Gamma::Algebra, gamma, + unsigned int, tSnk, std::string, output); }; @@ -140,17 +149,22 @@ void TGamma3pt::execute(void) << par().q3 << "', with " << par().gamma << " insertion." << std::endl; + // Initialise variables. q2 and q3 are normal propagators, q1 may be + // sink smeared. CorrWriter writer(par().output); - PropagatorField1 &q1 = *env().template getObject(par().q1); + SlicedPropagator1 &q1 = *env().template getObject(par().q1); PropagatorField2 &q2 = *env().template getObject(par().q2); - PropagatorField3 &q3 = *env().template getObject(par().q3); + PropagatorField3 &q3 = *env().template getObject(par().q3); LatticeComplex c(env().getGrid()); Gamma g5(Gamma::Algebra::Gamma5); Gamma gamma(par().gamma); std::vector buf; Result result; - - c = trace(g5*q1*adj(q2)*(g5*gamma)*q3); + + // Extract relevant timeslice of sinked propagator q1, then contract & + // sum over all spacial positions of gamma insertion. + SitePropagator1 q1Snk = q1[par().tSnk]; + c = trace(g5*q1Snk*adj(q2)*(g5*gamma)*q3); sliceSum(c, buf, Tp); result.gamma = par().gamma; diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp index 0a3c2e31..302b207e 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp @@ -76,6 +76,7 @@ public: std::string, q2, std::string, q3, std::string, q4, + unsigned int, tSnk, std::string, output); }; diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc index a44c2534..314b080a 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc @@ -54,6 +54,8 @@ using namespace MContraction; * * S: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1]*q4*gL[mu][p_2]) * E: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1])*trace(q4*gL[mu][p_2]) + * + * Note q1 must be sink smeared. */ /****************************************************************************** @@ -94,15 +96,15 @@ void TWeakHamiltonianEye::execute(void) << "'." << std::endl; CorrWriter writer(par().output); - PropagatorField &q1 = *env().template getObject(par().q1); - PropagatorField &q2 = *env().template getObject(par().q2); - PropagatorField &q3 = *env().template getObject(par().q3); - PropagatorField &q4 = *env().template getObject(par().q4); - Gamma g5 = Gamma(Gamma::Algebra::Gamma5); - LatticeComplex expbuf(env().getGrid()); - std::vector corrbuf; - std::vector result(n_eye_diag); - unsigned int ndim = env().getNd(); + SlicedPropagator &q1 = *env().template getObject(par().q1); + PropagatorField &q2 = *env().template getObject(par().q2); + PropagatorField &q3 = *env().template getObject(par().q3); + PropagatorField &q4 = *env().template getObject(par().q4); + Gamma g5 = Gamma(Gamma::Algebra::Gamma5); + LatticeComplex expbuf(env().getGrid()); + std::vector corrbuf; + std::vector result(n_eye_diag); + unsigned int ndim = env().getNd(); PropagatorField tmp1(env().getGrid()); LatticeComplex tmp2(env().getGrid()); @@ -111,10 +113,13 @@ void TWeakHamiltonianEye::execute(void) std::vector E_body(ndim, tmp2); std::vector E_loop(ndim, tmp2); + // Get sink timeslice of q1. + SitePropagator q1Snk = q1[par().tSnk]; + // Setup for S-type contractions. for (int mu = 0; mu < ndim; ++mu) { - S_body[mu] = MAKE_SE_BODY(q1, q2, q3, GammaL(Gamma::gmu[mu])); + S_body[mu] = MAKE_SE_BODY(q1Snk, q2, q3, GammaL(Gamma::gmu[mu])); S_loop[mu] = MAKE_SE_LOOP(q4, GammaL(Gamma::gmu[mu])); } From 0366288b1c8a42ff15eacb0f5e23eee2e89fb50f Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Sun, 16 Jul 2017 13:45:55 +0100 Subject: [PATCH 053/174] Hadrons: added tests for 3pt contractions. --- tests/hadrons/Test_hadrons.hpp | 75 ++++++++--- .../hadrons/Test_hadrons_3pt_contractions.cc | 122 ++++++++++++++++++ 2 files changed, 182 insertions(+), 15 deletions(-) create mode 100644 tests/hadrons/Test_hadrons_3pt_contractions.cc diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index 6ea51d72..9bd3ee0a 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -269,6 +269,26 @@ inline void makeConservedSequentialSource(Application &application, } } +/******************************************************************************* + * Name: makeNoiseSource + * Parameters: application - main application that stores modules. + * srcName - name of source module to create. + * tA - lower source timeslice limit. + * tB - upper source timeslice limit. + * Returns: None. + ******************************************************************************/ +inline void makeNoiseSource(Application &application, std::string &srcName, + unsigned int tA, unsigned int tB) +{ + if (!(Environment::getInstance().hasModule(srcName))) + { + MSource::Z2::Par noisePar; + noisePar.tA = tA; + noisePar.tB = tB; + application.createModule(srcName, noisePar); + } + } + /******************************************************************************* * Name: makeWallSource * Purpose: Construct wall source and add to application module. @@ -292,26 +312,46 @@ inline void makeWallSource(Application &application, std::string &srcName, } /******************************************************************************* - * Name: makeWallSink - * Purpose: Wall sink smearing of a propagator. + * Name: makePointSink + * Purpose: Create function for point sink smearing of a propagator. * Parameters: application - main application that stores modules. * propName - name of input propagator. - * wallName - name of smeared propagator. + * sinkFnct - name of output sink smearing module. * mom - momentum insertion (default is zero). * Returns: None. ******************************************************************************/ -inline void makeWallSink(Application &application, std::string &propName, - std::string &wallName, std::string mom = ZERO_MOM) +inline void makePointSink(Application &application, std::string &sinkFnct, + std::string mom = ZERO_MOM) +{ + // If the sink function already exists, don't make it again. + if (!(Environment::getInstance().hasModule(sinkFnct))) + { + MSink::Point::Par pointPar; + pointPar.mom = mom; + application.createModule(sinkFnct, pointPar); + } +} + +/******************************************************************************* + * Name: sinkSmear + * Purpose: Perform sink smearing of a propagator. + * Parameters: application - main application that stores modules. + * sinkFnct - sink smearing module. + * propName - propagator to smear. + * smearedProp - name of output smeared propagator. + * Returns: None. + ******************************************************************************/ +inline void sinkSmear(Application &application, std::string &sinkFnct, + std::string &propName, std::string &smearedProp) { // If the propagator has already been smeared, don't smear it again. - // Temporarily removed, strategy for sink smearing likely to change. - /*if (!(Environment::getInstance().hasModule(wallName))) + if (!(Environment::getInstance().hasModule(smearedProp))) { - MSink::Wall::Par wallPar; - wallPar.q = propName; - wallPar.mom = mom; - application.createModule(wallName, wallPar); - }*/ + MSink::Smear::Par smearPar; + smearPar.q = propName; + smearPar.sink = sinkFnct; + application.createModule(smearedProp, smearPar); + } } /******************************************************************************* @@ -398,16 +438,18 @@ inline void mesonContraction(Application &application, * Purpose: Create gamma3pt contraction module and add to application module. * Parameters: application - main application that stores modules. * npt - specify n-point correlator (for labelling). - * q1 - quark propagator 1. + * q1 - quark propagator 1, sink smeared. * q2 - quark propagator 2. * q3 - quark propagator 3. * label - unique label to construct module name. + * tSnk - sink position of sink for q1. * gamma - gamma insertions between q2 and q3. * Returns: None. ******************************************************************************/ inline void gamma3ptContraction(Application &application, unsigned int npt, std::string &q1, std::string &q2, - std::string &q3, std::string &label, + std::string &q3, std::string &label, + unsigned int tSnk = 0, Gamma::Algebra gamma = Gamma::Algebra::Identity) { std::string modName = std::to_string(npt) + "pt_" + label; @@ -418,6 +460,7 @@ inline void gamma3ptContraction(Application &application, unsigned int npt, gamma3ptPar.q1 = q1; gamma3ptPar.q2 = q2; gamma3ptPar.q3 = q3; + gamma3ptPar.tSnk = tSnk; gamma3ptPar.gamma = gamma; application.createModule(modName, gamma3ptPar); } @@ -434,13 +477,14 @@ inline void gamma3ptContraction(Application &application, unsigned int npt, * q3 - quark propagator 3. * q4 - quark propagator 4. * label - unique label to construct module name. + * tSnk - time position of sink (for sink smearing). * Returns: None. ******************************************************************************/ #define HW_CONTRACTION(top) \ inline void weakContraction##top(Application &application, unsigned int npt,\ std::string &q1, std::string &q2, \ std::string &q3, std::string &q4, \ - std::string &label)\ + std::string &label, unsigned int tSnk = 0)\ {\ std::string modName = std::to_string(npt) + "pt_" + label;\ if (!(Environment::getInstance().hasModule(modName)))\ @@ -451,6 +495,7 @@ inline void weakContraction##top(Application &application, unsigned int npt,\ weakPar.q2 = q2;\ weakPar.q3 = q3;\ weakPar.q4 = q4;\ + weakPar.tSnk = tSnk;\ application.createModule(modName, weakPar);\ }\ } diff --git a/tests/hadrons/Test_hadrons_3pt_contractions.cc b/tests/hadrons/Test_hadrons_3pt_contractions.cc new file mode 100644 index 00000000..452fc34d --- /dev/null +++ b/tests/hadrons/Test_hadrons_3pt_contractions.cc @@ -0,0 +1,122 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: tests/hadrons/Test_hadrons_3pt_contractions.cc + + Copyright (C) 2017 + + Author: Andrew Lawson + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution + directory. + *******************************************************************************/ + +#include "Test_hadrons.hpp" + +using namespace Grid; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + // initialization ////////////////////////////////////////////////////////// + HADRONS_DEFAULT_INIT; + + // run setup /////////////////////////////////////////////////////////////// + Application application; + double mass = 0.04; + double M5 = 1.8; + unsigned int Ls = 12; + unsigned int nt = GridDefaultLatt()[Tp]; + unsigned int t_i = 0; + unsigned int t_f = nt / 2; + std::string mom = "1. 0. 0. 0."; + + // global parameters + HADRONS_DEFAULT_GLOBALS(application); + + // gauge field + std::string gaugeField = "gauge"; + application.createModule(gaugeField); + + // Action & solver setup. + std::string action = "DWF"; + std::string solver = "CG"; + makeDWFAction(application, action, gaugeField, mass, M5, Ls); + makeRBPrecCGSolver(application, solver, action); + + /*************************************************************************** + * Weak Contraction test: Non-Eye class. + **************************************************************************/ + // Make wall source propagators for each leg of 4-quark vertex. + std::string q_i_0 = "q_i_0"; + std::string q_i_p = "q_i_p"; + std::string q_f_0 = "q_f_0"; + std::string q_f_p = "q_f_p"; + MAKE_WALL_PROP(t_i, q_i_0, solver); + MAKE_WALL_PROP(t_f, q_f_0, solver); + MAKE_3MOM_WALL_PROP(t_i, mom, q_i_p, solver); + MAKE_3MOM_WALL_PROP(t_f, mom, q_f_p, solver); + + // Perform contractions, zero and non-zero momentum. + std::string HW_CW_0 = LABEL_3PT("HW_CW_0", t_i, t_f); + std::string HW_CW_p = LABEL_3PT("HW_CW_p", t_i, t_f); + weakContractionNonEye(application, 3, q_i_0, q_i_0, q_f_0, q_f_0, HW_CW_0); + weakContractionNonEye(application, 3, q_i_0, q_i_p, q_f_p, q_f_0, HW_CW_p); + + /*************************************************************************** + * Weak Contraction test: Eye-class. + **************************************************************************/ + // Create random propagator for loop. + std::string eta = "noise_source"; + makeNoiseSource(application, eta, 0, nt - 1); + std::string loopProp = "loop"; + std::string loopRes = loopProp + "_res"; + makePropagator(application, loopRes, eta, solver); + makeLoop(application, loopProp, eta, loopRes); + + // Wall sink smear the propagator directly connecting the source & sink. + // (i.e. make point sink but smear before the contraction) + std::string wallSink = "wall_sink"; + std::string qWall = "q_wall"; + makePointSink(application, wallSink); + sinkSmear(application, wallSink, q_i_0, qWall); + + // Perform contractions, zero and non-zero momentum. + std::string HW_SE_0 = LABEL_3PT("HW_SE_0", t_i, t_f); + std::string HW_SE_p = LABEL_3PT("HW_SE_p", t_i, t_f); + weakContractionEye(application, 3, qWall, q_i_0, q_f_p, loopProp, HW_SE_0, t_f); + weakContractionEye(application, 3, qWall, q_i_p, q_f_p, loopProp, HW_SE_p, t_f); + + /*************************************************************************** + * Gamma insertion test. + **************************************************************************/ + Gamma::Algebra gamma = Gamma::Algebra::GammaT; + std::string sd_0 = LABEL_3PT("sd_0", t_i, t_f); + std::string sd_p = LABEL_3PT("sd_p", t_i, t_f); + gamma3ptContraction(application, 3, qWall, q_i_0, q_f_0, sd_0, t_f, gamma); + gamma3ptContraction(application, 3, qWall, q_i_p, q_f_p, sd_p, t_f, gamma); + + // execution + application.saveParameterFile("ContractionTest3pt.xml"); + application.run(); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} \ No newline at end of file From 875e1a841f24166084cc26e16aea363c1200070c Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Sun, 16 Jul 2017 13:47:00 +0100 Subject: [PATCH 054/174] Hadrons: updated Quark -> MFermion/GaugeProp module name in test. --- tests/hadrons/Test_hadrons_quark.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/hadrons/Test_hadrons_quark.cc b/tests/hadrons/Test_hadrons_quark.cc index 5b9d0ce1..eac065e9 100644 --- a/tests/hadrons/Test_hadrons_quark.cc +++ b/tests/hadrons/Test_hadrons_quark.cc @@ -26,7 +26,7 @@ *******************************************************************************/ #include "Test_hadrons.hpp" -#include +#include using namespace Grid; using namespace QCD; From 67b34e5789aec1b39d34c2cdbedb156ff9509e11 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Mon, 31 Jul 2017 11:35:01 +0100 Subject: [PATCH 055/174] Modified conserved current 5th dimension loop for compatibility with 5D vectorisation. --- lib/qcd/action/fermion/WilsonFermion5D.cc | 61 +++++++++++++++++------ 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index 5daed3de..5ddfde9a 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -12,6 +12,7 @@ Author: Peter Boyle Author: Peter Boyle Author: paboyle Author: Guido Cossu +Author: Andrew Lawson This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -676,6 +677,21 @@ void WilsonFermion5D::MomentumSpacePropagatorHw(FermionField &out,const Fe * to make a conserved current sink or inserting the conserved current * sequentially. ******************************************************************************/ + +// Helper macro to reverse Simd vector. Fixme: slow, generic implementation. +#define REVERSE_LS(qSite, qSiteRev, Nsimd) \ +{ \ + std::vector qSiteVec(Nsimd); \ + extract(qSite, qSiteVec); \ + for (int i = 0; i < Nsimd / 2; ++i) \ + { \ + typename SitePropagator::scalar_object tmp = qSiteVec[i]; \ + qSiteVec[i] = qSiteVec[Nsimd - i - 1]; \ + qSiteVec[Nsimd - i - 1] = tmp; \ + } \ + merge(qSiteRev, qSiteVec); \ +} + template void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, PropagatorField &q_in_2, @@ -687,6 +703,7 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, conformable(q_in_1._grid, q_in_2._grid); conformable(_FourDimGrid, q_out._grid); PropagatorField tmp1(FermionGrid()), tmp2(FermionGrid()); + unsigned int LLs = q_in_1._grid->_rdimensions[0]; q_out = zero; // Forward, need q1(x + mu, s), q2(x, Ls - 1 - s). Backward, need q1(x, s), @@ -695,18 +712,33 @@ void WilsonFermion5D::ContractConservedCurrent(PropagatorField &q_in_1, tmp2 = Cshift(q_in_2, mu + 1, 1); parallel_for (unsigned int sU = 0; sU < Umu._grid->oSites(); ++sU) { - unsigned int sF1 = sU * Ls; - unsigned int sF2 = (sU + 1) * Ls - 1; - for (int s = 0; s < Ls; ++s) + unsigned int sF1 = sU * LLs; + unsigned int sF2 = (sU + 1) * LLs - 1; + + for (unsigned int s = 0; s < LLs; ++s) { - bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ - true : false; + bool axial_sign = ((curr_type == Current::Axial) && \ + (s < (LLs / 2))); + SitePropagator qSite2, qmuSite2; + + // If vectorised in 5th dimension, reverse q2 vector to match up + // sites correctly. + if (Impl::LsVectorised) + { + REVERSE_LS(q_in_2._odata[sF2], qSite2, Ls / LLs); + REVERSE_LS(tmp2._odata[sF2], qmuSite2, Ls / LLs); + } + else + { + qSite2 = q_in_2._odata[sF2]; + qmuSite2 = tmp2._odata[sF2]; + } Kernels::ContractConservedCurrentSiteFwd(tmp1._odata[sF1], - q_in_2._odata[sF2], + qSite2, q_out._odata[sU], Umu, sU, mu, axial_sign); Kernels::ContractConservedCurrentSiteBwd(q_in_1._odata[sF1], - tmp2._odata[sF2], + qmuSite2, q_out._odata[sU], Umu, sU, mu, axial_sign); sF1++; @@ -732,6 +764,7 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, tmp(FermionGrid()); Complex i(0.0, 1.0); int tshift = (mu == Tp) ? 1 : 0; + unsigned int LLs = q_in._grid->_rdimensions[0]; // Momentum projection. ph = zero; @@ -764,11 +797,10 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, if (timeSlices > 0) { - unsigned int sF = sU * Ls; - for (unsigned int s = 0; s < Ls; ++s) + unsigned int sF = sU * LLs; + for (unsigned int s = 0; s < LLs; ++s) { - bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ - true : false; + bool axial_sign = ((curr_type == Current::Axial) && (s < (LLs / 2))); Kernels::SeqConservedCurrentSiteFwd(tmpFwd._odata[sF], q_out._odata[sF], Umu, sU, mu, t_mask, axial_sign); @@ -783,11 +815,10 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, if (timeSlices > 0) { - unsigned int sF = sU * Ls; - for (unsigned int s = 0; s < Ls; ++s) + unsigned int sF = sU * LLs; + for (unsigned int s = 0; s < LLs; ++s) { - bool axial_sign = ((curr_type == Current::Axial) && (s < (Ls / 2))) ? \ - true : false; + bool axial_sign = ((curr_type == Current::Axial) && (s < (LLs / 2))); Kernels::SeqConservedCurrentSiteBwd(tmpBwd._odata[sF], q_out._odata[sF], Umu, sU, mu, t_mask, axial_sign); From 323e9c439ab0889d69c60b4736e1bd07d7724c06 Mon Sep 17 00:00:00 2001 From: Lanny91 Date: Mon, 31 Jul 2017 12:26:34 +0100 Subject: [PATCH 056/174] Hadrons: Legal banner fixes --- extras/Hadrons/Modules.hpp | 30 ++++++++++++++++++ extras/Hadrons/Modules/MFermion/GaugeProp.hpp | 31 +++++++++++++++++++ extras/Hadrons/Modules/MSink/Point.hpp | 28 +++++++++++++++++ extras/Hadrons/Modules/MSink/Smear.hpp | 28 +++++++++++++++++ .../Modules/MUtilities/TestSeqGamma.hpp | 28 +++++++++++++++++ 5 files changed, 145 insertions(+) diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index d0d0d80d..e1f06f32 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -1,3 +1,33 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules.hpp + +Copyright (C) 2015 +Copyright (C) 2016 +Copyright (C) 2017 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + #include #include #include diff --git a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp index 050f8381..8add9a00 100644 --- a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -1,3 +1,34 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MFermion/GaugeProp.hpp + +Copyright (C) 2015 +Copyright (C) 2016 +Copyright (C) 2017 + +Author: Antonin Portelli + Andrew Lawson + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + #ifndef Hadrons_MFermion_GaugeProp_hpp_ #define Hadrons_MFermion_GaugeProp_hpp_ diff --git a/extras/Hadrons/Modules/MSink/Point.hpp b/extras/Hadrons/Modules/MSink/Point.hpp index 7b3aa9de..0761c4c4 100644 --- a/extras/Hadrons/Modules/MSink/Point.hpp +++ b/extras/Hadrons/Modules/MSink/Point.hpp @@ -1,3 +1,31 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MSink/Point.hpp + +Copyright (C) 2017 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + #ifndef Hadrons_MSink_Point_hpp_ #define Hadrons_MSink_Point_hpp_ diff --git a/extras/Hadrons/Modules/MSink/Smear.hpp b/extras/Hadrons/Modules/MSink/Smear.hpp index 9327001f..c3973d2b 100644 --- a/extras/Hadrons/Modules/MSink/Smear.hpp +++ b/extras/Hadrons/Modules/MSink/Smear.hpp @@ -1,3 +1,31 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MSink/Smear.hpp + +Copyright (C) 2017 + +Author: Andrew Lawson + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + #ifndef Hadrons_MSink_Smear_hpp_ #define Hadrons_MSink_Smear_hpp_ diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp index 3dbd7d63..2799e5d0 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp @@ -1,3 +1,31 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp + +Copyright (C) 2017 + +Author: Andrew Lawson + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + #ifndef Hadrons_MUtilities_TestSeqGamma_hpp_ #define Hadrons_MUtilities_TestSeqGamma_hpp_ From 75ee6cfc86e2365baf0a50cd4bf317e7c6fb097a Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Fri, 4 Aug 2017 16:08:07 +0100 Subject: [PATCH 057/174] Debugging the Clover term --- .gitignore | 2 + .vscode/settings.json | 11 ++- lib/cartesian/Cartesian_base.h | 2 + lib/cartesian/Cartesian_full.h | 5 +- lib/cartesian/Cartesian_red_black.h | 1 + lib/qcd/action/fermion/WilsonCloverFermion.cc | 78 +++++++-------- lib/qcd/action/fermion/WilsonCloverFermion.h | 99 +++++++++++++++++-- tests/core/Test_wilson_clover.cc | 3 +- 8 files changed, 149 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index d743ee06..6b92b1a4 100644 --- a/.gitignore +++ b/.gitignore @@ -123,3 +123,5 @@ make-bin-BUCK.sh lib/qcd/spin/gamma-gen/*.h lib/qcd/spin/gamma-gen/*.cc +.vscode/settings.json +settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json index dd8f0473..3e49029b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -36,6 +36,15 @@ "tuple": "cpp", "type_traits": "cpp", "typeinfo": "cpp", - "utility": "cpp" + "utility": "cpp", + "iostream": "cpp", + "strstream": "cpp", + "complex": "cpp", + "fstream": "cpp", + "iomanip": "cpp", + "istream": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "streambuf": "cpp" } } \ No newline at end of file diff --git a/lib/cartesian/Cartesian_base.h b/lib/cartesian/Cartesian_base.h index 0db6ce0d..e435bbba 100644 --- a/lib/cartesian/Cartesian_base.h +++ b/lib/cartesian/Cartesian_base.h @@ -69,6 +69,8 @@ public: std::vector _lstart; // local start of array in gcoors _processor_coor[d]*_ldimensions[d] std::vector _lend ; // local end of array in gcoors _processor_coor[d]*_ldimensions[d]+_ldimensions_[d]-1 + bool _isCheckerBoarded; + public: //////////////////////////////////////////////////////////////// diff --git a/lib/cartesian/Cartesian_full.h b/lib/cartesian/Cartesian_full.h index b0e47fa4..3be3e8cd 100644 --- a/lib/cartesian/Cartesian_full.h +++ b/lib/cartesian/Cartesian_full.h @@ -69,6 +69,7 @@ public: /////////////////////// // Grid information /////////////////////// + _isCheckerBoarded = false; _ndimension = dimensions.size(); _fdimensions.resize(_ndimension); @@ -76,8 +77,8 @@ public: _ldimensions.resize(_ndimension); _rdimensions.resize(_ndimension); _simd_layout.resize(_ndimension); - _lstart.resize(_ndimension); - _lend.resize(_ndimension); + _lstart.resize(_ndimension); + _lend.resize(_ndimension); _ostride.resize(_ndimension); _istride.resize(_ndimension); diff --git a/lib/cartesian/Cartesian_red_black.h b/lib/cartesian/Cartesian_red_black.h index 3037de00..a440538a 100644 --- a/lib/cartesian/Cartesian_red_black.h +++ b/lib/cartesian/Cartesian_red_black.h @@ -139,6 +139,7 @@ public: /////////////////////// // Grid information /////////////////////// + _isCheckerBoarded = true; _checker_dim = checker_dim; assert(checker_dim_mask[checker_dim]==1); _ndimension = dimensions.size(); diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index e1900830..f8b62ba4 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -35,27 +35,6 @@ namespace Grid namespace QCD { -//WilsonLoop::CloverPlaquette -///////////////////////////////////////////////////// -//// Clover plaquette combination in mu,nu plane with Double Stored U -//////////////////////////////////////////////////// -//static void CloverPlaquette(GaugeMat &Q, const std::vector &U, -// const int mu, const int nu){ -// Q = zero; -// Q += Gimpl::CovShiftBackward( -// U[mu], mu, Gimpl::CovShiftBackward( -// U[nu], nu, Gimpl::CovShiftForward(U[mu], mu, U[nu] ))); -// Q += Gimpl::CovShiftForward( -// U[mu], mu, Gimpl::CovShiftForward( -// U[nu], nu, Gimpl::CovShiftBackward(U[mu], mu, U[nu+Nd] ))); -// Q += Gimpl::CovShiftBackward( -// U[nu], nu, Gimpl::CovShiftForward( -// U[mu], mu, Gimpl::CovShiftForward(U[nu], nu, U[mu+Nd] ))); -// Q += Gimpl::CovShiftForward( -// U[mu], mu, Gimpl::CovShiftBackward( -// U[nu], nu, Gimpl::CovShiftBackward(U[mu], mu, U[nu] ))); -// } - // *NOT* EO template RealD WilsonCloverFermion::M(const FermionField &in, FermionField &out) @@ -89,10 +68,10 @@ RealD WilsonCloverFermion::Mdag(const FermionField &in, FermionField &out) template void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) { - this->ImportGauge(_Umu); + WilsonFermion::ImportGauge(_Umu); GridBase *grid = _Umu._grid; typename Impl::GaugeLinkField Bx(grid), By(grid), Bz(grid), Ex(grid), Ey(grid), Ez(grid); - + // Compute the field strength terms WilsonLoops::FieldStrength(Bx, _Umu, Ydir, Zdir); WilsonLoops::FieldStrength(By, _Umu, Zdir, Xdir); @@ -102,12 +81,12 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); // Compute the Clover Operator acting on Colour and Spin - CloverTerm = fillClover(Bx) * (Gamma(Gamma::Algebra::SigmaYZ)); - CloverTerm += fillClover(By) * (Gamma(Gamma::Algebra::MinusSigmaXZ)); - CloverTerm += fillClover(Bz) * (Gamma(Gamma::Algebra::SigmaXY)); - CloverTerm += fillClover(Ex) * (Gamma(Gamma::Algebra::MinusSigmaXT)); - CloverTerm += fillClover(Ey) * (Gamma(Gamma::Algebra::MinusSigmaYT)); - CloverTerm += fillClover(Ez) * (Gamma(Gamma::Algebra::MinusSigmaZT)); + CloverTerm = fillCloverYZ(Bx); + CloverTerm += fillCloverXZ(By); + CloverTerm += fillCloverXY(Bz); + CloverTerm += fillCloverXT(Ex); + CloverTerm += fillCloverYT(Ey); + CloverTerm += fillCloverZT(Ez) ; CloverTerm *= csw; int lvol = _Umu._grid->lSites(); @@ -130,8 +109,11 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) for (int a = 0; a < DimRep; a++) for (int b = 0; b < DimRep; b++) EigenCloverOp(a + j * DimRep, b + k * DimRep) = Qx()(j, k)(a, b); + //std::cout << EigenCloverOp << std::endl; + EigenInvCloverOp = EigenCloverOp.inverse(); + //std::cout << EigenInvCloverOp << std::endl; for (int j = 0; j < Ns; j++) for (int k = 0; k < Ns; k++) for (int a = 0; a < DimRep; a++) @@ -139,17 +121,21 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) Qxinv()(j, k)(a, b) = EigenInvCloverOp(a + j * DimRep, b + k * DimRep); pokeLocalSite(Qxinv, CloverTermInv, lcoor); - // Separate the even and odd parts. - pickCheckerboard(Even, CloverTermEven, CloverTerm); - pickCheckerboard( Odd, CloverTermOdd, CloverTerm); - pickCheckerboard(Even, CloverTermInvEven, CloverTermInv); - pickCheckerboard( Odd, CloverTermInvOdd, CloverTermInv); } + + // Separate the even and odd parts. + pickCheckerboard(Even, CloverTermEven, CloverTerm); + pickCheckerboard( Odd, CloverTermOdd, CloverTerm); + + pickCheckerboard(Even, CloverTermInvEven, CloverTermInv); + pickCheckerboard( Odd, CloverTermInvOdd, CloverTermInv); + } template void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out) { + conformable(in,out); this->MooeeInternal(in, out, DaggerNo, InverseNo); } @@ -176,15 +162,27 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie { out.checkerboard = in.checkerboard; CloverFieldType *Clover; - if (in.checkerboard == Odd){ - std::cout << "Calling clover term Odd" << std::endl; - Clover = (inv) ? &CloverTermInvOdd : &CloverTermOdd; + assert(in.checkerboard == Odd || in.checkerboard == Even); + + if (in._grid->_isCheckerBoarded) + { + if (in.checkerboard == Odd) + { + std::cout << "Calling clover term Odd" << std::endl; + Clover = (inv) ? &CloverTermInvOdd : &CloverTermOdd; + } + else + { + std::cout << "Calling clover term Even" << std::endl; + Clover = (inv) ? &CloverTermInvEven : &CloverTermEven; + } } - if (in.checkerboard == Even){ - std::cout << "Calling clover term Even" << std::endl; - Clover = (inv) ? &CloverTermInvEven : &CloverTermEven; + else + { + Clover = (inv) ? &CloverTermInv : &CloverTerm; } + std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; if (dag){ out = adj(*Clover) * in;} else { out = *Clover * in;} } // MooeeInternal diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index c9e7be39..fd9d1f60 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -94,17 +94,102 @@ private: // eventually these two can be compressed into 6x6 blocks instead of the 12x12 // using the DeGrand-Rossi basis for the gamma matrices - CloverFieldType fillClover(const GaugeLinkField& F){ + CloverFieldType fillCloverYZ(const GaugeLinkField &F) + { CloverFieldType T(F._grid); + T = zero; PARALLEL_FOR_LOOP - for (int i = 0; i < CloverTerm._grid->oSites(); i++){ - for (int s1 = 0; s1 < Nc; s1++) - for (int s2 = 0; s2 < Nc; s2++) - T._odata[i]()(s1,s2) = F._odata[i]()(); + for (int i = 0; i < CloverTerm._grid->oSites(); i++) + { + T._odata[i]()(0, 1) = timesMinusI(F._odata[i]()()); + T._odata[i]()(1, 0) = timesMinusI(F._odata[i]()()); + T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); + T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); } - return T; - } + return T; +} + + CloverFieldType fillCloverXZ(const GaugeLinkField &F) + { + CloverFieldType T(F._grid); + T = zero; + PARALLEL_FOR_LOOP + for (int i = 0; i < CloverTerm._grid->oSites(); i++) + { + T._odata[i]()(0, 1) = -F._odata[i]()(); + T._odata[i]()(1, 0) = F._odata[i]()(); + T._odata[i]()(2, 3) = -F._odata[i]()(); + T._odata[i]()(3, 2) = F._odata[i]()(); + } + + return T; +} + + CloverFieldType fillCloverXY(const GaugeLinkField &F) + { + CloverFieldType T(F._grid); + T = zero; + PARALLEL_FOR_LOOP + for (int i = 0; i < CloverTerm._grid->oSites(); i++) + { + T._odata[i]()(0, 0) = timesMinusI(F._odata[i]()()); + T._odata[i]()(1, 1) = timesI(F._odata[i]()()); + T._odata[i]()(2, 2) = timesMinusI(F._odata[i]()()); + T._odata[i]()(3, 3) = timesI(F._odata[i]()()); + } + + return T; +} + + CloverFieldType fillCloverXT(const GaugeLinkField &F) + { + CloverFieldType T(F._grid); + T = zero; + PARALLEL_FOR_LOOP + for (int i = 0; i < CloverTerm._grid->oSites(); i++) + { + T._odata[i]()(0, 1) = timesMinusI(F._odata[i]()()); + T._odata[i]()(1, 0) = timesMinusI(F._odata[i]()()); + T._odata[i]()(2, 3) = timesI(F._odata[i]()()); + T._odata[i]()(3, 2) = timesI(F._odata[i]()()); + } + + return T; +} + + CloverFieldType fillCloverYT(const GaugeLinkField &F) + { + CloverFieldType T(F._grid); + T = zero; + PARALLEL_FOR_LOOP + for (int i = 0; i < CloverTerm._grid->oSites(); i++) + { + T._odata[i]()(0, 1) = (F._odata[i]()()); + T._odata[i]()(1, 0) = -(F._odata[i]()()); + T._odata[i]()(2, 3) = -(F._odata[i]()()); + T._odata[i]()(3, 2) = (F._odata[i]()()); + } + + return T; +} + + CloverFieldType fillCloverZT(const GaugeLinkField &F) + { + CloverFieldType T(F._grid); + T = zero; + PARALLEL_FOR_LOOP + for (int i = 0; i < CloverTerm._grid->oSites(); i++) + { + T._odata[i]()(0, 0) = timesMinusI(F._odata[i]()()); + T._odata[i]()(1, 1) = timesI(F._odata[i]()()); + T._odata[i]()(2, 2) = timesI(F._odata[i]()()); + T._odata[i]()(3, 3) = timesMinusI(F._odata[i]()()); + } + + return T; +} + }; } } diff --git a/tests/core/Test_wilson_clover.cc b/tests/core/Test_wilson_clover.cc index 3df69e3b..1b208e2d 100644 --- a/tests/core/Test_wilson_clover.cc +++ b/tests/core/Test_wilson_clover.cc @@ -91,7 +91,7 @@ int main (int argc, char ** argv) } WilsonCloverFermionR Dwc(Umu,Grid,RBGrid,mass,csw,params); - + Dwc.ImportGauge(Umu); std::cout< Date: Tue, 15 Aug 2017 10:50:44 +0100 Subject: [PATCH 058/174] Correction of the dagger version of the Clover --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index f8b62ba4..ce120846 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -142,19 +142,22 @@ void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out) template void WilsonCloverFermion::MooeeDag(const FermionField &in, FermionField &out) { - this->MooeeInternal(in, out, DaggerNo, InverseYes); + conformable(in,out); + this->MooeeInternal(in, out, DaggerYes, InverseYes); } template void WilsonCloverFermion::MooeeInv(const FermionField &in, FermionField &out) { + conformable(in,out); this->MooeeInternal(in, out, DaggerNo, InverseYes); } template void WilsonCloverFermion::MooeeInvDag(const FermionField &in, FermionField &out) { - this->MooeeInternal(in, out, DaggerNo, InverseYes); + conformable(in,out); + this->MooeeInternal(in, out, DaggerYes, InverseYes); } template @@ -183,7 +186,10 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie } std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; - if (dag){ out = adj(*Clover) * in;} else { out = *Clover * in;} + std::cout << GridLogMessage << "in.checkerboard " << in.checkerboard << std::endl; + std::cout << GridLogMessage << "out.checkerboard " << out.checkerboard << std::endl; + out = *Clover * in; + //if (dag){ out = adj(*Clover) * in;} else { out = *Clover * in;} } // MooeeInternal // Derivative parts From 91eaace19de25f45db52420a10350b36c548ad5e Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Fri, 15 Sep 2017 11:33:45 +0100 Subject: [PATCH 059/174] Added support for FFT accelerated updates --- lib/qcd/action/scalar/ScalarImpl.h | 129 +++++++++++++++++++++++++---- 1 file changed, 114 insertions(+), 15 deletions(-) diff --git a/lib/qcd/action/scalar/ScalarImpl.h b/lib/qcd/action/scalar/ScalarImpl.h index f85ab840..3755d0ee 100644 --- a/lib/qcd/action/scalar/ScalarImpl.h +++ b/lib/qcd/action/scalar/ScalarImpl.h @@ -16,12 +16,12 @@ class ScalarImplTypes { typedef iImplField SiteField; typedef SiteField SitePropagator; typedef SiteField SiteComplex; - + typedef Lattice Field; typedef Field ComplexField; typedef Field FermionField; typedef Field PropagatorField; - + static inline void generate_momenta(Field& P, GridParallelRNG& pRNG){ gaussian(pRNG, P); } @@ -47,54 +47,58 @@ class ScalarImplTypes { static inline void ColdConfiguration(GridParallelRNG &pRNG, Field &U) { U = 1.0; } - + static void MomentumSpacePropagator(Field &out, RealD m) { GridBase *grid = out._grid; Field kmu(grid), one(grid); const unsigned int nd = grid->_ndimension; std::vector &l = grid->_fdimensions; - + one = Complex(1.0,0.0); out = m*m; for(int mu = 0; mu < nd; mu++) { Real twoPiL = M_PI*2./l[mu]; - + LatticeCoordinate(kmu,mu); kmu = 2.*sin(.5*twoPiL*kmu); out = out + kmu*kmu; } out = one/out; } - + static void FreePropagator(const Field &in, Field &out, const Field &momKernel) { FFT fft((GridCartesian *)in._grid); Field inFT(in._grid); - + fft.FFT_all_dim(inFT, in, FFT::forward); inFT = inFT*momKernel; fft.FFT_all_dim(out, inFT, FFT::backward); } - + static void FreePropagator(const Field &in, Field &out, RealD m) { Field momKernel(in._grid); - + MomentumSpacePropagator(momKernel, m); FreePropagator(in, out, momKernel); } - + }; + + #define USE_FFT_ACCELERATION + + template class ScalarAdjMatrixImplTypes { public: typedef S Simd; typedef QCD::SU Group; - + template using iImplField = iScalar>>; template @@ -103,24 +107,119 @@ class ScalarImplTypes { typedef iImplField SiteField; typedef SiteField SitePropagator; typedef iImplComplex SiteComplex; - + typedef Lattice Field; typedef Lattice ComplexField; typedef Field FermionField; typedef Field PropagatorField; + + static void MomentaSquare(ComplexField& out){ + GridBase *grid = out._grid; + const std::vector &l = grid->FullDimensions(); + ComplexField kmu(grid); + + for(int mu = 0; mu < grid->Nd(); mu++) + { + Real twoPiL = M_PI*2.0/l[mu]; + LatticeCoordinate(kmu,mu); + kmu = 2.0*sin(0.5*twoPiL*kmu); + out += kmu*kmu; + } + } + + static void MomentumSpacePropagator(ComplexField &out, RealD m) + { + GridBase *grid = out._grid; + ComplexField one(grid); one = Complex(1.0,0.0); + out = m*m; + MomentaSquare(out); + out = one/out; + } + + static inline void generate_momenta(Field& P, GridParallelRNG& pRNG) { + #ifndef USE_FFT_ACCELERATION Group::GaussianFundamentalLieAlgebraMatrix(pRNG, P); + #else + + Field Ptmp(P._grid), Pp(P._grid); + Group::GaussianFundamentalLieAlgebraMatrix(pRNG, Ptmp); + // if we change the mass I need a renormalization here + // transform and multiply by (M*M+p*p)^-1 + GridCartesian *Grid = dynamic_cast(P._grid); + FFT theFFT(Grid); + ComplexField p2(Grid); + RealD M = 1.0; + p2= zero; + + theFFT.FFT_all_dim(Pp,Ptmp,FFT::forward); + MomentaSquare(p2); + p2 += M*M; + p2 = sqrt(p2); + Pp *= p2; + theFFT.FFT_all_dim(P,Pp,FFT::backward); + + #endif //USE_FFT_ACCELERATION } static inline Field projectForce(Field& P) {return P;} static inline void update_field(Field& P, Field& U, double ep) { + #ifndef USE_FFT_ACCELERATION U += P*ep; + #else + // Here we can eventually add the Fourier acceleration + // FFT transform P(x) -> P(p) + // divide by (M^2+p^2) M external parameter (how to pass?) + // P'(p) = P(p)/(M^2+p^2) + // Transform back -> P'(x) + // U += P'(x)*ep + + // the dynamic cast is safe + GridCartesian *Grid = dynamic_cast(U._grid); + FFT theFFT(Grid); + Field Pp(Grid), Pnew(Grid); + std::vector full_dim = Grid->FullDimensions(); + + theFFT.FFT_all_dim(Pp,P,FFT::forward); + RealD M = 1.0; + static bool first_call = true; + static ComplexField p2(Grid); + if (first_call){ + MomentumSpacePropagator(p2,M); + first_call = false; + } + Pp *= p2; + theFFT.FFT_all_dim(Pnew,Pp,FFT::backward); + U += Pnew * ep; + + #endif //USE_FFT_ACCELERATION } - static inline RealD FieldSquareNorm(Field& U) { + static inline RealD FieldSquareNorm(Field &U) + { + #ifndef USE_FFT_ACCELERATION return (TensorRemove(sum(trace(U*U))).real()); + #else + // In case of Fourier acceleration we have to: + // compute U(p)*U(p)/(M^2+p^2)) Parseval theorem + // 1 FFT needed U(x) -> U(p) + // M to be passed + + GridCartesian *Grid = dynamic_cast(U._grid); + FFT theFFT(Grid); + Field Up(Grid), Utilde(Grid); + std::vector full_dim = Grid->FullDimensions(); + + theFFT.FFT_all_dim(Up, U, FFT::forward); + RealD M = 1.0; + ComplexField p2(Grid); + MomentumSpacePropagator(p2,M); + Field Up2 = Up*p2; + // from the definition of the DFT we need to divide by the volume + return (-TensorRemove(sum(trace(adj(Up)*Up2))).real()/U._grid->gSites()); + #endif //USE_FFT_ACCELERATION } static inline void HotConfiguration(GridParallelRNG &pRNG, Field &U) { @@ -146,7 +245,7 @@ class ScalarImplTypes { typedef ScalarImplTypes ScalarImplCR; typedef ScalarImplTypes ScalarImplCF; typedef ScalarImplTypes ScalarImplCD; - + // Hardcoding here the size of the matrices typedef ScalarAdjMatrixImplTypes ScalarAdjImplR; typedef ScalarAdjMatrixImplTypes ScalarAdjImplF; @@ -155,7 +254,7 @@ class ScalarImplTypes { template using ScalarNxNAdjImplR = ScalarAdjMatrixImplTypes; template using ScalarNxNAdjImplF = ScalarAdjMatrixImplTypes; template using ScalarNxNAdjImplD = ScalarAdjMatrixImplTypes; - + //} } From b542d349b8784fdd47339977e94575a7fdef5a58 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Fri, 15 Sep 2017 11:48:36 +0100 Subject: [PATCH 060/174] Minor cosmetic changes --- lib/qcd/action/scalar/ScalarImpl.h | 137 ++++++++++++++--------------- 1 file changed, 68 insertions(+), 69 deletions(-) diff --git a/lib/qcd/action/scalar/ScalarImpl.h b/lib/qcd/action/scalar/ScalarImpl.h index 3755d0ee..3dd3cc70 100644 --- a/lib/qcd/action/scalar/ScalarImpl.h +++ b/lib/qcd/action/scalar/ScalarImpl.h @@ -91,6 +91,9 @@ class ScalarImplTypes { #define USE_FFT_ACCELERATION + #ifdef USE_FFT_ACCELERATION + #define FFT_MASS 0.707 + #endif template @@ -113,113 +116,109 @@ class ScalarImplTypes { typedef Field FermionField; typedef Field PropagatorField; + static void MomentaSquare(ComplexField &out) + { + GridBase *grid = out._grid; + const std::vector &l = grid->FullDimensions(); + ComplexField kmu(grid); - static void MomentaSquare(ComplexField& out){ - GridBase *grid = out._grid; - const std::vector &l = grid->FullDimensions(); - ComplexField kmu(grid); - - for(int mu = 0; mu < grid->Nd(); mu++) + for (int mu = 0; mu < grid->Nd(); mu++) { - Real twoPiL = M_PI*2.0/l[mu]; - LatticeCoordinate(kmu,mu); - kmu = 2.0*sin(0.5*twoPiL*kmu); - out += kmu*kmu; + Real twoPiL = M_PI * 2.0 / l[mu]; + LatticeCoordinate(kmu, mu); + kmu = 2.0 * sin(0.5 * twoPiL * kmu); + out += kmu * kmu; } } static void MomentumSpacePropagator(ComplexField &out, RealD m) { - GridBase *grid = out._grid; - ComplexField one(grid); one = Complex(1.0,0.0); - out = m*m; + GridBase *grid = out._grid; + ComplexField one(grid); + one = Complex(1.0, 0.0); + out = m * m; MomentaSquare(out); - out = one/out; + out = one / out; } - - static inline void generate_momenta(Field& P, GridParallelRNG& pRNG) { - #ifndef USE_FFT_ACCELERATION + static inline void generate_momenta(Field &P, GridParallelRNG &pRNG) + { +#ifndef USE_FFT_ACCELERATION Group::GaussianFundamentalLieAlgebraMatrix(pRNG, P); - #else - - Field Ptmp(P._grid), Pp(P._grid); - Group::GaussianFundamentalLieAlgebraMatrix(pRNG, Ptmp); - // if we change the mass I need a renormalization here - // transform and multiply by (M*M+p*p)^-1 - GridCartesian *Grid = dynamic_cast(P._grid); - FFT theFFT(Grid); - ComplexField p2(Grid); - RealD M = 1.0; - p2= zero; +#else - theFFT.FFT_all_dim(Pp,Ptmp,FFT::forward); + Field Pgaussian(P._grid), Pp(P._grid); + ComplexField p2(P._grid); p2 = zero; + RealD M = FFT_MASS; + + Group::GaussianFundamentalLieAlgebraMatrix(pRNG, Pgaussian); + + FFT theFFT((GridCartesian*)P._grid); + theFFT.FFT_all_dim(Pp, Pgaussian, FFT::forward); MomentaSquare(p2); - p2 += M*M; + p2 += M * M; p2 = sqrt(p2); Pp *= p2; - theFFT.FFT_all_dim(P,Pp,FFT::backward); - - #endif //USE_FFT_ACCELERATION + theFFT.FFT_all_dim(P, Pp, FFT::backward); + +#endif //USE_FFT_ACCELERATION } static inline Field projectForce(Field& P) {return P;} - static inline void update_field(Field& P, Field& U, double ep) { - #ifndef USE_FFT_ACCELERATION - U += P*ep; - #else - // Here we can eventually add the Fourier acceleration + static inline void update_field(Field &P, Field &U, double ep) + { +#ifndef USE_FFT_ACCELERATION + U += P * ep; +#else // FFT transform P(x) -> P(p) // divide by (M^2+p^2) M external parameter (how to pass?) // P'(p) = P(p)/(M^2+p^2) // Transform back -> P'(x) // U += P'(x)*ep - - // the dynamic cast is safe - GridCartesian *Grid = dynamic_cast(U._grid); - FFT theFFT(Grid); - Field Pp(Grid), Pnew(Grid); - std::vector full_dim = Grid->FullDimensions(); - theFFT.FFT_all_dim(Pp,P,FFT::forward); - RealD M = 1.0; + Field Pp(U._grid), P_FFT(U._grid); + static ComplexField p2(U._grid); + RealD M = FFT_MASS; + + FFT theFFT((GridCartesian*)U._grid); + theFFT.FFT_all_dim(Pp, P, FFT::forward); + static bool first_call = true; - static ComplexField p2(Grid); - if (first_call){ - MomentumSpacePropagator(p2,M); - first_call = false; + if (first_call) + { + // avoid recomputing + MomentumSpacePropagator(p2, M); + first_call = false; } Pp *= p2; - theFFT.FFT_all_dim(Pnew,Pp,FFT::backward); - U += Pnew * ep; - - #endif //USE_FFT_ACCELERATION + theFFT.FFT_all_dim(P_FFT, Pp, FFT::backward); + U += P_FFT * ep; + +#endif //USE_FFT_ACCELERATION } static inline RealD FieldSquareNorm(Field &U) { - #ifndef USE_FFT_ACCELERATION - return (TensorRemove(sum(trace(U*U))).real()); - #else +#ifndef USE_FFT_ACCELERATION + return (TensorRemove(sum(trace(U * U))).real()); +#else // In case of Fourier acceleration we have to: // compute U(p)*U(p)/(M^2+p^2)) Parseval theorem // 1 FFT needed U(x) -> U(p) // M to be passed - - GridCartesian *Grid = dynamic_cast(U._grid); - FFT theFFT(Grid); - Field Up(Grid), Utilde(Grid); - std::vector full_dim = Grid->FullDimensions(); - + + FFT theFFT((GridCartesian*)U._grid); + Field Up(U._grid); + theFFT.FFT_all_dim(Up, U, FFT::forward); - RealD M = 1.0; - ComplexField p2(Grid); - MomentumSpacePropagator(p2,M); - Field Up2 = Up*p2; + RealD M = FFT_MASS; + ComplexField p2(U._grid); + MomentumSpacePropagator(p2, M); + Field Up2 = Up * p2; // from the definition of the DFT we need to divide by the volume - return (-TensorRemove(sum(trace(adj(Up)*Up2))).real()/U._grid->gSites()); - #endif //USE_FFT_ACCELERATION + return (-TensorRemove(sum(trace(adj(Up) * Up2))).real() / U._grid->gSites()); +#endif //USE_FFT_ACCELERATION } static inline void HotConfiguration(GridParallelRNG &pRNG, Field &U) { From 999c62359046674117c0e0e1348072e002622c15 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 18 Sep 2017 14:39:04 +0100 Subject: [PATCH 061/174] Solving a memory leak in Communicator_mpi --- lib/cartesian/Cartesian_base.h | 3 + lib/cartesian/Cartesian_full.h | 3 + lib/communicator/Communicator_base.h | 1 + lib/communicator/Communicator_mpi.cc | 7 + .../action/scalar/ScalarInteractionAction.h | 220 ++++++++++-------- 5 files changed, 135 insertions(+), 99 deletions(-) diff --git a/lib/cartesian/Cartesian_base.h b/lib/cartesian/Cartesian_base.h index f4f9a269..0c67e951 100644 --- a/lib/cartesian/Cartesian_base.h +++ b/lib/cartesian/Cartesian_base.h @@ -50,6 +50,9 @@ public: GridBase(const std::vector & processor_grid) : CartesianCommunicator(processor_grid) {}; + virtual ~GridBase() = default; + + // Physics Grid information. std::vector _simd_layout;// Which dimensions get relayed out over simd lanes. std::vector _fdimensions;// (full) Global dimensions of array prior to cb removal diff --git a/lib/cartesian/Cartesian_full.h b/lib/cartesian/Cartesian_full.h index 815e3b22..62481bb8 100644 --- a/lib/cartesian/Cartesian_full.h +++ b/lib/cartesian/Cartesian_full.h @@ -93,6 +93,7 @@ public: // Use a reduced simd grid _ldimensions[d] = _gdimensions[d] / _processors[d]; //local dimensions + //std::cout << _ldimensions[d] << " " << _gdimensions[d] << " " << _processors[d] << std::endl; assert(_ldimensions[d] * _processors[d] == _gdimensions[d]); _rdimensions[d] = _ldimensions[d] / _simd_layout[d]; //overdecomposition @@ -137,6 +138,8 @@ public: block = block * _rdimensions[d]; } }; + + virtual ~GridCartesian() = default; }; } #endif diff --git a/lib/communicator/Communicator_base.h b/lib/communicator/Communicator_base.h index ac866ced..ada017b0 100644 --- a/lib/communicator/Communicator_base.h +++ b/lib/communicator/Communicator_base.h @@ -152,6 +152,7 @@ class CartesianCommunicator { // Constructor of any given grid //////////////////////////////////////////////// CartesianCommunicator(const std::vector &pdimensions_in); + virtual ~CartesianCommunicator(); //////////////////////////////////////////////////////////////////////////////////////// // Wraps MPI_Cart routines, or implements equivalent on other impls diff --git a/lib/communicator/Communicator_mpi.cc b/lib/communicator/Communicator_mpi.cc index bd2a62fb..a3427b00 100644 --- a/lib/communicator/Communicator_mpi.cc +++ b/lib/communicator/Communicator_mpi.cc @@ -75,6 +75,13 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) assert(Size==_Nprocessors); } + +CartesianCommunicator::~CartesianCommunicator(){ + if (communicator && !MPI::Is_finalized()) + MPI_Comm_free(&communicator); +} + + void CartesianCommunicator::GlobalSum(uint32_t &u){ int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_SUM,communicator); assert(ierr==0); diff --git a/lib/qcd/action/scalar/ScalarInteractionAction.h b/lib/qcd/action/scalar/ScalarInteractionAction.h index 4d189352..a681b62c 100644 --- a/lib/qcd/action/scalar/ScalarInteractionAction.h +++ b/lib/qcd/action/scalar/ScalarInteractionAction.h @@ -30,119 +30,141 @@ directory #ifndef SCALAR_INT_ACTION_H #define SCALAR_INT_ACTION_H - // Note: this action can completely absorb the ScalarAction for real float fields // use the scalarObjs to generalise the structure -namespace Grid { - // FIXME drop the QCD namespace everywhere here +namespace Grid +{ +// FIXME drop the QCD namespace everywhere here - template - class ScalarInteractionAction : public QCD::Action { - public: - INHERIT_FIELD_TYPES(Impl); - private: - RealD mass_square; - RealD lambda; +template +class ScalarInteractionAction : public QCD::Action +{ +public: + INHERIT_FIELD_TYPES(Impl); +private: + RealD mass_square; + RealD lambda; - typedef typename Field::vector_object vobj; - typedef CartesianStencil Stencil; + typedef typename Field::vector_object vobj; + typedef CartesianStencil Stencil; - SimpleCompressor compressor; - int npoint = 2*Ndim; - std::vector directions;// = {0,1,2,3,0,1,2,3}; // forcing 4 dimensions - std::vector displacements;// = {1,1,1,1, -1,-1,-1,-1}; + SimpleCompressor compressor; + int npoint = 2 * Ndim; + std::vector directions; // = {0,1,2,3,0,1,2,3}; // forcing 4 dimensions + std::vector displacements; // = {1,1,1,1, -1,-1,-1,-1}; - - public: - - ScalarInteractionAction(RealD ms, RealD l) : mass_square(ms), lambda(l), displacements(2*Ndim,0), directions(2*Ndim,0){ - for (int mu = 0 ; mu < Ndim; mu++){ - directions[mu] = mu; directions[mu+Ndim] = mu; - displacements[mu] = 1; displacements[mu+Ndim] = -1; - } +public: + ScalarInteractionAction(RealD ms, RealD l) : mass_square(ms), lambda(l), displacements(2 * Ndim, 0), directions(2 * Ndim, 0) + { + for (int mu = 0; mu < Ndim; mu++) + { + directions[mu] = mu; + directions[mu + Ndim] = mu; + displacements[mu] = 1; + displacements[mu + Ndim] = -1; } + } - virtual std::string LogParameters() { - std::stringstream sstream; - sstream << GridLogMessage << "[ScalarAction] lambda : " << lambda << std::endl; - sstream << GridLogMessage << "[ScalarAction] mass_square : " << mass_square << std::endl; - return sstream.str(); - } + virtual std::string LogParameters() + { + std::stringstream sstream; + sstream << GridLogMessage << "[ScalarAction] lambda : " << lambda << std::endl; + sstream << GridLogMessage << "[ScalarAction] mass_square : " << mass_square << std::endl; + return sstream.str(); + } - virtual std::string action_name() {return "ScalarAction";} + virtual std::string action_name() { return "ScalarAction"; } - virtual void refresh(const Field &U, GridParallelRNG &pRNG) {} + virtual void refresh(const Field &U, GridParallelRNG &pRNG) {} - virtual RealD S(const Field &p) { - assert(p._grid->Nd() == Ndim); - static Stencil phiStencil(p._grid, npoint, 0, directions, displacements); - phiStencil.HaloExchange(p, compressor); - Field action(p._grid), pshift(p._grid), phisquared(p._grid); - phisquared = p*p; - action = (2.0*Ndim + mass_square)*phisquared - lambda/24.*phisquared*phisquared; - for (int mu = 0; mu < Ndim; mu++) { - // pshift = Cshift(p, mu, +1); // not efficient, implement with stencils - parallel_for (int i = 0; i < p._grid->oSites(); i++) { - int permute_type; - StencilEntry *SE; - vobj temp2; - const vobj *temp, *t_p; - - SE = phiStencil.GetEntry(permute_type, mu, i); - t_p = &p._odata[i]; - if ( SE->_is_local ) { - temp = &p._odata[SE->_offset]; - if ( SE->_permute ) { - permute(temp2, *temp, permute_type); - action._odata[i] -= temp2*(*t_p) + (*t_p)*temp2; - } else { - action._odata[i] -= (*temp)*(*t_p) + (*t_p)*(*temp); - } - } else { - action._odata[i] -= phiStencil.CommBuf()[SE->_offset]*(*t_p) + (*t_p)*phiStencil.CommBuf()[SE->_offset]; - } - } - // action -= pshift*p + p*pshift; - } - // NB the trace in the algebra is normalised to 1/2 - // minus sign coming from the antihermitian fields - return -(TensorRemove(sum(trace(action)))).real(); - }; - - virtual void deriv(const Field &p, Field &force) { - assert(p._grid->Nd() == Ndim); - force = (2.0*Ndim + mass_square)*p - lambda/12.*p*p*p; - // move this outside - static Stencil phiStencil(p._grid, npoint, 0, directions, displacements); - phiStencil.HaloExchange(p, compressor); - - //for (int mu = 0; mu < QCD::Nd; mu++) force -= Cshift(p, mu, -1) + Cshift(p, mu, 1); - for (int point = 0; point < npoint; point++) { - parallel_for (int i = 0; i < p._grid->oSites(); i++) { - const vobj *temp; - vobj temp2; - int permute_type; - StencilEntry *SE; - SE = phiStencil.GetEntry(permute_type, point, i); - - if ( SE->_is_local ) { - temp = &p._odata[SE->_offset]; - if ( SE->_permute ) { - permute(temp2, *temp, permute_type); - force._odata[i] -= temp2; - } else { - force._odata[i] -= *temp; - } - } else { - force._odata[i] -= phiStencil.CommBuf()[SE->_offset]; - } - } + virtual RealD S(const Field &p) + { + assert(p._grid->Nd() == Ndim); + static Stencil phiStencil(p._grid, npoint, 0, directions, displacements); + phiStencil.HaloExchange(p, compressor); + Field action(p._grid), pshift(p._grid), phisquared(p._grid); + phisquared = p * p; + action = (2.0 * Ndim + mass_square) * phisquared - lambda / 24. * phisquared * phisquared; + for (int mu = 0; mu < Ndim; mu++) + { + // pshift = Cshift(p, mu, +1); // not efficient, implement with stencils + parallel_for(int i = 0; i < p._grid->oSites(); i++) + { + int permute_type; + StencilEntry *SE; + vobj temp2; + const vobj *temp, *t_p; + + SE = phiStencil.GetEntry(permute_type, mu, i); + t_p = &p._odata[i]; + if (SE->_is_local) + { + temp = &p._odata[SE->_offset]; + if (SE->_permute) + { + permute(temp2, *temp, permute_type); + action._odata[i] -= temp2 * (*t_p) + (*t_p) * temp2; + } + else + { + action._odata[i] -= (*temp) * (*t_p) + (*t_p) * (*temp); + } + } + else + { + action._odata[i] -= phiStencil.CommBuf()[SE->_offset] * (*t_p) + (*t_p) * phiStencil.CommBuf()[SE->_offset]; + } } + // action -= pshift*p + p*pshift; } + // NB the trace in the algebra is normalised to 1/2 + // minus sign coming from the antihermitian fields + return -(TensorRemove(sum(trace(action)))).real(); }; - -} // namespace Grid -#endif // SCALAR_INT_ACTION_H + virtual void deriv(const Field &p, Field &force) + { + assert(p._grid->Nd() == Ndim); + force = (2.0 * Ndim + mass_square) * p - lambda / 12. * p * p * p; + // move this outside + static Stencil phiStencil(p._grid, npoint, 0, directions, displacements); + phiStencil.HaloExchange(p, compressor); + + //for (int mu = 0; mu < QCD::Nd; mu++) force -= Cshift(p, mu, -1) + Cshift(p, mu, 1); + for (int point = 0; point < npoint; point++) + { + parallel_for(int i = 0; i < p._grid->oSites(); i++) + { + const vobj *temp; + vobj temp2; + int permute_type; + StencilEntry *SE; + SE = phiStencil.GetEntry(permute_type, point, i); + + if (SE->_is_local) + { + temp = &p._odata[SE->_offset]; + if (SE->_permute) + { + permute(temp2, *temp, permute_type); + force._odata[i] -= temp2; + } + else + { + force._odata[i] -= *temp; + } + } + else + { + force._odata[i] -= phiStencil.CommBuf()[SE->_offset]; + } + } + } + } +}; + +} // namespace Grid + +#endif // SCALAR_INT_ACTION_H From 9a827d0242f7164a4bc02c5b8cefe606878fcb84 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 18 Sep 2017 14:55:51 +0100 Subject: [PATCH 062/174] Fixing a compilation error --- lib/communicator/Communicator_mpi3.cc | 3 +++ lib/communicator/Communicator_mpi3_leader.cc | 3 +++ lib/communicator/Communicator_mpit.cc | 3 +++ lib/communicator/Communicator_none.cc | 2 ++ lib/communicator/Communicator_shmem.cc | 3 +++ 5 files changed, 14 insertions(+) diff --git a/lib/communicator/Communicator_mpi3.cc b/lib/communicator/Communicator_mpi3.cc index 44aa1024..bb256e79 100644 --- a/lib/communicator/Communicator_mpi3.cc +++ b/lib/communicator/Communicator_mpi3.cc @@ -587,6 +587,9 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) } } }; + +CartesianCommunicator::~CartesianCommunicator() = default; + void CartesianCommunicator::GlobalSum(uint32_t &u){ int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_SUM,communicator); assert(ierr==0); diff --git a/lib/communicator/Communicator_mpi3_leader.cc b/lib/communicator/Communicator_mpi3_leader.cc index 6e26bd3e..da863508 100644 --- a/lib/communicator/Communicator_mpi3_leader.cc +++ b/lib/communicator/Communicator_mpi3_leader.cc @@ -830,6 +830,9 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) MPI_Cart_coords(communicator,_processor,_ndimension,&_processor_coor[0]); }; +CartesianCommunicator::~CartesianCommunicator() = default; + + void CartesianCommunicator::GlobalSum(uint32_t &u){ int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_SUM,communicator); assert(ierr==0); diff --git a/lib/communicator/Communicator_mpit.cc b/lib/communicator/Communicator_mpit.cc index eb6ef87d..7b7ec14c 100644 --- a/lib/communicator/Communicator_mpit.cc +++ b/lib/communicator/Communicator_mpit.cc @@ -80,6 +80,9 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) assert(Size==_Nprocessors); } + +CartesianCommunicator::~CartesianCommunicator() = default; + void CartesianCommunicator::GlobalSum(uint32_t &u){ int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_SUM,communicator); assert(ierr==0); diff --git a/lib/communicator/Communicator_none.cc b/lib/communicator/Communicator_none.cc index 5319ab93..a4e6cf54 100644 --- a/lib/communicator/Communicator_none.cc +++ b/lib/communicator/Communicator_none.cc @@ -53,6 +53,8 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) } } +CartesianCommunicator::~CartesianCommunicator() = default; + void CartesianCommunicator::GlobalSum(float &){} void CartesianCommunicator::GlobalSumVector(float *,int N){} void CartesianCommunicator::GlobalSum(double &){} diff --git a/lib/communicator/Communicator_shmem.cc b/lib/communicator/Communicator_shmem.cc index 3c76c808..826471c4 100644 --- a/lib/communicator/Communicator_shmem.cc +++ b/lib/communicator/Communicator_shmem.cc @@ -98,6 +98,9 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) assert(Size==_Nprocessors); } +CartesianCommunicator::~CartesianCommunicator() = default; + + void CartesianCommunicator::GlobalSum(uint32_t &u){ static long long source ; static long long dest ; From df21668f2c6d25b2c8c79e353514956517ed7682 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 22 Sep 2017 14:21:18 +0100 Subject: [PATCH 063/174] memory profiler update --- lib/allocator/AlignedAllocator.cc | 4 +- lib/allocator/AlignedAllocator.h | 72 +++++++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/lib/allocator/AlignedAllocator.cc b/lib/allocator/AlignedAllocator.cc index 967b2571..944e287f 100644 --- a/lib/allocator/AlignedAllocator.cc +++ b/lib/allocator/AlignedAllocator.cc @@ -3,9 +3,11 @@ namespace Grid { +MemoryStats *MemoryProfiler::stats = nullptr; + int PointerCache::victim; - PointerCache::PointerCacheEntry PointerCache::Entries[PointerCache::Ncache]; +PointerCache::PointerCacheEntry PointerCache::Entries[PointerCache::Ncache]; void *PointerCache::Insert(void *ptr,size_t bytes) { diff --git a/lib/allocator/AlignedAllocator.h b/lib/allocator/AlignedAllocator.h index e64a5949..68fad0d2 100644 --- a/lib/allocator/AlignedAllocator.h +++ b/lib/allocator/AlignedAllocator.h @@ -63,6 +63,18 @@ namespace Grid { static void *Lookup(size_t bytes) ; }; + + struct MemoryStats + { + size_t totalAllocated{0}, maxAllocated{0}, + currentlyAllocated{0}, totalFreed{0}; + }; + + class MemoryProfiler + { + public: + static MemoryStats *stats; + }; void check_huge_pages(void *Buf,uint64_t BYTES); @@ -93,6 +105,13 @@ public: { size_type bytes = __n*sizeof(_Tp); + if (auto s = MemoryProfiler::stats) + { + s->totalAllocated += bytes; + s->currentlyAllocated += bytes; + s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated); + } + _Tp *ptr = (_Tp *) PointerCache::Lookup(bytes); // if ( ptr != NULL ) // std::cout << "alignedAllocator "<<__n << " cache hit "<< std::hex << ptr <totalFreed += bytes; + s->currentlyAllocated -= bytes; + } + pointer __freeme = (pointer)PointerCache::Insert((void *)__p,bytes); #ifdef HAVE_MM_MALLOC_H @@ -172,10 +197,18 @@ public: #ifdef GRID_COMMS_SHMEM pointer allocate(size_type __n, const void* _p= 0) { + size_type bytes = __n*sizeof(_Tp); + + if (auto s = MemoryProfiler::stats) + { + s->totalAllocated += bytes; + s->currentlyAllocated += bytes; + s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated); + } #ifdef CRAY - _Tp *ptr = (_Tp *) shmem_align(__n*sizeof(_Tp),64); + _Tp *ptr = (_Tp *) shmem_align(bytes,64); #else - _Tp *ptr = (_Tp *) shmem_align(64,__n*sizeof(_Tp)); + _Tp *ptr = (_Tp *) shmem_align(64,bytes); #endif #ifdef PARANOID_SYMMETRIC_HEAP static void * bcast; @@ -193,18 +226,32 @@ public: #endif return ptr; } - void deallocate(pointer __p, size_type) { + void deallocate(pointer __p, size_type __n) { + size_type bytes = __n*sizeof(_Tp); + + if (auto s = MemoryProfiler::stats) + { + s->totalFreed += bytes; + s->currentlyAllocated -= bytes; + } shmem_free((void *)__p); } #else pointer allocate(size_type __n, const void* _p= 0) { -#ifdef HAVE_MM_MALLOC_H - _Tp * ptr = (_Tp *) _mm_malloc(__n*sizeof(_Tp),GRID_ALLOC_ALIGN); -#else - _Tp * ptr = (_Tp *) memalign(GRID_ALLOC_ALIGN,__n*sizeof(_Tp)); -#endif size_type bytes = __n*sizeof(_Tp); + + if (auto s = MemoryProfiler::stats) + { + s->totalAllocated += bytes; + s->currentlyAllocated += bytes; + s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated); + } +#ifdef HAVE_MM_MALLOC_H + _Tp * ptr = (_Tp *) _mm_malloc(bytes, GRID_ALLOC_ALIGN); +#else + _Tp * ptr = (_Tp *) memalign(GRID_ALLOC_ALIGN, bytes); +#endif uint8_t *cp = (uint8_t *)ptr; // One touch per 4k page, static OMP loop to catch same loop order #pragma omp parallel for schedule(static) @@ -213,7 +260,14 @@ public: } return ptr; } - void deallocate(pointer __p, size_type) { + void deallocate(pointer __p, size_type __n) { + size_type bytes = __n*sizeof(_Tp); + + if (auto s = MemoryProfiler::stats) + { + s->totalFreed += bytes; + s->currentlyAllocated -= bytes; + } #ifdef HAVE_MM_MALLOC_H _mm_free((void *)__p); #else From 56478d63a5589e0ece63d7394b3c5167d5ef11bd Mon Sep 17 00:00:00 2001 From: David Preti Date: Sun, 24 Sep 2017 19:32:15 +0200 Subject: [PATCH 064/174] clover + test (valence) --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 126 +++++++++++++++--- lib/qcd/action/fermion/WilsonCloverFermion.h | 35 +++-- tests/core/Test_wilson_clover.cc | 44 +++--- 3 files changed, 142 insertions(+), 63 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index f8b62ba4..54e72353 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -86,8 +86,8 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) CloverTerm += fillCloverXY(Bz); CloverTerm += fillCloverXT(Ex); CloverTerm += fillCloverYT(Ey); - CloverTerm += fillCloverZT(Ez) ; - CloverTerm *= csw; + CloverTerm += fillCloverZT(Ez); + CloverTerm *= 0.5 * csw; // FieldStrength normalization? should be ( -i/8 ). Is it the anti-symmetric combination? int lvol = _Umu._grid->lSites(); int DimRep = Impl::Dimension; @@ -109,7 +109,7 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) for (int a = 0; a < DimRep; a++) for (int b = 0; b < DimRep; b++) EigenCloverOp(a + j * DimRep, b + k * DimRep) = Qx()(j, k)(a, b); - //std::cout << EigenCloverOp << std::endl; + // if (site==0) std::cout << "site =" << site << "\n" << EigenCloverOp << std::endl; EigenInvCloverOp = EigenCloverOp.inverse(); @@ -119,6 +119,7 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) for (int a = 0; a < DimRep; a++) for (int b = 0; b < DimRep; b++) Qxinv()(j, k)(a, b) = EigenInvCloverOp(a + j * DimRep, b + k * DimRep); + // if (site==0) std::cout << "site =" << site << "\n" << EigenInvCloverOp << std::endl; pokeLocalSite(Qxinv, CloverTermInv, lcoor); } @@ -127,8 +128,17 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) pickCheckerboard(Even, CloverTermEven, CloverTerm); pickCheckerboard( Odd, CloverTermOdd, CloverTerm); + + pickCheckerboard(Even, CloverTermDagEven, adj(CloverTerm)); + pickCheckerboard( Odd, CloverTermDagOdd, adj(CloverTerm)); + + pickCheckerboard(Even, CloverTermInvEven, CloverTermInv); pickCheckerboard( Odd, CloverTermInvOdd, CloverTermInv); + + + pickCheckerboard(Even, CloverTermInvDagEven, adj(CloverTermInv)); + pickCheckerboard( Odd, CloverTermInvDagOdd, adj(CloverTermInv)); } @@ -142,7 +152,7 @@ void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out) template void WilsonCloverFermion::MooeeDag(const FermionField &in, FermionField &out) { - this->MooeeInternal(in, out, DaggerNo, InverseYes); + this->MooeeInternal(in, out, DaggerYes, InverseNo); } template @@ -154,7 +164,7 @@ void WilsonCloverFermion::MooeeInv(const FermionField &in, FermionField &o template void WilsonCloverFermion::MooeeInvDag(const FermionField &in, FermionField &out) { - this->MooeeInternal(in, out, DaggerNo, InverseYes); + this->MooeeInternal(in, out, DaggerYes, InverseYes); } template @@ -164,26 +174,98 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie CloverFieldType *Clover; assert(in.checkerboard == Odd || in.checkerboard == Even); - if (in._grid->_isCheckerBoarded) - { - if (in.checkerboard == Odd) - { - std::cout << "Calling clover term Odd" << std::endl; - Clover = (inv) ? &CloverTermInvOdd : &CloverTermOdd; + + + + if (dag){ + if (in._grid->_isCheckerBoarded){ + if (in.checkerboard == Odd){ + std::cout << "Calling clover term adj Odd" << std::endl; + Clover = (inv) ? &CloverTermInvDagOdd : &CloverTermDagOdd; + +/* test + int DimRep = Impl::Dimension; + Eigen::MatrixXcd A = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep); + std::vector lcoor; + typename SiteCloverType::scalar_object Qx2 = zero; + GridBase *grid = in._grid; + int site = 0 ; + grid->LocalIndexToLocalCoor(site, lcoor); + peekLocalSite(Qx2, *Clover, lcoor); + for (int j = 0; j < Ns; j++) + for (int k = 0; k < Ns; k++) + for (int a = 0; a < DimRep; a++) + for (int b = 0; b < DimRep; b++) + A(a + j * DimRep, b + k * DimRep) = Qx2()(j, k)(a, b); + std::cout << "adj Odd =" << site << "\n" << A << std::endl; + end test */ + + + + } else { + std::cout << "Calling clover term adj Even" << std::endl; + Clover = (inv) ? &CloverTermInvDagEven : &CloverTermDagEven; + +/* test + int DimRep = Impl::Dimension; + Eigen::MatrixXcd A = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep); + std::vector lcoor; + typename SiteCloverType::scalar_object Qx2 = zero; + GridBase *grid = in._grid; + int site = 0 ; + grid->LocalIndexToLocalCoor(site, lcoor); + peekLocalSite(Qx2, *Clover, lcoor); + for (int j = 0; j < Ns; j++) + for (int k = 0; k < Ns; k++) + for (int a = 0; a < DimRep; a++) + for (int b = 0; b < DimRep; b++) + A(a + j * DimRep, b + k * DimRep) = Qx2()(j, k)(a, b); + std::cout << "adj Odd =" << site << "\n" << A << std::endl; + end test */ + + } - else - { - std::cout << "Calling clover term Even" << std::endl; - Clover = (inv) ? &CloverTermInvEven : &CloverTermEven; - } - } - else - { - Clover = (inv) ? &CloverTermInv : &CloverTerm; + std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; + out = *Clover * in; + } else { + Clover = (inv) ? &CloverTermInv : &CloverTerm; + out = adj(*Clover) * in; } - std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; - if (dag){ out = adj(*Clover) * in;} else { out = *Clover * in;} + + + + } else { + if (in._grid->_isCheckerBoarded){ + + if (in.checkerboard == Odd){ + std::cout << "Calling clover term Odd" << std::endl; + Clover = (inv) ? &CloverTermInvOdd : &CloverTermOdd; + } else { + std::cout << "Calling clover term Even" << std::endl; + Clover = (inv) ? &CloverTermInvEven : &CloverTermEven; + } + out = *Clover * in; + std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; + } else { + Clover = (inv) ? &CloverTermInv : &CloverTerm; + out = *Clover * in; + } + } + + + + + + + +/* + } else { + out = *Clover * in; + } + */ + + } // MooeeInternal // Derivative parts diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index fd9d1f60..e8654513 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -63,7 +63,11 @@ public: CloverTermEven(&Hgrid), CloverTermOdd(&Hgrid), CloverTermInvEven(&Hgrid), - CloverTermInvOdd(&Hgrid) + CloverTermInvOdd(&Hgrid), + CloverTermDagEven(&Hgrid), //test + CloverTermDagOdd(&Hgrid), //test + CloverTermInvDagEven(&Hgrid), //test + CloverTermInvDagOdd(&Hgrid) //test { csw = _csw; assert(Nd == 4); // require 4 dimensions @@ -91,6 +95,11 @@ private: CloverFieldType CloverTerm, CloverTermInv; // Clover term CloverFieldType CloverTermEven, CloverTermOdd; CloverFieldType CloverTermInvEven, CloverTermInvOdd; // Clover term + + CloverFieldType CloverTermInvDagEven, CloverTermInvDagOdd; //test + CloverFieldType CloverTermDagEven, CloverTermDagOdd; //test + + // eventually these two can be compressed into 6x6 blocks instead of the 12x12 // using the DeGrand-Rossi basis for the gamma matrices @@ -149,10 +158,10 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { - T._odata[i]()(0, 1) = timesMinusI(F._odata[i]()()); - T._odata[i]()(1, 0) = timesMinusI(F._odata[i]()()); - T._odata[i]()(2, 3) = timesI(F._odata[i]()()); - T._odata[i]()(3, 2) = timesI(F._odata[i]()()); + T._odata[i]()(0, 1) = timesI(F._odata[i]()()); //fixed + T._odata[i]()(1, 0) = timesI(F._odata[i]()()); //fixed + T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); //fixed + T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); //fixed } return T; @@ -165,10 +174,10 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { - T._odata[i]()(0, 1) = (F._odata[i]()()); - T._odata[i]()(1, 0) = -(F._odata[i]()()); - T._odata[i]()(2, 3) = -(F._odata[i]()()); - T._odata[i]()(3, 2) = (F._odata[i]()()); + T._odata[i]()(0, 1) = -(F._odata[i]()()); //fixed + T._odata[i]()(1, 0) = (F._odata[i]()()); //fixed + T._odata[i]()(2, 3) = (F._odata[i]()()); //fixed + T._odata[i]()(3, 2) = -(F._odata[i]()()); //fixed } return T; @@ -181,10 +190,10 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { - T._odata[i]()(0, 0) = timesMinusI(F._odata[i]()()); - T._odata[i]()(1, 1) = timesI(F._odata[i]()()); - T._odata[i]()(2, 2) = timesI(F._odata[i]()()); - T._odata[i]()(3, 3) = timesMinusI(F._odata[i]()()); + T._odata[i]()(0, 0) = timesI(F._odata[i]()()); //fixed + T._odata[i]()(1, 1) = timesMinusI(F._odata[i]()()); //fixed + T._odata[i]()(2, 2) = timesMinusI(F._odata[i]()()); //fixed + T._odata[i]()(3, 3) = timesI(F._odata[i]()()); //fixed } return T; diff --git a/tests/core/Test_wilson_clover.cc b/tests/core/Test_wilson_clover.cc index 1b208e2d..9e5b246e 100644 --- a/tests/core/Test_wilson_clover.cc +++ b/tests/core/Test_wilson_clover.cc @@ -172,11 +172,6 @@ int main (int argc, char ** argv) std::cout< HermOpEO(Dwc); - HermOpEO.MpcDagMpc(chi_e,dchi_e,t1,t2); - HermOpEO.MpcDagMpc(chi_o,dchi_o,t1,t2); + Dwc.MooeeDag(chi_e,src_e); + Dwc.MooeeInv(src_e,phi_e); - HermOpEO.MpcDagMpc(phi_e,dphi_e,t1,t2); - HermOpEO.MpcDagMpc(phi_o,dphi_o,t1,t2); + Dwc.MooeeDag(chi_o,src_o); + Dwc.MooeeInv(src_o,phi_o); - pDce = innerProduct(phi_e,dchi_e); - pDco = innerProduct(phi_o,dchi_o); - cDpe = innerProduct(chi_e,dphi_e); - cDpo = innerProduct(chi_o,dphi_o); - - std::cout< Date: Fri, 29 Sep 2017 16:09:34 +0100 Subject: [PATCH 065/174] Scalar: SU(N) action change to t'Hooft scaling --- lib/qcd/action/scalar/ScalarInteractionAction.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/qcd/action/scalar/ScalarInteractionAction.h b/lib/qcd/action/scalar/ScalarInteractionAction.h index a681b62c..9d855137 100644 --- a/lib/qcd/action/scalar/ScalarInteractionAction.h +++ b/lib/qcd/action/scalar/ScalarInteractionAction.h @@ -44,8 +44,9 @@ public: INHERIT_FIELD_TYPES(Impl); private: - RealD mass_square; - RealD lambda; + RealD mass_square; + RealD lambda; + const unsigned int N = Impl::Group::Dimension; typedef typename Field::vector_object vobj; typedef CartesianStencil Stencil; @@ -85,8 +86,8 @@ public: static Stencil phiStencil(p._grid, npoint, 0, directions, displacements); phiStencil.HaloExchange(p, compressor); Field action(p._grid), pshift(p._grid), phisquared(p._grid); - phisquared = p * p; - action = (2.0 * Ndim + mass_square) * phisquared - lambda / 24. * phisquared * phisquared; + phisquared = p*p; + action = (2.*Ndim + mass_square) * phisquared - phisquared * phisquared; for (int mu = 0; mu < Ndim; mu++) { // pshift = Cshift(p, mu, +1); // not efficient, implement with stencils @@ -121,13 +122,13 @@ public: } // NB the trace in the algebra is normalised to 1/2 // minus sign coming from the antihermitian fields - return -(TensorRemove(sum(trace(action)))).real(); + return -(TensorRemove(sum(trace(action)))).real()*N/lambda; }; virtual void deriv(const Field &p, Field &force) { assert(p._grid->Nd() == Ndim); - force = (2.0 * Ndim + mass_square) * p - lambda / 12. * p * p * p; + force = (2.0 * Ndim + mass_square) * p - 2. * p * p * p; // move this outside static Stencil phiStencil(p._grid, npoint, 0, directions, displacements); phiStencil.HaloExchange(p, compressor); @@ -162,6 +163,7 @@ public: } } } + force *= N/lambda; } }; From 05c1c88440a9b00c4a35e8487ab92a27afb48aea Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 3 Oct 2017 14:26:20 +0100 Subject: [PATCH 066/174] Scalar: more action generalisation --- lib/qcd/action/scalar/ScalarInteractionAction.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/qcd/action/scalar/ScalarInteractionAction.h b/lib/qcd/action/scalar/ScalarInteractionAction.h index 9d855137..3848751d 100644 --- a/lib/qcd/action/scalar/ScalarInteractionAction.h +++ b/lib/qcd/action/scalar/ScalarInteractionAction.h @@ -46,6 +46,7 @@ public: private: RealD mass_square; RealD lambda; + RealD g; const unsigned int N = Impl::Group::Dimension; typedef typename Field::vector_object vobj; @@ -57,7 +58,7 @@ private: std::vector displacements; // = {1,1,1,1, -1,-1,-1,-1}; public: - ScalarInteractionAction(RealD ms, RealD l) : mass_square(ms), lambda(l), displacements(2 * Ndim, 0), directions(2 * Ndim, 0) + ScalarInteractionAction(RealD ms, RealD l, RealD gval) : mass_square(ms), lambda(l), g(gval), displacements(2 * Ndim, 0), directions(2 * Ndim, 0) { for (int mu = 0; mu < Ndim; mu++) { @@ -73,6 +74,7 @@ public: std::stringstream sstream; sstream << GridLogMessage << "[ScalarAction] lambda : " << lambda << std::endl; sstream << GridLogMessage << "[ScalarAction] mass_square : " << mass_square << std::endl; + sstream << GridLogMessage << "[ScalarAction] g : " << g << std::endl; return sstream.str(); } @@ -86,8 +88,8 @@ public: static Stencil phiStencil(p._grid, npoint, 0, directions, displacements); phiStencil.HaloExchange(p, compressor); Field action(p._grid), pshift(p._grid), phisquared(p._grid); - phisquared = p*p; - action = (2.*Ndim + mass_square) * phisquared - phisquared * phisquared; + phisquared = p * p; + action = (2.0 * Ndim + mass_square) * phisquared - lambda * phisquared * phisquared; for (int mu = 0; mu < Ndim; mu++) { // pshift = Cshift(p, mu, +1); // not efficient, implement with stencils @@ -122,13 +124,13 @@ public: } // NB the trace in the algebra is normalised to 1/2 // minus sign coming from the antihermitian fields - return -(TensorRemove(sum(trace(action)))).real()*N/lambda; + return -(TensorRemove(sum(trace(action)))).real()*N/g; }; virtual void deriv(const Field &p, Field &force) { assert(p._grid->Nd() == Ndim); - force = (2.0 * Ndim + mass_square) * p - 2. * p * p * p; + force = (2. * Ndim + mass_square) * p - 2. * lambda * p * p * p; // move this outside static Stencil phiStencil(p._grid, npoint, 0, directions, displacements); phiStencil.HaloExchange(p, compressor); @@ -163,7 +165,7 @@ public: } } } - force *= N/lambda; + force *= N/g; } }; From 8784f2a88d780c7134574cf452d7c5550bda5769 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 3 Oct 2017 14:38:10 +0100 Subject: [PATCH 067/174] post-merge fix --- lib/communicator/Communicator_none.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/communicator/Communicator_none.cc b/lib/communicator/Communicator_none.cc index c97a181b..40feefec 100644 --- a/lib/communicator/Communicator_none.cc +++ b/lib/communicator/Communicator_none.cc @@ -56,8 +56,6 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) } } -CartesianCommunicator::~CartesianCommunicator() = default; - void CartesianCommunicator::GlobalSum(float &){} void CartesianCommunicator::GlobalSumVector(float *,int N){} void CartesianCommunicator::GlobalSum(double &){} From d38cee73bf1a9cc14bfa0e1f8aefcb2b99bdbb8d Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 3 Oct 2017 17:29:34 +0100 Subject: [PATCH 068/174] Scalar: easier Fourier acceleration parametrisation through -D flags --- lib/qcd/action/scalar/ScalarImpl.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/qcd/action/scalar/ScalarImpl.h b/lib/qcd/action/scalar/ScalarImpl.h index 3dd3cc70..650f4d17 100644 --- a/lib/qcd/action/scalar/ScalarImpl.h +++ b/lib/qcd/action/scalar/ScalarImpl.h @@ -89,13 +89,12 @@ class ScalarImplTypes { }; - - #define USE_FFT_ACCELERATION - #ifdef USE_FFT_ACCELERATION - #define FFT_MASS 0.707 + #ifdef USE_FFT_ACCELERATION + #ifndef FFT_MASS + #error "USE_FFT_ACCELERATION is defined but not FFT_MASS" #endif - - + #endif + template class ScalarAdjMatrixImplTypes { public: From d810e8c8fb765236fadcc23d76daf9a2eb0f3144 Mon Sep 17 00:00:00 2001 From: David Preti Date: Thu, 5 Oct 2017 10:13:53 +0200 Subject: [PATCH 069/174] first attempt to write C terms in clover derivative. Some shifts to be fixed --- lib/perfmon/PerfCount.h | 3 +- lib/perfmon/Stat.cc | 30 ++++---- lib/qcd/action/fermion/WilsonCloverFermion.cc | 75 +++++++++++++++---- 3 files changed, 77 insertions(+), 31 deletions(-) diff --git a/lib/perfmon/PerfCount.h b/lib/perfmon/PerfCount.h index 73d2c70f..cb27c283 100644 --- a/lib/perfmon/PerfCount.h +++ b/lib/perfmon/PerfCount.h @@ -90,9 +90,10 @@ inline uint64_t cyclecount(void){ } #elif defined __x86_64__ inline uint64_t cyclecount(void){ - return __rdtsc(); + //return __rdtsc(); // unsigned int dummy; // return __rdtscp(&dummy); +return 0; // <- remove this; } #else diff --git a/lib/perfmon/Stat.cc b/lib/perfmon/Stat.cc index 3f47fd83..75679412 100644 --- a/lib/perfmon/Stat.cc +++ b/lib/perfmon/Stat.cc @@ -57,35 +57,37 @@ void PmuStat::start(void) pmu_start(); ++count; xmemctrs(&mrstart, &mwstart); - tstart = __rdtsc(); + //tstart = __rdtsc(); +tstart=0; #endif } void PmuStat::enter(int t) { #ifdef __x86_64__ - counters[0][t] = __rdpmc(0); - counters[1][t] = __rdpmc(1); - counters[2][t] = __rdpmc((1<<30)|0); - counters[3][t] = __rdpmc((1<<30)|1); - counters[4][t] = __rdpmc((1<<30)|2); - counters[5][t] = __rdtsc(); + counters[0][t] = 0;//__rdpmc(0); + counters[1][t] = 0;//__rdpmc(1); + counters[2][t] = 0;//__rdpmc((1<<30)|0); + counters[3][t] = 0;//__rdpmc((1<<30)|1); + counters[4][t] = 0;//__rdpmc((1<<30)|2); + counters[5][t] = 0;//__rdtsc(); #endif } void PmuStat::exit(int t) { #ifdef __x86_64__ - counters[0][t] = __rdpmc(0) - counters[0][t]; - counters[1][t] = __rdpmc(1) - counters[1][t]; - counters[2][t] = __rdpmc((1<<30)|0) - counters[2][t]; - counters[3][t] = __rdpmc((1<<30)|1) - counters[3][t]; - counters[4][t] = __rdpmc((1<<30)|2) - counters[4][t]; - counters[5][t] = __rdtsc() - counters[5][t]; + counters[0][t] = 0;//__rdpmc(0) - counters[0][t]; + counters[1][t] = 0;// __rdpmc(1) - counters[1][t]; + counters[2][t] = 0;// __rdpmc((1<<30)|0) - counters[2][t]; + counters[3][t] = 0;// __rdpmc((1<<30)|1) - counters[3][t]; + counters[4][t] = 0;// __rdpmc((1<<30)|2) - counters[4][t]; + counters[5][t] = 0;// __rdtsc() - counters[5][t]; #endif } void PmuStat::accum(int nthreads) { #ifdef __x86_64__ - tend = __rdtsc(); + // tend = __rdtsc(); + tend =0 ; xmemctrs(&mrend, &mwend); pmu_stop(); for (int t = 0; t < nthreads; ++t) { diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 54e72353..bc996ccb 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -253,25 +253,14 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie } } - - - - - - -/* - } else { - out = *Clover * in; - } - */ - - } // MooeeInternal // Derivative parts template void WilsonCloverFermion::MDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) { + + GaugeField tmp(mat._grid); conformable(U._grid, V._grid); @@ -287,10 +276,64 @@ void WilsonCloverFermion::MDeriv(GaugeField &mat, const FermionField &U, c // Derivative parts template -void WilsonCloverFermion::MooDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) +void WilsonCloverFermion::MooDeriv(GaugeField &mat, const FermionField &X, const FermionField &Y, int dag) { - // Compute the 8 terms of the derivative - assert(0); // not implemented yet + +GridBase *grid = mat._grid; + +GaugeLinkField Lambda(grid), tmp(grid); +Lambda = zero; //Y*dag(X)+X*dag(Y); // I have to peek spin and decide the color structure + +conformable(mat._grid, X._grid); +conformable(Y._grid, X._grid); + +std::vector C1p(Nd,grid), C2p(Nd,grid), C3p(Nd,grid), C4p(Nd,grid); +std::vector C1m(Nd,grid), C2m(Nd,grid), C3m(Nd,grid), C4m(Nd,grid); +std::vector U(Nd, mat._grid); + +for (int mu = 0; mu < Nd; mu++) { + U[mu] = PeekIndex(mat, mu); + C1p[mu]=zero; C2p[mu]=zero; C3p[mu]=zero; C4p[mu]=zero; + C1m[mu]=zero; C2m[mu]=zero; C3m[mu]=zero; C4m[mu]=zero; +} + + +for (int mu=0;mu<4;mu++){ + for (int nu=0;nu<4;nu++){ +// insertion in upper staple + tmp = Impl::CovShiftIdentityBackward(Lambda, nu) * U[nu]; + C1p[mu]+= Cshift(Impl::CovShiftForward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, Cshift(U[nu], nu, -1))), mu, 1); + + tmp = Impl::CovShiftIdentityForward(Lambda, mu) * U[mu]; + C2p[mu]+= Cshift(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, Cshift(U[nu], nu, -1))), mu, 1); + + tmp = Impl::CovShiftIdentityForward(Lambda, nu) * U[nu]; + C3p[mu]+= Cshift(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Cshift(tmp, nu, -1))), mu, 1); + + tmp = Lambda; + C4p[mu]+= Cshift(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Cshift(U[nu], nu, -1))),mu,1) * tmp; + +// insertion in lower staple + tmp = Impl::CovShiftIdentityForward(Lambda, nu) * U[nu]; + C1m[mu]+= Cshift(Impl::CovShiftBackward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu, 1); + + tmp = Cshift(Cshift(Lambda, nu, 2),mu, 1) * U[mu]; + C2m[mu]+= Cshift(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, U[nu])), mu ,1); + + tmp = Cshift(Lambda, nu, 2) * U[nu]; + C3m[mu]+= Cshift(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, tmp)), mu, 1); + + tmp = Lambda; + C4m[mu]+= Cshift(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu, 1)* tmp; + } +} + + +//Still implementing. Have to be tested, and understood how to project EO + + + + } // Derivative parts From 15d690e9b9bd79e3ee9b6dae1a12753f131c024f Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 9 Oct 2017 09:59:58 +0100 Subject: [PATCH 070/174] Adding the cartesian communicator destructor --- lib/communicator/Communicator_none.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/communicator/Communicator_none.cc b/lib/communicator/Communicator_none.cc index 40feefec..4b9029d6 100644 --- a/lib/communicator/Communicator_none.cc +++ b/lib/communicator/Communicator_none.cc @@ -56,6 +56,9 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) } } +CartesianCommunicator::~CartesianCommunicator(){} + + void CartesianCommunicator::GlobalSum(float &){} void CartesianCommunicator::GlobalSumVector(float *,int N){} void CartesianCommunicator::GlobalSum(double &){} From 317ddfedee2104de5bfb96d9174dc31542af9797 Mon Sep 17 00:00:00 2001 From: pretidav Date: Mon, 16 Oct 2017 02:47:33 +0200 Subject: [PATCH 071/174] updated test clover + first attempt derivative clove term (still missing spin part) --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 79 +++++---- lib/qcd/action/fermion/WilsonCloverFermion.h | 16 +- tests/core/Test_wilson_clover.cc | 156 ++++++++++++++---- 3 files changed, 180 insertions(+), 71 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index bc996ccb..7f58f277 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -46,7 +46,6 @@ RealD WilsonCloverFermion::M(const FermionField &in, FermionField &out) // apply the sigma and Fmunu FermionField temp(out._grid); Mooee(in, temp); - // overall factor out += temp; return axpy_norm(out, 4 + this->mass, in, out); } @@ -89,6 +88,7 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) CloverTerm += fillCloverZT(Ez); CloverTerm *= 0.5 * csw; // FieldStrength normalization? should be ( -i/8 ). Is it the anti-symmetric combination? + int lvol = _Umu._grid->lSites(); int DimRep = Impl::Dimension; @@ -98,20 +98,21 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) std::vector lcoor; typename SiteCloverType::scalar_object Qx = zero, Qxinv = zero; + for (int site = 0; site < lvol; site++) { grid->LocalIndexToLocalCoor(site, lcoor); EigenCloverOp = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep); peekLocalSite(Qx, CloverTerm, lcoor); Qxinv = zero; +//if (csw!=0){ for (int j = 0; j < Ns; j++) for (int k = 0; k < Ns; k++) for (int a = 0; a < DimRep; a++) for (int b = 0; b < DimRep; b++) EigenCloverOp(a + j * DimRep, b + k * DimRep) = Qx()(j, k)(a, b); - // if (site==0) std::cout << "site =" << site << "\n" << EigenCloverOp << std::endl; - - + // if (site==0) std::cout << "site =" << site << "\n" << EigenCloverOp << std::endl; + EigenInvCloverOp = EigenCloverOp.inverse(); //std::cout << EigenInvCloverOp << std::endl; for (int j = 0; j < Ns; j++) @@ -120,9 +121,11 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) for (int b = 0; b < DimRep; b++) Qxinv()(j, k)(a, b) = EigenInvCloverOp(a + j * DimRep, b + k * DimRep); // if (site==0) std::cout << "site =" << site << "\n" << EigenInvCloverOp << std::endl; - +// } pokeLocalSite(Qxinv, CloverTermInv, lcoor); - } + } + + // Separate the even and odd parts. pickCheckerboard(Even, CloverTermEven, CloverTerm); @@ -180,7 +183,7 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie if (dag){ if (in._grid->_isCheckerBoarded){ if (in.checkerboard == Odd){ - std::cout << "Calling clover term adj Odd" << std::endl; +// std::cout << "Calling clover term adj Odd" << std::endl; Clover = (inv) ? &CloverTermInvDagOdd : &CloverTermDagOdd; /* test @@ -203,7 +206,7 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie } else { - std::cout << "Calling clover term adj Even" << std::endl; +// std::cout << "Calling clover term adj Even" << std::endl; Clover = (inv) ? &CloverTermInvDagEven : &CloverTermDagEven; /* test @@ -225,7 +228,7 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie } - std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; + // std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; out = *Clover * in; } else { Clover = (inv) ? &CloverTermInv : &CloverTerm; @@ -239,14 +242,14 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie if (in._grid->_isCheckerBoarded){ if (in.checkerboard == Odd){ - std::cout << "Calling clover term Odd" << std::endl; + // std::cout << "Calling clover term Odd" << std::endl; Clover = (inv) ? &CloverTermInvOdd : &CloverTermOdd; } else { - std::cout << "Calling clover term Even" << std::endl; + // std::cout << "Calling clover term Even" << std::endl; Clover = (inv) ? &CloverTermInvEven : &CloverTermEven; } out = *Clover * in; - std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; + // std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; } else { Clover = (inv) ? &CloverTermInv : &CloverTerm; out = *Clover * in; @@ -281,8 +284,12 @@ void WilsonCloverFermion::MooDeriv(GaugeField &mat, const FermionField &X, GridBase *grid = mat._grid; +//GaugeLinkField Lambdaodd(grid), Lambdaeven(grid), tmp(grid); +//Lambdaodd = zero; //Yodd*dag(Xodd)+Xodd*dag(Yodd); // I have to peek spin and decide the color structure +//Lambdaeven = zero; //Teven*dag(Xeven)+Xeven*dag(Yeven) + 2*(Dee^-1) + GaugeLinkField Lambda(grid), tmp(grid); -Lambda = zero; //Y*dag(X)+X*dag(Y); // I have to peek spin and decide the color structure +Lambda=zero; conformable(mat._grid, X._grid); conformable(Y._grid, X._grid); @@ -297,37 +304,53 @@ for (int mu = 0; mu < Nd; mu++) { C1m[mu]=zero; C2m[mu]=zero; C3m[mu]=zero; C4m[mu]=zero; } +/* + PARALLEL_FOR_LOOP + for (int i = 0; i < CloverTerm._grid->oSites(); i++) + { + T._odata[i]()(0, 1) = timesMinusI(F._odata[i]()()); + T._odata[i]()(1, 0) = timesMinusI(F._odata[i]()()); + T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); + T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); + } +*/ + +for (int i=0;i<4;i++){ //spin + for(int j=0;j<4;j++){ //spin + +for (int mu=0;mu<4;mu++){ //color + for (int nu=0;nu<4;nu++){ //color -for (int mu=0;mu<4;mu++){ - for (int nu=0;nu<4;nu++){ // insertion in upper staple - tmp = Impl::CovShiftIdentityBackward(Lambda, nu) * U[nu]; - C1p[mu]+= Cshift(Impl::CovShiftForward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, Cshift(U[nu], nu, -1))), mu, 1); + tmp = Lambda * U[nu]; + C1p[mu]+=Impl::ShiftStaple(Impl::CovShiftForward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); - tmp = Impl::CovShiftIdentityForward(Lambda, mu) * U[mu]; - C2p[mu]+= Cshift(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, Cshift(U[nu], nu, -1))), mu, 1); + tmp = Lambda * U[mu]; + C2p[mu]+= Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); tmp = Impl::CovShiftIdentityForward(Lambda, nu) * U[nu]; - C3p[mu]+= Cshift(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Cshift(tmp, nu, -1))), mu, 1); + C3p[mu]+= Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(tmp, nu))), mu); tmp = Lambda; - C4p[mu]+= Cshift(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Cshift(U[nu], nu, -1))),mu,1) * tmp; + C4p[mu]+= Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))),mu) * tmp; // insertion in lower staple - tmp = Impl::CovShiftIdentityForward(Lambda, nu) * U[nu]; - C1m[mu]+= Cshift(Impl::CovShiftBackward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu, 1); + tmp = Lambda * U[nu]; + C1m[mu]+= Impl::ShiftStaple(Impl::CovShiftBackward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu); - tmp = Cshift(Cshift(Lambda, nu, 2),mu, 1) * U[mu]; - C2m[mu]+= Cshift(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, U[nu])), mu ,1); + tmp = Lambda * U[mu]; + C2m[mu]+= Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, U[nu])), mu); - tmp = Cshift(Lambda, nu, 2) * U[nu]; - C3m[mu]+= Cshift(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, tmp)), mu, 1); + tmp = Lambda * U[nu]; + C3m[mu]+= Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, tmp)), mu); tmp = Lambda; - C4m[mu]+= Cshift(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu, 1)* tmp; + C4m[mu]+= Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu)* tmp; } } +} +} //Still implementing. Have to be tested, and understood how to project EO diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index e8654513..7840af90 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -44,7 +44,7 @@ public: INHERIT_IMPL_TYPES(Impl); template using iImplClover = iScalar, Ns> >; typedef iImplClover SiteCloverType; - typedef Lattice CloverFieldType; + typedef Lattice CloverFieldType; public: typedef WilsonFermion WilsonBase; @@ -91,14 +91,12 @@ public: private: // here fixing the 4 dimensions, make it more general? - RealD csw; // Clover coefficient - CloverFieldType CloverTerm, CloverTermInv; // Clover term - CloverFieldType CloverTermEven, CloverTermOdd; - CloverFieldType CloverTermInvEven, CloverTermInvOdd; // Clover term - - CloverFieldType CloverTermInvDagEven, CloverTermInvDagOdd; //test - CloverFieldType CloverTermDagEven, CloverTermDagOdd; //test - + RealD csw; // Clover coefficient + CloverFieldType CloverTerm=zero, CloverTermInv=zero; // Clover term + CloverFieldType CloverTermEven=zero, CloverTermOdd=zero; // Clover term EO + CloverFieldType CloverTermInvEven=zero, CloverTermInvOdd=zero; // Clover term Inv EO + CloverFieldType CloverTermDagEven=zero, CloverTermDagOdd=zero; // Clover term Dag EO + CloverFieldType CloverTermInvDagEven=zero, CloverTermInvDagOdd=zero; // Clover term Inv Dag EO // eventually these two can be compressed into 6x6 blocks instead of the 12x12 // using the DeGrand-Rossi basis for the gamma matrices diff --git a/tests/core/Test_wilson_clover.cc b/tests/core/Test_wilson_clover.cc index 9e5b246e..9a5fffe2 100644 --- a/tests/core/Test_wilson_clover.cc +++ b/tests/core/Test_wilson_clover.cc @@ -55,13 +55,15 @@ int main (int argc, char ** argv) typedef typename WilsonCloverFermionR::FermionField FermionField; typename WilsonCloverFermionR::ImplParams params; - FermionField src (&Grid); random(pRNG,src); - FermionField result(&Grid); result=zero; - FermionField ref(&Grid); ref=zero; - FermionField tmp(&Grid); tmp=zero; - FermionField err(&Grid); tmp=zero; - FermionField phi (&Grid); random(pRNG,phi); - FermionField chi (&Grid); random(pRNG,chi); + FermionField src (&Grid); random(pRNG,src); + FermionField result(&Grid); result=zero; + FermionField result2(&Grid); result2=zero; + FermionField ref(&Grid); ref=zero; + FermionField tmp(&Grid); tmp=zero; + FermionField err(&Grid); err=zero; + FermionField err2(&Grid); err2=zero; + FermionField phi (&Grid); random(pRNG,phi); + FermionField chi (&Grid); random(pRNG,chi); LatticeGaugeField Umu(&Grid); SU3::HotConfiguration(pRNG,Umu); std::vector U(4,&Grid); @@ -71,24 +73,9 @@ int main (int argc, char ** argv) volume=volume*latt_size[mu]; } - // Only one non-zero (y) - for(int mu=0;mu(Umu,mu); - /* Debug force unit - U[mu] = 1.0; - PokeIndex(Umu,U[mu],mu); - */ - } - - ref = zero; - - RealD mass=0.1; + RealD mass= 0.1; RealD csw = 1.0; - { // Simple clover implementation - - // ref = ref + mass * src; - } WilsonCloverFermionR Dwc(Umu,Grid,RBGrid,mass,csw,params); Dwc.ImportGauge(Umu); @@ -176,27 +163,26 @@ int main (int argc, char ** argv) std::cout< seeds2({5,6,7,8}); + GridParallelRNG pRNG2(&Grid); pRNG2.SeedFixedIntegers(seeds2); + LatticeColourMatrix Omega(&Grid); + LatticeColourMatrix ShiftedOmega(&Grid); + LatticeGaugeField U_prime(&Grid); U_prime=zero; + LatticeColourMatrix U_prime_mu(&Grid); U_prime_mu=zero; + SU::LieRandomize(pRNG2, Omega, 1.0); + for (int mu=0;mu Date: Mon, 23 Oct 2017 13:32:26 +0100 Subject: [PATCH 072/174] Changes in the Makefile to compile against Chroma on Linux --- tests/qdpxx/Makefile.am | 3 ++- tests/qdpxx/Makefile.am.qdpxx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/qdpxx/Makefile.am b/tests/qdpxx/Makefile.am index f7f30b85..bbcd0412 100644 --- a/tests/qdpxx/Makefile.am +++ b/tests/qdpxx/Makefile.am @@ -1,4 +1,5 @@ AM_CXXFLAGS += `chroma-config --cxxflags` -AM_LDFLAGS += `chroma-config --ldflags` `chroma-config --libs` +AM_LDFLAGS += `chroma-config --ldflags` +LIBS += `chroma-config --libs` include Make.inc diff --git a/tests/qdpxx/Makefile.am.qdpxx b/tests/qdpxx/Makefile.am.qdpxx index 3ccfa4b8..f212413f 100644 --- a/tests/qdpxx/Makefile.am.qdpxx +++ b/tests/qdpxx/Makefile.am.qdpxx @@ -1,6 +1,7 @@ # additional include paths necessary to compile the C++ library AM_CXXFLAGS = -I$(top_srcdir)/include `chroma-config --cxxflags` -AM_LDFLAGS = -L$(top_builddir)/lib `chroma-config --ldflags` `chroma-config --libs` +AM_LDFLAGS = -L$(top_builddir)/lib `chroma-config --ldflags` +AM_LIBS = `chroma-config --libs` include Make.inc From 6391b2a1d0ae8128dafa25349be754a198b978d3 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 23 Oct 2017 14:42:35 +0100 Subject: [PATCH 073/174] Added test for Wilson and Clover fermions --- .vscode/settings.json | 3 +- tests/qdpxx/Test_qdpxx_wilson.cc | 463 +++++++++++++++++++++++++++++++ 2 files changed, 465 insertions(+), 1 deletion(-) create mode 100644 tests/qdpxx/Test_qdpxx_wilson.cc diff --git a/.vscode/settings.json b/.vscode/settings.json index 3e49029b..f13d503b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -45,6 +45,7 @@ "istream": "cpp", "ostream": "cpp", "sstream": "cpp", - "streambuf": "cpp" + "streambuf": "cpp", + "algorithm": "cpp" } } \ No newline at end of file diff --git a/tests/qdpxx/Test_qdpxx_wilson.cc b/tests/qdpxx/Test_qdpxx_wilson.cc new file mode 100644 index 00000000..70a8b1bf --- /dev/null +++ b/tests/qdpxx/Test_qdpxx_wilson.cc @@ -0,0 +1,463 @@ +/************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./tests/qdpxx/Test_qdpxx_wilson.cc + + Copyright (C) 2017 + + Author: Guido Cossu + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ +/* END LEGAL */ + +#include + +// Mass +double mq = 0.1; + +// Define Wilson Types +typedef Grid::QCD::WilsonImplR::FermionField FermionField; +typedef Grid::QCD::LatticeGaugeField GaugeField; + +#include +#include +#include + +enum ChromaAction +{ + Wilson, // Wilson + WilsonClover // CloverFermions +}; + +void make_gauge(GaugeField &lat, FermionField &src); +void calc_grid(ChromaAction CA, GaugeField &lat, FermionField &src, FermionField &res, int dag); +void calc_chroma(ChromaAction CA, GaugeField &lat, FermionField &src, FermionField &res, int dag); + +namespace Chroma +{ + +class ChromaWrapper +{ +public: + typedef multi1d U; + typedef LatticeFermion T4; + + static void ImportGauge(GaugeField &gr, + QDP::multi1d &ch) + { + Grid::QCD::LorentzColourMatrix LCM; + Grid::Complex cc; + QDP::ColorMatrix cm; + QDP::Complex c; + + std::vector x(4); + QDP::multi1d cx(4); + std::vector gd = gr._grid->GlobalDimensions(); + + for (x[0] = 0; x[0] < gd[0]; x[0]++) + { + for (x[1] = 0; x[1] < gd[1]; x[1]++) + { + for (x[2] = 0; x[2] < gd[2]; x[2]++) + { + for (x[3] = 0; x[3] < gd[3]; x[3]++) + { + cx[0] = x[0]; + cx[1] = x[1]; + cx[2] = x[2]; + cx[3] = x[3]; + Grid::peekSite(LCM, gr, x); + + for (int mu = 0; mu < 4; mu++) + { + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + cc = LCM(mu)()(i, j); + c = QDP::cmplx(QDP::Real(real(cc)), QDP::Real(imag(cc))); + QDP::pokeColor(cm, c, i, j); + } + } + QDP::pokeSite(ch[mu], cm, cx); + } + } + } + } + } + } + + static void ExportGauge(GaugeField &gr, + QDP::multi1d &ch) + { + Grid::QCD::LorentzColourMatrix LCM; + Grid::Complex cc; + QDP::ColorMatrix cm; + QDP::Complex c; + + std::vector x(4); + QDP::multi1d cx(4); + std::vector gd = gr._grid->GlobalDimensions(); + + for (x[0] = 0; x[0] < gd[0]; x[0]++) + { + for (x[1] = 0; x[1] < gd[1]; x[1]++) + { + for (x[2] = 0; x[2] < gd[2]; x[2]++) + { + for (x[3] = 0; x[3] < gd[3]; x[3]++) + { + cx[0] = x[0]; + cx[1] = x[1]; + cx[2] = x[2]; + cx[3] = x[3]; + + for (int mu = 0; mu < 4; mu++) + { + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + cm = QDP::peekSite(ch[mu], cx); + c = QDP::peekColor(cm, i, j); + cc = Grid::Complex(toDouble(real(c)), toDouble(imag(c))); + LCM(mu) + ()(i, j) = cc; + } + } + } + Grid::pokeSite(LCM, gr, x); + } + } + } + } + } + + // Specific for Wilson Fermions + static void ImportFermion(Grid::QCD::LatticeFermion &gr, + QDP::LatticeFermion &ch) + { + Grid::QCD::SpinColourVector F; + Grid::Complex c; + + QDP::Fermion cF; + QDP::SpinVector cS; + QDP::Complex cc; + + std::vector x(4); // explicit 4d fermions in Grid + QDP::multi1d cx(4); + std::vector gd = gr._grid->GlobalDimensions(); + + for (x[0] = 0; x[0] < gd[0]; x[0]++) + { + for (x[1] = 0; x[1] < gd[1]; x[1]++) + { + for (x[2] = 0; x[2] < gd[2]; x[2]++) + { + for (x[3] = 0; x[3] < gd[3]; x[3]++) + { + cx[0] = x[0]; + cx[1] = x[1]; + cx[2] = x[2]; + cx[3] = x[3]; + + Grid::peekSite(F, gr, x); + + for (int j = 0; j < 3; j++) + { + for (int sp = 0; sp < 4; sp++) + { + + c = F()(sp)(j); + + cc = QDP::cmplx(QDP::Real(real(c)), QDP::Real(imag(c))); + + QDP::pokeSpin(cS, cc, sp); + } + QDP::pokeColor(cF, cS, j); + } + QDP::pokeSite(ch, cF, cx); + } + } + } + } + } + + // Specific for 4d Wilson fermions + static void ExportFermion(Grid::QCD::LatticeFermion &gr, + QDP::LatticeFermion &ch) + { + Grid::QCD::SpinColourVector F; + Grid::Complex c; + + QDP::Fermion cF; + QDP::SpinVector cS; + QDP::Complex cc; + + std::vector x(4); // 4d fermions + QDP::multi1d cx(4); + std::vector gd = gr._grid->GlobalDimensions(); + + for (x[0] = 0; x[0] < gd[0]; x[0]++) + { + for (x[1] = 0; x[1] < gd[1]; x[1]++) + { + for (x[2] = 0; x[2] < gd[2]; x[2]++) + { + for (x[3] = 0; x[3] < gd[3]; x[3]++) + { + cx[0] = x[0]; + cx[1] = x[1]; + cx[2] = x[2]; + cx[3] = x[3]; + + cF = QDP::peekSite(ch, cx); + for (int sp = 0; sp < 4; sp++) + { + for (int j = 0; j < 3; j++) + { + cS = QDP::peekColor(cF, j); + cc = QDP::peekSpin(cS, sp); + c = Grid::Complex(QDP::toDouble(QDP::real(cc)), + QDP::toDouble(QDP::imag(cc))); + F() + (sp)(j) = c; + } + } + Grid::pokeSite(F, gr, x); + } + } + } + } + } + + static Handle> GetLinOp(U &u, ChromaAction params) + { + QDP::Real _mq(mq); + QDP::multi1d bcs(QDP::Nd); + + // Boundary conditions + bcs[0] = bcs[1] = bcs[2] = bcs[3] = 1; + + if (params == Wilson) + { + + Chroma::WilsonFermActParams p; + p.Mass = _mq; + + Chroma::Handle> fbc(new Chroma::SimpleFermBC(bcs)); + Chroma::Handle> cfs(new Chroma::CreateSimpleFermState(fbc)); + Chroma::UnprecWilsonFermAct S_f(cfs, p); + Chroma::Handle> ffs(S_f.createState(u)); + return S_f.linOp(ffs); + } + + if (params == WilsonClover) + { + Chroma::CloverFermActParams p; + p.Mass = _mq; + p.clovCoeffR = QDP::Real(1.0); + p.clovCoeffT = QDP::Real(1.0); + Real u0 = QDP::Real(0.0); + + + Chroma::Handle> fbc(new Chroma::SimpleFermBC(bcs)); + Chroma::Handle> cfs(new Chroma::CreateSimpleFermState(fbc)); + Chroma::UnprecCloverFermAct S_f(cfs, p); + Chroma::Handle> ffs(S_f.createState(u)); + return S_f.linOp(ffs); + } + } +}; +} // namespace Chroma + +int main(int argc, char **argv) +{ + + /******************************************************** + * Setup QDP + *********************************************************/ + Chroma::initialize(&argc, &argv); + Chroma::WilsonTypeFermActs4DEnv::registerAll(); + + /******************************************************** + * Setup Grid + *********************************************************/ + Grid::Grid_init(&argc, &argv); + Grid::GridCartesian *UGrid = Grid::QCD::SpaceTimeGrid::makeFourDimGrid(Grid::GridDefaultLatt(), + Grid::GridDefaultSimd(Grid::QCD::Nd, Grid::vComplex::Nsimd()), + Grid::GridDefaultMpi()); + + std::vector gd = UGrid->GlobalDimensions(); + QDP::multi1d nrow(QDP::Nd); + for (int mu = 0; mu < 4; mu++) + nrow[mu] = gd[mu]; + + QDP::Layout::setLattSize(nrow); + QDP::Layout::create(); + + GaugeField Ug(UGrid); + FermionField src(UGrid); + FermionField res_chroma(UGrid); + FermionField res_grid(UGrid); + + std::vector ActionList({Wilson, WilsonClover}); + std::vector ActionName({"Wilson", "WilsonClover"}); + + { + + for (int i = 0; i < ActionList.size(); i++) + { + std::cout << "*****************************" << std::endl; + std::cout << "Action " << ActionName[i] << std::endl; + std::cout << "*****************************" << std::endl; + make_gauge(Ug, src); // fills the gauge field and the fermion field with random numbers + + for (int dag = 0; dag < 2; dag++) + { + + { + + std::cout << "Dag = " << dag << std::endl; + + calc_chroma(ActionList[i], Ug, src, res_chroma, dag); + + // Remove the normalisation of Chroma Gauge links ???????? + std::cout << "Norm of Chroma " << ActionName[i] << " multiply " << Grid::norm2(res_chroma) << std::endl; + calc_grid(ActionList[i], Ug, src, res_grid, dag); + + std::cout << "Norm of gauge " << Grid::norm2(Ug) << std::endl; + + std::cout << "Norm of Grid " << ActionName[i] << " multiply " << Grid::norm2(res_grid) << std::endl; + + res_chroma = res_chroma - res_grid; + std::cout << "Norm of difference " << Grid::norm2(res_chroma) << std::endl; + } + } + + std::cout << "Finished test " << std::endl; + + Chroma::finalize(); + } + } +} + + +void calc_chroma(ChromaAction action, GaugeField &lat, FermionField &src, FermionField &res, int dag) +{ + QDP::multi1d u(4); + Chroma::ChromaWrapper::ImportGauge(lat, u); + + QDP::LatticeFermion check; + QDP::LatticeFermion result; + QDP::LatticeFermion psi; + + Chroma::ChromaWrapper::ImportFermion(src, psi); + + for (int mu = 0; mu < 4; mu++) + { + std::cout << "Imported Gauge norm [" << mu << "] " << QDP::norm2(u[mu]) << std::endl; + } + std::cout << "Imported Fermion norm " << QDP::norm2(psi) << std::endl; + + typedef QDP::LatticeFermion T; + typedef QDP::multi1d U; + + auto linop = Chroma::ChromaWrapper::GetLinOp(u, action); + + printf("Calling Chroma Linop\n"); + fflush(stdout); + + if (dag) + (*linop)(check, psi, Chroma::MINUS); + else + (*linop)(check, psi, Chroma::PLUS); + + printf("Called Chroma Linop\n"); + fflush(stdout); + + // std::cout << "Calling Chroma Linop " << std::endl; + // linop->evenEvenLinOp(tmp, psi, isign); + // check[rb[0]] = tmp; + // linop->oddOddLinOp(tmp, psi, isign); + // check[rb[1]] = tmp; + // linop->evenOddLinOp(tmp, psi, isign); + // check[rb[0]] += tmp; + // linop->oddEvenLinOp(tmp, psi, isign); + // check[rb[1]] += tmp; + + Chroma::ChromaWrapper::ExportFermion(res, check); +} + +void make_gauge(GaugeField &Umu, FermionField &src) +{ + using namespace Grid; + using namespace Grid::QCD; + + std::vector seeds4({1, 2, 3, 4}); + + Grid::GridCartesian *UGrid = (Grid::GridCartesian *)Umu._grid; + Grid::GridParallelRNG RNG4(UGrid); + RNG4.SeedFixedIntegers(seeds4); + Grid::QCD::SU3::HotConfiguration(RNG4, Umu); + Grid::gaussian(RNG4, src); +} + +void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD::LatticeFermion &src, Grid::QCD::LatticeFermion &res, int dag) +{ + using namespace Grid; + using namespace Grid::QCD; + + Grid::GridCartesian *UGrid = (Grid::GridCartesian *)Umu._grid; + Grid::GridRedBlackCartesian *UrbGrid = Grid::QCD::SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); + + Grid::RealD _mass = mq; + + if (action == Wilson) + { + + Grid::QCD::WilsonFermionR Wf(Umu, *UGrid, *UrbGrid, _mass); + + std::cout << Grid::GridLogMessage << " Calling Grid Wilson Fermion multiply " << std::endl; + + if (dag) + Wf.Mdag(src, res); + else + Wf.M(src, res); + return; + } + + if (action == WilsonClover) + { + Grid::RealD _csw = 1.0; + + Grid::QCD::WilsonCloverFermionR Wf(Umu, *UGrid, *UrbGrid, _mass, _csw); + Wf.ImportGauge(Umu); + + std::cout << Grid::GridLogMessage << " Calling Grid Wilson Clover Fermion multiply " << std::endl; + + if (dag) + Wf.Mdag(src, res); + else + Wf.M(src, res); + return; + } + + assert(0); +} From 031c94e02e0644701f4eb2337a2dd684615f29c0 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 23 Oct 2017 18:27:34 +0100 Subject: [PATCH 074/174] Debugging process for the clover term --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 11 ++-- lib/qcd/action/fermion/WilsonCloverFermion.h | 24 ++++----- tests/qdpxx/Test_qdpxx_wilson.cc | 52 +++++++++++++++++-- 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 7f58f277..5e7e0034 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -71,10 +71,10 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) GridBase *grid = _Umu._grid; typename Impl::GaugeLinkField Bx(grid), By(grid), Bz(grid), Ex(grid), Ey(grid), Ez(grid); - // Compute the field strength terms - WilsonLoops::FieldStrength(Bx, _Umu, Ydir, Zdir); + // Compute the field strength terms mu>nu + WilsonLoops::FieldStrength(Bx, _Umu, Zdir, Ydir); WilsonLoops::FieldStrength(By, _Umu, Zdir, Xdir); - WilsonLoops::FieldStrength(Bz, _Umu, Xdir, Ydir); + WilsonLoops::FieldStrength(Bz, _Umu, Ydir, Xdir); WilsonLoops::FieldStrength(Ex, _Umu, Tdir, Xdir); WilsonLoops::FieldStrength(Ey, _Umu, Tdir, Ydir); WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); @@ -86,7 +86,7 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) CloverTerm += fillCloverXT(Ex); CloverTerm += fillCloverYT(Ey); CloverTerm += fillCloverZT(Ez); - CloverTerm *= 0.5 * csw; // FieldStrength normalization? should be ( -i/8 ). Is it the anti-symmetric combination? + CloverTerm *= (0.5) * csw; int lvol = _Umu._grid->lSites(); @@ -232,7 +232,8 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie out = *Clover * in; } else { Clover = (inv) ? &CloverTermInv : &CloverTerm; - out = adj(*Clover) * in; + //out = adj(*Clover) * in; + out = adj(CloverTerm) * in; } diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index 7840af90..18386485 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -156,10 +156,10 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { - T._odata[i]()(0, 1) = timesI(F._odata[i]()()); //fixed - T._odata[i]()(1, 0) = timesI(F._odata[i]()()); //fixed - T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); //fixed - T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); //fixed + T._odata[i]()(0, 1) = timesI(F._odata[i]()()); + T._odata[i]()(1, 0) = timesI(F._odata[i]()()); + T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); + T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); } return T; @@ -172,10 +172,10 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { - T._odata[i]()(0, 1) = -(F._odata[i]()()); //fixed - T._odata[i]()(1, 0) = (F._odata[i]()()); //fixed - T._odata[i]()(2, 3) = (F._odata[i]()()); //fixed - T._odata[i]()(3, 2) = -(F._odata[i]()()); //fixed + T._odata[i]()(0, 1) = -(F._odata[i]()()); + T._odata[i]()(1, 0) = (F._odata[i]()()); + T._odata[i]()(2, 3) = (F._odata[i]()()); + T._odata[i]()(3, 2) = -(F._odata[i]()()); } return T; @@ -188,10 +188,10 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { - T._odata[i]()(0, 0) = timesI(F._odata[i]()()); //fixed - T._odata[i]()(1, 1) = timesMinusI(F._odata[i]()()); //fixed - T._odata[i]()(2, 2) = timesMinusI(F._odata[i]()()); //fixed - T._odata[i]()(3, 3) = timesI(F._odata[i]()()); //fixed + T._odata[i]()(0, 0) = timesI(F._odata[i]()()); + T._odata[i]()(1, 1) = timesMinusI(F._odata[i]()()); + T._odata[i]()(2, 2) = timesMinusI(F._odata[i]()()); + T._odata[i]()(3, 3) = timesI(F._odata[i]()()); } return T; diff --git a/tests/qdpxx/Test_qdpxx_wilson.cc b/tests/qdpxx/Test_qdpxx_wilson.cc index 70a8b1bf..1e1f6a23 100644 --- a/tests/qdpxx/Test_qdpxx_wilson.cc +++ b/tests/qdpxx/Test_qdpxx_wilson.cc @@ -29,7 +29,7 @@ #include // Mass -double mq = 0.1; +double mq = 0.0; // Define Wilson Types typedef Grid::QCD::WilsonImplR::FermionField FermionField; @@ -274,7 +274,7 @@ public: p.Mass = _mq; p.clovCoeffR = QDP::Real(1.0); p.clovCoeffT = QDP::Real(1.0); - Real u0 = QDP::Real(0.0); + Real u0 = QDP::Real(1.0); Chroma::Handle> fbc(new Chroma::SimpleFermBC(bcs)); @@ -316,6 +316,8 @@ int main(int argc, char **argv) FermionField src(UGrid); FermionField res_chroma(UGrid); FermionField res_grid(UGrid); + FermionField only_wilson(UGrid); + FermionField difference(UGrid); std::vector ActionList({Wilson, WilsonClover}); std::vector ActionName({"Wilson", "WilsonClover"}); @@ -346,8 +348,19 @@ int main(int argc, char **argv) std::cout << "Norm of Grid " << ActionName[i] << " multiply " << Grid::norm2(res_grid) << std::endl; - res_chroma = res_chroma - res_grid; - std::cout << "Norm of difference " << Grid::norm2(res_chroma) << std::endl; + difference = res_chroma - res_grid; + std::cout << "Norm of difference " << Grid::norm2(difference) << std::endl; + + // Isolate Clover term + calc_grid(Wilson, Ug, src, only_wilson, dag);// Wilson term + res_grid -= only_wilson; + res_chroma -= only_wilson; + + std::cout << "Chroma:" << res_chroma << std::endl; + std::cout << "Grid :" << res_grid << std::endl; + + + } } @@ -416,7 +429,36 @@ void make_gauge(GaugeField &Umu, FermionField &src) Grid::GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); Grid::QCD::SU3::HotConfiguration(RNG4, Umu); - Grid::gaussian(RNG4, src); + + // Fermion field + //Grid::gaussian(RNG4, src); + Grid::QCD::SpinColourVector F; + Grid::Complex c; + + std::vector x(4); // 4d fermions + std::vector gd = src._grid->GlobalDimensions(); + + for (x[0] = 0; x[0] < gd[0]; x[0]++) + { + for (x[1] = 0; x[1] < gd[1]; x[1]++) + { + for (x[2] = 0; x[2] < gd[2]; x[2]++) + { + for (x[3] = 0; x[3] < gd[3]; x[3]++) + { + for (int sp = 0; sp < 1; sp++) + { + for (int j = 1; j < 2; j++)// colours + { + c = Grid::Complex(1.0, 0.0); + F()(sp)(j) = c; + } + } + Grid::pokeSite(F, src, x); + } + } + } + } } void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD::LatticeFermion &src, Grid::QCD::LatticeFermion &res, int dag) From 6579dd30ff6fd12378c0386d2ca317980586faff Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 23 Oct 2017 18:47:00 +0100 Subject: [PATCH 075/174] More debug test --- tests/qdpxx/Test_qdpxx_wilson.cc | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/tests/qdpxx/Test_qdpxx_wilson.cc b/tests/qdpxx/Test_qdpxx_wilson.cc index 1e1f6a23..8046c00d 100644 --- a/tests/qdpxx/Test_qdpxx_wilson.cc +++ b/tests/qdpxx/Test_qdpxx_wilson.cc @@ -276,7 +276,6 @@ public: p.clovCoeffT = QDP::Real(1.0); Real u0 = QDP::Real(1.0); - Chroma::Handle> fbc(new Chroma::SimpleFermBC(bcs)); Chroma::Handle> cfs(new Chroma::CreateSimpleFermState(fbc)); Chroma::UnprecCloverFermAct S_f(cfs, p); @@ -350,17 +349,16 @@ int main(int argc, char **argv) difference = res_chroma - res_grid; std::cout << "Norm of difference " << Grid::norm2(difference) << std::endl; - + // Isolate Clover term - calc_grid(Wilson, Ug, src, only_wilson, dag);// Wilson term + calc_grid(Wilson, Ug, src, only_wilson, dag); // Wilson term res_grid -= only_wilson; res_chroma -= only_wilson; - + std::cout << "Chroma:" << res_chroma << std::endl; std::cout << "Grid :" << res_grid << std::endl; - - - + difference = (res_grid-res_chroma); + std::cout << "Difference :" << difference << std::endl; } } @@ -371,7 +369,6 @@ int main(int argc, char **argv) } } - void calc_chroma(ChromaAction action, GaugeField &lat, FermionField &src, FermionField &res, int dag) { QDP::multi1d u(4); @@ -429,12 +426,14 @@ void make_gauge(GaugeField &Umu, FermionField &src) Grid::GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); Grid::QCD::SU3::HotConfiguration(RNG4, Umu); - + // Fermion field //Grid::gaussian(RNG4, src); Grid::QCD::SpinColourVector F; Grid::Complex c; + + std::vector x(4); // 4d fermions std::vector gd = src._grid->GlobalDimensions(); @@ -446,15 +445,20 @@ void make_gauge(GaugeField &Umu, FermionField &src) { for (x[3] = 0; x[3] < gd[3]; x[3]++) { - for (int sp = 0; sp < 1; sp++) + for (int sp = 0; sp < 4; sp++) { - for (int j = 1; j < 2; j++)// colours + for (int j = 0; j < 3; j++) // colours { - c = Grid::Complex(1.0, 0.0); - F()(sp)(j) = c; + F()(sp)(j) = Grid::Complex(0.0,0.0); + if (((sp == 0)|| (sp==3)) && (j==0)) + { + c = Grid::Complex(1.0, 0.0); + F()(sp)(j) = c; + } } } Grid::pokeSite(F, src, x); + } } } From cbda4f66e0cdfdcd1405cf6b1c20a8ea55e976ad Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 24 Oct 2017 10:20:13 +0100 Subject: [PATCH 076/174] Debug of the field strength --- lib/qcd/utils/WilsonLoops.h | 4 +++- tests/qdpxx/Test_qdpxx_wilson.cc | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/qcd/utils/WilsonLoops.h b/lib/qcd/utils/WilsonLoops.h index ff49cf4e..fe813298 100644 --- a/lib/qcd/utils/WilsonLoops.h +++ b/lib/qcd/utils/WilsonLoops.h @@ -337,7 +337,9 @@ static void StapleMult(GaugeMat &staple, const GaugeLorentz &Umu, int mu) { GaugeMat v = Vup - Vdn; GaugeMat u = PeekIndex(Umu, mu); // some redundant copies GaugeMat vu = v*u; - FS = 0.25*Ta(u*v + Cshift(vu, mu, -1)); + //FS = 0.25*Ta(u*v + Cshift(vu, mu, -1)); + FS = (u*v + Cshift(vu, mu, -1)); + FS = 0.125*(FS - adj(FS)); } static Real TopologicalCharge(GaugeLorentz &U){ diff --git a/tests/qdpxx/Test_qdpxx_wilson.cc b/tests/qdpxx/Test_qdpxx_wilson.cc index 8046c00d..7e2b3f7e 100644 --- a/tests/qdpxx/Test_qdpxx_wilson.cc +++ b/tests/qdpxx/Test_qdpxx_wilson.cc @@ -351,6 +351,7 @@ int main(int argc, char **argv) std::cout << "Norm of difference " << Grid::norm2(difference) << std::endl; // Isolate Clover term + /* calc_grid(Wilson, Ug, src, only_wilson, dag); // Wilson term res_grid -= only_wilson; res_chroma -= only_wilson; @@ -359,6 +360,7 @@ int main(int argc, char **argv) std::cout << "Grid :" << res_grid << std::endl; difference = (res_grid-res_chroma); std::cout << "Difference :" << difference << std::endl; + */ } } @@ -428,7 +430,8 @@ void make_gauge(GaugeField &Umu, FermionField &src) Grid::QCD::SU3::HotConfiguration(RNG4, Umu); // Fermion field - //Grid::gaussian(RNG4, src); + Grid::gaussian(RNG4, src); + /* Grid::QCD::SpinColourVector F; Grid::Complex c; @@ -450,7 +453,7 @@ void make_gauge(GaugeField &Umu, FermionField &src) for (int j = 0; j < 3; j++) // colours { F()(sp)(j) = Grid::Complex(0.0,0.0); - if (((sp == 0)|| (sp==3)) && (j==0)) + if (((sp == 0)|| (sp==3)) && (j==2)) { c = Grid::Complex(1.0, 0.0); F()(sp)(j) = c; @@ -463,6 +466,8 @@ void make_gauge(GaugeField &Umu, FermionField &src) } } } + */ + } void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD::LatticeFermion &src, Grid::QCD::LatticeFermion &res, int dag) From ec8cd11c1f7fce1c3deee79977745ba4f6c9776c Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 24 Oct 2017 13:21:17 +0100 Subject: [PATCH 077/174] Cleanup and prepare for pull request --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 279 ++++++++---------- lib/qcd/action/fermion/WilsonCloverFermion.h | 104 +++---- tests/core/Test_wilson_clover.cc | 10 +- tests/qdpxx/Test_qdpxx_wilson.cc | 172 +++++------ 4 files changed, 258 insertions(+), 307 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 5e7e0034..73e2bf69 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -39,29 +39,33 @@ namespace QCD template RealD WilsonCloverFermion::M(const FermionField &in, FermionField &out) { + FermionField temp(out._grid); + // Wilson term out.checkerboard = in.checkerboard; this->Dhop(in, out, DaggerNo); + // Clover term - // apply the sigma and Fmunu - FermionField temp(out._grid); Mooee(in, temp); + out += temp; - return axpy_norm(out, 4 + this->mass, in, out); + return norm2(out); } template RealD WilsonCloverFermion::Mdag(const FermionField &in, FermionField &out) { + FermionField temp(out._grid); + // Wilson term out.checkerboard = in.checkerboard; this->Dhop(in, out, DaggerYes); + // Clover term - // apply the sigma and Fmunu - FermionField temp(out._grid); MooeeDag(in, temp); - out+=temp; - return axpy_norm(out, 4 + this->mass, in, out); + + out += temp; + return norm2(out); } template @@ -80,14 +84,14 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); // Compute the Clover Operator acting on Colour and Spin - CloverTerm = fillCloverYZ(Bx); + CloverTerm = fillCloverYZ(Bx); CloverTerm += fillCloverXZ(By); CloverTerm += fillCloverXY(Bz); CloverTerm += fillCloverXT(Ex); CloverTerm += fillCloverYT(Ey); CloverTerm += fillCloverZT(Ez); - CloverTerm *= (0.5) * csw; - + CloverTerm *= (0.5) * csw; + CloverTerm += (4.0 + this->mass); int lvol = _Umu._grid->lSites(); int DimRep = Impl::Dimension; @@ -98,21 +102,20 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) std::vector lcoor; typename SiteCloverType::scalar_object Qx = zero, Qxinv = zero; - for (int site = 0; site < lvol; site++) { grid->LocalIndexToLocalCoor(site, lcoor); EigenCloverOp = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep); peekLocalSite(Qx, CloverTerm, lcoor); Qxinv = zero; -//if (csw!=0){ + //if (csw!=0){ for (int j = 0; j < Ns; j++) for (int k = 0; k < Ns; k++) for (int a = 0; a < DimRep; a++) for (int b = 0; b < DimRep; b++) EigenCloverOp(a + j * DimRep, b + k * DimRep) = Qx()(j, k)(a, b); - // if (site==0) std::cout << "site =" << site << "\n" << EigenCloverOp << std::endl; - + // if (site==0) std::cout << "site =" << site << "\n" << EigenCloverOp << std::endl; + EigenInvCloverOp = EigenCloverOp.inverse(); //std::cout << EigenInvCloverOp << std::endl; for (int j = 0; j < Ns; j++) @@ -120,35 +123,29 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) for (int a = 0; a < DimRep; a++) for (int b = 0; b < DimRep; b++) Qxinv()(j, k)(a, b) = EigenInvCloverOp(a + j * DimRep, b + k * DimRep); - // if (site==0) std::cout << "site =" << site << "\n" << EigenInvCloverOp << std::endl; -// } + // if (site==0) std::cout << "site =" << site << "\n" << EigenInvCloverOp << std::endl; + // } pokeLocalSite(Qxinv, CloverTermInv, lcoor); - } - + } - - // Separate the even and odd parts. + // Separate the even and odd parts pickCheckerboard(Even, CloverTermEven, CloverTerm); - pickCheckerboard( Odd, CloverTermOdd, CloverTerm); - + pickCheckerboard(Odd, CloverTermOdd, CloverTerm); pickCheckerboard(Even, CloverTermDagEven, adj(CloverTerm)); - pickCheckerboard( Odd, CloverTermDagOdd, adj(CloverTerm)); - + pickCheckerboard(Odd, CloverTermDagOdd, adj(CloverTerm)); pickCheckerboard(Even, CloverTermInvEven, CloverTermInv); - pickCheckerboard( Odd, CloverTermInvOdd, CloverTermInv); - + pickCheckerboard(Odd, CloverTermInvOdd, CloverTermInv); pickCheckerboard(Even, CloverTermInvDagEven, adj(CloverTermInv)); - pickCheckerboard( Odd, CloverTermInvDagOdd, adj(CloverTermInv)); - + pickCheckerboard(Odd, CloverTermInvDagOdd, adj(CloverTermInv)); } template void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out) { - conformable(in,out); + conformable(in, out); this->MooeeInternal(in, out, DaggerNo, InverseNo); } @@ -177,85 +174,50 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie CloverFieldType *Clover; assert(in.checkerboard == Odd || in.checkerboard == Even); - - - - if (dag){ - if (in._grid->_isCheckerBoarded){ - if (in.checkerboard == Odd){ -// std::cout << "Calling clover term adj Odd" << std::endl; - Clover = (inv) ? &CloverTermInvDagOdd : &CloverTermDagOdd; - -/* test - int DimRep = Impl::Dimension; - Eigen::MatrixXcd A = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep); - std::vector lcoor; - typename SiteCloverType::scalar_object Qx2 = zero; - GridBase *grid = in._grid; - int site = 0 ; - grid->LocalIndexToLocalCoor(site, lcoor); - peekLocalSite(Qx2, *Clover, lcoor); - for (int j = 0; j < Ns; j++) - for (int k = 0; k < Ns; k++) - for (int a = 0; a < DimRep; a++) - for (int b = 0; b < DimRep; b++) - A(a + j * DimRep, b + k * DimRep) = Qx2()(j, k)(a, b); - std::cout << "adj Odd =" << site << "\n" << A << std::endl; - end test */ - - - - } else { -// std::cout << "Calling clover term adj Even" << std::endl; - Clover = (inv) ? &CloverTermInvDagEven : &CloverTermDagEven; - -/* test - int DimRep = Impl::Dimension; - Eigen::MatrixXcd A = Eigen::MatrixXcd::Zero(Ns * DimRep, Ns * DimRep); - std::vector lcoor; - typename SiteCloverType::scalar_object Qx2 = zero; - GridBase *grid = in._grid; - int site = 0 ; - grid->LocalIndexToLocalCoor(site, lcoor); - peekLocalSite(Qx2, *Clover, lcoor); - for (int j = 0; j < Ns; j++) - for (int k = 0; k < Ns; k++) - for (int a = 0; a < DimRep; a++) - for (int b = 0; b < DimRep; b++) - A(a + j * DimRep, b + k * DimRep) = Qx2()(j, k)(a, b); - std::cout << "adj Odd =" << site << "\n" << A << std::endl; - end test */ - - + if (dag) + { + if (in._grid->_isCheckerBoarded) + { + if (in.checkerboard == Odd) + { + Clover = (inv) ? &CloverTermInvDagOdd : &CloverTermDagOdd; + } + else + { + Clover = (inv) ? &CloverTermInvDagEven : &CloverTermDagEven; + } + out = *Clover * in; + } + else + { + Clover = (inv) ? &CloverTermInv : &CloverTerm; + out = adj(*Clover) * in; } - // std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; - out = *Clover * in; - } else { - Clover = (inv) ? &CloverTermInv : &CloverTerm; - //out = adj(*Clover) * in; - out = adj(CloverTerm) * in; } + else + { + if (in._grid->_isCheckerBoarded) + { - - - - } else { - if (in._grid->_isCheckerBoarded){ - - if (in.checkerboard == Odd){ - // std::cout << "Calling clover term Odd" << std::endl; - Clover = (inv) ? &CloverTermInvOdd : &CloverTermOdd; - } else { - // std::cout << "Calling clover term Even" << std::endl; - Clover = (inv) ? &CloverTermInvEven : &CloverTermEven; - } - out = *Clover * in; - // std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; - } else { - Clover = (inv) ? &CloverTermInv : &CloverTerm; - out = *Clover * in; + if (in.checkerboard == Odd) + { + // std::cout << "Calling clover term Odd" << std::endl; + Clover = (inv) ? &CloverTermInvOdd : &CloverTermOdd; + } + else + { + // std::cout << "Calling clover term Even" << std::endl; + Clover = (inv) ? &CloverTermInvEven : &CloverTermEven; + } + out = *Clover * in; + // std::cout << GridLogMessage << "*Clover.checkerboard " << (*Clover).checkerboard << std::endl; + } + else + { + Clover = (inv) ? &CloverTermInv : &CloverTerm; + out = *Clover * in; + } } - } } // MooeeInternal @@ -264,7 +226,6 @@ template void WilsonCloverFermion::MDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) { - GaugeField tmp(mat._grid); conformable(U._grid, V._grid); @@ -282,30 +243,37 @@ void WilsonCloverFermion::MDeriv(GaugeField &mat, const FermionField &U, c template void WilsonCloverFermion::MooDeriv(GaugeField &mat, const FermionField &X, const FermionField &Y, int dag) { - -GridBase *grid = mat._grid; -//GaugeLinkField Lambdaodd(grid), Lambdaeven(grid), tmp(grid); -//Lambdaodd = zero; //Yodd*dag(Xodd)+Xodd*dag(Yodd); // I have to peek spin and decide the color structure -//Lambdaeven = zero; //Teven*dag(Xeven)+Xeven*dag(Yeven) + 2*(Dee^-1) + GridBase *grid = mat._grid; -GaugeLinkField Lambda(grid), tmp(grid); -Lambda=zero; + //GaugeLinkField Lambdaodd(grid), Lambdaeven(grid), tmp(grid); + //Lambdaodd = zero; //Yodd*dag(Xodd)+Xodd*dag(Yodd); // I have to peek spin and decide the color structure + //Lambdaeven = zero; //Teven*dag(Xeven)+Xeven*dag(Yeven) + 2*(Dee^-1) -conformable(mat._grid, X._grid); -conformable(Y._grid, X._grid); + GaugeLinkField Lambda(grid), tmp(grid); + Lambda = zero; -std::vector C1p(Nd,grid), C2p(Nd,grid), C3p(Nd,grid), C4p(Nd,grid); -std::vector C1m(Nd,grid), C2m(Nd,grid), C3m(Nd,grid), C4m(Nd,grid); -std::vector U(Nd, mat._grid); + conformable(mat._grid, X._grid); + conformable(Y._grid, X._grid); -for (int mu = 0; mu < Nd; mu++) { - U[mu] = PeekIndex(mat, mu); - C1p[mu]=zero; C2p[mu]=zero; C3p[mu]=zero; C4p[mu]=zero; - C1m[mu]=zero; C2m[mu]=zero; C3m[mu]=zero; C4m[mu]=zero; -} + std::vector C1p(Nd, grid), C2p(Nd, grid), C3p(Nd, grid), C4p(Nd, grid); + std::vector C1m(Nd, grid), C2m(Nd, grid), C3m(Nd, grid), C4m(Nd, grid); + std::vector U(Nd, mat._grid); -/* + for (int mu = 0; mu < Nd; mu++) + { + U[mu] = PeekIndex(mat, mu); + C1p[mu] = zero; + C2p[mu] = zero; + C3p[mu] = zero; + C4p[mu] = zero; + C1m[mu] = zero; + C2m[mu] = zero; + C3m[mu] = zero; + C4m[mu] = zero; + } + + /* PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { @@ -314,50 +282,49 @@ for (int mu = 0; mu < Nd; mu++) { T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); } -*/ +*/ -for (int i=0;i<4;i++){ //spin - for(int j=0;j<4;j++){ //spin + for (int i = 0; i < 4; i++) + { //spin + for (int j = 0; j < 4; j++) + { //spin -for (int mu=0;mu<4;mu++){ //color - for (int nu=0;nu<4;nu++){ //color + for (int mu = 0; mu < 4; mu++) + { //color + for (int nu = 0; nu < 4; nu++) + { //color -// insertion in upper staple - tmp = Lambda * U[nu]; - C1p[mu]+=Impl::ShiftStaple(Impl::CovShiftForward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); + // insertion in upper staple + tmp = Lambda * U[nu]; + C1p[mu] += Impl::ShiftStaple(Impl::CovShiftForward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); - tmp = Lambda * U[mu]; - C2p[mu]+= Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); + tmp = Lambda * U[mu]; + C2p[mu] += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); - tmp = Impl::CovShiftIdentityForward(Lambda, nu) * U[nu]; - C3p[mu]+= Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(tmp, nu))), mu); - - tmp = Lambda; - C4p[mu]+= Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))),mu) * tmp; + tmp = Impl::CovShiftIdentityForward(Lambda, nu) * U[nu]; + C3p[mu] += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(tmp, nu))), mu); -// insertion in lower staple - tmp = Lambda * U[nu]; - C1m[mu]+= Impl::ShiftStaple(Impl::CovShiftBackward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu); + tmp = Lambda; + C4p[mu] += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu) * tmp; - tmp = Lambda * U[mu]; - C2m[mu]+= Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, U[nu])), mu); + // insertion in lower staple + tmp = Lambda * U[nu]; + C1m[mu] += Impl::ShiftStaple(Impl::CovShiftBackward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu); - tmp = Lambda * U[nu]; - C3m[mu]+= Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, tmp)), mu); + tmp = Lambda * U[mu]; + C2m[mu] += Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, U[nu])), mu); - tmp = Lambda; - C4m[mu]+= Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu)* tmp; + tmp = Lambda * U[nu]; + C3m[mu] += Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, tmp)), mu); + + tmp = Lambda; + C4m[mu] += Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu) * tmp; + } + } + } } -} - -} -} - -//Still implementing. Have to be tested, and understood how to project EO - - - + //Still implementing. Have to be tested, and understood how to project EO } // Derivative parts diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index 18386485..34482941 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -26,6 +26,7 @@ See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ + #ifndef GRID_QCD_WILSON_CLOVER_FERMION_H #define GRID_QCD_WILSON_CLOVER_FERMION_H @@ -42,9 +43,11 @@ class WilsonCloverFermion : public WilsonFermion public: // Types definitions INHERIT_IMPL_TYPES(Impl); - template using iImplClover = iScalar, Ns> >; - typedef iImplClover SiteCloverType; - typedef Lattice CloverFieldType; + template + using iImplClover = iScalar, Ns>>; + typedef iImplClover SiteCloverType; + typedef Lattice CloverFieldType; + public: typedef WilsonFermion WilsonBase; @@ -58,19 +61,21 @@ public: Fgrid, Hgrid, _mass, p), - CloverTerm(&Fgrid), - CloverTermInv(&Fgrid), - CloverTermEven(&Hgrid), - CloverTermOdd(&Hgrid), - CloverTermInvEven(&Hgrid), - CloverTermInvOdd(&Hgrid), - CloverTermDagEven(&Hgrid), //test - CloverTermDagOdd(&Hgrid), //test - CloverTermInvDagEven(&Hgrid), //test - CloverTermInvDagOdd(&Hgrid) //test + CloverTerm(&Fgrid), + CloverTermInv(&Fgrid), + CloverTermEven(&Hgrid), + CloverTermOdd(&Hgrid), + CloverTermInvEven(&Hgrid), + CloverTermInvOdd(&Hgrid), + CloverTermDagEven(&Hgrid), + CloverTermDagOdd(&Hgrid), + CloverTermInvDagEven(&Hgrid), + CloverTermInvDagOdd(&Hgrid) { csw = _csw; assert(Nd == 4); // require 4 dimensions + + if (csw == 0) std::cout << GridLogWarning << "Initializing WilsonCloverFermion with csw = 0" << std::endl; } virtual RealD M(const FermionField &in, FermionField &out); @@ -91,12 +96,12 @@ public: private: // here fixing the 4 dimensions, make it more general? - RealD csw; // Clover coefficient - CloverFieldType CloverTerm=zero, CloverTermInv=zero; // Clover term - CloverFieldType CloverTermEven=zero, CloverTermOdd=zero; // Clover term EO - CloverFieldType CloverTermInvEven=zero, CloverTermInvOdd=zero; // Clover term Inv EO - CloverFieldType CloverTermDagEven=zero, CloverTermDagOdd=zero; // Clover term Dag EO - CloverFieldType CloverTermInvDagEven=zero, CloverTermInvDagOdd=zero; // Clover term Inv Dag EO + RealD csw; // Clover coefficient + CloverFieldType CloverTerm, CloverTermInv; // Clover term + CloverFieldType CloverTermEven, CloverTermOdd; // Clover term EO + CloverFieldType CloverTermInvEven, CloverTermInvOdd; // Clover term Inv EO + CloverFieldType CloverTermDagEven, CloverTermDagOdd; // Clover term Dag EO + CloverFieldType CloverTermInvDagEven, CloverTermInvDagOdd; // Clover term Inv Dag EO // eventually these two can be compressed into 6x6 blocks instead of the 12x12 // using the DeGrand-Rossi basis for the gamma matrices @@ -113,9 +118,9 @@ private: T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); } - - return T; -} + + return T; + } CloverFieldType fillCloverXZ(const GaugeLinkField &F) { @@ -129,9 +134,9 @@ private: T._odata[i]()(2, 3) = -F._odata[i]()(); T._odata[i]()(3, 2) = F._odata[i]()(); } - - return T; -} + + return T; + } CloverFieldType fillCloverXY(const GaugeLinkField &F) { @@ -145,9 +150,9 @@ private: T._odata[i]()(2, 2) = timesMinusI(F._odata[i]()()); T._odata[i]()(3, 3) = timesI(F._odata[i]()()); } - - return T; -} + + return T; + } CloverFieldType fillCloverXT(const GaugeLinkField &F) { @@ -156,14 +161,14 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { - T._odata[i]()(0, 1) = timesI(F._odata[i]()()); - T._odata[i]()(1, 0) = timesI(F._odata[i]()()); - T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); - T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); + T._odata[i]()(0, 1) = timesI(F._odata[i]()()); + T._odata[i]()(1, 0) = timesI(F._odata[i]()()); + T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); + T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); } - - return T; -} + + return T; + } CloverFieldType fillCloverYT(const GaugeLinkField &F) { @@ -172,14 +177,14 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { - T._odata[i]()(0, 1) = -(F._odata[i]()()); - T._odata[i]()(1, 0) = (F._odata[i]()()); - T._odata[i]()(2, 3) = (F._odata[i]()()); - T._odata[i]()(3, 2) = -(F._odata[i]()()); + T._odata[i]()(0, 1) = -(F._odata[i]()()); + T._odata[i]()(1, 0) = (F._odata[i]()()); + T._odata[i]()(2, 3) = (F._odata[i]()()); + T._odata[i]()(3, 2) = -(F._odata[i]()()); } - - return T; -} + + return T; + } CloverFieldType fillCloverZT(const GaugeLinkField &F) { @@ -188,17 +193,16 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { - T._odata[i]()(0, 0) = timesI(F._odata[i]()()); - T._odata[i]()(1, 1) = timesMinusI(F._odata[i]()()); - T._odata[i]()(2, 2) = timesMinusI(F._odata[i]()()); - T._odata[i]()(3, 3) = timesI(F._odata[i]()()); + T._odata[i]()(0, 0) = timesI(F._odata[i]()()); + T._odata[i]()(1, 1) = timesMinusI(F._odata[i]()()); + T._odata[i]()(2, 2) = timesMinusI(F._odata[i]()()); + T._odata[i]()(3, 3) = timesI(F._odata[i]()()); } - - return T; -} + return T; + } }; } } -#endif // GRID_QCD_WILSON_CLOVER_FERMION_H +#endif // GRID_QCD_WILSON_CLOVER_FERMION_H diff --git a/tests/core/Test_wilson_clover.cc b/tests/core/Test_wilson_clover.cc index 9a5fffe2..9a55f6b2 100644 --- a/tests/core/Test_wilson_clover.cc +++ b/tests/core/Test_wilson_clover.cc @@ -237,7 +237,7 @@ int main (int argc, char ** argv) setCheckerboard(src,src_o); - //Gauge Transformation + ////////////////////// Gauge Transformation std::vector seeds2({5,6,7,8}); GridParallelRNG pRNG2(&Grid); pRNG2.SeedFixedIntegers(seeds2); LatticeColourMatrix Omega(&Grid); @@ -251,7 +251,7 @@ int main (int argc, char ** argv) U_prime_mu=Omega*U[mu]*adj(ShiftedOmega); pokeLorentz(U_prime,U_prime_mu,mu); } - + ///////////////// WilsonCloverFermionR Dwc_prime(U_prime,Grid,RBGrid,mass,csw,params); Dwc_prime.ImportGauge(U_prime); @@ -298,7 +298,7 @@ int main (int argc, char ** argv) std::cout< +#include +#include +#include // Mass -double mq = 0.0; +double mq = 0.01; // Define Wilson Types typedef Grid::QCD::WilsonImplR::FermionField FermionField; typedef Grid::QCD::LatticeGaugeField GaugeField; -#include -#include -#include - enum ChromaAction { Wilson, // Wilson WilsonClover // CloverFermions }; -void make_gauge(GaugeField &lat, FermionField &src); -void calc_grid(ChromaAction CA, GaugeField &lat, FermionField &src, FermionField &res, int dag); -void calc_chroma(ChromaAction CA, GaugeField &lat, FermionField &src, FermionField &res, int dag); - namespace Chroma { @@ -286,91 +281,6 @@ public: }; } // namespace Chroma -int main(int argc, char **argv) -{ - - /******************************************************** - * Setup QDP - *********************************************************/ - Chroma::initialize(&argc, &argv); - Chroma::WilsonTypeFermActs4DEnv::registerAll(); - - /******************************************************** - * Setup Grid - *********************************************************/ - Grid::Grid_init(&argc, &argv); - Grid::GridCartesian *UGrid = Grid::QCD::SpaceTimeGrid::makeFourDimGrid(Grid::GridDefaultLatt(), - Grid::GridDefaultSimd(Grid::QCD::Nd, Grid::vComplex::Nsimd()), - Grid::GridDefaultMpi()); - - std::vector gd = UGrid->GlobalDimensions(); - QDP::multi1d nrow(QDP::Nd); - for (int mu = 0; mu < 4; mu++) - nrow[mu] = gd[mu]; - - QDP::Layout::setLattSize(nrow); - QDP::Layout::create(); - - GaugeField Ug(UGrid); - FermionField src(UGrid); - FermionField res_chroma(UGrid); - FermionField res_grid(UGrid); - FermionField only_wilson(UGrid); - FermionField difference(UGrid); - - std::vector ActionList({Wilson, WilsonClover}); - std::vector ActionName({"Wilson", "WilsonClover"}); - - { - - for (int i = 0; i < ActionList.size(); i++) - { - std::cout << "*****************************" << std::endl; - std::cout << "Action " << ActionName[i] << std::endl; - std::cout << "*****************************" << std::endl; - make_gauge(Ug, src); // fills the gauge field and the fermion field with random numbers - - for (int dag = 0; dag < 2; dag++) - { - - { - - std::cout << "Dag = " << dag << std::endl; - - calc_chroma(ActionList[i], Ug, src, res_chroma, dag); - - // Remove the normalisation of Chroma Gauge links ???????? - std::cout << "Norm of Chroma " << ActionName[i] << " multiply " << Grid::norm2(res_chroma) << std::endl; - calc_grid(ActionList[i], Ug, src, res_grid, dag); - - std::cout << "Norm of gauge " << Grid::norm2(Ug) << std::endl; - - std::cout << "Norm of Grid " << ActionName[i] << " multiply " << Grid::norm2(res_grid) << std::endl; - - difference = res_chroma - res_grid; - std::cout << "Norm of difference " << Grid::norm2(difference) << std::endl; - - // Isolate Clover term - /* - calc_grid(Wilson, Ug, src, only_wilson, dag); // Wilson term - res_grid -= only_wilson; - res_chroma -= only_wilson; - - std::cout << "Chroma:" << res_chroma << std::endl; - std::cout << "Grid :" << res_grid << std::endl; - difference = (res_grid-res_chroma); - std::cout << "Difference :" << difference << std::endl; - */ - } - } - - std::cout << "Finished test " << std::endl; - - Chroma::finalize(); - } - } -} - void calc_chroma(ChromaAction action, GaugeField &lat, FermionField &src, FermionField &res, int dag) { QDP::multi1d u(4); @@ -467,7 +377,6 @@ void make_gauge(GaugeField &Umu, FermionField &src) } } */ - } void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD::LatticeFermion &src, Grid::QCD::LatticeFermion &res, int dag) @@ -512,3 +421,76 @@ void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD assert(0); } + +int main(int argc, char **argv) +{ + + /******************************************************** + * Setup QDP + *********************************************************/ + Chroma::initialize(&argc, &argv); + Chroma::WilsonTypeFermActs4DEnv::registerAll(); + + /******************************************************** + * Setup Grid + *********************************************************/ + Grid::Grid_init(&argc, &argv); + Grid::GridCartesian *UGrid = Grid::QCD::SpaceTimeGrid::makeFourDimGrid(Grid::GridDefaultLatt(), + Grid::GridDefaultSimd(Grid::QCD::Nd, Grid::vComplex::Nsimd()), + Grid::GridDefaultMpi()); + + std::vector gd = UGrid->GlobalDimensions(); + QDP::multi1d nrow(QDP::Nd); + for (int mu = 0; mu < 4; mu++) + nrow[mu] = gd[mu]; + + QDP::Layout::setLattSize(nrow); + QDP::Layout::create(); + + GaugeField Ug(UGrid); + FermionField src(UGrid); + FermionField res_chroma(UGrid); + FermionField res_grid(UGrid); + FermionField only_wilson(UGrid); + FermionField difference(UGrid); + + std::vector ActionList({Wilson, WilsonClover}); + std::vector ActionName({"Wilson", "WilsonClover"}); + + { + + for (int i = 0; i < ActionList.size(); i++) + { + std::cout << "*****************************" << std::endl; + std::cout << "Action " << ActionName[i] << std::endl; + std::cout << "*****************************" << std::endl; + make_gauge(Ug, src); // fills the gauge field and the fermion field with random numbers + + for (int dag = 0; dag < 2; dag++) + { + + { + + std::cout << "Dag = " << dag << std::endl; + + calc_chroma(ActionList[i], Ug, src, res_chroma, dag); + + // Remove the normalisation of Chroma Gauge links ???????? + std::cout << "Norm of Chroma " << ActionName[i] << " multiply " << Grid::norm2(res_chroma) << std::endl; + calc_grid(ActionList[i], Ug, src, res_grid, dag); + + std::cout << "Norm of gauge " << Grid::norm2(Ug) << std::endl; + + std::cout << "Norm of Grid " << ActionName[i] << " multiply " << Grid::norm2(res_grid) << std::endl; + + difference = res_chroma - res_grid; + std::cout << "Norm of difference " << Grid::norm2(difference) << std::endl; + } + } + + std::cout << "Finished test " << std::endl; + + Chroma::finalize(); + } + } +} From 657779374be6b8e02ce8eb6452316acc310fdf26 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 24 Oct 2017 13:27:17 +0100 Subject: [PATCH 078/174] Adding vscode to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6b92b1a4..8eccbc7d 100644 --- a/.gitignore +++ b/.gitignore @@ -123,5 +123,6 @@ make-bin-BUCK.sh lib/qcd/spin/gamma-gen/*.h lib/qcd/spin/gamma-gen/*.cc +.vscode/ .vscode/settings.json settings.json From 2986aa76f80f2857d846c0e48f508de8299052a3 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 24 Oct 2017 13:32:02 +0100 Subject: [PATCH 079/174] Restoring Perfcounts --- lib/perfmon/PerfCount.h | 3 +-- lib/perfmon/Stat.cc | 30 ++++++++++++++---------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/perfmon/PerfCount.h b/lib/perfmon/PerfCount.h index cb27c283..73d2c70f 100644 --- a/lib/perfmon/PerfCount.h +++ b/lib/perfmon/PerfCount.h @@ -90,10 +90,9 @@ inline uint64_t cyclecount(void){ } #elif defined __x86_64__ inline uint64_t cyclecount(void){ - //return __rdtsc(); + return __rdtsc(); // unsigned int dummy; // return __rdtscp(&dummy); -return 0; // <- remove this; } #else diff --git a/lib/perfmon/Stat.cc b/lib/perfmon/Stat.cc index 75679412..3f47fd83 100644 --- a/lib/perfmon/Stat.cc +++ b/lib/perfmon/Stat.cc @@ -57,37 +57,35 @@ void PmuStat::start(void) pmu_start(); ++count; xmemctrs(&mrstart, &mwstart); - //tstart = __rdtsc(); -tstart=0; + tstart = __rdtsc(); #endif } void PmuStat::enter(int t) { #ifdef __x86_64__ - counters[0][t] = 0;//__rdpmc(0); - counters[1][t] = 0;//__rdpmc(1); - counters[2][t] = 0;//__rdpmc((1<<30)|0); - counters[3][t] = 0;//__rdpmc((1<<30)|1); - counters[4][t] = 0;//__rdpmc((1<<30)|2); - counters[5][t] = 0;//__rdtsc(); + counters[0][t] = __rdpmc(0); + counters[1][t] = __rdpmc(1); + counters[2][t] = __rdpmc((1<<30)|0); + counters[3][t] = __rdpmc((1<<30)|1); + counters[4][t] = __rdpmc((1<<30)|2); + counters[5][t] = __rdtsc(); #endif } void PmuStat::exit(int t) { #ifdef __x86_64__ - counters[0][t] = 0;//__rdpmc(0) - counters[0][t]; - counters[1][t] = 0;// __rdpmc(1) - counters[1][t]; - counters[2][t] = 0;// __rdpmc((1<<30)|0) - counters[2][t]; - counters[3][t] = 0;// __rdpmc((1<<30)|1) - counters[3][t]; - counters[4][t] = 0;// __rdpmc((1<<30)|2) - counters[4][t]; - counters[5][t] = 0;// __rdtsc() - counters[5][t]; + counters[0][t] = __rdpmc(0) - counters[0][t]; + counters[1][t] = __rdpmc(1) - counters[1][t]; + counters[2][t] = __rdpmc((1<<30)|0) - counters[2][t]; + counters[3][t] = __rdpmc((1<<30)|1) - counters[3][t]; + counters[4][t] = __rdpmc((1<<30)|2) - counters[4][t]; + counters[5][t] = __rdtsc() - counters[5][t]; #endif } void PmuStat::accum(int nthreads) { #ifdef __x86_64__ - // tend = __rdtsc(); - tend =0 ; + tend = __rdtsc(); xmemctrs(&mrend, &mwend); pmu_stop(); for (int t = 0; t < nthreads; ++t) { From 91b8bf061323e5aeb73f84c41345a07447a90e47 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Thu, 26 Oct 2017 18:23:55 +0100 Subject: [PATCH 080/174] Debugging force term --- lib/qcd/action/fermion/FermionOperatorImpl.h | 52 ++++- lib/qcd/action/fermion/WilsonCloverFermion.cc | 30 +-- lib/qcd/action/fermion/WilsonCloverFermion.h | 128 ++++++++++- tests/forces/Test_wilson_force.cc | 7 +- tests/forces/Test_wilsonclover_force.cc | 209 ++++++++++++++++++ 5 files changed, 395 insertions(+), 31 deletions(-) create mode 100644 tests/forces/Test_wilsonclover_force.cc diff --git a/lib/qcd/action/fermion/FermionOperatorImpl.h b/lib/qcd/action/fermion/FermionOperatorImpl.h index 9d24deb2..89bd9a15 100644 --- a/lib/qcd/action/fermion/FermionOperatorImpl.h +++ b/lib/qcd/action/fermion/FermionOperatorImpl.h @@ -254,8 +254,22 @@ namespace QCD { GaugeLinkField link(mat._grid); link = TraceIndex(outerProduct(Btilde,A)); PokeIndex(mat,link,mu); - } + } + + inline void outerProductImpl(PropagatorField &mat, const FermionField &B, const FermionField &A){ + mat = outerProduct(B,A); + } + + inline void TraceSpinImpl(GaugeLinkField &mat, PropagatorField&P) { + mat = TraceIndex(P); + } + inline void extractLinkField(std::vector &mat, DoubledGaugeField &Uds){ + for (int mu = 0; mu < Nd; mu++) + mat[mu] = PeekIndex(Uds, mu); + } + + inline void InsertForce5D(GaugeField &mat, FermionField &Btilde, FermionField Ã,int mu){ int Ls=Btilde._grid->_fdimensions[0]; @@ -373,6 +387,19 @@ class DomainWallVec5dImpl : public PeriodicGaugeImpl< GaugeImplTypes< S,Nrepres assert(0); } + inline void outerProductImpl(PropagatorField &mat, const FermionField &Btilde, const FermionField &A){ + assert(0); + } + + inline void TraceSpinImpl(GaugeLinkField &mat, PropagatorField&P) { + assert(0); + } + + inline void extractLinkField(std::vector &mat, DoubledGaugeField &Uds){ + assert(0); + } + + inline void InsertForce5D(GaugeField &mat, FermionField &Btilde, FermionField Ã, int mu) { assert(0); @@ -611,6 +638,25 @@ class GparityWilsonImpl : public ConjugateGaugeImpl(P); + parallel_for(auto ss = tmp.begin(); ss < tmp.end(); ss++) { + mat[ss]() = tmp[ss](0, 0) + conjugate(tmp[ss](1, 1)); + } + */ + } + + inline void extractLinkField(std::vector &mat, DoubledGaugeField &Uds){ + assert(0); + } + inline void InsertForce5D(GaugeField &mat, FermionField &Btilde, FermionField Ã, int mu) { int Ls = Btilde._grid->_fdimensions[0]; @@ -751,8 +797,8 @@ class StaggeredImpl : public PeriodicGaugeImpl(outerProduct(Btilde,A)); PokeIndex(mat,link,mu); - } - + } + inline void InsertForce5D(GaugeField &mat, FermionField &Btilde, FermionField Ã,int mu){ assert (0); // Must never hit diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 1dd12f52..2159fffc 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -43,11 +43,15 @@ RealD WilsonCloverFermion::M(const FermionField &in, FermionField &out) // Wilson term out.checkerboard = in.checkerboard; - this->Dhop(in, out, DaggerNo); + //this->Dhop(in, out, DaggerNo); // Clover term Mooee(in, temp); + //hack + out = zero; + + out += temp; return norm2(out); } @@ -59,11 +63,14 @@ RealD WilsonCloverFermion::Mdag(const FermionField &in, FermionField &out) // Wilson term out.checkerboard = in.checkerboard; - this->Dhop(in, out, DaggerYes); + //this->Dhop(in, out, DaggerYes); // Clover term MooeeDag(in, temp); + //hack + out = zero; + out += temp; return norm2(out); } @@ -84,7 +91,7 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); // Compute the Clover Operator acting on Colour and Spin - CloverTerm = fillCloverYZ(Bx); + CloverTerm = fillCloverYZ(Bx); CloverTerm += fillCloverXZ(By); CloverTerm += fillCloverXY(Bz); CloverTerm += fillCloverXT(Ex); @@ -223,23 +230,6 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie } // MooeeInternal -// Derivative parts -template -void WilsonCloverFermion::MDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag) -{ - - GaugeField tmp(mat._grid); - - conformable(U._grid, V._grid); - conformable(U._grid, mat._grid); - - mat.checkerboard = U.checkerboard; - tmp.checkerboard = U.checkerboard; - - this->DhopDeriv(mat, U, V, dag); - MooDeriv(tmp, U, V, dag); - mat += tmp; -} // Derivative parts template diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index 34482941..d8a42129 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -67,15 +67,18 @@ public: CloverTermOdd(&Hgrid), CloverTermInvEven(&Hgrid), CloverTermInvOdd(&Hgrid), - CloverTermDagEven(&Hgrid), - CloverTermDagOdd(&Hgrid), - CloverTermInvDagEven(&Hgrid), - CloverTermInvDagOdd(&Hgrid) + CloverTermDagEven(&Hgrid), + CloverTermDagOdd(&Hgrid), + CloverTermInvDagEven(&Hgrid), + CloverTermInvDagOdd(&Hgrid) { csw = _csw; assert(Nd == 4); // require 4 dimensions - if (csw == 0) std::cout << GridLogWarning << "Initializing WilsonCloverFermion with csw = 0" << std::endl; + if (csw == 0) + std::cout << GridLogWarning << "Initializing WilsonCloverFermion with csw = 0" << std::endl; + + ImportGauge(_Umu); } virtual RealD M(const FermionField &in, FermionField &out); @@ -87,16 +90,127 @@ public: virtual void MooeeInvDag(const FermionField &in, FermionField &out); virtual void MooeeInternal(const FermionField &in, FermionField &out, int dag, int inv); - virtual void MDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag); + //virtual void MDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag); virtual void MooDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag); virtual void MeeDeriv(GaugeField &mat, const FermionField &U, const FermionField &V, int dag); void ImportGauge(const GaugeField &_Umu); + // Derivative parts unpreconditioned pseudofermions + void MDeriv(GaugeField &force, const FermionField &X, const FermionField &Y, int dag) + { + conformable(X._grid, Y._grid); + conformable(X._grid, force._grid); + GaugeLinkField force_mu(force._grid), lambda(force._grid); + GaugeField clover_force(force._grid); + PropagatorField Lambda(force._grid); + + // Here we are hitting some performance issues: + // need to extract the components of the DoubledGaugeField + // for each call + // Possible solution + // Create a vector object to store them? (cons: wasting space) + std::vector U(Nd, this->Umu._grid); + + Impl::extractLinkField(U, this->Umu); + + force = zero; + // Derivative of the Wilson hopping term + //this->DhopDeriv(force, X, Y, dag); + + /////////////////////////////////////////////////////////// + // Clover term derivative + /////////////////////////////////////////////////////////// + Impl::outerProductImpl(Lambda, X, Y); + + Gamma::Algebra sigma[] = { + Gamma::Algebra::SigmaXY, + Gamma::Algebra::SigmaXZ, + Gamma::Algebra::SigmaXT, + Gamma::Algebra::MinusSigmaXY, + Gamma::Algebra::SigmaYZ, + Gamma::Algebra::SigmaYT, + Gamma::Algebra::MinusSigmaXZ, + Gamma::Algebra::MinusSigmaYZ, + Gamma::Algebra::SigmaZT, + Gamma::Algebra::MinusSigmaXT, + Gamma::Algebra::MinusSigmaYT, + Gamma::Algebra::MinusSigmaZT}; + + /* + sigma_{\mu \nu}= + | 0 sigma[0] sigma[1] sigma[2] | + | sigma[3] 0 sigma[4] sigma[5] | + | sigma[6] sigma[7] 0 sigma[8] | + | sigma[9] sigma[10] sigma[11] 0 | + */ + + int count = 0; + clover_force = zero; + for (int mu = 0; mu < 4; mu++) + { + force_mu = zero; + for (int nu = 0; nu < 4; nu++) + { + if (mu == nu) continue; + PropagatorField Slambda = Gamma(sigma[count]) * Lambda; + Impl::TraceSpinImpl(lambda, Slambda); //traceSpin + force_mu += Cmunu(U, lambda, mu, nu); + count++; + } + + pokeLorentz(clover_force, U[mu] * force_mu, mu); + } + clover_force *= csw / 8.; + force += clover_force; + } + + // Computing C_{\mu \nu}(x) as in Eq.(B.39) in Zbigniew Sroczynski's PhD thesis + GaugeLinkField Cmunu(std::vector &U, GaugeLinkField &lambda, int mu, int nu) + { + conformable(lambda._grid, U[0]._grid); + GaugeLinkField out(lambda._grid), tmp(lambda._grid); + + // insertion in upper staple + // please check redundancy of shift operations + + // C1+ + tmp = lambda * U[nu]; + out = Impl::ShiftStaple(Impl::CovShiftForward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); + + // C2+ + tmp = U[mu] * Impl::CovShiftIdentityForward(adj(lambda), mu); + out += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); + + // C3+ + tmp = U[nu] * Impl::CovShiftIdentityForward(adj(lambda), nu); + out += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(tmp, nu))), mu); + + // C4+ + out += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu) * lambda; + + // insertion in lower staple + // C1- + out -= Impl::ShiftStaple(lambda, mu) * Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu); + + // C2- + tmp = adj(lambda) * U[nu]; + out -= Impl::ShiftStaple(Impl::CovShiftBackward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu); + + // C3- + tmp = lambda * U[nu]; + out -= Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, tmp)), mu); + + // C4- + out -= Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu) * lambda; + + return out; + } + private: // here fixing the 4 dimensions, make it more general? - RealD csw; // Clover coefficient + RealD csw; // Clover coefficient CloverFieldType CloverTerm, CloverTermInv; // Clover term CloverFieldType CloverTermEven, CloverTermOdd; // Clover term EO CloverFieldType CloverTermInvEven, CloverTermInvOdd; // Clover term Inv EO diff --git a/tests/forces/Test_wilson_force.cc b/tests/forces/Test_wilson_force.cc index 1f34a48a..f834726b 100644 --- a/tests/forces/Test_wilson_force.cc +++ b/tests/forces/Test_wilson_force.cc @@ -50,7 +50,12 @@ int main (int argc, char ** argv) std::vector seeds({1,2,3,4}); GridParallelRNG pRNG(&Grid); - pRNG.SeedFixedIntegers(std::vector({45,12,81,9})); + std::vector vrand(4); + std::srand(std::time(0)); + std::generate(vrand.begin(), vrand.end(), std::rand); + std::cout << GridLogMessage << vrand << std::endl; + pRNG.SeedFixedIntegers(vrand); + //pRNG.SeedFixedIntegers(std::vector({45,12,81,9})); LatticeFermion phi (&Grid); gaussian(pRNG,phi); LatticeFermion Mphi (&Grid); diff --git a/tests/forces/Test_wilsonclover_force.cc b/tests/forces/Test_wilsonclover_force.cc new file mode 100644 index 00000000..c99cfa98 --- /dev/null +++ b/tests/forces/Test_wilsonclover_force.cc @@ -0,0 +1,209 @@ +/************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./tests/Test_wilson_force.cc + + Copyright (C) 2015 + +Author: Peter Boyle + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ +/* END LEGAL */ +#include + +using namespace std; +using namespace Grid; +using namespace Grid::QCD; + +int main(int argc, char **argv) +{ + Grid_init(&argc, &argv); + + std::vector latt_size = GridDefaultLatt(); + std::vector simd_layout = GridDefaultSimd(Nd, vComplex::Nsimd()); + std::vector mpi_layout = GridDefaultMpi(); + + GridCartesian Grid(latt_size, simd_layout, mpi_layout); + GridRedBlackCartesian RBGrid(&Grid); + + int threads = GridThread::GetThreads(); + std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; + + std::vector seeds({1, 2, 3, 4}); + + GridParallelRNG pRNG(&Grid); + std::vector vrand(4); + std::srand(std::time(0)); + std::generate(vrand.begin(), vrand.end(), std::rand); + std::cout << GridLogMessage << vrand << std::endl; + pRNG.SeedFixedIntegers(vrand); + + LatticeFermion phi(&Grid); + gaussian(pRNG, phi); + LatticeFermion Mphi(&Grid); + LatticeFermion MphiPrime(&Grid); + + LatticeGaugeField U(&Grid); + + SU3::HotConfiguration(pRNG,U); + //SU3::ColdConfiguration(pRNG, U); + + //////////////////////////////////// + // Unmodified matrix element + //////////////////////////////////// + RealD mass = -4.0; //kills the diagonal term + Real csw = 1.0; + WilsonCloverFermionR Dw(U, Grid, RBGrid, mass, csw); + + Dw.M(phi, Mphi); + ComplexD S = innerProduct(Mphi, Mphi); // Action : pdag MdagM p + + // get the deriv of phidag MdagM phi with respect to "U" + LatticeGaugeField UdSdU(&Grid); + LatticeGaugeField tmp(&Grid); + + Dw.MDeriv(tmp, Mphi, phi, DaggerNo); UdSdU = tmp; + Dw.MDeriv(tmp, phi, Mphi, DaggerYes); UdSdU += tmp; + // Take the traceless antihermitian component + UdSdU = Ta(UdSdU); + + //////////////////////////////////// + // Modify the gauge field a little + //////////////////////////////////// + RealD dt = 0.0001; + RealD Hmom = 0.0; + RealD Hmomprime = 0.0; + RealD Hmompp = 0.0; + LatticeColourMatrix mommu(&Grid); + LatticeColourMatrix forcemu(&Grid); + LatticeGaugeField mom(&Grid); + LatticeGaugeField Uprime(&Grid); + + for (int mu = 0; mu < Nd; mu++) { + // Traceless antihermitian momentum; gaussian in lie alg + SU3::GaussianFundamentalLieAlgebraMatrix(pRNG, mommu); + Hmom -= real(sum(trace(mommu * mommu))); + PokeIndex(mom, mommu, mu); + } + + parallel_for(int ss=0;ssoSites();ss++){ + for (int mu = 0; mu < Nd; mu++) + Uprime[ss]._internal[mu] = ProjectOnGroup(Exponentiate(mom[ss]._internal[mu], dt, 12) * U[ss]._internal[mu]); + } + + std::cout << GridLogMessage << "Initial mom hamiltonian is " << Hmom << std::endl; + + // New action + Dw.ImportGauge(Uprime); + Dw.M(phi, MphiPrime); + + ComplexD Sprime = innerProduct(MphiPrime, MphiPrime); + + ////////////////////////////////////////////// + // Use derivative to estimate dS + ////////////////////////////////////////////// + + /////////////////////////////////////////////////////// + std::cout << GridLogMessage << "Antihermiticity tests - 1 " << std::endl; + for (int mu = 0; mu < Nd; mu++) + { + mommu = PeekIndex(mom, mu); + std::cout << GridLogMessage << " Mommu " << norm2(mommu) << std::endl; + mommu = mommu + adj(mommu); + std::cout << GridLogMessage << " Test: Mommu + Mommudag " << norm2(mommu) << std::endl; + mommu = PeekIndex(UdSdU, mu); + std::cout << GridLogMessage << " dsdumu " << norm2(mommu) << std::endl; + mommu = mommu + adj(mommu); + std::cout << GridLogMessage << " Test: dsdumu + dag " << norm2(mommu) << std::endl; + std::cout << "" << std::endl; + } + //////////////////////////////////////////////////////// + + LatticeComplex dS(&Grid); + dS = zero; + LatticeComplex dSmom(&Grid); + dSmom = zero; + LatticeComplex dSmom2(&Grid); + dSmom2 = zero; + + + // need for this??? + // ultimately it is just a 2.0 factor in UdSdU + for (int mu = 0; mu < Nd; mu++) + { + mommu = PeekIndex(UdSdU, mu); // P_mu = + mommu = Ta(mommu) * 2.0; // Mom = (P_mu - P_mu^dag) - trace(P_mu - P_mu^dag) + PokeIndex(UdSdU, mommu, mu); // UdSdU_mu = Mom + } + + std::cout << GridLogMessage<< "Antihermiticity tests - 2 " << std::endl; + for (int mu = 0; mu < Nd; mu++) + { + mommu = PeekIndex(mom, mu); + std::cout << GridLogMessage << " Mommu " << norm2(mommu) << std::endl; + mommu = mommu + adj(mommu); + std::cout << GridLogMessage << " Mommu + Mommudag " << norm2(mommu) << std::endl; + mommu = PeekIndex(UdSdU, mu); + std::cout << GridLogMessage << " dsdumu " << norm2(mommu) << std::endl; + mommu = mommu + adj(mommu); + std::cout << GridLogMessage << " dsdumu + dag " << norm2(mommu) << std::endl; + std::cout << "" << std::endl; + } + ///////////////////////////////////////////////////// + + + for (int mu = 0; mu < Nd; mu++) + { + forcemu = PeekIndex(UdSdU, mu); + mommu = PeekIndex(mom, mu); + + // Update PF action density + dS = dS + trace(mommu * forcemu) * dt; + + dSmom = dSmom - trace(mommu * forcemu) * dt; + dSmom2 = dSmom2 - trace(forcemu * forcemu) * (0.25 * dt * dt); + + // Update mom action density + mommu = mommu + forcemu * (dt * 0.5); + + Hmomprime -= real(sum(trace(mommu * mommu))); + } + + ComplexD dSpred = sum(dS); + ComplexD dSm = sum(dSmom); + ComplexD dSm2 = sum(dSmom2); + + std::cout << GridLogMessage << "Initial mom hamiltonian is " << Hmom << std::endl; + std::cout << GridLogMessage << "Final mom hamiltonian is " << Hmomprime << std::endl; + std::cout << GridLogMessage << "Delta mom hamiltonian is " << Hmomprime - Hmom << std::endl; + + std::cout << GridLogMessage << " S " << S << std::endl; + std::cout << GridLogMessage << " Sprime " << Sprime << std::endl; + std::cout << GridLogMessage << "dS " << Sprime - S << std::endl; + std::cout << GridLogMessage << "predict dS " << dSpred << std::endl; + std::cout << GridLogMessage << "dSm " << dSm << std::endl; + std::cout << GridLogMessage << "dSm2" << dSm2 << std::endl; + + std::cout << GridLogMessage << "Total dS " << Hmomprime - Hmom + Sprime - S << std::endl; + + assert(fabs(real(Sprime - S - dSpred)) < 1.0); + + std::cout << GridLogMessage << "Done" << std::endl; + Grid_finalize(); +} From 76bcf6cd8c767b0f3a254b3407b951cdf0782d6d Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Thu, 26 Oct 2017 18:45:41 +0100 Subject: [PATCH 081/174] Deleting vscode settings file --- .vscode/settings.json | 51 ------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index f13d503b..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,51 +0,0 @@ -// Place your settings in this file to overwrite default and user settings. -{ - "files.associations": { - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "csignal": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "array": "cpp", - "atomic": "cpp", - "*.tcc": "cpp", - "chrono": "cpp", - "codecvt": "cpp", - "condition_variable": "cpp", - "cstdint": "cpp", - "exception": "cpp", - "slist": "cpp", - "functional": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "limits": "cpp", - "memory": "cpp", - "mutex": "cpp", - "new": "cpp", - "ratio": "cpp", - "stdexcept": "cpp", - "system_error": "cpp", - "thread": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "typeinfo": "cpp", - "utility": "cpp", - "iostream": "cpp", - "strstream": "cpp", - "complex": "cpp", - "fstream": "cpp", - "iomanip": "cpp", - "istream": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "streambuf": "cpp", - "algorithm": "cpp" - } -} \ No newline at end of file From f941c4ee180aa20b3f3a24a939018357457e5bbf Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Sun, 29 Oct 2017 11:43:33 +0000 Subject: [PATCH 082/174] Clover term force ok --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 9 +- lib/qcd/action/fermion/WilsonCloverFermion.h | 24 ++-- lib/qcd/utils/WilsonLoops.h | 2 +- tests/forces/Test_wilsonclover_force.cc | 118 +++++++++++++++--- 4 files changed, 118 insertions(+), 35 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 2159fffc..e678835a 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -48,10 +48,7 @@ RealD WilsonCloverFermion::M(const FermionField &in, FermionField &out) // Clover term Mooee(in, temp); - //hack - out = zero; - - + out= zero; out += temp; return norm2(out); } @@ -68,9 +65,7 @@ RealD WilsonCloverFermion::Mdag(const FermionField &in, FermionField &out) // Clover term MooeeDag(in, temp); - //hack - out = zero; - + out=zero; out += temp; return norm2(out); } diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index d8a42129..402a9a7e 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -122,6 +122,8 @@ public: // Clover term derivative /////////////////////////////////////////////////////////// Impl::outerProductImpl(Lambda, X, Y); + //std::cout << "Lambda:" << Lambda << std::endl; + Gamma::Algebra sigma[] = { Gamma::Algebra::SigmaXY, @@ -153,16 +155,18 @@ public: for (int nu = 0; nu < 4; nu++) { if (mu == nu) continue; - PropagatorField Slambda = Gamma(sigma[count]) * Lambda; - Impl::TraceSpinImpl(lambda, Slambda); //traceSpin - force_mu += Cmunu(U, lambda, mu, nu); + PropagatorField Slambda = Gamma(sigma[count]) * Lambda; // sigma checked + Impl::TraceSpinImpl(lambda, Slambda); // traceSpin ok + force_mu -= Cmunu(U, lambda, mu, nu); // checked count++; } pokeLorentz(clover_force, U[mu] * force_mu, mu); } - clover_force *= csw / 8.; + clover_force *= csw; force += clover_force; + + } // Computing C_{\mu \nu}(x) as in Eq.(B.39) in Zbigniew Sroczynski's PhD thesis @@ -170,20 +174,19 @@ public: { conformable(lambda._grid, U[0]._grid); GaugeLinkField out(lambda._grid), tmp(lambda._grid); - // insertion in upper staple // please check redundancy of shift operations - + // C1+ tmp = lambda * U[nu]; out = Impl::ShiftStaple(Impl::CovShiftForward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); - + // C2+ - tmp = U[mu] * Impl::CovShiftIdentityForward(adj(lambda), mu); + tmp = U[mu] * Impl::ShiftStaple(adj(lambda), mu); out += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); - + // C3+ - tmp = U[nu] * Impl::CovShiftIdentityForward(adj(lambda), nu); + tmp = U[nu] * Impl::ShiftStaple(adj(lambda), nu); out += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(tmp, nu))), mu); // C4+ @@ -259,6 +262,7 @@ private: PARALLEL_FOR_LOOP for (int i = 0; i < CloverTerm._grid->oSites(); i++) { + T._odata[i]()(0, 0) = timesMinusI(F._odata[i]()()); T._odata[i]()(1, 1) = timesI(F._odata[i]()()); T._odata[i]()(2, 2) = timesMinusI(F._odata[i]()()); diff --git a/lib/qcd/utils/WilsonLoops.h b/lib/qcd/utils/WilsonLoops.h index fe813298..86609ffc 100644 --- a/lib/qcd/utils/WilsonLoops.h +++ b/lib/qcd/utils/WilsonLoops.h @@ -327,7 +327,7 @@ static void StapleMult(GaugeMat &staple, const GaugeLorentz &Umu, int mu) { static void FieldStrength(GaugeMat &FS, const GaugeLorentz &Umu, int mu, int nu){ // Fmn +--<--+ Ut +--<--+ // | | | | - // (x)+-->--+ +-->--+(x) + // (x)+-->--+ +-->--+(x) - h.c. // | | | | // +--<--+ +--<--+ diff --git a/tests/forces/Test_wilsonclover_force.cc b/tests/forces/Test_wilsonclover_force.cc index c99cfa98..82adb8ab 100644 --- a/tests/forces/Test_wilsonclover_force.cc +++ b/tests/forces/Test_wilsonclover_force.cc @@ -1,6 +1,6 @@ /************************************************************************************* - Grid physics library, www.github.com/paboyle/Grid + Grid physics library, www.github.com/paboyle/Grid Source file: ./tests/Test_wilson_force.cc @@ -45,14 +45,17 @@ int main(int argc, char **argv) int threads = GridThread::GetThreads(); std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; - std::vector seeds({1, 2, 3, 4}); + std::vector seeds({1, 2, 30, 50}); GridParallelRNG pRNG(&Grid); + std::vector vrand(4); std::srand(std::time(0)); std::generate(vrand.begin(), vrand.end(), std::rand); std::cout << GridLogMessage << vrand << std::endl; pRNG.SeedFixedIntegers(vrand); + + //pRNG.SeedFixedIntegers(seeds); LatticeFermion phi(&Grid); gaussian(pRNG, phi); @@ -61,16 +64,53 @@ int main(int argc, char **argv) LatticeGaugeField U(&Grid); - SU3::HotConfiguration(pRNG,U); +/* + std::vector x(4); // 4d fermions + std::vector gd = Grid.GlobalDimensions(); + Grid::QCD::SpinColourVector F; + Grid::Complex c; + + phi = zero; + for (x[0] = 0; x[0] < 1; x[0]++) + { + for (x[1] = 0; x[1] < 1; x[1]++) + { + for (x[2] = 0; x[2] < 1; x[2]++) + { + for (x[3] = 0; x[3] < 1; x[3]++) + { + for (int sp = 0; sp < 4; sp++) + { + for (int j = 0; j < 3; j++) // colours + { + F()(sp)(j) = Grid::Complex(0.0,0.0); + if (((sp == 0) && (j==0))) + { + c = Grid::Complex(1.0, 0.0); + F()(sp)(j) = c; + } + } + } + Grid::pokeSite(F, phi, x); + + } + } + } + } +*/ + + std::vector site = {0, 0, 0, 0}; + SU3::HotConfiguration(pRNG, U); //SU3::ColdConfiguration(pRNG, U); + //////////////////////////////////// // Unmodified matrix element //////////////////////////////////// RealD mass = -4.0; //kills the diagonal term Real csw = 1.0; WilsonCloverFermionR Dw(U, Grid, RBGrid, mass, csw); - + Dw.ImportGauge(U); Dw.M(phi, Mphi); ComplexD S = innerProduct(Mphi, Mphi); // Action : pdag MdagM p @@ -78,11 +118,23 @@ int main(int argc, char **argv) LatticeGaugeField UdSdU(&Grid); LatticeGaugeField tmp(&Grid); - Dw.MDeriv(tmp, Mphi, phi, DaggerNo); UdSdU = tmp; - Dw.MDeriv(tmp, phi, Mphi, DaggerYes); UdSdU += tmp; + //////////////////////////////////////////// + Dw.MDeriv(tmp, Mphi, phi, DaggerNo); + UdSdU = tmp; + Dw.MDeriv(tmp, phi, Mphi, DaggerYes); + UdSdU += tmp; + ///////////////////////////////////////////// + // Take the traceless antihermitian component - UdSdU = Ta(UdSdU); - + //UdSdU = Ta(UdSdU); + + //std::cout << UdSdU << std::endl; + //SU3::LatticeAlgebraVector hforce(&Grid); + LatticeColourMatrix mommu(&Grid); + //mommu = PeekIndex(UdSdU, 0); + //SU3::projectOnAlgebra(hforce, mommu); + //std::cout << hforce << std::endl; + //////////////////////////////////// // Modify the gauge field a little //////////////////////////////////// @@ -90,28 +142,63 @@ int main(int argc, char **argv) RealD Hmom = 0.0; RealD Hmomprime = 0.0; RealD Hmompp = 0.0; - LatticeColourMatrix mommu(&Grid); LatticeColourMatrix forcemu(&Grid); LatticeGaugeField mom(&Grid); LatticeGaugeField Uprime(&Grid); + for (int mu = 0; mu < Nd; mu++) { // Traceless antihermitian momentum; gaussian in lie alg SU3::GaussianFundamentalLieAlgebraMatrix(pRNG, mommu); Hmom -= real(sum(trace(mommu * mommu))); PokeIndex(mom, mommu, mu); } + /* + SU3::AlgebraVector h; + SU3::LatticeAlgebraVector hl(&Grid); + h()()(0) = 1.0; + hl = zero; + pokeSite(h, hl, site); + SU3::FundamentalLieAlgebraMatrix(hl, mommu); + mom = zero; + PokeIndex(mom, mommu, 0); + Hmom -= real(sum(trace(mommu * mommu))); + */ + /* parallel_for(int ss=0;ssoSites();ss++){ - for (int mu = 0; mu < Nd; mu++) + for (int mu = 0; mu < Nd; mu++) Uprime[ss]._internal[mu] = ProjectOnGroup(Exponentiate(mom[ss]._internal[mu], dt, 12) * U[ss]._internal[mu]); - } + } +*/ + + for (int mu = 0; mu < Nd; mu++) + { + parallel_for(auto i = mom.begin(); i < mom.end(); i++) + { + Uprime[i](mu) = U[i](mu); + Uprime[i](mu) += mom[i](mu) * U[i](mu) * dt; + Uprime[i](mu) += mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt / 2.0); + Uprime[i](mu) += mom[i](mu) * mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt * dt / 6.0); + Uprime[i](mu) += mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt * dt * dt / 24.0); + Uprime[i](mu) += mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt * dt * dt * dt / 120.0); + Uprime[i](mu) += mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt * dt * dt * dt * dt / 720.0); + } + } std::cout << GridLogMessage << "Initial mom hamiltonian is " << Hmom << std::endl; - + // New action + LatticeGaugeField diff(&Grid); + diff = Uprime - U; + //std::cout << "Diff:" << diff << std::endl; Dw.ImportGauge(Uprime); Dw.M(phi, MphiPrime); + LatticeFermion DiffFermion(&Grid); + DiffFermion = MphiPrime - Mphi; + //std::cout << "DiffFermion:" << DiffFermion << std::endl; + //std::cout << "Mphi:" << Mphi << std::endl; + //std::cout << "MphiPrime:" << MphiPrime << std::endl; ComplexD Sprime = innerProduct(MphiPrime, MphiPrime); @@ -143,16 +230,14 @@ int main(int argc, char **argv) dSmom2 = zero; - // need for this??? - // ultimately it is just a 2.0 factor in UdSdU for (int mu = 0; mu < Nd; mu++) { - mommu = PeekIndex(UdSdU, mu); // P_mu = + mommu = PeekIndex(UdSdU, mu); // P_mu = mommu = Ta(mommu) * 2.0; // Mom = (P_mu - P_mu^dag) - trace(P_mu - P_mu^dag) PokeIndex(UdSdU, mommu, mu); // UdSdU_mu = Mom } - std::cout << GridLogMessage<< "Antihermiticity tests - 2 " << std::endl; + std::cout << GridLogMessage << "Antihermiticity tests - 2 " << std::endl; for (int mu = 0; mu < Nd; mu++) { mommu = PeekIndex(mom, mu); @@ -167,7 +252,6 @@ int main(int argc, char **argv) } ///////////////////////////////////////////////////// - for (int mu = 0; mu < Nd; mu++) { forcemu = PeekIndex(UdSdU, mu); From 749189fd7209181f7923cb77ba8075c0efaf420b Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Sun, 29 Oct 2017 12:03:08 +0000 Subject: [PATCH 083/174] Full clover force correct --- lib/qcd/action/fermion/WilsonCloverFermion.cc | 6 +- lib/qcd/action/fermion/WilsonCloverFermion.h | 2 +- tests/forces/Test_wilsonclover_force.cc | 123 ++---------------- 3 files changed, 15 insertions(+), 116 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index e678835a..fff970a2 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -43,12 +43,11 @@ RealD WilsonCloverFermion::M(const FermionField &in, FermionField &out) // Wilson term out.checkerboard = in.checkerboard; - //this->Dhop(in, out, DaggerNo); + this->Dhop(in, out, DaggerNo); // Clover term Mooee(in, temp); - out= zero; out += temp; return norm2(out); } @@ -60,12 +59,11 @@ RealD WilsonCloverFermion::Mdag(const FermionField &in, FermionField &out) // Wilson term out.checkerboard = in.checkerboard; - //this->Dhop(in, out, DaggerYes); + this->Dhop(in, out, DaggerYes); // Clover term MooeeDag(in, temp); - out=zero; out += temp; return norm2(out); } diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index 402a9a7e..cd13b225 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -116,7 +116,7 @@ public: force = zero; // Derivative of the Wilson hopping term - //this->DhopDeriv(force, X, Y, dag); + this->DhopDeriv(force, X, Y, dag); /////////////////////////////////////////////////////////// // Clover term derivative diff --git a/tests/forces/Test_wilsonclover_force.cc b/tests/forces/Test_wilsonclover_force.cc index 82adb8ab..bcf67be4 100644 --- a/tests/forces/Test_wilsonclover_force.cc +++ b/tests/forces/Test_wilsonclover_force.cc @@ -48,13 +48,12 @@ int main(int argc, char **argv) std::vector seeds({1, 2, 30, 50}); GridParallelRNG pRNG(&Grid); - + std::vector vrand(4); std::srand(std::time(0)); std::generate(vrand.begin(), vrand.end(), std::rand); std::cout << GridLogMessage << vrand << std::endl; pRNG.SeedFixedIntegers(vrand); - //pRNG.SeedFixedIntegers(seeds); LatticeFermion phi(&Grid); @@ -64,50 +63,14 @@ int main(int argc, char **argv) LatticeGaugeField U(&Grid); -/* - std::vector x(4); // 4d fermions - std::vector gd = Grid.GlobalDimensions(); - Grid::QCD::SpinColourVector F; - Grid::Complex c; - - phi = zero; - for (x[0] = 0; x[0] < 1; x[0]++) - { - for (x[1] = 0; x[1] < 1; x[1]++) - { - for (x[2] = 0; x[2] < 1; x[2]++) - { - for (x[3] = 0; x[3] < 1; x[3]++) - { - for (int sp = 0; sp < 4; sp++) - { - for (int j = 0; j < 3; j++) // colours - { - F()(sp)(j) = Grid::Complex(0.0,0.0); - if (((sp == 0) && (j==0))) - { - c = Grid::Complex(1.0, 0.0); - F()(sp)(j) = c; - } - } - } - Grid::pokeSite(F, phi, x); - - } - } - } - } -*/ - std::vector site = {0, 0, 0, 0}; SU3::HotConfiguration(pRNG, U); - //SU3::ColdConfiguration(pRNG, U); - + //SU3::ColdConfiguration(pRNG, U);// Clover term zero //////////////////////////////////// // Unmodified matrix element //////////////////////////////////// - RealD mass = -4.0; //kills the diagonal term + RealD mass = 0.1; Real csw = 1.0; WilsonCloverFermionR Dw(U, Grid, RBGrid, mass, csw); Dw.ImportGauge(U); @@ -125,103 +88,42 @@ int main(int argc, char **argv) UdSdU += tmp; ///////////////////////////////////////////// - // Take the traceless antihermitian component - //UdSdU = Ta(UdSdU); - - //std::cout << UdSdU << std::endl; - //SU3::LatticeAlgebraVector hforce(&Grid); - LatticeColourMatrix mommu(&Grid); - //mommu = PeekIndex(UdSdU, 0); - //SU3::projectOnAlgebra(hforce, mommu); - //std::cout << hforce << std::endl; - //////////////////////////////////// // Modify the gauge field a little //////////////////////////////////// - RealD dt = 0.0001; + RealD dt = 0.00005; RealD Hmom = 0.0; RealD Hmomprime = 0.0; RealD Hmompp = 0.0; + LatticeColourMatrix mommu(&Grid); LatticeColourMatrix forcemu(&Grid); LatticeGaugeField mom(&Grid); LatticeGaugeField Uprime(&Grid); - - for (int mu = 0; mu < Nd; mu++) { + for (int mu = 0; mu < Nd; mu++) + { // Traceless antihermitian momentum; gaussian in lie alg SU3::GaussianFundamentalLieAlgebraMatrix(pRNG, mommu); Hmom -= real(sum(trace(mommu * mommu))); PokeIndex(mom, mommu, mu); - } - /* - SU3::AlgebraVector h; - SU3::LatticeAlgebraVector hl(&Grid); - h()()(0) = 1.0; - hl = zero; - pokeSite(h, hl, site); - SU3::FundamentalLieAlgebraMatrix(hl, mommu); - mom = zero; - PokeIndex(mom, mommu, 0); - Hmom -= real(sum(trace(mommu * mommu))); - */ - /* - parallel_for(int ss=0;ssoSites();ss++){ - for (int mu = 0; mu < Nd; mu++) - Uprime[ss]._internal[mu] = ProjectOnGroup(Exponentiate(mom[ss]._internal[mu], dt, 12) * U[ss]._internal[mu]); - } -*/ - - for (int mu = 0; mu < Nd; mu++) - { - parallel_for(auto i = mom.begin(); i < mom.end(); i++) + parallel_for(int ss = 0; ss < mom._grid->oSites(); ss++) { - Uprime[i](mu) = U[i](mu); - Uprime[i](mu) += mom[i](mu) * U[i](mu) * dt; - Uprime[i](mu) += mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt / 2.0); - Uprime[i](mu) += mom[i](mu) * mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt * dt / 6.0); - Uprime[i](mu) += mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt * dt * dt / 24.0); - Uprime[i](mu) += mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt * dt * dt * dt / 120.0); - Uprime[i](mu) += mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * mom[i](mu) * U[i](mu) * (dt * dt * dt * dt * dt * dt / 720.0); + Uprime[ss]._internal[mu] = ProjectOnGroup(Exponentiate(mom[ss]._internal[mu], dt, 12) * U[ss]._internal[mu]); } } std::cout << GridLogMessage << "Initial mom hamiltonian is " << Hmom << std::endl; // New action - LatticeGaugeField diff(&Grid); - diff = Uprime - U; - //std::cout << "Diff:" << diff << std::endl; Dw.ImportGauge(Uprime); Dw.M(phi, MphiPrime); - LatticeFermion DiffFermion(&Grid); - DiffFermion = MphiPrime - Mphi; - //std::cout << "DiffFermion:" << DiffFermion << std::endl; - //std::cout << "Mphi:" << Mphi << std::endl; - //std::cout << "MphiPrime:" << MphiPrime << std::endl; - ComplexD Sprime = innerProduct(MphiPrime, MphiPrime); ////////////////////////////////////////////// // Use derivative to estimate dS ////////////////////////////////////////////// - /////////////////////////////////////////////////////// - std::cout << GridLogMessage << "Antihermiticity tests - 1 " << std::endl; - for (int mu = 0; mu < Nd; mu++) - { - mommu = PeekIndex(mom, mu); - std::cout << GridLogMessage << " Mommu " << norm2(mommu) << std::endl; - mommu = mommu + adj(mommu); - std::cout << GridLogMessage << " Test: Mommu + Mommudag " << norm2(mommu) << std::endl; - mommu = PeekIndex(UdSdU, mu); - std::cout << GridLogMessage << " dsdumu " << norm2(mommu) << std::endl; - mommu = mommu + adj(mommu); - std::cout << GridLogMessage << " Test: dsdumu + dag " << norm2(mommu) << std::endl; - std::cout << "" << std::endl; - } - //////////////////////////////////////////////////////// - LatticeComplex dS(&Grid); dS = zero; LatticeComplex dSmom(&Grid); @@ -229,7 +131,6 @@ int main(int argc, char **argv) LatticeComplex dSmom2(&Grid); dSmom2 = zero; - for (int mu = 0; mu < Nd; mu++) { mommu = PeekIndex(UdSdU, mu); // P_mu = @@ -237,7 +138,7 @@ int main(int argc, char **argv) PokeIndex(UdSdU, mommu, mu); // UdSdU_mu = Mom } - std::cout << GridLogMessage << "Antihermiticity tests - 2 " << std::endl; + std::cout << GridLogMessage << "Antihermiticity tests" << std::endl; for (int mu = 0; mu < Nd; mu++) { mommu = PeekIndex(mom, mu); @@ -279,8 +180,8 @@ int main(int argc, char **argv) std::cout << GridLogMessage << " S " << S << std::endl; std::cout << GridLogMessage << " Sprime " << Sprime << std::endl; - std::cout << GridLogMessage << "dS " << Sprime - S << std::endl; - std::cout << GridLogMessage << "predict dS " << dSpred << std::endl; + std::cout << GridLogMessage << "dS (S' - S) :" << Sprime - S << std::endl; + std::cout << GridLogMessage << "predict dS (force) :" << dSpred << std::endl; std::cout << GridLogMessage << "dSm " << dSm << std::endl; std::cout << GridLogMessage << "dSm2" << dSm2 << std::endl; From fa5e4add47bfdb2d0c54486ebb99236b9db11326 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 31 Oct 2017 18:20:38 +0000 Subject: [PATCH 084/174] Added support for anisotropy to the WilsonFermion class --- lib/qcd/action/fermion/WilsonFermion.cc | 42 ++++++++++++++++++++----- lib/qcd/action/fermion/WilsonFermion.h | 21 +++++++++++-- tests/qdpxx/Test_qdpxx_wilson.cc | 28 ++++++++++++++--- 3 files changed, 76 insertions(+), 15 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonFermion.cc b/lib/qcd/action/fermion/WilsonFermion.cc index 19f9674d..55ef5a51 100644 --- a/lib/qcd/action/fermion/WilsonFermion.cc +++ b/lib/qcd/action/fermion/WilsonFermion.cc @@ -47,7 +47,8 @@ int WilsonFermionStatic::HandOptDslash; template WilsonFermion::WilsonFermion(GaugeField &_Umu, GridCartesian &Fgrid, GridRedBlackCartesian &Hgrid, RealD _mass, - const ImplParams &p) + const ImplParams &p, + const WilsonAnisotropyCoefficients &anis) : Kernels(p), _grid(&Fgrid), _cbgrid(&Hgrid), @@ -60,16 +61,41 @@ WilsonFermion::WilsonFermion(GaugeField &_Umu, GridCartesian &Fgrid, Umu(&Fgrid), UmuEven(&Hgrid), UmuOdd(&Hgrid), - _tmp(&Hgrid) + _tmp(&Hgrid), + anisotropyCoeff(anis) { // Allocate the required comms buffer ImportGauge(_Umu); + if (anisotropyCoeff.isAnisotropic){ + diag_mass = mass + 1.0 + (Nd-1)*(anisotropyCoeff.nu / anisotropyCoeff.xi_0); + } else { + diag_mass = 4.0 + mass; + } + + } template void WilsonFermion::ImportGauge(const GaugeField &_Umu) { GaugeField HUmu(_Umu._grid); - HUmu = _Umu * (-0.5); + + //Here multiply the anisotropy coefficients + if (anisotropyCoeff.isAnisotropic) + { + + for (int mu = 0; mu < Nd; mu++) + { + GaugeLinkField U_dir = (-0.5)*PeekIndex(_Umu, mu); + if (mu != anisotropyCoeff.t_direction) + U_dir *= (anisotropyCoeff.nu / anisotropyCoeff.xi_0); + + PokeIndex(HUmu, U_dir, mu); + } + } + else + { + HUmu = _Umu * (-0.5); + } Impl::DoubleStore(GaugeGrid(), Umu, HUmu); pickCheckerboard(Even, UmuEven, Umu); pickCheckerboard(Odd, UmuOdd, Umu); @@ -83,14 +109,14 @@ template RealD WilsonFermion::M(const FermionField &in, FermionField &out) { out.checkerboard = in.checkerboard; Dhop(in, out, DaggerNo); - return axpy_norm(out, 4 + mass, in, out); + return axpy_norm(out, diag_mass, in, out); } template RealD WilsonFermion::Mdag(const FermionField &in, FermionField &out) { out.checkerboard = in.checkerboard; Dhop(in, out, DaggerYes); - return axpy_norm(out, 4 + mass, in, out); + return axpy_norm(out, diag_mass, in, out); } template @@ -114,7 +140,7 @@ void WilsonFermion::MeooeDag(const FermionField &in, FermionField &out) { template void WilsonFermion::Mooee(const FermionField &in, FermionField &out) { out.checkerboard = in.checkerboard; - typename FermionField::scalar_type scal(4.0 + mass); + typename FermionField::scalar_type scal(diag_mass); out = scal * in; } @@ -127,7 +153,7 @@ void WilsonFermion::MooeeDag(const FermionField &in, FermionField &out) { template void WilsonFermion::MooeeInv(const FermionField &in, FermionField &out) { out.checkerboard = in.checkerboard; - out = (1.0/(4.0+mass))*in; + out = (1.0/(diag_mass))*in; } template @@ -204,7 +230,7 @@ void WilsonFermion::DerivInternal(StencilImpl &st, DoubledGaugeField &U, FermionField Btilde(B._grid); FermionField Atilde(B._grid); - Atilde = A; + Atilde = A;//redundant st.HaloExchange(B, compressor); diff --git a/lib/qcd/action/fermion/WilsonFermion.h b/lib/qcd/action/fermion/WilsonFermion.h index 50f4f884..7b2b5206 100644 --- a/lib/qcd/action/fermion/WilsonFermion.h +++ b/lib/qcd/action/fermion/WilsonFermion.h @@ -44,6 +44,19 @@ class WilsonFermionStatic { static const int npoint = 8; }; +struct WilsonAnisotropyCoefficients{ + bool isAnisotropic; + int t_direction; + double xi_0; + double nu; + + WilsonAnisotropyCoefficients(): + isAnisotropic(false), + t_direction(Nd-1), + xi_0(1.0), + nu(1.0){} +}; + template class WilsonFermion : public WilsonKernels, public WilsonFermionStatic { public: @@ -117,8 +130,9 @@ class WilsonFermion : public WilsonKernels, public WilsonFermionStatic { // Constructor WilsonFermion(GaugeField &_Umu, GridCartesian &Fgrid, - GridRedBlackCartesian &Hgrid, RealD _mass, - const ImplParams &p = ImplParams()); + GridRedBlackCartesian &Hgrid, RealD _mass, + const ImplParams &p = ImplParams(), + const WilsonAnisotropyCoefficients &anis = WilsonAnisotropyCoefficients() ); // DoubleStore impl dependent void ImportGauge(const GaugeField &_Umu); @@ -130,6 +144,7 @@ class WilsonFermion : public WilsonKernels, public WilsonFermionStatic { // protected: public: RealD mass; + RealD diag_mass; GridBase *_grid; GridBase *_cbgrid; @@ -146,6 +161,8 @@ class WilsonFermion : public WilsonKernels, public WilsonFermionStatic { LebesgueOrder Lebesgue; LebesgueOrder LebesgueEvenOdd; + + WilsonAnisotropyCoefficients anisotropyCoeff; }; typedef WilsonFermion WilsonFermionF; diff --git a/tests/qdpxx/Test_qdpxx_wilson.cc b/tests/qdpxx/Test_qdpxx_wilson.cc index 6e6eb213..a084ebad 100644 --- a/tests/qdpxx/Test_qdpxx_wilson.cc +++ b/tests/qdpxx/Test_qdpxx_wilson.cc @@ -32,7 +32,7 @@ #include // Mass -double mq = 0.02; +double mq = 0.1; // Define Wilson Types typedef Grid::QCD::WilsonImplR::FermionField FermionField; @@ -255,6 +255,12 @@ public: Chroma::WilsonFermActParams p; p.Mass = _mq; + AnisoParam_t _apar; + _apar.anisoP = true; + _apar.t_dir = 3; // in 4d + _apar.xi_0 = 2.0; + _apar.nu = 1.0; + p.anisoParam = _apar; Chroma::Handle> fbc(new Chroma::SimpleFermBC(bcs)); Chroma::Handle> cfs(new Chroma::CreateSimpleFermState(fbc)); @@ -269,7 +275,13 @@ public: p.Mass = _mq; p.clovCoeffR = QDP::Real(1.0); p.clovCoeffT = QDP::Real(1.0); - Real u0 = QDP::Real(1.0); + p.u0 = QDP::Real(1.0); + AnisoParam_t _apar; + _apar.anisoP = false; + _apar.t_dir = 3; // in 4d + _apar.xi_0 = 2.0; + _apar.nu = 1.0; + p.anisoParam = _apar; Chroma::Handle> fbc(new Chroma::SimpleFermBC(bcs)); Chroma::Handle> cfs(new Chroma::CreateSimpleFermState(fbc)); @@ -391,8 +403,13 @@ void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD if (action == Wilson) { - - Grid::QCD::WilsonFermionR Wf(Umu, *UGrid, *UrbGrid, _mass); + WilsonAnisotropyCoefficients anis; + anis.isAnisotropic = true; + anis.t_direction = 3; + anis.xi_0 = 2.0; + anis.nu = 1.0; + WilsonImplParams iParam; + Grid::QCD::WilsonFermionR Wf(Umu, *UGrid, *UrbGrid, _mass, iParam, anis); std::cout << Grid::GridLogMessage << " Calling Grid Wilson Fermion multiply " << std::endl; @@ -406,7 +423,8 @@ void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD if (action == WilsonClover) { Grid::RealD _csw = 1.0; - + WilsonAnisotropyCoefficients anis; + WilsonImplParams implParam; Grid::QCD::WilsonCloverFermionR Wf(Umu, *UGrid, *UrbGrid, _mass, _csw); Wf.ImportGauge(Umu); From 8e057721a91c3d58bb3c076f111504aacb515906 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Wed, 1 Nov 2017 12:50:54 +0000 Subject: [PATCH 085/174] Anisotropic Clover term written and tested --- lib/algorithms/LinearOperator.h | 10 +- lib/qcd/action/fermion/WilsonCloverFermion.cc | 102 +--- lib/qcd/action/fermion/WilsonCloverFermion.h | 116 +++-- lib/qcd/action/fermion/WilsonFermion.h | 9 +- tests/core/Test_wilson_clover.cc | 492 ++++++++++-------- tests/forces/Test_wilsonclover_force.cc | 2 +- .../Test_hmc_EOWilsonCloverFermionGauge.cc | 139 +++++ .../hmc/Test_hmc_WilsonCloverFermionGauge.cc | 126 +++++ tests/qdpxx/Test_qdpxx_wilson.cc | 15 +- 9 files changed, 637 insertions(+), 374 deletions(-) create mode 100644 tests/hmc/Test_hmc_EOWilsonCloverFermionGauge.cc create mode 100644 tests/hmc/Test_hmc_WilsonCloverFermionGauge.cc diff --git a/lib/algorithms/LinearOperator.h b/lib/algorithms/LinearOperator.h index f1b8820e..ee97e96d 100644 --- a/lib/algorithms/LinearOperator.h +++ b/lib/algorithms/LinearOperator.h @@ -183,11 +183,13 @@ namespace Grid { virtual RealD Mpc (const Field &in, Field &out) =0; virtual RealD MpcDag (const Field &in, Field &out) =0; virtual void MpcDagMpc(const Field &in, Field &out,RealD &ni,RealD &no) { - Field tmp(in._grid); + Field tmp(in._grid); + tmp.checkerboard = in.checkerboard; ni=Mpc(in,tmp); no=MpcDag(tmp,out); } virtual void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ + out.checkerboard = in.checkerboard; MpcDagMpc(in,out,n1,n2); } virtual void HermOp(const Field &in, Field &out){ @@ -215,13 +217,15 @@ namespace Grid { public: SchurDiagMooeeOperator (Matrix &Mat): _Mat(Mat){}; virtual RealD Mpc (const Field &in, Field &out) { - Field tmp(in._grid); -// std::cout <<"grid pointers: in._grid="<< in._grid << " out._grid=" << out._grid << " _Mat.Grid=" << _Mat.Grid() << " _Mat.RedBlackGrid=" << _Mat.RedBlackGrid() << std::endl; + Field tmp(in._grid); + tmp.checkerboard = !in.checkerboard; + //std::cout <<"grid pointers: in._grid="<< in._grid << " out._grid=" << out._grid << " _Mat.Grid=" << _Mat.Grid() << " _Mat.RedBlackGrid=" << _Mat.RedBlackGrid() << std::endl; _Mat.Meooe(in,tmp); _Mat.MooeeInv(tmp,out); _Mat.Meooe(out,tmp); + //std::cout << "cb in " << in.checkerboard << " cb out " << out.checkerboard << std::endl; _Mat.Mooee(in,out); return axpy_norm(out,-1.0,tmp,out); } diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index fff970a2..3ec90e06 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -84,14 +84,14 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) WilsonLoops::FieldStrength(Ez, _Umu, Tdir, Zdir); // Compute the Clover Operator acting on Colour and Spin - CloverTerm = fillCloverYZ(Bx); - CloverTerm += fillCloverXZ(By); - CloverTerm += fillCloverXY(Bz); - CloverTerm += fillCloverXT(Ex); - CloverTerm += fillCloverYT(Ey); - CloverTerm += fillCloverZT(Ez); - CloverTerm *= (0.5) * csw; - CloverTerm += (4.0 + this->mass); + // multiply here by the clover coefficients for the anisotropy + CloverTerm = fillCloverYZ(Bx) * csw_r; + CloverTerm += fillCloverXZ(By) * csw_r; + CloverTerm += fillCloverXY(Bz) * csw_r; + CloverTerm += fillCloverXT(Ex) * csw_t; + CloverTerm += fillCloverYT(Ey) * csw_t; + CloverTerm += fillCloverZT(Ez) * csw_t; + CloverTerm += diag_mass; int lvol = _Umu._grid->lSites(); int DimRep = Impl::Dimension; @@ -145,7 +145,6 @@ void WilsonCloverFermion::ImportGauge(const GaugeField &_Umu) template void WilsonCloverFermion::Mooee(const FermionField &in, FermionField &out) { - conformable(in, out); this->MooeeInternal(in, out, DaggerNo, InverseNo); } @@ -158,14 +157,12 @@ void WilsonCloverFermion::MooeeDag(const FermionField &in, FermionField &o template void WilsonCloverFermion::MooeeInv(const FermionField &in, FermionField &out) { - conformable(in,out); this->MooeeInternal(in, out, DaggerNo, InverseYes); } template void WilsonCloverFermion::MooeeInvDag(const FermionField &in, FermionField &out) { - conformable(in,out); this->MooeeInternal(in, out, DaggerYes, InverseYes); } @@ -228,88 +225,7 @@ void WilsonCloverFermion::MooeeInternal(const FermionField &in, FermionFie template void WilsonCloverFermion::MooDeriv(GaugeField &mat, const FermionField &X, const FermionField &Y, int dag) { - - GridBase *grid = mat._grid; - - //GaugeLinkField Lambdaodd(grid), Lambdaeven(grid), tmp(grid); - //Lambdaodd = zero; //Yodd*dag(Xodd)+Xodd*dag(Yodd); // I have to peek spin and decide the color structure - //Lambdaeven = zero; //Teven*dag(Xeven)+Xeven*dag(Yeven) + 2*(Dee^-1) - - GaugeLinkField Lambda(grid), tmp(grid); - Lambda = zero; - - conformable(mat._grid, X._grid); - conformable(Y._grid, X._grid); - - std::vector C1p(Nd, grid), C2p(Nd, grid), C3p(Nd, grid), C4p(Nd, grid); - std::vector C1m(Nd, grid), C2m(Nd, grid), C3m(Nd, grid), C4m(Nd, grid); - std::vector U(Nd, mat._grid); - - for (int mu = 0; mu < Nd; mu++) - { - U[mu] = PeekIndex(mat, mu); - C1p[mu] = zero; - C2p[mu] = zero; - C3p[mu] = zero; - C4p[mu] = zero; - C1m[mu] = zero; - C2m[mu] = zero; - C3m[mu] = zero; - C4m[mu] = zero; - } - - /* - PARALLEL_FOR_LOOP - for (int i = 0; i < CloverTerm._grid->oSites(); i++) - { - T._odata[i]()(0, 1) = timesMinusI(F._odata[i]()()); - T._odata[i]()(1, 0) = timesMinusI(F._odata[i]()()); - T._odata[i]()(2, 3) = timesMinusI(F._odata[i]()()); - T._odata[i]()(3, 2) = timesMinusI(F._odata[i]()()); - } -*/ - - for (int i = 0; i < 4; i++) - { //spin - for (int j = 0; j < 4; j++) - { //spin - - for (int mu = 0; mu < 4; mu++) - { //color - for (int nu = 0; nu < 4; nu++) - { //color - - // insertion in upper staple - tmp = Lambda * U[nu]; - C1p[mu] += Impl::ShiftStaple(Impl::CovShiftForward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); - - tmp = Lambda * U[mu]; - C2p[mu] += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); - - tmp = Impl::CovShiftIdentityForward(Lambda, nu) * U[nu]; - C3p[mu] += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(tmp, nu))), mu); - - tmp = Lambda; - C4p[mu] += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu) * tmp; - - // insertion in lower staple - tmp = Lambda * U[nu]; - C1m[mu] += Impl::ShiftStaple(Impl::CovShiftBackward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu); - - tmp = Lambda * U[mu]; - C2m[mu] += Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, U[nu])), mu); - - tmp = Lambda * U[nu]; - C3m[mu] += Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, tmp)), mu); - - tmp = Lambda; - C4m[mu] += Impl::ShiftStaple(Impl::CovShiftBackward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, U[nu])), mu) * tmp; - } - } - } - } - - //Still implementing. Have to be tested, and understood how to project EO + assert(0); } // Derivative parts diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.h b/lib/qcd/action/fermion/WilsonCloverFermion.h index cd13b225..268564c0 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.h +++ b/lib/qcd/action/fermion/WilsonCloverFermion.h @@ -6,8 +6,8 @@ Copyright (C) 2017 - Author: paboyle Author: Guido Cossu + Author: David Preti <> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,6 +37,22 @@ namespace Grid namespace QCD { +/////////////////////////////////////////////////////////////////// +// Wilson Clover +// +// Operator ( with anisotropy coefficients): +// +// Q = 1 + (Nd-1)/xi_0 + m +// + W_t + (nu/xi_0) * W_s +// - 1/2*[ csw_t * sum_s (sigma_ts F_ts) + (csw_s/xi_0) * sum_ss (sigma_ss F_ss) ] +// +// s spatial, t temporal directions. +// where W_t and W_s are the temporal and spatial components of the +// Wilson Dirac operator +// +// csw_r = csw_t to recover the isotropic version +////////////////////////////////////////////////////////////////// + template class WilsonCloverFermion : public WilsonFermion { @@ -55,28 +71,43 @@ public: // Constructors WilsonCloverFermion(GaugeField &_Umu, GridCartesian &Fgrid, GridRedBlackCartesian &Hgrid, - RealD _mass, - RealD _csw, - const ImplParams &p = ImplParams()) : WilsonFermion(_Umu, - Fgrid, - Hgrid, - _mass, p), - CloverTerm(&Fgrid), - CloverTermInv(&Fgrid), - CloverTermEven(&Hgrid), - CloverTermOdd(&Hgrid), - CloverTermInvEven(&Hgrid), - CloverTermInvOdd(&Hgrid), - CloverTermDagEven(&Hgrid), - CloverTermDagOdd(&Hgrid), - CloverTermInvDagEven(&Hgrid), - CloverTermInvDagOdd(&Hgrid) + const RealD _mass, + const RealD _csw_r = 0.0, + const RealD _csw_t = 0.0, + const WilsonAnisotropyCoefficients &clover_anisotropy = WilsonAnisotropyCoefficients(), + const ImplParams &impl_p = ImplParams()) : WilsonFermion(_Umu, + Fgrid, + Hgrid, + _mass, impl_p, clover_anisotropy), + CloverTerm(&Fgrid), + CloverTermInv(&Fgrid), + CloverTermEven(&Hgrid), + CloverTermOdd(&Hgrid), + CloverTermInvEven(&Hgrid), + CloverTermInvOdd(&Hgrid), + CloverTermDagEven(&Hgrid), + CloverTermDagOdd(&Hgrid), + CloverTermInvDagEven(&Hgrid), + CloverTermInvDagOdd(&Hgrid) { - csw = _csw; assert(Nd == 4); // require 4 dimensions - if (csw == 0) - std::cout << GridLogWarning << "Initializing WilsonCloverFermion with csw = 0" << std::endl; + if (clover_anisotropy.isAnisotropic) + { + csw_r = _csw_r * 0.5 / clover_anisotropy.xi_0; + diag_mass = _mass + 1.0 + (Nd - 1) * (clover_anisotropy.nu / clover_anisotropy.xi_0); + } + else + { + csw_r = _csw_r * 0.5; + diag_mass = 4.0 + _mass; + } + csw_t = _csw_t * 0.5; + + if (csw_r == 0) + std::cout << GridLogWarning << "Initializing WilsonCloverFermion with csw_r = 0" << std::endl; + if (csw_t == 0) + std::cout << GridLogWarning << "Initializing WilsonCloverFermion with csw_t = 0" << std::endl; ImportGauge(_Umu); } @@ -105,15 +136,15 @@ public: GaugeField clover_force(force._grid); PropagatorField Lambda(force._grid); - // Here we are hitting some performance issues: + // Guido: Here we are hitting some performance issues: // need to extract the components of the DoubledGaugeField // for each call // Possible solution // Create a vector object to store them? (cons: wasting space) std::vector U(Nd, this->Umu._grid); - + Impl::extractLinkField(U, this->Umu); - + force = zero; // Derivative of the Wilson hopping term this->DhopDeriv(force, X, Y, dag); @@ -121,10 +152,9 @@ public: /////////////////////////////////////////////////////////// // Clover term derivative /////////////////////////////////////////////////////////// - Impl::outerProductImpl(Lambda, X, Y); + Impl::outerProductImpl(Lambda, X, Y); //std::cout << "Lambda:" << Lambda << std::endl; - Gamma::Algebra sigma[] = { Gamma::Algebra::SigmaXY, Gamma::Algebra::SigmaXZ, @@ -148,25 +178,34 @@ public: */ int count = 0; - clover_force = zero; + clover_force = zero; for (int mu = 0; mu < 4; mu++) { force_mu = zero; for (int nu = 0; nu < 4; nu++) { - if (mu == nu) continue; + if (mu == nu) + continue; + + RealD factor; + if (nu == 4 || mu == 4) + { + factor = 2.0 * csw_t; + } + else + { + factor = 2.0 * csw_r; + } PropagatorField Slambda = Gamma(sigma[count]) * Lambda; // sigma checked - Impl::TraceSpinImpl(lambda, Slambda); // traceSpin ok - force_mu -= Cmunu(U, lambda, mu, nu); // checked + Impl::TraceSpinImpl(lambda, Slambda); // traceSpin ok + force_mu -= factor*Cmunu(U, lambda, mu, nu); // checked count++; } pokeLorentz(clover_force, U[mu] * force_mu, mu); } - clover_force *= csw; + //clover_force *= csw; force += clover_force; - - } // Computing C_{\mu \nu}(x) as in Eq.(B.39) in Zbigniew Sroczynski's PhD thesis @@ -176,15 +215,15 @@ public: GaugeLinkField out(lambda._grid), tmp(lambda._grid); // insertion in upper staple // please check redundancy of shift operations - + // C1+ tmp = lambda * U[nu]; out = Impl::ShiftStaple(Impl::CovShiftForward(tmp, nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); - + // C2+ tmp = U[mu] * Impl::ShiftStaple(adj(lambda), mu); out += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(tmp, mu, Impl::CovShiftIdentityBackward(U[nu], nu))), mu); - + // C3+ tmp = U[nu] * Impl::ShiftStaple(adj(lambda), nu); out += Impl::ShiftStaple(Impl::CovShiftForward(U[nu], nu, Impl::CovShiftBackward(U[mu], mu, Impl::CovShiftIdentityBackward(tmp, nu))), mu); @@ -213,16 +252,17 @@ public: private: // here fixing the 4 dimensions, make it more general? - RealD csw; // Clover coefficient + RealD csw_r; // Clover coefficient - spatial + RealD csw_t; // Clover coefficient - temporal + RealD diag_mass; // Mass term CloverFieldType CloverTerm, CloverTermInv; // Clover term CloverFieldType CloverTermEven, CloverTermOdd; // Clover term EO CloverFieldType CloverTermInvEven, CloverTermInvOdd; // Clover term Inv EO CloverFieldType CloverTermDagEven, CloverTermDagOdd; // Clover term Dag EO CloverFieldType CloverTermInvDagEven, CloverTermInvDagOdd; // Clover term Inv Dag EO - // eventually these two can be compressed into 6x6 blocks instead of the 12x12 + // eventually these can be compressed into 6x6 blocks instead of the 12x12 // using the DeGrand-Rossi basis for the gamma matrices - CloverFieldType fillCloverYZ(const GaugeLinkField &F) { CloverFieldType T(F._grid); diff --git a/lib/qcd/action/fermion/WilsonFermion.h b/lib/qcd/action/fermion/WilsonFermion.h index 7b2b5206..ca5eba8b 100644 --- a/lib/qcd/action/fermion/WilsonFermion.h +++ b/lib/qcd/action/fermion/WilsonFermion.h @@ -45,10 +45,11 @@ class WilsonFermionStatic { }; struct WilsonAnisotropyCoefficients{ - bool isAnisotropic; - int t_direction; - double xi_0; - double nu; + GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonAnisotropyCoefficients, + bool, isAnisotropic, + int, t_direction, + double, xi_0, + double, nu); WilsonAnisotropyCoefficients(): isAnisotropic(false), diff --git a/tests/core/Test_wilson_clover.cc b/tests/core/Test_wilson_clover.cc index 9a55f6b2..9281e298 100644 --- a/tests/core/Test_wilson_clover.cc +++ b/tests/core/Test_wilson_clover.cc @@ -1,4 +1,4 @@ - /************************************************************************************* +/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid @@ -24,302 +24,334 @@ See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ - /* END LEGAL */ +/* END LEGAL */ #include using namespace std; using namespace Grid; using namespace Grid::QCD; -int main (int argc, char ** argv) +int main(int argc, char **argv) { - Grid_init(&argc,&argv); + Grid_init(&argc, &argv); - std::vector latt_size = GridDefaultLatt(); - std::vector simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); - std::vector mpi_layout = GridDefaultMpi(); - GridCartesian Grid(latt_size,simd_layout,mpi_layout); - GridRedBlackCartesian RBGrid(latt_size,simd_layout,mpi_layout); + std::vector latt_size = GridDefaultLatt(); + std::vector simd_layout = GridDefaultSimd(Nd, vComplex::Nsimd()); + std::vector mpi_layout = GridDefaultMpi(); + GridCartesian Grid(latt_size, simd_layout, mpi_layout); + GridRedBlackCartesian RBGrid(&Grid); int threads = GridThread::GetThreads(); - std::cout< seeds({1,2,3,4}); - GridParallelRNG pRNG(&Grid); + std::vector seeds({1, 2, 3, 4}); + GridParallelRNG pRNG(&Grid); pRNG.SeedFixedIntegers(seeds); // pRNG.SeedFixedIntegers(std::vector({45,12,81,9}); - typedef typename WilsonCloverFermionR::FermionField FermionField; - typename WilsonCloverFermionR::ImplParams params; + typedef typename WilsonCloverFermionR::FermionField FermionField; + typename WilsonCloverFermionR::ImplParams params; + WilsonAnisotropyCoefficients anis; - FermionField src (&Grid); random(pRNG,src); - FermionField result(&Grid); result=zero; - FermionField result2(&Grid); result2=zero; - FermionField ref(&Grid); ref=zero; - FermionField tmp(&Grid); tmp=zero; - FermionField err(&Grid); err=zero; - FermionField err2(&Grid); err2=zero; - FermionField phi (&Grid); random(pRNG,phi); - FermionField chi (&Grid); random(pRNG,chi); - LatticeGaugeField Umu(&Grid); SU3::HotConfiguration(pRNG,Umu); - std::vector U(4,&Grid); + FermionField src(&Grid); + random(pRNG, src); + FermionField result(&Grid); + result = zero; + FermionField result2(&Grid); + result2 = zero; + FermionField ref(&Grid); + ref = zero; + FermionField tmp(&Grid); + tmp = zero; + FermionField err(&Grid); + err = zero; + FermionField err2(&Grid); + err2 = zero; + FermionField phi(&Grid); + random(pRNG, phi); + FermionField chi(&Grid); + random(pRNG, chi); + LatticeGaugeField Umu(&Grid); + SU3::HotConfiguration(pRNG, Umu); + std::vector U(4, &Grid); - - double volume=1; - for(int mu=0;mu * = < chi | Deo^dag| phi> "< * = < chi | Deo^dag| phi> " << std::endl; + std::cout << GridLogMessage << "==============================================================" << std::endl; - FermionField dchi_e (&RBGrid); - FermionField dchi_o (&RBGrid); + FermionField chi_e(&RBGrid); + FermionField chi_o(&RBGrid); - FermionField phi_e (&RBGrid); - FermionField phi_o (&RBGrid); + FermionField dchi_e(&RBGrid); + FermionField dchi_o(&RBGrid); - FermionField dphi_e (&RBGrid); - FermionField dphi_o (&RBGrid); + FermionField phi_e(&RBGrid); + FermionField phi_o(&RBGrid); - pickCheckerboard(Even,chi_e,chi); - pickCheckerboard(Odd ,chi_o,chi); - pickCheckerboard(Even,phi_e,phi); - pickCheckerboard(Odd ,phi_o,phi); + FermionField dphi_e(&RBGrid); + FermionField dphi_o(&RBGrid); - Dwc.Meooe(chi_e,dchi_o); - Dwc.Meooe(chi_o,dchi_e); - Dwc.MeooeDag(phi_e,dphi_o); - Dwc.MeooeDag(phi_o,dphi_e); + pickCheckerboard(Even, chi_e, chi); + pickCheckerboard(Odd, chi_o, chi); + pickCheckerboard(Even, phi_e, phi); + pickCheckerboard(Odd, phi_o, phi); - ComplexD pDce = innerProduct(phi_e,dchi_e); - ComplexD pDco = innerProduct(phi_o,dchi_o); - ComplexD cDpe = innerProduct(chi_e,dphi_e); - ComplexD cDpo = innerProduct(chi_o,dphi_o); + Dwc.Meooe(chi_e, dchi_o); + Dwc.Meooe(chi_o, dchi_e); + Dwc.MeooeDag(phi_e, dphi_o); + Dwc.MeooeDag(phi_o, dphi_e); - std::cout< seeds2({5,6,7,8}); - GridParallelRNG pRNG2(&Grid); pRNG2.SeedFixedIntegers(seeds2); + std::vector seeds2({5, 6, 7, 8}); + GridParallelRNG pRNG2(&Grid); + pRNG2.SeedFixedIntegers(seeds2); LatticeColourMatrix Omega(&Grid); LatticeColourMatrix ShiftedOmega(&Grid); - LatticeGaugeField U_prime(&Grid); U_prime=zero; - LatticeColourMatrix U_prime_mu(&Grid); U_prime_mu=zero; + LatticeGaugeField U_prime(&Grid); + U_prime = zero; + LatticeColourMatrix U_prime_mu(&Grid); + U_prime_mu = zero; SU::LieRandomize(pRNG2, Omega, 1.0); - for (int mu=0;mu + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + +int main(int argc, char **argv) { + using namespace Grid; + using namespace Grid::QCD; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // here make a routine to print all the relevant information on the run + std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; + + // Typedefs to simplify notation + typedef GenericHMCRunner HMCWrapper; // Uses the default minimum norm + typedef WilsonImplR FermionImplPolicy; + typedef WilsonCloverFermionR FermionAction; + typedef typename FermionAction::FermionField FermionField; + + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + HMCWrapper TheHMC; + + // Grid from the command line + TheHMC.Resources.AddFourDimGrid("gauge"); + // Possibile to create the module by hand + // hardcoding parameters or using a Reader + + + // Checkpointer definition + CheckpointerParameters CPparams; + CPparams.config_prefix = "ckpoint_lat"; + CPparams.rng_prefix = "ckpoint_rng"; + CPparams.saveInterval = 5; + CPparams.format = "IEEE64BIG"; + + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar; + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + // here there is too much indirection + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + ////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////// + // Collect actions, here use more encapsulation + // need wrappers of the fermionic classes + // that have a complex construction + // standard + RealD beta = 5.6 ; + WilsonGaugeActionR Waction(beta); + + // temporarily need a gauge field + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + + LatticeGaugeField U(GridPtr); + + Real mass = 0.01; + Real csw = 1.0; + + FermionAction FermOp(U, *GridPtr, *GridRBPtr, mass, csw); + + ConjugateGradient CG(1.0e-8, 2000); + + TwoFlavourEvenOddPseudoFermionAction Nf2(FermOp, CG, CG); + + // Set smearing (true/false), default: false + Nf2.is_smeared = false; + + + // Collect actions + ActionLevel Level1(1); + Level1.push_back(&Nf2); + + ActionLevel Level2(4); + Level2.push_back(&Waction); + + TheHMC.TheAction.push_back(Level1); + TheHMC.TheAction.push_back(Level2); + ///////////////////////////////////////////////////////////// + + /* + double rho = 0.1; // smearing parameter + int Nsmear = 2; // number of smearing levels + Smear_Stout Stout(rho); + SmearedConfiguration SmearingPolicy( + UGrid, Nsmear, Stout); + */ + + // HMC parameters are serialisable + TheHMC.Parameters.MD.MDsteps = 20; + TheHMC.Parameters.MD.trajL = 1.0; + + TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file + TheHMC.Run(); // no smearing + // TheHMC.Run(SmearingPolicy); // for smearing + + Grid_finalize(); + +} // main + + + + + + + diff --git a/tests/hmc/Test_hmc_WilsonCloverFermionGauge.cc b/tests/hmc/Test_hmc_WilsonCloverFermionGauge.cc new file mode 100644 index 00000000..322bb304 --- /dev/null +++ b/tests/hmc/Test_hmc_WilsonCloverFermionGauge.cc @@ -0,0 +1,126 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./tests/Test_hmc_WilsonFermionGauge.cc + +Copyright (C) 2017 + +Author: Guido Cossu + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + +int main(int argc, char **argv) +{ + using namespace Grid; + using namespace Grid::QCD; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // here make a routine to print all the relevant information on the run + std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; + + // Typedefs to simplify notation + typedef GenericHMCRunner HMCWrapper; // Uses the default minimum norm + typedef WilsonImplR FermionImplPolicy; + typedef WilsonCloverFermionR FermionAction; + typedef typename FermionAction::FermionField FermionField; + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + HMCWrapper TheHMC; + + // Grid from the command line + TheHMC.Resources.AddFourDimGrid("gauge"); + + // Checkpointer definition + CheckpointerParameters CPparams; + CPparams.config_prefix = "ckpoint_lat"; + CPparams.rng_prefix = "ckpoint_rng"; + CPparams.saveInterval = 5; + CPparams.format = "IEEE64BIG"; + + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar; + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + ////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////// + // Collect actions, here use more encapsulation + // need wrappers of the fermionic classes + // that have a complex construction + // standard + RealD beta = 5.6; + WilsonGaugeActionR Waction(beta); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + + // temporarily need a gauge field + LatticeGaugeField U(GridPtr); + + Real mass = 0.01; + Real csw = 1.0; + + FermionAction FermOp(U, *GridPtr, *GridRBPtr, mass, csw); + ConjugateGradient CG(1.0e-8, 5000); + + TwoFlavourPseudoFermionAction Nf2(FermOp, CG, CG); + + // Set smearing (true/false), default: false + Nf2.is_smeared = false; + + // Collect actions + ActionLevel Level1(1); + Level1.push_back(&Nf2); + + ActionLevel Level2(4); + Level2.push_back(&Waction); + + TheHMC.TheAction.push_back(Level1); + TheHMC.TheAction.push_back(Level2); + ///////////////////////////////////////////////////////////// + + /* + double rho = 0.1; // smearing parameter + int Nsmear = 2; // number of smearing levels + Smear_Stout Stout(rho); + SmearedConfiguration SmearingPolicy( + UGrid, Nsmear, Stout); + */ + + // HMC parameters are serialisable + TheHMC.Parameters.MD.MDsteps = 20; + TheHMC.Parameters.MD.trajL = 1.0; + + TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file + TheHMC.Run(); // no smearing + // TheHMC.Run(SmearingPolicy); // for smearing + + Grid_finalize(); + +} // main diff --git a/tests/qdpxx/Test_qdpxx_wilson.cc b/tests/qdpxx/Test_qdpxx_wilson.cc index a084ebad..29e9c9ce 100644 --- a/tests/qdpxx/Test_qdpxx_wilson.cc +++ b/tests/qdpxx/Test_qdpxx_wilson.cc @@ -274,10 +274,10 @@ public: Chroma::CloverFermActParams p; p.Mass = _mq; p.clovCoeffR = QDP::Real(1.0); - p.clovCoeffT = QDP::Real(1.0); + p.clovCoeffT = QDP::Real(2.0); p.u0 = QDP::Real(1.0); AnisoParam_t _apar; - _apar.anisoP = false; + _apar.anisoP = true; _apar.t_dir = 3; // in 4d _apar.xi_0 = 2.0; _apar.nu = 1.0; @@ -422,10 +422,15 @@ void calc_grid(ChromaAction action, Grid::QCD::LatticeGaugeField &Umu, Grid::QCD if (action == WilsonClover) { - Grid::RealD _csw = 1.0; + Grid::RealD _csw_r = 1.0; + Grid::RealD _csw_t = 2.0; WilsonAnisotropyCoefficients anis; - WilsonImplParams implParam; - Grid::QCD::WilsonCloverFermionR Wf(Umu, *UGrid, *UrbGrid, _mass, _csw); + anis.isAnisotropic = true; + anis.t_direction = 3; + anis.xi_0 = 2.0; + anis.nu = 1.0; + WilsonImplParams CloverImplParam; + Grid::QCD::WilsonCloverFermionR Wf(Umu, *UGrid, *UrbGrid, _mass, _csw_r, _csw_t, anis, CloverImplParam); Wf.ImportGauge(Umu); std::cout << Grid::GridLogMessage << " Calling Grid Wilson Clover Fermion multiply " << std::endl; From 7b42ac9982da4b9f6c9ae0934ccef62506672425 Mon Sep 17 00:00:00 2001 From: pretidav Date: Thu, 2 Nov 2017 21:58:16 +0100 Subject: [PATCH 086/174] added polyakov loop observable to the hmc --- lib/qcd/modules/ObservableModules.h | 13 ++++ lib/qcd/observables/hmc_observable.h | 2 + lib/qcd/observables/polyakov_loop.h | 68 +++++++++++++++++++ lib/qcd/utils/WilsonLoops.h | 23 +++++++ .../hmc/Test_hmc_WilsonCloverFermionGauge.cc | 3 + 5 files changed, 109 insertions(+) create mode 100644 lib/qcd/observables/polyakov_loop.h diff --git a/lib/qcd/modules/ObservableModules.h b/lib/qcd/modules/ObservableModules.h index 24511617..fbffc236 100644 --- a/lib/qcd/modules/ObservableModules.h +++ b/lib/qcd/modules/ObservableModules.h @@ -92,6 +92,19 @@ class PlaquetteMod: public ObservableModule, NoParameters> PlaquetteMod(): ObsBase(NoParameters()){} }; +template < class Impl > +class PolyakovMod: public ObservableModule, NoParameters>{ + typedef ObservableModule, NoParameters> ObsBase; + using ObsBase::ObsBase; // for constructors + + // acquire resource + virtual void initialize(){ + this->ObservablePtr.reset(new PolyakovLogger()); + } + public: + PolyakovMod(): ObsBase(NoParameters()){} +}; + template < class Impl > class TopologicalChargeMod: public ObservableModule, TopologyObsParameters>{ diff --git a/lib/qcd/observables/hmc_observable.h b/lib/qcd/observables/hmc_observable.h index db629ce7..fcf11774 100644 --- a/lib/qcd/observables/hmc_observable.h +++ b/lib/qcd/observables/hmc_observable.h @@ -45,5 +45,7 @@ class HmcObservable { #include "plaquette.h" #include "topological_charge.h" +#include "polyakov_loop.h" + #endif // HMC_OBSERVABLE_H diff --git a/lib/qcd/observables/polyakov_loop.h b/lib/qcd/observables/polyakov_loop.h new file mode 100644 index 00000000..d708b474 --- /dev/null +++ b/lib/qcd/observables/polyakov_loop.h @@ -0,0 +1,68 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./lib/qcd/modules/polyakov_line.h + +Copyright (C) 2017 + +Author: David Preti + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ + +#ifndef HMC_POLYAKOV_H +#define HMC_POLYAKOV_H + +namespace Grid { +namespace QCD { + +// this is only defined for a gauge theory +template +class PolyakovLogger : public HmcObservable { + public: + // here forces the Impl to be of gauge fields + // if not the compiler will complain + INHERIT_GIMPL_TYPES(Impl); + + // necessary for HmcObservable compatibility + typedef typename Impl::Field Field; + + void TrajectoryComplete(int traj, + Field &U, + GridSerialRNG &sRNG, + GridParallelRNG &pRNG) { + + ComplexD polyakov = WilsonLoops::avgPolyakovLoop(U); + + int def_prec = std::cout.precision(); + + std::cout << GridLogMessage + << std::setprecision(std::numeric_limits::digits10 + 1) + << "Polyakov Loop: [ " << traj << " ] "<< polyakov << std::endl; + + std::cout.precision(def_prec); + + } +}; + +} // namespace QCD +} // namespace Grid + +#endif // HMC_POLYAKOV_H diff --git a/lib/qcd/utils/WilsonLoops.h b/lib/qcd/utils/WilsonLoops.h index 86609ffc..1e57015c 100644 --- a/lib/qcd/utils/WilsonLoops.h +++ b/lib/qcd/utils/WilsonLoops.h @@ -123,6 +123,29 @@ public: return sumplaq / vol / faces / Nc; // Nd , Nc dependent... FIXME } + + ////////////////////////////////////////////////// + // average over all x,y,z the temporal loop + ////////////////////////////////////////////////// + static ComplexD avgPolyakovLoop(const GaugeField &Umu) { //assume Nd=4 + GaugeMat Ut(Umu._grid), P(Umu._grid); + ComplexD out; + int T = Umu._grid->GlobalDimensions()[3]; + int X = Umu._grid->GlobalDimensions()[0]; + int Y = Umu._grid->GlobalDimensions()[1]; + int Z = Umu._grid->GlobalDimensions()[2]; + + std::cout << X << Y << Z << T << std::endl; + Ut = peekLorentz(Umu,3); //Select temporal direction + P = Ut; + for (int t=1;t PlaqObs; TheHMC.Resources.AddObservable(); + + typedef PolyakovMod PolyakovObs; + TheHMC.Resources.AddObservable(); ////////////////////////////////////////////// ///////////////////////////////////////////////////////////// From c79606a5dc4acfc4ba1453262b344031bee8a07b Mon Sep 17 00:00:00 2001 From: pretidav Date: Fri, 3 Nov 2017 22:46:32 +0100 Subject: [PATCH 087/174] Test production code wilson clover. Still missing QObs measurement on-the-fly. --- lib/qcd/utils/WilsonLoops.h | 1 - tests/hmc/Test_hmc_WCFG_Production.cc | 210 ++++++++++++++++++++++++++ 2 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 tests/hmc/Test_hmc_WCFG_Production.cc diff --git a/lib/qcd/utils/WilsonLoops.h b/lib/qcd/utils/WilsonLoops.h index 1e57015c..cdd76ecc 100644 --- a/lib/qcd/utils/WilsonLoops.h +++ b/lib/qcd/utils/WilsonLoops.h @@ -135,7 +135,6 @@ public: int Y = Umu._grid->GlobalDimensions()[1]; int Z = Umu._grid->GlobalDimensions()[2]; - std::cout << X << Y << Z << T << std::endl; Ut = peekLorentz(Umu,3); //Select temporal direction P = Ut; for (int t=1;t + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + + +namespace Grid{ + struct FermionParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(FermionParameters, + double, mass, + double, csw, + double, StoppingCondition, + int, MaxCGIterations, + bool, ApplySmearing); + }; + + + struct WilsonCloverHMCParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonCloverHMCParameters, + double, gauge_beta, + FermionParameters, WilsonClover) + + template + WilsonCloverHMCParameters(Reader& Reader){ + read(Reader, "Action", *this); + } + }; + + struct SmearingParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(SmearingParameters, + double, rho, + Integer, Nsmear) + + template + SmearingParameters(Reader& Reader){ + read(Reader, "StoutSmearing", *this); + } + + }; + + +} + +int main(int argc, char **argv) +{ + using namespace Grid; + using namespace Grid::QCD; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // here make a routine to print all the relevant information on the run + std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; + + // Typedefs to simplify notation + typedef GenericHMCRunner HMCWrapper; // Uses the default minimum norm + typedef WilsonImplR FermionImplPolicy; + typedef WilsonCloverFermionR FermionAction; + typedef typename FermionAction::FermionField FermionField; + typedef Grid::JSONReader Serialiser; + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + HMCWrapper TheHMC; + + // Grid from the command line + TheHMC.ReadCommandLine(argc, argv); + if (TheHMC.ParameterFile.empty()){ + std::cout << "Input file not specified." + << "Use --ParameterFile option in the command line.\nAborting" + << std::endl; + exit(1); + } + Serialiser Reader(TheHMC.ParameterFile); + WilsonCloverHMCParameters MyParams(Reader); + + // Apply smearing to the fermionic action + bool ApplySmearing = MyParams.WilsonClover.ApplySmearing; + + TheHMC.Resources.AddFourDimGrid("gauge"); + + // Checkpointer definition + CheckpointerParameters CPparams(Reader); + + /* + CPparams.config_prefix = "ckpoint_lat"; + CPparams.rng_prefix = "ckpoint_rng"; + CPparams.saveInterval = 5; + CPparams.format = "IEEE64BIG"; + */ + + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar(Reader); + /* + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + */ + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + + typedef PolyakovMod PolyakovObs; + TheHMC.Resources.AddObservable(); + + //typedef TopologicalChargeMod QObs; + //TopologyObsParameters TopParams(Reader); + //TheHMC.Resources.AddObservable(TopParams); + ////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////// + // Collect actions, here use more encapsulation + // need wrappers of the fermionic classes + // that have a complex construction + // standard + + //RealD beta = 5.6; + WilsonGaugeActionR Waction(MyParams.gauge_beta); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + + // temporarily need a gauge field + LatticeGaugeField U(GridPtr); + + //Real mass = 0.01; + //Real csw = 1.0; + + Real mass = MyParams.WilsonClover.mass; + Real csw = MyParams.WilsonClover.csw; + + std::cout << "mass and csw" << mass << " and " << csw << std::endl; + + FermionAction FermOp(U, *GridPtr, *GridRBPtr, mass, csw, csw); + ConjugateGradient CG(MyParams.WilsonClover.StoppingCondition, MyParams.WilsonClover.MaxCGIterations); + TwoFlavourPseudoFermionAction Nf2(FermOp, CG, CG); + + // Set smearing (true/false), default: false + Nf2.is_smeared = ApplySmearing; + + // Collect actions + ActionLevel Level1(1); + Level1.push_back(&Nf2); + + ActionLevel Level2(4); + Level2.push_back(&Waction); + + TheHMC.TheAction.push_back(Level1); + TheHMC.TheAction.push_back(Level2); + ///////////////////////////////////////////////////////////// + + + /* + double rho = 0.1; // smearing parameter + int Nsmear = 2; // number of smearing levels + Smear_Stout Stout(rho); + SmearedConfiguration SmearingPolicy( + UGrid, Nsmear, Stout); + */ + + // HMC parameters are serialisable + + TheHMC.Parameters.initialize(Reader); + //TheHMC.Parameters.MD.MDsteps = 20; + //TheHMC.Parameters.MD.trajL = 1.0; + + if (ApplySmearing){ + SmearingParameters SmPar(Reader); + //double rho = 0.1; // smearing parameter + //int Nsmear = 3; // number of smearing levels + Smear_Stout Stout(SmPar.rho); + SmearedConfiguration SmearingPolicy(GridPtr, SmPar.Nsmear, Stout); + TheHMC.Run(SmearingPolicy); // for smearing + } else { + TheHMC.Run(); // no smearing + } + + //TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file + //TheHMC.Run(); // no smearing + // TheHMC.Run(SmearingPolicy); // for smearing + + Grid_finalize(); + +} // main From 915f610da0c986c43ee706f8716ebbb453b0342c Mon Sep 17 00:00:00 2001 From: pretidav Date: Sat, 4 Nov 2017 01:17:06 +0100 Subject: [PATCH 088/174] clover 2indexSymm hmc production test created. clover 2indexAsymm and clover mixed to be filled. --- lib/qcd/action/fermion/Fermion.h | 17 ++ lib/qcd/action/fermion/FermionOperatorImpl.h | 4 + lib/qcd/action/fermion/WilsonCloverFermion.cc | 6 +- tests/hmc/Test_hmc_WC2ASFG_Production.cc | 129 +++++++++++ tests/hmc/Test_hmc_WC2SFG_Production.cc | 212 ++++++++++++++++++ tests/hmc/Test_hmc_WCMixedRepFG_Production.cc | 139 ++++++++++++ 6 files changed, 504 insertions(+), 3 deletions(-) create mode 100644 tests/hmc/Test_hmc_WC2ASFG_Production.cc create mode 100644 tests/hmc/Test_hmc_WC2SFG_Production.cc create mode 100644 tests/hmc/Test_hmc_WCMixedRepFG_Production.cc diff --git a/lib/qcd/action/fermion/Fermion.h b/lib/qcd/action/fermion/Fermion.h index bc8397ba..2a008cb7 100644 --- a/lib/qcd/action/fermion/Fermion.h +++ b/lib/qcd/action/fermion/Fermion.h @@ -106,6 +106,10 @@ typedef WilsonFermion WilsonTwoIndexSymmetricFermi typedef WilsonFermion WilsonTwoIndexSymmetricFermionF; typedef WilsonFermion WilsonTwoIndexSymmetricFermionD; +typedef WilsonFermion WilsonTwoIndexAntiSymmetricFermionR; +typedef WilsonFermion WilsonTwoIndexAntiSymmetricFermionF; +typedef WilsonFermion WilsonTwoIndexAntiSymmetricFermionD; + // Twisted mass fermion typedef WilsonTMFermion WilsonTMFermionR; typedef WilsonTMFermion WilsonTMFermionF; @@ -116,6 +120,19 @@ typedef WilsonCloverFermion WilsonCloverFermionR; typedef WilsonCloverFermion WilsonCloverFermionF; typedef WilsonCloverFermion WilsonCloverFermionD; +typedef WilsonCloverFermion WilsonCloverAdjFermionR; +typedef WilsonCloverFermion WilsonCloverAdjFermionF; +typedef WilsonCloverFermion WilsonCloverAdjFermionD; + +typedef WilsonCloverFermion WilsonCloverTwoIndexSymmetricFermionR; +typedef WilsonCloverFermion WilsonCloverTwoIndexSymmetricFermionF; +typedef WilsonCloverFermion WilsonCloverTwoIndexSymmetricFermionD; + +typedef WilsonCloverFermion WilsonCloverTwoIndexAntiSymmetricFermionR; +typedef WilsonCloverFermion WilsonCloverTwoIndexAntiSymmetricFermionF; +typedef WilsonCloverFermion WilsonCloverTwoIndexAntiSymmetricFermionD; + +// Domain Wall fermions typedef DomainWallFermion DomainWallFermionR; typedef DomainWallFermion DomainWallFermionF; typedef DomainWallFermion DomainWallFermionD; diff --git a/lib/qcd/action/fermion/FermionOperatorImpl.h b/lib/qcd/action/fermion/FermionOperatorImpl.h index 89bd9a15..85d6ffea 100644 --- a/lib/qcd/action/fermion/FermionOperatorImpl.h +++ b/lib/qcd/action/fermion/FermionOperatorImpl.h @@ -1004,6 +1004,10 @@ typedef WilsonImpl Wilso typedef WilsonImpl WilsonTwoIndexSymmetricImplF; // Float typedef WilsonImpl WilsonTwoIndexSymmetricImplD; // Double +typedef WilsonImpl WilsonTwoIndexAntiSymmetricImplR; // Real.. whichever prec +typedef WilsonImpl WilsonTwoIndexAntiSymmetricImplF; // Float +typedef WilsonImpl WilsonTwoIndexAntiSymmetricImplD; // Double + typedef DomainWallVec5dImpl DomainWallVec5dImplR; // Real.. whichever prec typedef DomainWallVec5dImpl DomainWallVec5dImplF; // Float typedef DomainWallVec5dImpl DomainWallVec5dImplD; // Double diff --git a/lib/qcd/action/fermion/WilsonCloverFermion.cc b/lib/qcd/action/fermion/WilsonCloverFermion.cc index 3ec90e06..3c082446 100644 --- a/lib/qcd/action/fermion/WilsonCloverFermion.cc +++ b/lib/qcd/action/fermion/WilsonCloverFermion.cc @@ -235,9 +235,9 @@ void WilsonCloverFermion::MeeDeriv(GaugeField &mat, const FermionField &U, assert(0); // not implemented yet } -FermOpTemplateInstantiate(WilsonCloverFermion); // now only for the fundamental representation -//AdjointFermOpTemplateInstantiate(WilsonCloverFermion); -//TwoIndexFermOpTemplateInstantiate(WilsonCloverFermion); +FermOpTemplateInstantiate(WilsonCloverFermion); +AdjointFermOpTemplateInstantiate(WilsonCloverFermion); +TwoIndexFermOpTemplateInstantiate(WilsonCloverFermion); //GparityFermOpTemplateInstantiate(WilsonCloverFermion); } } diff --git a/tests/hmc/Test_hmc_WC2ASFG_Production.cc b/tests/hmc/Test_hmc_WC2ASFG_Production.cc new file mode 100644 index 00000000..b0d1d3a4 --- /dev/null +++ b/tests/hmc/Test_hmc_WC2ASFG_Production.cc @@ -0,0 +1,129 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./tests/Test_hmc_WilsonAdjointFermionGauge.cc + +Copyright (C) 2015 + +Author: Peter Boyle +Author: neo + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include "Grid/Grid.h" + +int main(int argc, char **argv) { + using namespace Grid; + using namespace Grid::QCD; + + // Here change the allowed (higher) representations + typedef Representations< FundamentalRepresentation, TwoIndexAntiSymmetricRepresentation > TheRepresentations; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // here make a routine to print all the relevant information on the run + std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; + + // Typedefs to simplify notation + typedef GenericHMCRunnerHirep HMCWrapper; + + typedef WilsonTwoIndexAntiSymmetricImplR FermionImplPolicy; // gauge field implemetation for the pseudofermions + typedef WilsonTwoIndexAntiSymmetricFermionR FermionAction; // type of lattice fermions (Wilson, DW, ...) + typedef typename FermionAction::FermionField FermionField; + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + HMCWrapper TheHMC; + + // Grid from the command line + TheHMC.Resources.AddFourDimGrid("gauge"); + // Possibile to create the module by hand + // hardcoding parameters or using a Reader + + + // Checkpointer definition + CheckpointerParameters CPparams; + CPparams.config_prefix = "ckpoint_lat"; + CPparams.rng_prefix = "ckpoint_rng"; + CPparams.saveInterval = 5; + CPparams.format = "IEEE64BIG"; + + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar; + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + ////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////// + // Collect actions, here use more encapsulation + // need wrappers of the fermionic classes + // that have a complex construction + // standard + RealD beta = 2.25 ; + WilsonGaugeActionR Waction(beta); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + + // temporarily need a gauge field + TwoIndexSymmetricRepresentation::LatticeField U(GridPtr); + + Real mass = -0.95; + + // Can we define an overloaded operator that does not need U and initialises + // it with zeroes? + FermionAction FermOp(U, *GridPtr, *GridRBPtr, mass); + + ConjugateGradient CG(1.0e-8, 2000, false); + + TwoFlavourPseudoFermionAction Nf2(FermOp, CG, CG); + + // Set smearing (true/false), default: false + Nf2.is_smeared = false; + + + // Collect actions + ActionLevel Level1(1); + Level1.push_back(&Nf2); + + ActionLevel Level2(4); + Level2.push_back(&Waction); + + TheHMC.TheAction.push_back(Level1); + TheHMC.TheAction.push_back(Level2); + + // HMC parameters are serialisable + TheHMC.Parameters.MD.MDsteps = 20; + TheHMC.Parameters.MD.trajL = 1.0; + + TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file + TheHMC.Run(); // no smearing + // TheHMC.Run(SmearingPolicy); // for smearing + + Grid_finalize(); + +} // main + + diff --git a/tests/hmc/Test_hmc_WC2SFG_Production.cc b/tests/hmc/Test_hmc_WC2SFG_Production.cc new file mode 100644 index 00000000..8d5fc458 --- /dev/null +++ b/tests/hmc/Test_hmc_WC2SFG_Production.cc @@ -0,0 +1,212 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./tests/Test_hmc_WilsonFermionGauge.cc + +Copyright (C) 2017 + +Author: Guido Cossu + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + + +namespace Grid{ + struct FermionParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(FermionParameters, + double, mass, + double, csw, + double, StoppingCondition, + int, MaxCGIterations, + bool, ApplySmearing); + }; + + + struct WilsonCloverHMCParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonCloverHMCParameters, + double, gauge_beta, + FermionParameters, WilsonClover) + + template + WilsonCloverHMCParameters(Reader& Reader){ + read(Reader, "Action", *this); + } + }; + + struct SmearingParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(SmearingParameters, + double, rho, + Integer, Nsmear) + + template + SmearingParameters(Reader& Reader){ + read(Reader, "StoutSmearing", *this); + } + + }; + + +} + +int main(int argc, char **argv) +{ + using namespace Grid; + using namespace Grid::QCD; + + typedef Representations< FundamentalRepresentation, TwoIndexSymmetricRepresentation > TheRepresentations; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // here make a routine to print all the relevant information on the run + std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; + + // Typedefs to simplify notation + typedef GenericHMCRunnerHirep HMCWrapper; // Uses the default minimum norm + typedef WilsonTwoIndexSymmetricImplR FermionImplPolicy; // gauge field implemetation for the pseudofermions + typedef WilsonCloverTwoIndexSymmetricFermionR FermionAction; // type of lattice fermions (Wilson, DW, ...) + typedef typename FermionAction::FermionField FermionField; + typedef Grid::JSONReader Serialiser; + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + HMCWrapper TheHMC; + + // Grid from the command line + TheHMC.ReadCommandLine(argc, argv); + if (TheHMC.ParameterFile.empty()){ + std::cout << "Input file not specified." + << "Use --ParameterFile option in the command line.\nAborting" + << std::endl; + exit(1); + } + Serialiser Reader(TheHMC.ParameterFile); + WilsonCloverHMCParameters MyParams(Reader); + + // Apply smearing to the fermionic action + bool ApplySmearing = MyParams.WilsonClover.ApplySmearing; + + TheHMC.Resources.AddFourDimGrid("gauge"); + + // Checkpointer definition + CheckpointerParameters CPparams(Reader); + + /* + CPparams.config_prefix = "ckpoint_lat"; + CPparams.rng_prefix = "ckpoint_rng"; + CPparams.saveInterval = 5; + CPparams.format = "IEEE64BIG"; + */ + + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar(Reader); + /* + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + */ + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + + typedef PolyakovMod PolyakovObs; + TheHMC.Resources.AddObservable(); + + //typedef TopologicalChargeMod QObs; + //TopologyObsParameters TopParams(Reader); + //TheHMC.Resources.AddObservable(TopParams); + ////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////// + // Collect actions, here use more encapsulation + // need wrappers of the fermionic classes + // that have a complex construction + // standard + + //RealD beta = 5.6; + WilsonGaugeActionR Waction(MyParams.gauge_beta); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + + // temporarily need a gauge field + TwoIndexSymmetricRepresentation::LatticeField U(GridPtr); + + //Real mass = 0.01; + //Real csw = 1.0; + + Real mass = MyParams.WilsonClover.mass; + Real csw = MyParams.WilsonClover.csw; + + std::cout << "mass and csw" << mass << " and " << csw << std::endl; + + FermionAction FermOp(U, *GridPtr, *GridRBPtr, mass, csw, csw); + ConjugateGradient CG(MyParams.WilsonClover.StoppingCondition, MyParams.WilsonClover.MaxCGIterations); + TwoFlavourPseudoFermionAction Nf2(FermOp, CG, CG); + + // Set smearing (true/false), default: false + Nf2.is_smeared = ApplySmearing; + + // Collect actions + ActionLevel Level1(1); + Level1.push_back(&Nf2); + + ActionLevel Level2(4); + Level2.push_back(&Waction); + + TheHMC.TheAction.push_back(Level1); + TheHMC.TheAction.push_back(Level2); + ///////////////////////////////////////////////////////////// + + + /* + double rho = 0.1; // smearing parameter + int Nsmear = 2; // number of smearing levels + Smear_Stout Stout(rho); + SmearedConfiguration SmearingPolicy( + UGrid, Nsmear, Stout); + */ + + // HMC parameters are serialisable + + TheHMC.Parameters.initialize(Reader); + //TheHMC.Parameters.MD.MDsteps = 20; + //TheHMC.Parameters.MD.trajL = 1.0; + + if (ApplySmearing){ + SmearingParameters SmPar(Reader); + //double rho = 0.1; // smearing parameter + //int Nsmear = 3; // number of smearing levels + Smear_Stout Stout(SmPar.rho); + SmearedConfiguration SmearingPolicy(GridPtr, SmPar.Nsmear, Stout); + TheHMC.Run(SmearingPolicy); // for smearing + } else { + TheHMC.Run(); // no smearing + } + + //TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file + //TheHMC.Run(); // no smearing + // TheHMC.Run(SmearingPolicy); // for smearing + + Grid_finalize(); + +} // main diff --git a/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc b/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc new file mode 100644 index 00000000..b54345cf --- /dev/null +++ b/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc @@ -0,0 +1,139 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./tests/Test_hmc_WilsonAdjointFermionGauge.cc + +Copyright (C) 2015 + +Author: Peter Boyle +Author: Peter Boyle +Author: neo +Author: paboyle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include "Grid/Grid.h" + + + + +int main(int argc, char **argv) { + using namespace Grid; + using namespace Grid::QCD; + + // Here change the allowed (higher) representations + typedef Representations< FundamentalRepresentation, AdjointRepresentation , TwoIndexSymmetricRepresentation> TheRepresentations; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // here make a routine to print all the relevant information on the run + std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; + + // Typedefs to simplify notation + typedef GenericHMCRunnerHirep HMCWrapper; + + typedef WilsonAdjImplR AdjImplPolicy; // gauge field implemetation for the pseudofermions + typedef WilsonAdjFermionR AdjFermionAction; // type of lattice fermions (Wilson, DW, ...) + typedef WilsonTwoIndexSymmetricImplR SymmImplPolicy; + typedef WilsonTwoIndexSymmetricFermionR SymmFermionAction; + + + typedef typename AdjFermionAction::FermionField AdjFermionField; + typedef typename SymmFermionAction::FermionField SymmFermionField; + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + HMCWrapper TheHMC; + + // Grid from the command line + TheHMC.Resources.AddFourDimGrid("gauge"); + // Possibile to create the module by hand + // hardcoding parameters or using a Reader + + + // Checkpointer definition + CheckpointerParameters CPparams; + CPparams.config_prefix = "ckpoint_lat"; + CPparams.rng_prefix = "ckpoint_rng"; + CPparams.saveInterval = 5; + CPparams.format = "IEEE64BIG"; + + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar; + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + ////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////// + // Collect actions, here use more encapsulation + // need wrappers of the fermionic classes + // that have a complex construction + // standard + RealD beta = 2.25 ; + WilsonGaugeActionR Waction(beta); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + + // temporarily need a gauge field + AdjointRepresentation::LatticeField UA(GridPtr); + TwoIndexSymmetricRepresentation::LatticeField US(GridPtr); + + Real adjoint_mass = -0.1; + Real symm_mass = -0.5; + AdjFermionAction AdjFermOp(UA, *GridPtr, *GridRBPtr, adjoint_mass); + SymmFermionAction SymmFermOp(US, *GridPtr, *GridRBPtr, symm_mass); + + ConjugateGradient CG_adj(1.0e-8, 10000, false); + ConjugateGradient CG_symm(1.0e-8, 10000, false); + + // Pass two solvers: one for the force computation and one for the action + TwoFlavourPseudoFermionAction Nf2_Adj(AdjFermOp, CG_adj, CG_adj); + TwoFlavourPseudoFermionAction Nf2_Symm(SymmFermOp, CG_symm, CG_symm); + + // Collect actions + ActionLevel Level1(1); + Level1.push_back(&Nf2_Adj); + Level1.push_back(&Nf2_Symm); + + + ActionLevel Level2(4); + Level2.push_back(&Waction); + + TheHMC.TheAction.push_back(Level1); + TheHMC.TheAction.push_back(Level2); + + // HMC parameters are serialisable + TheHMC.Parameters.MD.MDsteps = 20; + TheHMC.Parameters.MD.trajL = 1.0; + + TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file + TheHMC.Run(); // no smearing + + Grid_finalize(); + +} // main + + From a4934292182ffa1e96a5ecad2062f3ce06727f1c Mon Sep 17 00:00:00 2001 From: pretidav Date: Sat, 4 Nov 2017 18:16:54 +0100 Subject: [PATCH 089/174] added Production tests for MixedRep, Adj, 2S, 2AS. Still missing QObs. The HMC is not printing correctly all the actions and forces. --- lib/qcd/action/fermion/FermionCore.h | 4 +- lib/qcd/action/fermion/WilsonKernelsHand.cc | 3 +- tests/hmc/Test_hmc_WC2ASFG_Production.cc | 162 +++++++++---- tests/hmc/Test_hmc_WCMixedRepFG_Production.cc | 215 ++++++++++++------ tests/hmc/Test_hmc_WCadjFG_Production.cc | 213 +++++++++++++++++ 5 files changed, 491 insertions(+), 106 deletions(-) create mode 100644 tests/hmc/Test_hmc_WCadjFG_Production.cc diff --git a/lib/qcd/action/fermion/FermionCore.h b/lib/qcd/action/fermion/FermionCore.h index 17006961..60632c3a 100644 --- a/lib/qcd/action/fermion/FermionCore.h +++ b/lib/qcd/action/fermion/FermionCore.h @@ -70,7 +70,9 @@ Author: Peter Boyle #define TwoIndexFermOpTemplateInstantiate(A) \ template class A; \ - template class A; + template class A; \ + template class A; \ + template class A; #define FermOp5dVecTemplateInstantiate(A) \ template class A; \ diff --git a/lib/qcd/action/fermion/WilsonKernelsHand.cc b/lib/qcd/action/fermion/WilsonKernelsHand.cc index 80b81714..aa6b5f6b 100644 --- a/lib/qcd/action/fermion/WilsonKernelsHand.cc +++ b/lib/qcd/action/fermion/WilsonKernelsHand.cc @@ -946,5 +946,6 @@ INSTANTIATE_THEM(DomainWallVec5dImplFH); INSTANTIATE_THEM(DomainWallVec5dImplDF); INSTANTIATE_THEM(ZDomainWallVec5dImplFH); INSTANTIATE_THEM(ZDomainWallVec5dImplDF); - +INSTANTIATE_THEM(WilsonTwoIndexAntiSymmetricImplF); +INSTANTIATE_THEM(WilsonTwoIndexAntiSymmetricImplD); }} diff --git a/tests/hmc/Test_hmc_WC2ASFG_Production.cc b/tests/hmc/Test_hmc_WC2ASFG_Production.cc index b0d1d3a4..d255ab5d 100644 --- a/tests/hmc/Test_hmc_WC2ASFG_Production.cc +++ b/tests/hmc/Test_hmc_WC2ASFG_Production.cc @@ -2,12 +2,11 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: ./tests/Test_hmc_WilsonAdjointFermionGauge.cc +Source file: ./tests/Test_hmc_WilsonFermionGauge.cc -Copyright (C) 2015 +Copyright (C) 2017 -Author: Peter Boyle -Author: neo +Author: Guido Cossu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,103 +26,188 @@ See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ -#include "Grid/Grid.h" +#include -int main(int argc, char **argv) { + +namespace Grid{ + struct FermionParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(FermionParameters, + double, mass, + double, csw, + double, StoppingCondition, + int, MaxCGIterations, + bool, ApplySmearing); + }; + + + struct WilsonCloverHMCParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonCloverHMCParameters, + double, gauge_beta, + FermionParameters, WilsonClover) + + template + WilsonCloverHMCParameters(Reader& Reader){ + read(Reader, "Action", *this); + } + }; + + struct SmearingParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(SmearingParameters, + double, rho, + Integer, Nsmear) + + template + SmearingParameters(Reader& Reader){ + read(Reader, "StoutSmearing", *this); + } + + }; + + +} + +int main(int argc, char **argv) +{ using namespace Grid; using namespace Grid::QCD; - // Here change the allowed (higher) representations - typedef Representations< FundamentalRepresentation, TwoIndexAntiSymmetricRepresentation > TheRepresentations; + typedef Representations< FundamentalRepresentation, TwoIndexAntiSymmetricRepresentation > TheRepresentations; Grid_init(&argc, &argv); int threads = GridThread::GetThreads(); // here make a routine to print all the relevant information on the run std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; - // Typedefs to simplify notation - typedef GenericHMCRunnerHirep HMCWrapper; - + // Typedefs to simplify notation + typedef GenericHMCRunnerHirep HMCWrapper; // Uses the default minimum norm typedef WilsonTwoIndexAntiSymmetricImplR FermionImplPolicy; // gauge field implemetation for the pseudofermions - typedef WilsonTwoIndexAntiSymmetricFermionR FermionAction; // type of lattice fermions (Wilson, DW, ...) + typedef WilsonCloverTwoIndexAntiSymmetricFermionR FermionAction; // type of lattice fermions (Wilson, DW, ...) typedef typename FermionAction::FermionField FermionField; + typedef Grid::JSONReader Serialiser; //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: HMCWrapper TheHMC; // Grid from the command line - TheHMC.Resources.AddFourDimGrid("gauge"); - // Possibile to create the module by hand - // hardcoding parameters or using a Reader + TheHMC.ReadCommandLine(argc, argv); + if (TheHMC.ParameterFile.empty()){ + std::cout << "Input file not specified." + << "Use --ParameterFile option in the command line.\nAborting" + << std::endl; + exit(1); + } + Serialiser Reader(TheHMC.ParameterFile); + WilsonCloverHMCParameters MyParams(Reader); + // Apply smearing to the fermionic action + bool ApplySmearing = MyParams.WilsonClover.ApplySmearing; + + TheHMC.Resources.AddFourDimGrid("gauge"); // Checkpointer definition - CheckpointerParameters CPparams; + CheckpointerParameters CPparams(Reader); + + /* CPparams.config_prefix = "ckpoint_lat"; CPparams.rng_prefix = "ckpoint_rng"; CPparams.saveInterval = 5; CPparams.format = "IEEE64BIG"; + */ TheHMC.Resources.LoadNerscCheckpointer(CPparams); - RNGModuleParameters RNGpar; + RNGModuleParameters RNGpar(Reader); + /* RNGpar.serial_seeds = "1 2 3 4 5"; RNGpar.parallel_seeds = "6 7 8 9 10"; TheHMC.Resources.SetRNGSeeds(RNGpar); + */ + TheHMC.Resources.SetRNGSeeds(RNGpar); // Construct observables typedef PlaquetteMod PlaqObs; TheHMC.Resources.AddObservable(); + + typedef PolyakovMod PolyakovObs; + TheHMC.Resources.AddObservable(); + + //typedef TopologicalChargeMod QObs; + //TopologyObsParameters TopParams(Reader); + //TheHMC.Resources.AddObservable(TopParams); ////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // Collect actions, here use more encapsulation - // need wrappers of the fermionic classes + // need wrappers of the fermionic classes // that have a complex construction // standard - RealD beta = 2.25 ; - WilsonGaugeActionR Waction(beta); - - auto GridPtr = TheHMC.Resources.GetCartesian(); + + //RealD beta = 5.6; + WilsonGaugeActionR Waction(MyParams.gauge_beta); + + auto GridPtr = TheHMC.Resources.GetCartesian(); auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); // temporarily need a gauge field - TwoIndexSymmetricRepresentation::LatticeField U(GridPtr); + TwoIndexAntiSymmetricRepresentation::LatticeField U(GridPtr); - Real mass = -0.95; + //Real mass = 0.01; + //Real csw = 1.0; - // Can we define an overloaded operator that does not need U and initialises - // it with zeroes? - FermionAction FermOp(U, *GridPtr, *GridRBPtr, mass); + Real mass = MyParams.WilsonClover.mass; + Real csw = MyParams.WilsonClover.csw; - ConjugateGradient CG(1.0e-8, 2000, false); + std::cout << "mass and csw" << mass << " and " << csw << std::endl; + FermionAction FermOp(U, *GridPtr, *GridRBPtr, mass, csw, csw); + ConjugateGradient CG(MyParams.WilsonClover.StoppingCondition, MyParams.WilsonClover.MaxCGIterations); TwoFlavourPseudoFermionAction Nf2(FermOp, CG, CG); // Set smearing (true/false), default: false - Nf2.is_smeared = false; + Nf2.is_smeared = ApplySmearing; - - // Collect actions - ActionLevel Level1(1); + // Collect actions + ActionLevel Level1(1); Level1.push_back(&Nf2); - ActionLevel Level2(4); + ActionLevel Level2(4); Level2.push_back(&Waction); TheHMC.TheAction.push_back(Level1); TheHMC.TheAction.push_back(Level2); + ///////////////////////////////////////////////////////////// - // HMC parameters are serialisable - TheHMC.Parameters.MD.MDsteps = 20; - TheHMC.Parameters.MD.trajL = 1.0; - TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file - TheHMC.Run(); // no smearing + /* + double rho = 0.1; // smearing parameter + int Nsmear = 2; // number of smearing levels + Smear_Stout Stout(rho); + SmearedConfiguration SmearingPolicy( + UGrid, Nsmear, Stout); + */ + + // HMC parameters are serialisable + + TheHMC.Parameters.initialize(Reader); + //TheHMC.Parameters.MD.MDsteps = 20; + //TheHMC.Parameters.MD.trajL = 1.0; + + if (ApplySmearing){ + SmearingParameters SmPar(Reader); + //double rho = 0.1; // smearing parameter + //int Nsmear = 3; // number of smearing levels + Smear_Stout Stout(SmPar.rho); + SmearedConfiguration SmearingPolicy(GridPtr, SmPar.Nsmear, Stout); + TheHMC.Run(SmearingPolicy); // for smearing + } else { + TheHMC.Run(); // no smearing + } + + //TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file + //TheHMC.Run(); // no smearing // TheHMC.Run(SmearingPolicy); // for smearing Grid_finalize(); } // main - diff --git a/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc b/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc index b54345cf..a79452f4 100644 --- a/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc +++ b/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc @@ -32,6 +32,40 @@ directory #include "Grid/Grid.h" +namespace Grid{ + struct FermionParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(FermionParameters, + double, mass, + double, csw, + double, StoppingCondition, + int, MaxCGIterations, + bool, ApplySmearing); + }; + + struct WilsonCloverHMCParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonCloverHMCParameters, + double, gauge_beta, + FermionParameters, WilsonCloverFund, + FermionParameters, WilsonCloverAS) + + template + WilsonCloverHMCParameters(Reader& Reader){ + read(Reader, "Action", *this); + } + }; + + struct SmearingParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(SmearingParameters, + double, rho, + Integer, Nsmear) + + template + SmearingParameters(Reader& Reader){ + read(Reader, "StoutSmearing", *this); + } + + }; +} int main(int argc, char **argv) { @@ -39,7 +73,7 @@ int main(int argc, char **argv) { using namespace Grid::QCD; // Here change the allowed (higher) representations - typedef Representations< FundamentalRepresentation, AdjointRepresentation , TwoIndexSymmetricRepresentation> TheRepresentations; + typedef Representations< FundamentalRepresentation, TwoIndexAntiSymmetricRepresentation> TheRepresentations; Grid_init(&argc, &argv); int threads = GridThread::GetThreads(); @@ -49,91 +83,142 @@ int main(int argc, char **argv) { // Typedefs to simplify notation typedef GenericHMCRunnerHirep HMCWrapper; - typedef WilsonAdjImplR AdjImplPolicy; // gauge field implemetation for the pseudofermions - typedef WilsonAdjFermionR AdjFermionAction; // type of lattice fermions (Wilson, DW, ...) - typedef WilsonTwoIndexSymmetricImplR SymmImplPolicy; - typedef WilsonTwoIndexSymmetricFermionR SymmFermionAction; + typedef WilsonImplR FundImplPolicy; + typedef WilsonCloverFermionR FundFermionAction; + typedef typename FundFermionAction::FermionField FundFermionField; + typedef WilsonTwoIndexAntiSymmetricImplR ASymmImplPolicy; + typedef WilsonCloverTwoIndexAntiSymmetricFermionR ASymmFermionAction; + typedef typename ASymmFermionAction::FermionField ASymmFermionField; - typedef typename AdjFermionAction::FermionField AdjFermionField; - typedef typename SymmFermionAction::FermionField SymmFermionField; - + typedef Grid::JSONReader Serialiser; //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: HMCWrapper TheHMC; - - // Grid from the command line - TheHMC.Resources.AddFourDimGrid("gauge"); - // Possibile to create the module by hand - // hardcoding parameters or using a Reader - - - // Checkpointer definition - CheckpointerParameters CPparams; - CPparams.config_prefix = "ckpoint_lat"; - CPparams.rng_prefix = "ckpoint_rng"; - CPparams.saveInterval = 5; - CPparams.format = "IEEE64BIG"; - TheHMC.Resources.LoadNerscCheckpointer(CPparams); - - RNGModuleParameters RNGpar; - RNGpar.serial_seeds = "1 2 3 4 5"; - RNGpar.parallel_seeds = "6 7 8 9 10"; - TheHMC.Resources.SetRNGSeeds(RNGpar); - - // Construct observables - typedef PlaquetteMod PlaqObs; - TheHMC.Resources.AddObservable(); - ////////////////////////////////////////////// - - ///////////////////////////////////////////////////////////// - // Collect actions, here use more encapsulation - // need wrappers of the fermionic classes - // that have a complex construction - // standard - RealD beta = 2.25 ; - WilsonGaugeActionR Waction(beta); + // Grid from the command line + TheHMC.ReadCommandLine(argc, argv); + if (TheHMC.ParameterFile.empty()){ + std::cout << "Input file not specified." + << "Use --ParameterFile option in the command line.\nAborting" + << std::endl; + exit(1); + } + Serialiser Reader(TheHMC.ParameterFile); + WilsonCloverHMCParameters MyParams(Reader); + + // Apply smearing to the fermionic action + bool ApplySmearingFund = MyParams.WilsonCloverFund.ApplySmearing; + bool ApplySmearingAS = MyParams.WilsonCloverAS.ApplySmearing; - auto GridPtr = TheHMC.Resources.GetCartesian(); - auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); - // temporarily need a gauge field - AdjointRepresentation::LatticeField UA(GridPtr); - TwoIndexSymmetricRepresentation::LatticeField US(GridPtr); + TheHMC.Resources.AddFourDimGrid("gauge"); + + // Checkpointer definition + CheckpointerParameters CPparams(Reader); + + /* + CPparams.config_prefix = "ckpoint_lat"; + CPparams.rng_prefix = "ckpoint_rng"; + CPparams.saveInterval = 5; + CPparams.format = "IEEE64BIG"; + */ + + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar(Reader); + /* + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + */ + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + + typedef PolyakovMod PolyakovObs; + TheHMC.Resources.AddObservable(); + + //typedef TopologicalChargeMod QObs; + //TopologyObsParameters TopParams(Reader); + //TheHMC.Resources.AddObservable(TopParams); + ////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////// + // Collect actions, here use more encapsulation + // need wrappers of the fermionic classes + // that have a complex construction + // standard + + //RealD beta = 5.6; + WilsonGaugeActionR Waction(MyParams.gauge_beta); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + + // temporarily need a gauge field + FundamentalRepresentation::LatticeField UF(GridPtr); + TwoIndexAntiSymmetricRepresentation::LatticeField UAS(GridPtr); - Real adjoint_mass = -0.1; - Real symm_mass = -0.5; - AdjFermionAction AdjFermOp(UA, *GridPtr, *GridRBPtr, adjoint_mass); - SymmFermionAction SymmFermOp(US, *GridPtr, *GridRBPtr, symm_mass); - ConjugateGradient CG_adj(1.0e-8, 10000, false); - ConjugateGradient CG_symm(1.0e-8, 10000, false); + Real Fundmass = MyParams.WilsonCloverFund.mass; + Real Fundcsw = MyParams.WilsonCloverFund.csw; + Real ASmass = MyParams.WilsonCloverAS.mass; + Real AScsw = MyParams.WilsonCloverAS.csw; - // Pass two solvers: one for the force computation and one for the action - TwoFlavourPseudoFermionAction Nf2_Adj(AdjFermOp, CG_adj, CG_adj); - TwoFlavourPseudoFermionAction Nf2_Symm(SymmFermOp, CG_symm, CG_symm); + + + std::cout << "Fund: mass and csw" << Fundmass << " and " << Fundcsw << std::endl; + std::cout << "AS : mass and csw" << ASmass << " and " << AScsw << std::endl; + + + FundFermionAction FundFermOp(UF, *GridPtr, *GridRBPtr, Fundmass, Fundcsw, Fundcsw); + ConjugateGradient CG_Fund(MyParams.WilsonCloverFund.StoppingCondition, MyParams.WilsonCloverFund.MaxCGIterations); + TwoFlavourPseudoFermionAction Nf2_Fund(FundFermOp, CG_Fund, CG_Fund); + + ASymmFermionAction ASFermOp(UAS, *GridPtr, *GridRBPtr, ASmass, AScsw, AScsw); + ConjugateGradient CG_AS(MyParams.WilsonCloverAS.StoppingCondition, MyParams.WilsonCloverAS.MaxCGIterations); + TwoFlavourPseudoFermionAction Nf2_AS(ASFermOp, CG_AS, CG_AS); + + Nf2_Fund.is_smeared = ApplySmearingFund; + Nf2_AS.is_smeared = ApplySmearingAS; + // Collect actions - ActionLevel Level1(1); - Level1.push_back(&Nf2_Adj); - Level1.push_back(&Nf2_Symm); + ActionLevel Level1(1); + Level1.push_back(&Nf2_Fund); + Level1.push_back(&Nf2_AS); - ActionLevel Level2(4); + ActionLevel Level2(4); Level2.push_back(&Waction); TheHMC.TheAction.push_back(Level1); TheHMC.TheAction.push_back(Level2); - // HMC parameters are serialisable - TheHMC.Parameters.MD.MDsteps = 20; - TheHMC.Parameters.MD.trajL = 1.0; + TheHMC.Parameters.initialize(Reader); + //TheHMC.Parameters.MD.MDsteps = 20; + //TheHMC.Parameters.MD.trajL = 1.0; +/* + if (ApplySmearingFund || ApplySmearingAS){ + SmearingParameters SmPar(Reader); + //double rho = 0.1; // smearing parameter + //int Nsmear = 3; // number of smearing levels + Smear_Stout Stout(SmPar.rho); + SmearedConfiguration SmearingPolicy(GridPtr, SmPar.Nsmear, Stout); + TheHMC.Run(SmearingPolicy); // for smearing + } else { + TheHMC.Run(); // no smearing + } +*/ + TheHMC.Run(); - TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file - TheHMC.Run(); // no smearing + + //TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file + //TheHMC.Run(); // no smearing + // TheHMC.Run(SmearingPolicy); // for smearing Grid_finalize(); } // main - - diff --git a/tests/hmc/Test_hmc_WCadjFG_Production.cc b/tests/hmc/Test_hmc_WCadjFG_Production.cc new file mode 100644 index 00000000..b99c1189 --- /dev/null +++ b/tests/hmc/Test_hmc_WCadjFG_Production.cc @@ -0,0 +1,213 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./tests/Test_hmc_WilsonFermionGauge.cc + +Copyright (C) 2017 + +Author: Guido Cossu + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + + +namespace Grid{ + struct FermionParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(FermionParameters, + double, mass, + double, csw, + double, StoppingCondition, + int, MaxCGIterations, + bool, ApplySmearing); + }; + + + struct WilsonCloverHMCParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonCloverHMCParameters, + double, gauge_beta, + FermionParameters, WilsonClover) + + template + WilsonCloverHMCParameters(Reader& Reader){ + read(Reader, "Action", *this); + } + }; + + struct SmearingParameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(SmearingParameters, + double, rho, + Integer, Nsmear) + + template + SmearingParameters(Reader& Reader){ + read(Reader, "StoutSmearing", *this); + } + + }; + + +} + +int main(int argc, char **argv) +{ + using namespace Grid; + using namespace Grid::QCD; + + typedef Representations< FundamentalRepresentation, AdjointRepresentation > TheRepresentations; + + Grid_init(&argc, &argv); + int threads = GridThread::GetThreads(); + // here make a routine to print all the relevant information on the run + std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl; + + // Typedefs to simplify notation + typedef GenericHMCRunnerHirep HMCWrapper; // Uses the default minimum norm + typedef WilsonAdjImplR FermionImplPolicy; // gauge field implemetation for the pseudofermions + typedef WilsonCloverAdjFermionR FermionAction; // type of lattice fermions (Wilson, DW, ...) + typedef typename FermionAction::FermionField FermionField; + typedef Grid::JSONReader Serialiser; + + //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + HMCWrapper TheHMC; + + // Grid from the command line + TheHMC.ReadCommandLine(argc, argv); + if (TheHMC.ParameterFile.empty()){ + std::cout << "Input file not specified." + << "Use --ParameterFile option in the command line.\nAborting" + << std::endl; + exit(1); + } + Serialiser Reader(TheHMC.ParameterFile); + WilsonCloverHMCParameters MyParams(Reader); + + // Apply smearing to the fermionic action + bool ApplySmearing = MyParams.WilsonClover.ApplySmearing; + + TheHMC.Resources.AddFourDimGrid("gauge"); + + // Checkpointer definition + CheckpointerParameters CPparams(Reader); + + /* + CPparams.config_prefix = "ckpoint_lat"; + CPparams.rng_prefix = "ckpoint_rng"; + CPparams.saveInterval = 5; + CPparams.format = "IEEE64BIG"; + */ + + TheHMC.Resources.LoadNerscCheckpointer(CPparams); + + RNGModuleParameters RNGpar(Reader); + /* + RNGpar.serial_seeds = "1 2 3 4 5"; + RNGpar.parallel_seeds = "6 7 8 9 10"; + TheHMC.Resources.SetRNGSeeds(RNGpar); + */ + TheHMC.Resources.SetRNGSeeds(RNGpar); + + // Construct observables + typedef PlaquetteMod PlaqObs; + TheHMC.Resources.AddObservable(); + + typedef PolyakovMod PolyakovObs; + TheHMC.Resources.AddObservable(); + + //typedef TopologicalChargeMod QObs; + //TopologyObsParameters TopParams(Reader); + //TheHMC.Resources.AddObservable(TopParams); + ////////////////////////////////////////////// + + ///////////////////////////////////////////////////////////// + // Collect actions, here use more encapsulation + // need wrappers of the fermionic classes + // that have a complex construction + // standard + + //RealD beta = 5.6; + WilsonGaugeActionR Waction(MyParams.gauge_beta); + + auto GridPtr = TheHMC.Resources.GetCartesian(); + auto GridRBPtr = TheHMC.Resources.GetRBCartesian(); + + // temporarily need a gauge field + AdjointRepresentation::LatticeField U(GridPtr); + + //Real mass = 0.01; + //Real csw = 1.0; + + Real mass = MyParams.WilsonClover.mass; + Real csw = MyParams.WilsonClover.csw; + + std::cout << "mass and csw" << mass << " and " << csw << std::endl; + + FermionAction FermOp(U, *GridPtr, *GridRBPtr, mass, csw, csw); + ConjugateGradient CG(MyParams.WilsonClover.StoppingCondition, MyParams.WilsonClover.MaxCGIterations); + TwoFlavourPseudoFermionAction Nf2(FermOp, CG, CG); + + // Set smearing (true/false), default: false + Nf2.is_smeared = ApplySmearing; + + // Collect actions + ActionLevel Level1(1); + Level1.push_back(&Nf2); + + ActionLevel Level2(4); + Level2.push_back(&Waction); + + TheHMC.TheAction.push_back(Level1); + TheHMC.TheAction.push_back(Level2); + ///////////////////////////////////////////////////////////// + + + /* + double rho = 0.1; // smearing parameter + int Nsmear = 2; // number of smearing levels + Smear_Stout Stout(rho); + SmearedConfiguration SmearingPolicy( + UGrid, Nsmear, Stout); + */ + + // HMC parameters are serialisable + + TheHMC.Parameters.initialize(Reader); + //TheHMC.Parameters.MD.MDsteps = 20; + //TheHMC.Parameters.MD.trajL = 1.0; + + if (ApplySmearing){ + SmearingParameters SmPar(Reader); + //double rho = 0.1; // smearing parameter + //int Nsmear = 3; // number of smearing levels + Smear_Stout Stout(SmPar.rho); + SmearedConfiguration SmearingPolicy(GridPtr, SmPar.Nsmear, Stout); + TheHMC.Run(SmearingPolicy); // for smearing + } else { + TheHMC.Run(); // no smearing + } + + //TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file + //TheHMC.Run(); // no smearing + // TheHMC.Run(SmearingPolicy); // for smearing + + Grid_finalize(); + +} // main + From 59d9ccf70cfaa57078aafe81aa3455f8e05b7d48 Mon Sep 17 00:00:00 2001 From: pretidav Date: Wed, 8 Nov 2017 22:02:32 +0100 Subject: [PATCH 090/174] restored WilsonKernelsHand.cc and added Qtop to production codes --- lib/qcd/action/fermion/WilsonKernelsHand.cc | 2 -- tests/hmc/Test_hmc_WCMixedRepFG_Production.cc | 6 +++--- tests/hmc/Test_hmc_WCadjFG_Production.cc | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonKernelsHand.cc b/lib/qcd/action/fermion/WilsonKernelsHand.cc index aa6b5f6b..90e6cb9b 100644 --- a/lib/qcd/action/fermion/WilsonKernelsHand.cc +++ b/lib/qcd/action/fermion/WilsonKernelsHand.cc @@ -946,6 +946,4 @@ INSTANTIATE_THEM(DomainWallVec5dImplFH); INSTANTIATE_THEM(DomainWallVec5dImplDF); INSTANTIATE_THEM(ZDomainWallVec5dImplFH); INSTANTIATE_THEM(ZDomainWallVec5dImplDF); -INSTANTIATE_THEM(WilsonTwoIndexAntiSymmetricImplF); -INSTANTIATE_THEM(WilsonTwoIndexAntiSymmetricImplD); }} diff --git a/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc b/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc index a79452f4..aa5cce85 100644 --- a/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc +++ b/tests/hmc/Test_hmc_WCMixedRepFG_Production.cc @@ -140,9 +140,9 @@ int main(int argc, char **argv) { typedef PolyakovMod PolyakovObs; TheHMC.Resources.AddObservable(); - //typedef TopologicalChargeMod QObs; - //TopologyObsParameters TopParams(Reader); - //TheHMC.Resources.AddObservable(TopParams); + typedef TopologicalChargeMod QObs; + TopologyObsParameters TopParams(Reader); + TheHMC.Resources.AddObservable(TopParams); ////////////////////////////////////////////// ///////////////////////////////////////////////////////////// diff --git a/tests/hmc/Test_hmc_WCadjFG_Production.cc b/tests/hmc/Test_hmc_WCadjFG_Production.cc index b99c1189..48cea756 100644 --- a/tests/hmc/Test_hmc_WCadjFG_Production.cc +++ b/tests/hmc/Test_hmc_WCadjFG_Production.cc @@ -131,9 +131,9 @@ int main(int argc, char **argv) typedef PolyakovMod PolyakovObs; TheHMC.Resources.AddObservable(); - //typedef TopologicalChargeMod QObs; - //TopologyObsParameters TopParams(Reader); - //TheHMC.Resources.AddObservable(TopParams); + typedef TopologicalChargeMod QObs; + TopologyObsParameters TopParams(Reader); + TheHMC.Resources.AddObservable(TopParams); ////////////////////////////////////////////// ///////////////////////////////////////////////////////////// From 6a15e2e8ef25e54c966d44169c7f2ab4d6d1c1d0 Mon Sep 17 00:00:00 2001 From: pretidav Date: Sun, 12 Nov 2017 14:16:19 +0100 Subject: [PATCH 091/174] Added WilsonTwoIndexAntiSymmImpl instantiation in WilsonKernelsHand.cc (shoud not be necessary) --- lib/qcd/action/fermion/WilsonKernelsHand.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/qcd/action/fermion/WilsonKernelsHand.cc b/lib/qcd/action/fermion/WilsonKernelsHand.cc index 90e6cb9b..aa6b5f6b 100644 --- a/lib/qcd/action/fermion/WilsonKernelsHand.cc +++ b/lib/qcd/action/fermion/WilsonKernelsHand.cc @@ -946,4 +946,6 @@ INSTANTIATE_THEM(DomainWallVec5dImplFH); INSTANTIATE_THEM(DomainWallVec5dImplDF); INSTANTIATE_THEM(ZDomainWallVec5dImplFH); INSTANTIATE_THEM(ZDomainWallVec5dImplDF); +INSTANTIATE_THEM(WilsonTwoIndexAntiSymmetricImplF); +INSTANTIATE_THEM(WilsonTwoIndexAntiSymmetricImplD); }} From 1f1d77b01a308a7716d429b09bb0ffa01cd7f835 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 14 Nov 2017 10:01:48 +0000 Subject: [PATCH 092/174] Performance metrics for the Scalar Action force term --- lib/qcd/action/scalar/ScalarImpl.h | 4 ++ .../action/scalar/ScalarInteractionAction.h | 62 ++++++++++++++----- lib/qcd/hmc/GenericHMCrunner.h | 2 +- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/lib/qcd/action/scalar/ScalarImpl.h b/lib/qcd/action/scalar/ScalarImpl.h index 650f4d17..55f5049d 100644 --- a/lib/qcd/action/scalar/ScalarImpl.h +++ b/lib/qcd/action/scalar/ScalarImpl.h @@ -168,7 +168,11 @@ class ScalarImplTypes { static inline void update_field(Field &P, Field &U, double ep) { #ifndef USE_FFT_ACCELERATION + double t0=usecond(); U += P * ep; + double t1=usecond(); + double total_time = (t1-t0)/1e6; + std::cout << GridLogIntegrator << "Total time for updating field (s) : " << total_time << std::endl; #else // FFT transform P(x) -> P(p) // divide by (M^2+p^2) M external parameter (how to pass?) diff --git a/lib/qcd/action/scalar/ScalarInteractionAction.h b/lib/qcd/action/scalar/ScalarInteractionAction.h index 3848751d..8738b647 100644 --- a/lib/qcd/action/scalar/ScalarInteractionAction.h +++ b/lib/qcd/action/scalar/ScalarInteractionAction.h @@ -44,18 +44,18 @@ public: INHERIT_FIELD_TYPES(Impl); private: - RealD mass_square; - RealD lambda; - RealD g; - const unsigned int N = Impl::Group::Dimension; + RealD mass_square; + RealD lambda; + RealD g; + const unsigned int N = Impl::Group::Dimension; typedef typename Field::vector_object vobj; typedef CartesianStencil Stencil; SimpleCompressor compressor; int npoint = 2 * Ndim; - std::vector directions; // = {0,1,2,3,0,1,2,3}; // forcing 4 dimensions - std::vector displacements; // = {1,1,1,1, -1,-1,-1,-1}; + std::vector directions; // + std::vector displacements; // public: ScalarInteractionAction(RealD ms, RealD l, RealD gval) : mass_square(ms), lambda(l), g(gval), displacements(2 * Ndim, 0), directions(2 * Ndim, 0) @@ -124,39 +124,55 @@ public: } // NB the trace in the algebra is normalised to 1/2 // minus sign coming from the antihermitian fields - return -(TensorRemove(sum(trace(action)))).real()*N/g; + return -(TensorRemove(sum(trace(action)))).real() * N / g; }; virtual void deriv(const Field &p, Field &force) { + double t0 = usecond(); assert(p._grid->Nd() == Ndim); force = (2. * Ndim + mass_square) * p - 2. * lambda * p * p * p; + double interm_t = usecond(); + // move this outside static Stencil phiStencil(p._grid, npoint, 0, directions, displacements); - phiStencil.HaloExchange(p, compressor); + phiStencil.HaloExchange(p, compressor); + double halo_t = usecond(); + int chunk = 128; //for (int mu = 0; mu < QCD::Nd; mu++) force -= Cshift(p, mu, -1) + Cshift(p, mu, 1); + + // inverting the order of the loops slows down the code(! g++ 7) + // cannot try to reduce the number of force writes by factor npoint... + // use cache blocking for (int point = 0; point < npoint; point++) { - parallel_for(int i = 0; i < p._grid->oSites(); i++) - { - const vobj *temp; - vobj temp2; + +#pragma omp parallel +{ int permute_type; StencilEntry *SE; + const vobj *temp; + +#pragma omp for schedule(static, chunk) + for (int i = 0; i < p._grid->oSites(); i++) + { SE = phiStencil.GetEntry(permute_type, point, i); + // prefetch next p? if (SE->_is_local) { temp = &p._odata[SE->_offset]; + if (SE->_permute) { + vobj temp2; permute(temp2, *temp, permute_type); force._odata[i] -= temp2; } else { - force._odata[i] -= *temp; + force._odata[i] -= *temp; // slow part. Dominated by this read/write (BW) } } else @@ -164,9 +180,27 @@ public: force._odata[i] -= phiStencil.CommBuf()[SE->_offset]; } } + } - force *= N/g; } + force *= N / g; + + double t1 = usecond(); + double total_time = (t1 - t0) / 1e6; + double interm_time = (interm_t - t0) / 1e6; + double halo_time = (halo_t - interm_t) / 1e6; + double stencil_time = (t1 - halo_t) / 1e6; + std::cout << GridLogIntegrator << "Total time for force computation (s) : " << total_time << std::endl; + std::cout << GridLogIntegrator << "Intermediate time for force computation (s): " << interm_time << std::endl; + std::cout << GridLogIntegrator << "Halo time in force computation (s) : " << halo_time << std::endl; + std::cout << GridLogIntegrator << "Stencil time in force computation (s) : " << stencil_time << std::endl; + double flops = p._grid->gSites() * (14 * N * N * N + 18 * N * N + 2); + double flops_no_stencil = p._grid->gSites() * (14 * N * N * N + 6 * N * N + 2); + double Gflops = flops / (total_time * 1e9); + double Gflops_no_stencil = flops_no_stencil / (interm_time * 1e9); + std::cout << GridLogIntegrator << "Flops: " << flops << " - Gflop/s : " << Gflops << std::endl; + std::cout << GridLogIntegrator << "Flops NS: " << flops_no_stencil << " - Gflop/s NS: " << Gflops_no_stencil << std::endl; +} }; } // namespace Grid diff --git a/lib/qcd/hmc/GenericHMCrunner.h b/lib/qcd/hmc/GenericHMCrunner.h index 4f6c1af0..26fec3d5 100644 --- a/lib/qcd/hmc/GenericHMCrunner.h +++ b/lib/qcd/hmc/GenericHMCrunner.h @@ -211,7 +211,7 @@ typedef HMCWrapperTemplate ScalarAdjGenericHMCRunner; template -using ScalarNxNAdjGenericHMCRunner = HMCWrapperTemplate < ScalarNxNAdjImplR, MinimumNorm2, ScalarNxNMatrixFields >; +using ScalarNxNAdjGenericHMCRunner = HMCWrapperTemplate < ScalarNxNAdjImplR, ForceGradient, ScalarNxNMatrixFields >; } // namespace QCD } // namespace Grid From f403ab01336b6ec2cdc4260f698a0f5001bb0a3d Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 22 Nov 2017 17:13:09 +0000 Subject: [PATCH 093/174] gitignore update --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d743ee06..399f2f6b 100644 --- a/.gitignore +++ b/.gitignore @@ -93,6 +93,7 @@ build*/* *.xcodeproj/* build.sh .vscode +*.code-workspace # Eigen source # ################ @@ -122,4 +123,3 @@ make-bin-BUCK.sh ##################### lib/qcd/spin/gamma-gen/*.h lib/qcd/spin/gamma-gen/*.cc - From a3fe874a5ba649fecec0a273e4f5a0dd52995a03 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 22 Nov 2017 23:27:19 +0000 Subject: [PATCH 094/174] Hadrons: everything is broken, repairing while implementing the new memory model --- extras/Hadrons/Application.cc | 14 +++ extras/Hadrons/Application.hpp | 2 + extras/Hadrons/Environment.cc | 106 ++++-------------- extras/Hadrons/Environment.hpp | 118 ++++++-------------- extras/Hadrons/Module.hpp | 6 + extras/Hadrons/Modules.hpp | 52 ++++----- extras/Hadrons/Modules/MAction/DWF.hpp | 25 ++--- extras/Hadrons/Modules/MAction/Wilson.hpp | 30 ++--- extras/Hadrons/Modules/MGauge/Unit.cc | 4 +- extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 27 ++--- extras/Hadrons/modules.inc | 74 ++++++------ 11 files changed, 174 insertions(+), 284 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 90ebcfd7..a94b617c 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -316,3 +316,17 @@ void Application::configLoop(void) LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; env().freeAll(); } + +// memory profile ////////////////////////////////////////////////////////////// +void Application::memoryProfile(void) +{ + auto graph = env().makeModuleGraph(); + auto program = graph.topoSort(); + bool msg; + + msg = HadronsLogMessage.isActive(); + HadronsLogMessage.Active(false); + + HadronsLogMessage.Active(msg); +} + diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index fce9b6eb..8b11b0c7 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -101,6 +101,8 @@ public: private: // environment shortcut Environment & env(void) const; + // memory profile + void memoryProfile(void); private: long unsigned int locVol_; std::string parameterFileName_{""}; diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 0e7a4326..eb0a6f70 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -67,6 +67,16 @@ bool Environment::isDryRun(void) const return dryRun_; } +void Environment::memoryProfile(const bool doMemoryProfile) +{ + memoryProfile_ = doMemoryProfile; +} + +bool Environment::doMemoryProfile(void) const +{ + return memoryProfile_; +} + // trajectory number /////////////////////////////////////////////////////////// void Environment::setTrajectory(const unsigned int traj) { @@ -349,10 +359,10 @@ Environment::executeProgram(const std::vector &p) auto it = std::find_if(p.rbegin(), p.rend(), pred); if (it != p.rend()) { - freeProg[p.rend() - it - 1].insert(i); + freeProg[std::distance(p.rend(), it) - 1].insert(i); } } - + // program execution for (unsigned int i = 0; i < p.size(); ++i) { @@ -448,6 +458,7 @@ void Environment::addObject(const std::string name, const int moduleAddress) info.name = name; info.module = moduleAddress; + info.data = nullptr; object_.push_back(std::move(info)); objectAddress_[name] = static_cast(object_.size() - 1); } @@ -457,39 +468,6 @@ void Environment::addObject(const std::string name, const int moduleAddress) } } -void Environment::registerObject(const unsigned int address, - const unsigned int size, const unsigned int Ls) -{ - if (!hasRegisteredObject(address)) - { - if (hasObject(address)) - { - object_[address].size = size; - object_[address].Ls = Ls; - object_[address].isRegistered = true; - } - else - { - HADRON_ERROR("no object with address " + std::to_string(address)); - } - } - else - { - HADRON_ERROR("object with address " + std::to_string(address) - + " already registered"); - } -} - -void Environment::registerObject(const std::string name, - const unsigned int size, const unsigned int Ls) -{ - if (!hasObject(name)) - { - addObject(name); - } - registerObject(getObjectAddress(name), size, Ls); -} - unsigned int Environment::getObjectAddress(const std::string name) const { if (hasObject(name)) @@ -516,7 +494,7 @@ std::string Environment::getObjectName(const unsigned int address) const std::string Environment::getObjectType(const unsigned int address) const { - if (hasRegisteredObject(address)) + if (hasObject(address)) { if (object_[address].type) { @@ -527,11 +505,6 @@ std::string Environment::getObjectType(const unsigned int address) const return ""; } } - else if (hasObject(address)) - { - HADRON_ERROR("object with address " + std::to_string(address) - + " exists but is not registered"); - } else { HADRON_ERROR("no object with address " + std::to_string(address)); @@ -545,15 +518,10 @@ std::string Environment::getObjectType(const std::string name) const Environment::Size Environment::getObjectSize(const unsigned int address) const { - if (hasRegisteredObject(address)) + if (hasObject(address)) { return object_[address].size; } - else if (hasObject(address)) - { - HADRON_ERROR("object with address " + std::to_string(address) - + " exists but is not registered"); - } else { HADRON_ERROR("no object with address " + std::to_string(address)); @@ -584,15 +552,10 @@ unsigned int Environment::getObjectModule(const std::string name) const unsigned int Environment::getObjectLs(const unsigned int address) const { - if (hasRegisteredObject(address)) + if (hasObject(address)) { return object_[address].Ls; } - else if (hasObject(address)) - { - HADRON_ERROR("object with address " + std::to_string(address) - + " exists but is not registered"); - } else { HADRON_ERROR("no object with address " + std::to_string(address)); @@ -616,30 +579,6 @@ bool Environment::hasObject(const std::string name) const return ((it != objectAddress_.end()) and hasObject(it->second)); } -bool Environment::hasRegisteredObject(const unsigned int address) const -{ - if (hasObject(address)) - { - return object_[address].isRegistered; - } - else - { - return false; - } -} - -bool Environment::hasRegisteredObject(const std::string name) const -{ - if (hasObject(name)) - { - return hasRegisteredObject(getObjectAddress(name)); - } - else - { - return false; - } -} - bool Environment::hasCreatedObject(const unsigned int address) const { if (hasObject(address)) @@ -680,10 +619,7 @@ Environment::Size Environment::getTotalSize(void) const for (auto &o: object_) { - if (o.isRegistered) - { - size += o.size; - } + size += o.size; } return size; @@ -738,7 +674,7 @@ bool Environment::freeObject(const unsigned int address) { if (!hasOwners(address)) { - if (!isDryRun() and object_[address].isRegistered) + if (!isDryRun()) { LOG(Message) << "Destroying object '" << object_[address].name << "'" << std::endl; @@ -747,10 +683,8 @@ bool Environment::freeObject(const unsigned int address) { object_[p].owners.erase(address); } - object_[address].size = 0; - object_[address].Ls = 0; - object_[address].isRegistered = false; - object_[address].type = nullptr; + object_[address].size = 0; + object_[address].type = nullptr; object_[address].owners.clear(); object_[address].properties.clear(); object_[address].data.reset(nullptr); diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 13264bd5..b426fb27 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -83,12 +83,12 @@ private: std::string name; ModPt data{nullptr}; std::vector input; + size_t maxAllocated; }; struct ObjInfo { Size size{0}; unsigned int Ls{0}; - bool isRegistered{false}; const std::type_info *type{nullptr}; std::string name; int module{-1}; @@ -99,6 +99,8 @@ public: // dry run void dryRun(const bool isDry); bool isDryRun(void) const; + void memoryProfile(const bool doMemoryProfile); + bool doMemoryProfile(void) const; // trajectory number void setTrajectory(const unsigned int traj); unsigned int getTrajectory(void) const; @@ -143,32 +145,17 @@ public: // general memory management void addObject(const std::string name, const int moduleAddress = -1); - void registerObject(const unsigned int address, - const unsigned int size, - const unsigned int Ls = 1); - void registerObject(const std::string name, - const unsigned int size, - const unsigned int Ls = 1); + template + void createObject(const std::string name, + const unsigned int Ls, + Ts ... args); template - unsigned int lattice4dSize(void) const; - template - void registerLattice(const unsigned int address, - const unsigned int Ls = 1); - template - void registerLattice(const std::string name, - const unsigned int Ls = 1); - template - void setObject(const unsigned int address, T *object); - template - void setObject(const std::string name, T *object); + void createLattice(const std::string name, + const unsigned int Ls = 1); template T * getObject(const unsigned int address) const; template T * getObject(const std::string name) const; - template - T * createLattice(const unsigned int address); - template - T * createLattice(const std::string name); unsigned int getObjectAddress(const std::string name) const; std::string getObjectName(const unsigned int address) const; std::string getObjectType(const unsigned int address) const; @@ -181,8 +168,6 @@ public: unsigned int getObjectLs(const std::string name) const; bool hasObject(const unsigned int address) const; bool hasObject(const std::string name) const; - bool hasRegisteredObject(const unsigned int address) const; - bool hasRegisteredObject(const std::string name) const; bool hasCreatedObject(const unsigned int address) const; bool hasCreatedObject(const std::string name) const; bool isObject5d(const unsigned int address) const; @@ -204,7 +189,7 @@ public: void printContent(void); private: // general - bool dryRun_{false}; + bool dryRun_{false}, memoryProfile_{false}; unsigned int traj_, locVol_; // grids std::vector dim_; @@ -296,56 +281,45 @@ M * Environment::getModule(const std::string name) const return getModule(getModuleAddress(name)); } -template -unsigned int Environment::lattice4dSize(void) const +template +void Environment::createObject(const std::string name, const unsigned int Ls, + Ts ... args) { - return sizeof(typename T::vector_object)/getGrid()->Nsimd(); -} - -template -void Environment::registerLattice(const unsigned int address, - const unsigned int Ls) -{ - createGrid(Ls); - registerObject(address, Ls*lattice4dSize(), Ls); -} - -template -void Environment::registerLattice(const std::string name, const unsigned int Ls) -{ - createGrid(Ls); - registerObject(name, Ls*lattice4dSize(), Ls); -} - -template -void Environment::setObject(const unsigned int address, T *object) -{ - if (hasRegisteredObject(address)) + if (!hasObject(name)) { - object_[address].data.reset(new Holder(object)); - object_[address].type = &typeid(T); + addObject(name); } - else if (hasObject(address)) + + unsigned int address = getObjectAddress(name); + + if (!object_[address].data) { - HADRON_ERROR("object with address " + std::to_string(address) + - " exists but is not registered"); + MemoryStats memStats; + + MemoryProfiler::stats = &memStats; + object_[address].Ls = Ls; + object_[address].data.reset(new Holder(new T(args...))); + object_[address].size = memStats.totalAllocated; + object_[address].type = &typeid(T); } else { - HADRON_ERROR("no object with address " + std::to_string(address)); + HADRON_ERROR("object '" + name + "' already allocated"); } } template -void Environment::setObject(const std::string name, T *object) +void Environment::createLattice(const std::string name, const unsigned int Ls) { - setObject(getObjectAddress(name), object); + GridCartesian *g = getGrid(Ls); + + createObject(name, Ls, g); } template T * Environment::getObject(const unsigned int address) const { - if (hasRegisteredObject(address)) + if (hasObject(address)) { if (auto h = dynamic_cast *>(object_[address].data.get())) { @@ -358,11 +332,6 @@ T * Environment::getObject(const unsigned int address) const "' (has type '" + getObjectType(address) + "')"); } } - else if (hasObject(address)) - { - HADRON_ERROR("object with address " + std::to_string(address) + - " exists but is not registered"); - } else { HADRON_ERROR("no object with address " + std::to_string(address)); @@ -375,26 +344,10 @@ T * Environment::getObject(const std::string name) const return getObject(getObjectAddress(name)); } -template -T * Environment::createLattice(const unsigned int address) -{ - GridCartesian *g = getGrid(getObjectLs(address)); - - setObject(address, new T(g)); - - return getObject(address); -} - -template -T * Environment::createLattice(const std::string name) -{ - return createLattice(getObjectAddress(name)); -} - template bool Environment::isObjectOfType(const unsigned int address) const { - if (hasRegisteredObject(address)) + if (hasObject(address)) { if (auto h = dynamic_cast *>(object_[address].data.get())) { @@ -405,11 +358,6 @@ bool Environment::isObjectOfType(const unsigned int address) const return false; } } - else if (hasObject(address)) - { - HADRON_ERROR("object with address " + std::to_string(address) + - " exists but is not registered"); - } else { HADRON_ERROR("no object with address " + std::to_string(address)); diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 071e254a..5500bf36 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -88,6 +88,12 @@ static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; #define ARG(...) __VA_ARGS__ +#define mCreateObj(type, name, Ls, ...)\ +env().template createObject(name, Ls, __VA_ARGS__) + +#define mGetObj(type, name)\ +*env().template getObject(name) + /****************************************************************************** * Module class * ******************************************************************************/ diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index e1f06f32..08678671 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -30,31 +30,31 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include +// #include #include -#include -#include -#include -#include -#include -#include +// #include +// #include +// #include +// #include +// #include +// #include #include -#include -#include -#include -#include -#include -#include -#include +// #include +// #include +// #include +// #include +// #include +// #include +// #include diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 78e0916c..a2ed063b 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -102,37 +102,30 @@ std::vector TDWF::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// template void TDWF::setup(void) -{ - unsigned int size; - - size = 2*env().template lattice4dSize(); - env().registerObject(getName(), size, par().Ls); -} - -// execution /////////////////////////////////////////////////////////////////// -template -void TDWF::execute(void) { LOG(Message) << "Setting up domain wall fermion matrix with m= " << par().mass << ", M5= " << par().M5 << " and Ls= " << par().Ls << " using gauge field '" << par().gauge << "'" << std::endl; - LOG(Message) << "Fermion boundary conditions: " << par().boundary + LOG(Message) << "Fermion boundary conditions: " << par().boundary << std::endl; env().createGrid(par().Ls); - auto &U = *env().template getObject(par().gauge); + auto &U = mGetObj(LatticeGaugeField, par().gauge); auto &g4 = *env().getGrid(); auto &grb4 = *env().getRbGrid(); auto &g5 = *env().getGrid(par().Ls); auto &grb5 = *env().getRbGrid(par().Ls); std::vector boundary = strToVec(par().boundary); typename DomainWallFermion::ImplParams implParams(boundary); - FMat *fMatPt = new DomainWallFermion(U, g5, grb5, g4, grb4, - par().mass, par().M5, - implParams); - env().setObject(getName(), fMatPt); + mCreateObj(DomainWallFermion, getName(), par().Ls, + U, g5, grb5, g4, grb4, par().mass, par().M5, implParams); } +// execution /////////////////////////////////////////////////////////////////// +template +void TDWF::execute(void) +{} + END_MODULE_NAMESPACE END_HADRONS_NAMESPACE diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index aab54245..bc892daf 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -101,29 +101,23 @@ std::vector TWilson::getOutput(void) template void TWilson::setup(void) { - unsigned int size; - - size = 2*env().template lattice4dSize(); - env().registerObject(getName(), size); + LOG(Message) << "Setting up TWilson fermion matrix with m= " << par().mass + << " using gauge field '" << par().gauge << "'" << std::endl; + LOG(Message) << "Fermion boundary conditions: " << par().boundary + << std::endl; + auto &U = mGetObj(LatticeGaugeField, par().gauge); + auto &grid = *env().getGrid(); + auto &gridRb = *env().getRbGrid(); + std::vector boundary = strToVec(par().boundary); + typename WilsonFermion::ImplParams implParams(boundary); + mCreateObj(WilsonFermion, getName(), 1, U, grid, gridRb, par().mass, + implParams); } // execution /////////////////////////////////////////////////////////////////// template void TWilson::execute() -{ - LOG(Message) << "Setting up TWilson fermion matrix with m= " << par().mass - << " using gauge field '" << par().gauge << "'" << std::endl; - LOG(Message) << "Fermion boundary conditions: " << par().boundary - << std::endl; - auto &U = *env().template getObject(par().gauge); - auto &grid = *env().getGrid(); - auto &gridRb = *env().getRbGrid(); - std::vector boundary = strToVec(par().boundary); - typename WilsonFermion::ImplParams implParams(boundary); - FMat *fMatPt = new WilsonFermion(U, grid, gridRb, par().mass, - implParams); - env().setObject(getName(), fMatPt); -} +{} END_MODULE_NAMESPACE diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index 18d75c59..b259b7d5 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -57,13 +57,13 @@ std::vector TUnit::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void TUnit::setup(void) { - env().registerLattice(getName()); + mCreateObj(LatticeGaugeField, getName(), 1, env().getGrid()); } // execution /////////////////////////////////////////////////////////////////// void TUnit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; - LatticeGaugeField &U = *env().createLattice(getName()); + auto &U = mGetObj(LatticeGaugeField, getName()); SU3::ColdConfiguration(*env().get4dRng(), U); } diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index b1f63a5d..fe6992fc 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -100,17 +100,12 @@ std::vector TRBPrecCG::getOutput(void) template void TRBPrecCG::setup(void) { - auto Ls = env().getObjectLs(par().action); - - env().registerObject(getName(), 0, Ls); - env().addOwnership(getName(), par().action); -} + LOG(Message) << "setting up Schur red-black preconditioned CG for" + << " action '" << par().action << "' with residual " + << par().residual << std::endl; -// execution /////////////////////////////////////////////////////////////////// -template -void TRBPrecCG::execute(void) -{ - auto &mat = *(env().template getObject(par().action)); + auto Ls = env().getObjectLs(par().action); + auto &mat = mGetObj(FMat, par().action); auto solver = [&mat, this](FermionField &sol, const FermionField &source) { ConjugateGradient cg(par().residual, 10000); @@ -118,13 +113,15 @@ void TRBPrecCG::execute(void) schurSolver(mat, source, sol); }; - - LOG(Message) << "setting up Schur red-black preconditioned CG for" - << " action '" << par().action << "' with residual " - << par().residual << std::endl; - env().setObject(getName(), new SolverFn(solver)); + mCreateObj(SolverFn, getName(), Ls, solver); + env().addOwnership(getName(), par().action); } +// execution /////////////////////////////////////////////////////////////////// +template +void TRBPrecCG::execute(void) +{} + END_MODULE_NAMESPACE END_HADRONS_NAMESPACE diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index fbbb2eb9..63745baf 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -1,42 +1,44 @@ modules_cc =\ - Modules/MContraction/WeakHamiltonianEye.cc \ - Modules/MContraction/WeakHamiltonianNonEye.cc \ - Modules/MContraction/WeakNeutral4ptDisc.cc \ - Modules/MGauge/Load.cc \ - Modules/MGauge/Random.cc \ - Modules/MGauge/StochEm.cc \ - Modules/MGauge/Unit.cc \ - Modules/MScalar/ChargedProp.cc \ - Modules/MScalar/FreeProp.cc + Modules/MGauge/Unit.cc + # Modules/MContraction/WeakHamiltonianEye.cc \ + # Modules/MContraction/WeakHamiltonianNonEye.cc \ + # Modules/MContraction/WeakNeutral4ptDisc.cc \ + # Modules/MGauge/Load.cc \ + # Modules/MGauge/Random.cc \ + # Modules/MGauge/StochEm.cc \ + # Modules/MScalar/ChargedProp.cc \ + # Modules/MScalar/FreeProp.cc modules_hpp =\ Modules/MAction/DWF.hpp \ Modules/MAction/Wilson.hpp \ - Modules/MContraction/Baryon.hpp \ - Modules/MContraction/DiscLoop.hpp \ - Modules/MContraction/Gamma3pt.hpp \ - Modules/MContraction/Meson.hpp \ - Modules/MContraction/WardIdentity.hpp \ - Modules/MContraction/WeakHamiltonian.hpp \ - Modules/MContraction/WeakHamiltonianEye.hpp \ - Modules/MContraction/WeakHamiltonianNonEye.hpp \ - Modules/MContraction/WeakNeutral4ptDisc.hpp \ - Modules/MFermion/GaugeProp.hpp \ - Modules/MGauge/Load.hpp \ - Modules/MGauge/Random.hpp \ - Modules/MGauge/StochEm.hpp \ Modules/MGauge/Unit.hpp \ - Modules/MLoop/NoiseLoop.hpp \ - Modules/MScalar/ChargedProp.hpp \ - Modules/MScalar/FreeProp.hpp \ - Modules/MScalar/Scalar.hpp \ - Modules/MSink/Point.hpp \ - Modules/MSink/Smear.hpp \ - Modules/MSolver/RBPrecCG.hpp \ - Modules/MSource/Point.hpp \ - Modules/MSource/SeqConserved.hpp \ - Modules/MSource/SeqGamma.hpp \ - Modules/MSource/Wall.hpp \ - Modules/MSource/Z2.hpp \ - Modules/MUtilities/TestSeqConserved.hpp \ - Modules/MUtilities/TestSeqGamma.hpp + Modules/MSolver/RBPrecCG.hpp + + # Modules/MContraction/Baryon.hpp \ + # Modules/MContraction/DiscLoop.hpp \ + # Modules/MContraction/Gamma3pt.hpp \ + # Modules/MContraction/Meson.hpp \ + # Modules/MContraction/WardIdentity.hpp \ + # Modules/MContraction/WeakHamiltonian.hpp \ + # Modules/MContraction/WeakHamiltonianEye.hpp \ + # Modules/MContraction/WeakHamiltonianNonEye.hpp \ + # Modules/MContraction/WeakNeutral4ptDisc.hpp \ + # Modules/MFermion/GaugeProp.hpp \ + # Modules/MGauge/Load.hpp \ + # Modules/MGauge/Random.hpp \ + # Modules/MGauge/StochEm.hpp \ + # Modules/MLoop/NoiseLoop.hpp \ + # Modules/MScalar/ChargedProp.hpp \ + # Modules/MScalar/FreeProp.hpp \ + # Modules/MScalar/Scalar.hpp \ + # Modules/MSink/Point.hpp \ + # Modules/MSink/Smear.hpp \ + # Modules/MSolver/RBPrecCG.hpp \ + # Modules/MSource/Point.hpp \ + # Modules/MSource/SeqConserved.hpp \ + # Modules/MSource/SeqGamma.hpp \ + # Modules/MSource/Wall.hpp \ + # Modules/MSource/Z2.hpp \ + # Modules/MUtilities/TestSeqConserved.hpp \ + # Modules/MUtilities/TestSeqGamma.hpp From 514993ed17671607a33d4b23873fd9f136b776e1 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 1 Dec 2017 19:38:23 +0000 Subject: [PATCH 095/174] Hadrons: progress on the interface, genetic algorithm freezing --- extras/Hadrons/Application.cc | 15 ++++-- extras/Hadrons/Environment.cc | 27 +++++++--- extras/Hadrons/Environment.hpp | 40 +++++++-------- extras/Hadrons/Module.hpp | 49 +++++++++++++++++-- extras/Hadrons/Modules.hpp | 8 +-- extras/Hadrons/Modules/MAction/DWF.hpp | 7 +-- extras/Hadrons/Modules/MAction/Wilson.hpp | 7 +-- extras/Hadrons/Modules/MContraction/Meson.hpp | 18 +++---- extras/Hadrons/Modules/MFermion/GaugeProp.hpp | 29 ++++++----- extras/Hadrons/Modules/MGauge/Unit.cc | 4 +- extras/Hadrons/Modules/MSink/Point.hpp | 36 +++++++++----- extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 4 +- extras/Hadrons/Modules/MSource/Point.hpp | 4 +- extras/Hadrons/modules.inc | 9 ++-- 14 files changed, 164 insertions(+), 93 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index a94b617c..0a7d0290 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -98,6 +98,8 @@ void Application::run(void) { parseParameterFile(parameterFileName_); } + env().checkGraph(); + env().printContent(); if (!scheduled_) { schedule(); @@ -124,8 +126,14 @@ void Application::parseParameterFile(const std::string parameterFileName) LOG(Message) << "Building application from '" << parameterFileName << "'..." << std::endl; read(reader, "parameters", par); setPar(par); - push(reader, "modules"); - push(reader, "module"); + if (!push(reader, "modules")) + { + HADRON_ERROR("Cannot open node 'modules' in parameter file '" + parameterFileName + "'"); + } + if (!push(reader, "module")) + { + HADRON_ERROR("Cannot open node 'modules/module' in parameter file '" + parameterFileName + "'"); + } do { read(reader, "id", id); @@ -186,6 +194,8 @@ void Application::schedule(void) // build module dependency graph LOG(Message) << "Building module graph..." << std::endl; auto graph = env().makeModuleGraph(); + LOG(Debug) << "Module graph:" << std::endl; + LOG(Debug) << graph << std::endl; auto con = graph.getConnectedComponents(); // constrained topological sort using a genetic algorithm @@ -329,4 +339,3 @@ void Application::memoryProfile(void) HadronsLogMessage.Active(msg); } - diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index eb0a6f70..a6855862 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -333,6 +333,17 @@ Graph Environment::makeModuleGraph(void) const return moduleGraph; } +void Environment::checkGraph(void) const +{ + for (auto &o: object_) + { + if (o.module < 0) + { + HADRON_ERROR("object '" + o.name + "' does not have a creator"); + } + } +} + #define BIG_SEP "===============" #define SEP "---------------" #define MEM_MSG(size)\ @@ -346,6 +357,7 @@ Environment::executeProgram(const std::vector &p) bool continueCollect, nothingFreed; // build garbage collection schedule + LOG(Debug) << "Building garbage collection schedule..." << std::endl; freeProg.resize(p.size()); for (unsigned int i = 0; i < object_.size(); ++i) { @@ -359,11 +371,12 @@ Environment::executeProgram(const std::vector &p) auto it = std::find_if(p.rbegin(), p.rend(), pred); if (it != p.rend()) { - freeProg[std::distance(p.rend(), it) - 1].insert(i); + freeProg[std::distance(it, p.rend()) - 1].insert(i); } } // program execution + LOG(Debug) << "Executing program..." << std::endl; for (unsigned int i = 0; i < p.size(); ++i) { // execute module @@ -712,16 +725,16 @@ void Environment::freeAll(void) void Environment::printContent(void) { - LOG(Message) << "Modules: " << std::endl; + LOG(Debug) << "Modules: " << std::endl; for (unsigned int i = 0; i < module_.size(); ++i) { - LOG(Message) << std::setw(4) << i << ": " - << getModuleName(i) << std::endl; + LOG(Debug) << std::setw(4) << i << ": " + << getModuleName(i) << std::endl; } - LOG(Message) << "Objects: " << std::endl; + LOG(Debug) << "Objects: " << std::endl; for (unsigned int i = 0; i < object_.size(); ++i) { - LOG(Message) << std::setw(4) << i << ": " - << getObjectName(i) << std::endl; + LOG(Debug) << std::setw(4) << i << ": " + << getObjectName(i) << std::endl; } } diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index b426fb27..58e035ac 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -76,6 +76,7 @@ public: typedef std::unique_ptr GridRbPt; typedef std::unique_ptr RngPt; typedef std::unique_ptr LatticePt; + enum class Storage {object, cache, temporary}; private: struct ModuleInfo { @@ -88,6 +89,7 @@ private: struct ObjInfo { Size size{0}; + Storage storage{Storage::object}; unsigned int Ls{0}; const std::type_info *type{nullptr}; std::string name; @@ -140,18 +142,17 @@ public: bool hasModule(const unsigned int address) const; bool hasModule(const std::string name) const; Graph makeModuleGraph(void) const; + void checkGraph(void) const; Size executeProgram(const std::vector &p); Size executeProgram(const std::vector &p); // general memory management void addObject(const std::string name, const int moduleAddress = -1); - template + template void createObject(const std::string name, + const Storage storage, const unsigned int Ls, - Ts ... args); - template - void createLattice(const std::string name, - const unsigned int Ls = 1); + P &&pt); template T * getObject(const unsigned int address) const; template @@ -203,6 +204,7 @@ private: // module and related maps std::vector module_; std::map moduleAddress_; + std::string currentModule_{""}; // lattice store std::map lattice_; // object store @@ -281,9 +283,11 @@ M * Environment::getModule(const std::string name) const return getModule(getModuleAddress(name)); } -template -void Environment::createObject(const std::string name, const unsigned int Ls, - Ts ... args) +template +void Environment::createObject(const std::string name, + const Environment::Storage storage, + const unsigned int Ls, + P &&pt) { if (!hasObject(name)) { @@ -296,11 +300,13 @@ void Environment::createObject(const std::string name, const unsigned int Ls, { MemoryStats memStats; - MemoryProfiler::stats = &memStats; - object_[address].Ls = Ls; - object_[address].data.reset(new Holder(new T(args...))); - object_[address].size = memStats.totalAllocated; - object_[address].type = &typeid(T); + MemoryProfiler::stats = &memStats; + object_[address].storage = storage; + object_[address].Ls = Ls; + object_[address].data.reset(new Holder(pt)); + object_[address].size = memStats.totalAllocated; + object_[address].type = &typeid(T); + MemoryProfiler::stats = nullptr; } else { @@ -308,14 +314,6 @@ void Environment::createObject(const std::string name, const unsigned int Ls, } } -template -void Environment::createLattice(const std::string name, const unsigned int Ls) -{ - GridCartesian *g = getGrid(Ls); - - createObject(name, Ls, g); -} - template T * Environment::getObject(const unsigned int address) const { diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 5500bf36..a0b062df 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -87,13 +87,54 @@ public:\ static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; #define ARG(...) __VA_ARGS__ +#define MACRO_REDIRECT(arg1, arg2, arg3, macro, ...) macro -#define mCreateObj(type, name, Ls, ...)\ -env().template createObject(name, Ls, __VA_ARGS__) - -#define mGetObj(type, name)\ +#define envGet(type, name)\ *env().template getObject(name) +#define envGetTmp(type, name)\ +*env().template getObject(getName() + "_tmp_" + name) + +#define envIsType(type, name)\ +env().template getObject(name) + +#define envCreate(type, name, Ls, pt)\ +env().template createObject(name, Environment::Storage::object, Ls, pt) + +#define envCreateLat4(type, name)\ +envCreate(type, name, 1, new type(env().getGrid())) + +#define envCreateLat5(type, name, Ls)\ +envCreate(type, name, Ls, new type(env().getGrid(Ls))) + +#define envCreateLat(...)\ +MACRO_REDIRECT(__VA_ARGS__, envCreateLat5, envCreateLat4)(__VA_ARGS__) + +#define envCache(type, name, Ls, pt)\ +env().template createObject(name, Environment::Storage::cache, Ls, pt) + +#define envCacheLat4(type, name)\ +envCache(type, name, 1, new type(env().getGrid())) + +#define envCacheLat5(type, name, Ls)\ +envCache(type, name, Ls, new type(env().getGrid(Ls))) + +#define envCacheLat(...)\ +MACRO_REDIRECT(__VA_ARGS__, envCacheLat5, envCacheLat4)(__VA_ARGS__) + +#define envTmp(type, name, Ls, pt)\ +env().template createObject(getName() + "_tmp_" + name, \ + Environment::Storage::temporary, Ls, pt) + +#define envTmpLat4(type, name)\ +envTmp(type, name, 1, new type(env().getGrid())) + +#define envTmpLat5(type, name, Ls)\ +envTmp(type, name, Ls, new type(env().getGrid(Ls))) + +#define envTmpLat(...)\ +MACRO_REDIRECT(__VA_ARGS__, envTmpLat5, envTmpLat4)(__VA_ARGS__) + /****************************************************************************** * Module class * ******************************************************************************/ diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 08678671..bb574a14 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -33,13 +33,13 @@ See the full license in the file "LICENSE" in the top level distribution directo // #include // #include // #include -// #include +#include // #include // #include // #include // #include // #include -// #include +#include // #include // #include // #include @@ -48,10 +48,10 @@ See the full license in the file "LICENSE" in the top level distribution directo // #include // #include // #include -// #include +#include // #include #include -// #include +#include // #include // #include // #include diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index a2ed063b..7c82fe8b 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -110,15 +110,16 @@ void TDWF::setup(void) LOG(Message) << "Fermion boundary conditions: " << par().boundary << std::endl; env().createGrid(par().Ls); - auto &U = mGetObj(LatticeGaugeField, par().gauge); + auto &U = envGet(LatticeGaugeField, par().gauge); auto &g4 = *env().getGrid(); auto &grb4 = *env().getRbGrid(); auto &g5 = *env().getGrid(par().Ls); auto &grb5 = *env().getRbGrid(par().Ls); std::vector boundary = strToVec(par().boundary); typename DomainWallFermion::ImplParams implParams(boundary); - mCreateObj(DomainWallFermion, getName(), par().Ls, - U, g5, grb5, g4, grb4, par().mass, par().M5, implParams); + envCreate(FMat, getName(), par().Ls, + new DomainWallFermion(U, g5, grb5, g4, grb4, par().mass, + par().M5, implParams)); } // execution /////////////////////////////////////////////////////////////////// diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index bc892daf..5c334f8d 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -105,13 +105,14 @@ void TWilson::setup(void) << " using gauge field '" << par().gauge << "'" << std::endl; LOG(Message) << "Fermion boundary conditions: " << par().boundary << std::endl; - auto &U = mGetObj(LatticeGaugeField, par().gauge); + auto &U = envGet(LatticeGaugeField, par().gauge); auto &grid = *env().getGrid(); auto &gridRb = *env().getRbGrid(); std::vector boundary = strToVec(par().boundary); typename WilsonFermion::ImplParams implParams(boundary); - mCreateObj(WilsonFermion, getName(), 1, U, grid, gridRb, par().mass, - implParams); + envCreate(FMat, getName(), 1, new WilsonFermion(U, grid, gridRb, + par().mass, + implParams)); } // execution /////////////////////////////////////////////////////////////////// diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index b71f7c08..ccc6dc55 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -153,7 +153,6 @@ void TMeson::parseGammaString(std::vector &gammaList) } } - // execution /////////////////////////////////////////////////////////////////// #define mesonConnected(q1, q2, gSnk, gSrc) \ (g5*(gSnk))*(q1)*(adj(gSrc)*g5)*adj(q2) @@ -180,11 +179,11 @@ void TMeson::execute(void) result[i].gamma_src = gammaList[i].second; result[i].corr.resize(nt); } - if (env().template isObjectOfType(par().q1) and - env().template isObjectOfType(par().q2)) + if (envIsType(SlicedPropagator1, par().q1) and + envIsType(SlicedPropagator2, par().q2)) { - SlicedPropagator1 &q1 = *env().template getObject(par().q1); - SlicedPropagator2 &q2 = *env().template getObject(par().q2); + SlicedPropagator1 &q1 = envGet(SlicedPropagator1, par().q1); + SlicedPropagator2 &q2 = envGet(SlicedPropagator2, par().q2); LOG(Message) << "(propagator already sinked)" << std::endl; for (unsigned int i = 0; i < result.size(); ++i) @@ -200,8 +199,8 @@ void TMeson::execute(void) } else { - PropagatorField1 &q1 = *env().template getObject(par().q1); - PropagatorField2 &q2 = *env().template getObject(par().q2); + PropagatorField1 &q1 = envGet(PropagatorField1, par().q1); + PropagatorField2 &q2 = envGet(PropagatorField2, par().q2); LatticeComplex c(env().getGrid()); LOG(Message) << "(using sink '" << par().sink << "')" << std::endl; @@ -214,15 +213,14 @@ void TMeson::execute(void) ns = env().getModuleNamespace(env().getObjectModule(par().sink)); if (ns == "MSource") { - PropagatorField1 &sink = - *env().template getObject(par().sink); + PropagatorField1 &sink = envGet(PropagatorField1, par().sink); c = trace(mesonConnected(q1, q2, gSnk, gSrc)*sink); sliceSum(c, buf, Tp); } else if (ns == "MSink") { - SinkFnScalar &sink = *env().template getObject(par().sink); + SinkFnScalar &sink = envGet(SinkFnScalar, par().sink); c = trace(mesonConnected(q1, q2, gSnk, gSrc)); buf = sink(c); diff --git a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp index 8add9a00..59994d0d 100644 --- a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -127,10 +127,13 @@ template void TGaugeProp::setup(void) { Ls_ = env().getObjectLs(par().solver); - env().template registerLattice(getName()); + envCreateLat(PropagatorField, getName()); + envTmpLat(FermionField, "source", Ls_); + envTmpLat(FermionField, "sol", Ls_); + envTmpLat(FermionField, "tmp"); if (Ls_ > 1) { - env().template registerLattice(getName() + "_5d", Ls_); + envCreateLat(PropagatorField, getName() + "_5d", Ls_); } } @@ -139,21 +142,18 @@ template void TGaugeProp::execute(void) { LOG(Message) << "Computing quark propagator '" << getName() << "'" - << std::endl; + << std::endl; - FermionField source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)), - tmp(env().getGrid()); + FermionField &source = envGetTmp(FermionField, "source"); + FermionField &sol = envGetTmp(FermionField, "sol"); + FermionField &tmp = envGetTmp(FermionField, "tmp"); std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); - PropagatorField &prop = *env().template createLattice(propName); - PropagatorField &fullSrc = *env().template getObject(par().source); - SolverFn &solver = *env().template getObject(par().solver); - if (Ls_ > 1) - { - env().template createLattice(getName()); - } + PropagatorField &prop = envGet(PropagatorField, propName); + PropagatorField &fullSrc = envGet(PropagatorField, par().source); + SolverFn &solver = envGet(SolverFn, par().solver); LOG(Message) << "Inverting using solver '" << par().solver - << "' on source '" << par().source << "'" << std::endl; + << "' on source '" << par().source << "'" << std::endl; for (unsigned int s = 0; s < Ns; ++s) for (unsigned int c = 0; c < Nc; ++c) { @@ -190,8 +190,7 @@ void TGaugeProp::execute(void) // create 4D propagators from 5D one if necessary if (Ls_ > 1) { - PropagatorField &p4d = - *env().template getObject(getName()); + PropagatorField &p4d = envGet(PropagatorField, getName()); make_4D(sol, tmp, Ls_); FermToProp(p4d, tmp, s, c); } diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index b259b7d5..b3a7d634 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -57,13 +57,13 @@ std::vector TUnit::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void TUnit::setup(void) { - mCreateObj(LatticeGaugeField, getName(), 1, env().getGrid()); + envCreateLat(LatticeGaugeField, getName()); } // execution /////////////////////////////////////////////////////////////////// void TUnit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; - auto &U = mGetObj(LatticeGaugeField, getName()); + auto &U = envGet(LatticeGaugeField, getName()); SU3::ColdConfiguration(*env().get4dRng(), U); } diff --git a/extras/Hadrons/Modules/MSink/Point.hpp b/extras/Hadrons/Modules/MSink/Point.hpp index 0761c4c4..b124e2e5 100644 --- a/extras/Hadrons/Modules/MSink/Point.hpp +++ b/extras/Hadrons/Modules/MSink/Point.hpp @@ -65,6 +65,9 @@ public: virtual void setup(void); // execution virtual void execute(void); +private: + bool hasPhase_{false}; + std::string momphName_; }; MODULE_REGISTER_NS(Point, TPoint, MSink); @@ -77,6 +80,7 @@ MODULE_REGISTER_NS(ScalarPoint, TPoint, MSink); template TPoint::TPoint(const std::string name) : Module(name) +, momphName_ (name + "_momph") {} // dependencies/products /////////////////////////////////////////////////////// @@ -100,30 +104,36 @@ std::vector TPoint::getOutput(void) template void TPoint::setup(void) { - unsigned int size; - - size = env().template lattice4dSize(); - env().registerObject(getName(), size); + envTmpLat(LatticeComplex, "coor"); + envCacheLat(LatticeComplex, momphName_); + envCreate(SinkFn, getName(), 1, nullptr); } // execution /////////////////////////////////////////////////////////////////// template void TPoint::execute(void) { - std::vector p = strToVec(par().mom); - LatticeComplex ph(env().getGrid()), coor(env().getGrid()); + std::vector p = strToVec(par().mom); + LatticeComplex &ph = envGet(LatticeComplex, momphName_); Complex i(0.0,1.0); LOG(Message) << "Setting up point sink function for momentum [" << par().mom << "]" << std::endl; - ph = zero; - for(unsigned int mu = 0; mu < env().getNd(); mu++) + + if (!hasPhase_) { - LatticeCoordinate(coor, mu); - ph = ph + (p[mu]/env().getGrid()->_fdimensions[mu])*coor; + LatticeComplex &coor = envGetTmp(LatticeComplex, "coor"); + + ph = zero; + for(unsigned int mu = 0; mu < env().getNd(); mu++) + { + LatticeCoordinate(coor, mu); + ph = ph + (p[mu]/env().getGrid()->_fdimensions[mu])*coor; + } + ph = exp((Real)(2*M_PI)*i*ph); + hasPhase_ = true; } - ph = exp((Real)(2*M_PI)*i*ph); - auto sink = [ph](const PropagatorField &field) + auto sink = [&ph](const PropagatorField &field) { SlicedPropagator res; PropagatorField tmp = ph*field; @@ -132,7 +142,7 @@ void TPoint::execute(void) return res; }; - env().setObject(getName(), new SinkFn(sink)); + envGet(SinkFn, getName()) = sink; } END_MODULE_NAMESPACE diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index fe6992fc..8063d939 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -105,7 +105,7 @@ void TRBPrecCG::setup(void) << par().residual << std::endl; auto Ls = env().getObjectLs(par().action); - auto &mat = mGetObj(FMat, par().action); + auto &mat = envGet(FMat, par().action); auto solver = [&mat, this](FermionField &sol, const FermionField &source) { ConjugateGradient cg(par().residual, 10000); @@ -113,7 +113,7 @@ void TRBPrecCG::setup(void) schurSolver(mat, source, sol); }; - mCreateObj(SolverFn, getName(), Ls, solver); + envCreate(SolverFn, getName(), Ls, new SolverFn(solver)); env().addOwnership(getName(), par().action); } diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index 7815e5c1..5e16149e 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -111,7 +111,7 @@ std::vector TPoint::getOutput(void) template void TPoint::setup(void) { - env().template registerLattice(getName()); + envCreateLat(PropagatorField, getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -123,7 +123,7 @@ void TPoint::execute(void) LOG(Message) << "Creating point source at position [" << par().position << "]" << std::endl; - PropagatorField &src = *env().template createLattice(getName()); + PropagatorField &src = envGet(PropagatorField, getName()); id = 1.; src = zero; pokeSite(id, src, position); diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 63745baf..5ce2435f 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -12,13 +12,16 @@ modules_cc =\ modules_hpp =\ Modules/MAction/DWF.hpp \ Modules/MAction/Wilson.hpp \ + Modules/MSink/Point.hpp \ + Modules/MSource/Point.hpp \ Modules/MGauge/Unit.hpp \ - Modules/MSolver/RBPrecCG.hpp + Modules/MSolver/RBPrecCG.hpp \ + Modules/MFermion/GaugeProp.hpp \ + Modules/MContraction/Meson.hpp # Modules/MContraction/Baryon.hpp \ # Modules/MContraction/DiscLoop.hpp \ # Modules/MContraction/Gamma3pt.hpp \ - # Modules/MContraction/Meson.hpp \ # Modules/MContraction/WardIdentity.hpp \ # Modules/MContraction/WeakHamiltonian.hpp \ # Modules/MContraction/WeakHamiltonianEye.hpp \ @@ -32,10 +35,8 @@ modules_hpp =\ # Modules/MScalar/ChargedProp.hpp \ # Modules/MScalar/FreeProp.hpp \ # Modules/MScalar/Scalar.hpp \ - # Modules/MSink/Point.hpp \ # Modules/MSink/Smear.hpp \ # Modules/MSolver/RBPrecCG.hpp \ - # Modules/MSource/Point.hpp \ # Modules/MSource/SeqConserved.hpp \ # Modules/MSource/SeqGamma.hpp \ # Modules/MSource/Wall.hpp \ From 2a9ebddad59116151e6db2a0bc8cdbf53dd5741c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sun, 3 Dec 2017 19:45:15 +0100 Subject: [PATCH 096/174] Hadrons: scheduler offline, minimal code working again --- extras/Hadrons/Application.cc | 93 ++++++++++--------- extras/Hadrons/Module.hpp | 4 +- extras/Hadrons/Modules/MContraction/Meson.hpp | 4 +- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 0a7d0290..0860437b 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -182,7 +182,7 @@ GeneticScheduler::ObjFunc memPeak = \ memPeak = env().executeProgram(program);\ env().dryRun(false);\ env().freeAll();\ - HadronsLogMessage.Active(true);\ + HadronsLogMessage.Active(msg);\ \ return memPeak;\ } @@ -199,58 +199,59 @@ void Application::schedule(void) auto con = graph.getConnectedComponents(); // constrained topological sort using a genetic algorithm - LOG(Message) << "Scheduling computation..." << std::endl; - LOG(Message) << " #module= " << graph.size() << std::endl; - LOG(Message) << " population size= " << par_.genetic.popSize << std::endl; - LOG(Message) << " max. generation= " << par_.genetic.maxGen << std::endl; - LOG(Message) << " max. cst. generation= " << par_.genetic.maxCstGen << std::endl; - LOG(Message) << " mutation rate= " << par_.genetic.mutationRate << std::endl; + // LOG(Message) << "Scheduling computation..." << std::endl; + // LOG(Message) << " #module= " << graph.size() << std::endl; + // LOG(Message) << " population size= " << par_.genetic.popSize << std::endl; + // LOG(Message) << " max. generation= " << par_.genetic.maxGen << std::endl; + // LOG(Message) << " max. cst. generation= " << par_.genetic.maxCstGen << std::endl; + // LOG(Message) << " mutation rate= " << par_.genetic.mutationRate << std::endl; - unsigned int k = 0, gen, prevPeak, nCstPeak = 0; - std::random_device rd; - GeneticScheduler::Parameters par; + // unsigned int k = 0, gen, prevPeak, nCstPeak = 0; + // std::random_device rd; + // GeneticScheduler::Parameters par; - par.popSize = par_.genetic.popSize; - par.mutationRate = par_.genetic.mutationRate; - par.seed = rd(); - memPeak_ = 0; - CartesianCommunicator::BroadcastWorld(0, &(par.seed), sizeof(par.seed)); + // par.popSize = par_.genetic.popSize; + // par.mutationRate = par_.genetic.mutationRate; + // par.seed = rd(); + // memPeak_ = 0; + // CartesianCommunicator::BroadcastWorld(0, &(par.seed), sizeof(par.seed)); for (unsigned int i = 0; i < con.size(); ++i) { - GeneticScheduler scheduler(con[i], memPeak, par); + // GeneticScheduler scheduler(con[i], memPeak, par); - gen = 0; - do - { - LOG(Debug) << "Generation " << gen << ":" << std::endl; - scheduler.nextGeneration(); - if (gen != 0) - { - if (prevPeak == scheduler.getMinValue()) - { - nCstPeak++; - } - else - { - nCstPeak = 0; - } - } + // gen = 0; + // do + // { + // LOG(Debug) << "Generation " << gen << ":" << std::endl; + // scheduler.nextGeneration(); + // if (gen != 0) + // { + // if (prevPeak == scheduler.getMinValue()) + // { + // nCstPeak++; + // } + // else + // { + // nCstPeak = 0; + // } + // } - prevPeak = scheduler.getMinValue(); - if (gen % 10 == 0) - { - LOG(Iterative) << "Generation " << gen << ": " - << MEM_MSG(scheduler.getMinValue()) << std::endl; - } + // prevPeak = scheduler.getMinValue(); + // if (gen % 10 == 0) + // { + // LOG(Iterative) << "Generation " << gen << ": " + // << MEM_MSG(scheduler.getMinValue()) << std::endl; + // } - gen++; - } while ((gen < par_.genetic.maxGen) - and (nCstPeak < par_.genetic.maxCstGen)); - auto &t = scheduler.getMinSchedule(); - if (scheduler.getMinValue() > memPeak_) - { - memPeak_ = scheduler.getMinValue(); - } + // gen++; + // } while ((gen < par_.genetic.maxGen) + // and (nCstPeak < par_.genetic.maxCstGen)); + // auto &t = scheduler.getMinSchedule(); + // if (scheduler.getMinValue() > memPeak_) + // { + // memPeak_ = scheduler.getMinValue(); + // } + auto t = con[i].topoSort(); for (unsigned int j = 0; j < t.size(); ++j) { program_.push_back(t[j]); diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index a0b062df..a9525029 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -95,8 +95,8 @@ static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; #define envGetTmp(type, name)\ *env().template getObject(getName() + "_tmp_" + name) -#define envIsType(type, name)\ -env().template getObject(name) +#define envHasType(type, name)\ +env().template isObjectOfType(name) #define envCreate(type, name, Ls, pt)\ env().template createObject(name, Environment::Storage::object, Ls, pt) diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index ccc6dc55..34127da3 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -179,8 +179,8 @@ void TMeson::execute(void) result[i].gamma_src = gammaList[i].second; result[i].corr.resize(nt); } - if (envIsType(SlicedPropagator1, par().q1) and - envIsType(SlicedPropagator2, par().q2)) + if (envHasType(SlicedPropagator1, par().q1) and + envHasType(SlicedPropagator2, par().q2)) { SlicedPropagator1 &q1 = envGet(SlicedPropagator1, par().q1); SlicedPropagator2 &q2 = envGet(SlicedPropagator2, par().q2); From 624246409cc769715c74665d876a4cb4038a9693 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sun, 3 Dec 2017 19:46:18 +0100 Subject: [PATCH 097/174] Hadrons: module setup/execute protected to forbid user to bypass execution control --- extras/Hadrons/Module.hpp | 5 +++-- extras/Hadrons/Modules/MAction/DWF.hpp | 1 + extras/Hadrons/Modules/MAction/Wilson.hpp | 1 + extras/Hadrons/Modules/MContraction/Baryon.hpp | 1 + extras/Hadrons/Modules/MContraction/DiscLoop.hpp | 1 + extras/Hadrons/Modules/MContraction/Gamma3pt.hpp | 1 + extras/Hadrons/Modules/MContraction/Meson.hpp | 1 + extras/Hadrons/Modules/MContraction/WardIdentity.hpp | 1 + extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp | 4 +++- extras/Hadrons/Modules/MFermion/GaugeProp.hpp | 1 + extras/Hadrons/Modules/MGauge/Load.hpp | 1 + extras/Hadrons/Modules/MGauge/Random.hpp | 1 + extras/Hadrons/Modules/MGauge/StochEm.hpp | 1 + extras/Hadrons/Modules/MGauge/Unit.hpp | 1 + extras/Hadrons/Modules/MLoop/NoiseLoop.hpp | 1 + extras/Hadrons/Modules/MScalar/ChargedProp.hpp | 1 + extras/Hadrons/Modules/MScalar/FreeProp.hpp | 1 + extras/Hadrons/Modules/MSink/Point.hpp | 1 + extras/Hadrons/Modules/MSink/Smear.hpp | 1 + extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 1 + extras/Hadrons/Modules/MSource/Point.hpp | 1 + extras/Hadrons/Modules/MSource/SeqConserved.hpp | 1 + extras/Hadrons/Modules/MSource/SeqGamma.hpp | 1 + extras/Hadrons/Modules/MSource/Wall.hpp | 1 + extras/Hadrons/Modules/MSource/Z2.hpp | 1 + extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp | 1 + extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp | 1 + 27 files changed, 31 insertions(+), 3 deletions(-) diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index a9525029..017a9172 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -157,10 +157,11 @@ public: // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name) = 0; virtual void saveParameters(XmlWriter &writer, const std::string name) = 0; - // setup - virtual void setup(void) {}; // execution void operator()(void); +protected: + // setup + virtual void setup(void) {}; virtual void execute(void) = 0; private: std::string name_; diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 7c82fe8b..36c70073 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -65,6 +65,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index 5c334f8d..7fe1f44e 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -63,6 +63,7 @@ public: // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MContraction/Baryon.hpp b/extras/Hadrons/Modules/MContraction/Baryon.hpp index 78bde5a2..da927391 100644 --- a/extras/Hadrons/Modules/MContraction/Baryon.hpp +++ b/extras/Hadrons/Modules/MContraction/Baryon.hpp @@ -72,6 +72,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // execution virtual void execute(void); }; diff --git a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp index 4f782cd3..f8da3943 100644 --- a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp +++ b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp @@ -68,6 +68,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp index 162ab786..a8653186 100644 --- a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp +++ b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp @@ -99,6 +99,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 34127da3..31640b7c 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -97,6 +97,7 @@ public: virtual std::vector getInput(void); virtual std::vector getOutput(void); virtual void parseGammaString(std::vector &gammaList); +protected: // execution virtual void execute(void); }; diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index 8a56e0eb..a298c1a1 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -74,6 +74,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp index 302b207e..7df40370 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp @@ -100,11 +100,13 @@ public:\ /* dependency relation */ \ virtual std::vector getInput(void);\ virtual std::vector getOutput(void);\ +public:\ + std::vector VA_label = {"V", "A"};\ +protected:\ /* setup */ \ virtual void setup(void);\ /* execution */ \ virtual void execute(void);\ - std::vector VA_label = {"V", "A"};\ };\ MODULE_REGISTER_NS(modname, T##modname, MContraction); diff --git a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp index 59994d0d..8529825b 100644 --- a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -85,6 +85,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MGauge/Load.hpp b/extras/Hadrons/Modules/MGauge/Load.hpp index 5ff6da0f..a338af79 100644 --- a/extras/Hadrons/Modules/MGauge/Load.hpp +++ b/extras/Hadrons/Modules/MGauge/Load.hpp @@ -58,6 +58,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MGauge/Random.hpp b/extras/Hadrons/Modules/MGauge/Random.hpp index a97d25cf..a07130e4 100644 --- a/extras/Hadrons/Modules/MGauge/Random.hpp +++ b/extras/Hadrons/Modules/MGauge/Random.hpp @@ -51,6 +51,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MGauge/StochEm.hpp b/extras/Hadrons/Modules/MGauge/StochEm.hpp index 12ce9fdc..bacb5172 100644 --- a/extras/Hadrons/Modules/MGauge/StochEm.hpp +++ b/extras/Hadrons/Modules/MGauge/StochEm.hpp @@ -60,6 +60,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MGauge/Unit.hpp b/extras/Hadrons/Modules/MGauge/Unit.hpp index 7cd15ef7..c1650cc7 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.hpp +++ b/extras/Hadrons/Modules/MGauge/Unit.hpp @@ -51,6 +51,7 @@ public: // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp b/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp index 5d2c4a13..1f40dd48 100644 --- a/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp +++ b/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp @@ -74,6 +74,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MScalar/ChargedProp.hpp b/extras/Hadrons/Modules/MScalar/ChargedProp.hpp index fbe75c05..ab6a0184 100644 --- a/extras/Hadrons/Modules/MScalar/ChargedProp.hpp +++ b/extras/Hadrons/Modules/MScalar/ChargedProp.hpp @@ -37,6 +37,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MScalar/FreeProp.hpp b/extras/Hadrons/Modules/MScalar/FreeProp.hpp index 97cf288a..38372a0c 100644 --- a/extras/Hadrons/Modules/MScalar/FreeProp.hpp +++ b/extras/Hadrons/Modules/MScalar/FreeProp.hpp @@ -33,6 +33,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MSink/Point.hpp b/extras/Hadrons/Modules/MSink/Point.hpp index b124e2e5..853a7c32 100644 --- a/extras/Hadrons/Modules/MSink/Point.hpp +++ b/extras/Hadrons/Modules/MSink/Point.hpp @@ -61,6 +61,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MSink/Smear.hpp b/extras/Hadrons/Modules/MSink/Smear.hpp index c3973d2b..b51d2f49 100644 --- a/extras/Hadrons/Modules/MSink/Smear.hpp +++ b/extras/Hadrons/Modules/MSink/Smear.hpp @@ -62,6 +62,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index 8063d939..d8a4b95f 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -62,6 +62,7 @@ public: // dependencies/products virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index 5e16149e..b9813688 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -72,6 +72,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MSource/SeqConserved.hpp b/extras/Hadrons/Modules/MSource/SeqConserved.hpp index 86a7dfb9..e8f91be1 100644 --- a/extras/Hadrons/Modules/MSource/SeqConserved.hpp +++ b/extras/Hadrons/Modules/MSource/SeqConserved.hpp @@ -83,6 +83,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MSource/SeqGamma.hpp b/extras/Hadrons/Modules/MSource/SeqGamma.hpp index e2129a46..8f67f8fa 100644 --- a/extras/Hadrons/Modules/MSource/SeqGamma.hpp +++ b/extras/Hadrons/Modules/MSource/SeqGamma.hpp @@ -81,6 +81,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MSource/Wall.hpp b/extras/Hadrons/Modules/MSource/Wall.hpp index 4de37e4d..57dee06d 100644 --- a/extras/Hadrons/Modules/MSource/Wall.hpp +++ b/extras/Hadrons/Modules/MSource/Wall.hpp @@ -73,6 +73,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index a7f7a3e6..e2cc4f34 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -76,6 +76,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp index b085eb8c..f8714d88 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -80,6 +80,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp index 2799e5d0..9736ab54 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp @@ -64,6 +64,7 @@ public: // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); +protected: // setup virtual void setup(void); // execution From 59aae5f5ec97133f4f9ba80f3d2f718284d9e7f7 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sun, 3 Dec 2017 19:47:11 +0100 Subject: [PATCH 098/174] Hadrons: garbage collector clean temporaries --- extras/Hadrons/Environment.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index a6855862..27849bd7 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -422,6 +422,15 @@ Environment::executeProgram(const std::vector &p) } } } while (continueCollect); + // free temporaries + for (unsigned int i = 0; i < object_.size(); ++i) + { + if ((object_[i].storage == Storage::temporary) + and hasCreatedObject(i)) + { + freeObject(i); + } + } // any remaining objects in step i garbage collection schedule // is scheduled for step i + 1 if (i + 1 < p.size()) @@ -687,7 +696,7 @@ bool Environment::freeObject(const unsigned int address) { if (!hasOwners(address)) { - if (!isDryRun()) + if (!isDryRun() and hasCreatedObject(address)) { LOG(Message) << "Destroying object '" << object_[address].name << "'" << std::endl; From 01f00385a4460ea21e09c2beaa77bd20c7a78550 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Sun, 3 Dec 2017 19:47:40 +0100 Subject: [PATCH 099/174] Hadrons: genetic pair selection based on exponential probability --- extras/Hadrons/GeneticScheduler.hpp | 33 ++++++++++++----------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index d0c52596..3b0195e7 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -212,28 +212,23 @@ typename GeneticScheduler::GenePair GeneticScheduler::selectPair(void) std::vector prob; unsigned int ind; Gene *p1, *p2; + const double max = population_.rbegin()->first; + for (auto &c: population_) { - prob.push_back(1./c.first); - } - do - { - double probCpy; - - std::discrete_distribution dis1(prob.begin(), prob.end()); - auto rIt = population_.begin(); - ind = dis1(gen_); - std::advance(rIt, ind); - p1 = &(rIt->second); - probCpy = prob[ind]; - prob[ind] = 0.; - std::discrete_distribution dis2(prob.begin(), prob.end()); - rIt = population_.begin(); - std::advance(rIt, dis2(gen_)); - p2 = &(rIt->second); - prob[ind] = probCpy; - } while (p1 == p2); + prob.push_back(std::exp((c.first-1.)/max)); + } + std::discrete_distribution dis1(prob.begin(), prob.end()); + auto rIt = population_.begin(); + ind = dis1(gen_); + std::advance(rIt, ind); + p1 = &(rIt->second); + prob[ind] = 0.; + std::discrete_distribution dis2(prob.begin(), prob.end()); + rIt = population_.begin(); + std::advance(rIt, dis2(gen_)); + p2 = &(rIt->second); return std::make_pair(p1, p2); } From 542225195903b5a54bd2b2768c8153b29fba5230 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 5 Dec 2017 15:31:59 +0100 Subject: [PATCH 100/174] Hadrons: execution part moved in a new virtual machine class --- extras/Hadrons/Application.cc | 41 +- extras/Hadrons/Application.hpp | 11 +- extras/Hadrons/Environment.cc | 387 ++--------------- extras/Hadrons/Environment.hpp | 124 +----- extras/Hadrons/Global.hpp | 4 + extras/Hadrons/Makefile.am | 6 +- extras/Hadrons/Module.cc | 8 +- extras/Hadrons/Module.hpp | 8 +- extras/Hadrons/Modules/MContraction/Meson.hpp | 2 +- extras/Hadrons/VirtualMachine.cc | 388 ++++++++++++++++++ extras/Hadrons/VirtualMachine.hpp | 164 ++++++++ 11 files changed, 647 insertions(+), 496 deletions(-) create mode 100644 extras/Hadrons/VirtualMachine.cc create mode 100644 extras/Hadrons/VirtualMachine.hpp diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 0860437b..af67dff3 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -73,12 +73,6 @@ Application::Application(const std::string parameterFileName) parameterFileName_ = parameterFileName; } -// environment shortcut //////////////////////////////////////////////////////// -Environment & Application::env(void) const -{ - return Environment::getInstance(); -} - // access ////////////////////////////////////////////////////////////////////// void Application::setPar(const Application::GlobalPar &par) { @@ -94,12 +88,13 @@ const Application::GlobalPar & Application::getPar(void) // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) { - if (!parameterFileName_.empty() and (env().getNModule() == 0)) + if (!parameterFileName_.empty() and (vm().getNModule() == 0)) { parseParameterFile(parameterFileName_); } - env().checkGraph(); + //vm().checkGraph(); env().printContent(); + vm().printContent(); if (!scheduled_) { schedule(); @@ -137,7 +132,7 @@ void Application::parseParameterFile(const std::string parameterFileName) do { read(reader, "id", id); - env().createModule(id.name, id.type, reader); + vm().createModule(id.name, id.type, reader); } while (reader.nextElement("module")); pop(reader); pop(reader); @@ -147,7 +142,7 @@ void Application::saveParameterFile(const std::string parameterFileName) { XmlWriter writer(parameterFileName); ObjectId id; - const unsigned int nMod = env().getNModule(); + const unsigned int nMod = vm().getNModule(); LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl; write(writer, "parameters", getPar()); @@ -155,10 +150,10 @@ void Application::saveParameterFile(const std::string parameterFileName) for (unsigned int i = 0; i < nMod; ++i) { push(writer, "module"); - id.name = env().getModuleName(i); - id.type = env().getModule(i)->getRegisteredName(); + id.name = vm().getModuleName(i); + id.type = vm().getModule(i)->getRegisteredName(); write(writer, "id", id); - env().getModule(i)->saveParameters(writer, "options"); + vm().getModule(i)->saveParameters(writer, "options"); pop(writer); } pop(writer); @@ -178,9 +173,9 @@ GeneticScheduler::ObjFunc memPeak = \ \ msg = HadronsLogMessage.isActive();\ HadronsLogMessage.Active(false);\ - env().dryRun(true);\ - memPeak = env().executeProgram(program);\ - env().dryRun(false);\ + vm().dryRun(true);\ + memPeak = vm().executeProgram(program);\ + vm().dryRun(false);\ env().freeAll();\ HadronsLogMessage.Active(msg);\ \ @@ -193,7 +188,7 @@ void Application::schedule(void) // build module dependency graph LOG(Message) << "Building module graph..." << std::endl; - auto graph = env().makeModuleGraph(); + auto graph = vm().makeModuleGraph(); LOG(Debug) << "Module graph:" << std::endl; LOG(Debug) << graph << std::endl; auto con = graph.getConnectedComponents(); @@ -273,7 +268,7 @@ void Application::saveSchedule(const std::string filename) << std::endl; for (auto address: program_) { - program.push_back(env().getModuleName(address)); + program.push_back(vm().getModuleName(address)); } write(writer, "schedule", program); } @@ -291,7 +286,7 @@ void Application::loadSchedule(const std::string filename) program_.clear(); for (auto &name: program) { - program_.push_back(env().getModuleAddress(name)); + program_.push_back(vm().getModuleAddress(name)); } scheduled_ = true; memPeak_ = memPeak(program_); @@ -308,7 +303,7 @@ void Application::printSchedule(void) for (unsigned int i = 0; i < program_.size(); ++i) { LOG(Message) << std::setw(4) << i + 1 << ": " - << env().getModuleName(program_[i]) << std::endl; + << vm().getModuleName(program_[i]) << std::endl; } } @@ -321,8 +316,8 @@ void Application::configLoop(void) { LOG(Message) << BIG_SEP << " Starting measurement for trajectory " << t << " " << BIG_SEP << std::endl; - env().setTrajectory(t); - env().executeProgram(program_); + vm().setTrajectory(t); + vm().executeProgram(program_); } LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; env().freeAll(); @@ -331,7 +326,7 @@ void Application::configLoop(void) // memory profile ////////////////////////////////////////////////////////////// void Application::memoryProfile(void) { - auto graph = env().makeModuleGraph(); + auto graph = vm().makeModuleGraph(); auto program = graph.topoSort(); bool msg; diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index 8b11b0c7..66488206 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -31,8 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo #define Hadrons_Application_hpp_ #include -#include -#include +#include #include BEGIN_HADRONS_NAMESPACE @@ -100,7 +99,9 @@ public: void configLoop(void); private: // environment shortcut - Environment & env(void) const; + DEFINE_ENV_ALIAS; + // virtual machine shortcut + DEFINE_VM_ALIAS; // memory profile void memoryProfile(void); private: @@ -119,14 +120,14 @@ private: template void Application::createModule(const std::string name) { - env().createModule(name); + vm().createModule(name); } template void Application::createModule(const std::string name, const typename M::Par &par) { - env().createModule(name, par); + vm().createModule(name, par); } END_HADRONS_NAMESPACE diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 27849bd7..ea41f343 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -56,38 +56,6 @@ Environment::Environment(void) rng4d_.reset(new GridParallelRNG(grid4d_.get())); } -// dry run ///////////////////////////////////////////////////////////////////// -void Environment::dryRun(const bool isDry) -{ - dryRun_ = isDry; -} - -bool Environment::isDryRun(void) const -{ - return dryRun_; -} - -void Environment::memoryProfile(const bool doMemoryProfile) -{ - memoryProfile_ = doMemoryProfile; -} - -bool Environment::doMemoryProfile(void) const -{ - return memoryProfile_; -} - -// trajectory number /////////////////////////////////////////////////////////// -void Environment::setTrajectory(const unsigned int traj) -{ - traj_ = traj; -} - -unsigned int Environment::getTrajectory(void) const -{ - return traj_; -} - // grids /////////////////////////////////////////////////////////////////////// void Environment::createGrid(const unsigned int Ls) { @@ -153,6 +121,11 @@ int Environment::getDim(const unsigned int mu) const return dim_[mu]; } +unsigned long int Environment::getLocalVolume(void) const +{ + return locVol_; +} + // random number generator ///////////////////////////////////////////////////// void Environment::setSeed(const std::vector &seed) { @@ -164,313 +137,6 @@ GridParallelRNG * Environment::get4dRng(void) const return rng4d_.get(); } -// module management /////////////////////////////////////////////////////////// -void Environment::pushModule(Environment::ModPt &pt) -{ - std::string name = pt->getName(); - - if (!hasModule(name)) - { - std::vector inputAddress; - unsigned int address; - ModuleInfo m; - - m.data = std::move(pt); - m.type = typeIdPt(*m.data.get()); - m.name = name; - auto input = m.data->getInput(); - for (auto &in: input) - { - if (!hasObject(in)) - { - addObject(in , -1); - } - m.input.push_back(objectAddress_[in]); - } - auto output = m.data->getOutput(); - module_.push_back(std::move(m)); - address = static_cast(module_.size() - 1); - moduleAddress_[name] = address; - for (auto &out: output) - { - if (!hasObject(out)) - { - addObject(out, address); - } - else - { - if (object_[objectAddress_[out]].module < 0) - { - object_[objectAddress_[out]].module = address; - } - else - { - HADRON_ERROR("object '" + out - + "' is already produced by module '" - + module_[object_[getObjectAddress(out)].module].name - + "' (while pushing module '" + name + "')"); - } - } - } - } - else - { - HADRON_ERROR("module '" + name + "' already exists"); - } -} - -unsigned int Environment::getNModule(void) const -{ - return module_.size(); -} - -void Environment::createModule(const std::string name, const std::string type, - XmlReader &reader) -{ - auto &factory = ModuleFactory::getInstance(); - auto pt = factory.create(type, name); - - pt->parseParameters(reader, "options"); - pushModule(pt); -} - -ModuleBase * Environment::getModule(const unsigned int address) const -{ - if (hasModule(address)) - { - return module_[address].data.get(); - } - else - { - HADRON_ERROR("no module with address " + std::to_string(address)); - } -} - -ModuleBase * Environment::getModule(const std::string name) const -{ - return getModule(getModuleAddress(name)); -} - -unsigned int Environment::getModuleAddress(const std::string name) const -{ - if (hasModule(name)) - { - return moduleAddress_.at(name); - } - else - { - HADRON_ERROR("no module with name '" + name + "'"); - } -} - -std::string Environment::getModuleName(const unsigned int address) const -{ - if (hasModule(address)) - { - return module_[address].name; - } - else - { - HADRON_ERROR("no module with address " + std::to_string(address)); - } -} - -std::string Environment::getModuleType(const unsigned int address) const -{ - if (hasModule(address)) - { - return typeName(module_[address].type); - } - else - { - HADRON_ERROR("no module with address " + std::to_string(address)); - } -} - -std::string Environment::getModuleType(const std::string name) const -{ - return getModuleType(getModuleAddress(name)); -} - -std::string Environment::getModuleNamespace(const unsigned int address) const -{ - std::string type = getModuleType(address), ns; - - auto pos2 = type.rfind("::"); - auto pos1 = type.rfind("::", pos2 - 2); - - return type.substr(pos1 + 2, pos2 - pos1 - 2); -} - -std::string Environment::getModuleNamespace(const std::string name) const -{ - return getModuleNamespace(getModuleAddress(name)); -} - -bool Environment::hasModule(const unsigned int address) const -{ - return (address < module_.size()); -} - -bool Environment::hasModule(const std::string name) const -{ - return (moduleAddress_.find(name) != moduleAddress_.end()); -} - -Graph Environment::makeModuleGraph(void) const -{ - Graph moduleGraph; - - for (unsigned int i = 0; i < module_.size(); ++i) - { - moduleGraph.addVertex(i); - for (auto &j: module_[i].input) - { - moduleGraph.addEdge(object_[j].module, i); - } - } - - return moduleGraph; -} - -void Environment::checkGraph(void) const -{ - for (auto &o: object_) - { - if (o.module < 0) - { - HADRON_ERROR("object '" + o.name + "' does not have a creator"); - } - } -} - -#define BIG_SEP "===============" -#define SEP "---------------" -#define MEM_MSG(size)\ -sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" - -Environment::Size -Environment::executeProgram(const std::vector &p) -{ - Size memPeak = 0, sizeBefore, sizeAfter; - std::vector> freeProg; - bool continueCollect, nothingFreed; - - // build garbage collection schedule - LOG(Debug) << "Building garbage collection schedule..." << std::endl; - freeProg.resize(p.size()); - for (unsigned int i = 0; i < object_.size(); ++i) - { - auto pred = [i, this](const unsigned int j) - { - auto &in = module_[j].input; - auto it = std::find(in.begin(), in.end(), i); - - return (it != in.end()) or (j == object_[i].module); - }; - auto it = std::find_if(p.rbegin(), p.rend(), pred); - if (it != p.rend()) - { - freeProg[std::distance(it, p.rend()) - 1].insert(i); - } - } - - // program execution - LOG(Debug) << "Executing program..." << std::endl; - for (unsigned int i = 0; i < p.size(); ++i) - { - // execute module - if (!isDryRun()) - { - LOG(Message) << SEP << " Measurement step " << i+1 << "/" - << p.size() << " (module '" << module_[p[i]].name - << "') " << SEP << std::endl; - } - (*module_[p[i]].data)(); - sizeBefore = getTotalSize(); - // print used memory after execution - if (!isDryRun()) - { - LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) - << std::endl; - } - if (sizeBefore > memPeak) - { - memPeak = sizeBefore; - } - // garbage collection for step i - if (!isDryRun()) - { - LOG(Message) << "Garbage collection..." << std::endl; - } - nothingFreed = true; - do - { - continueCollect = false; - auto toFree = freeProg[i]; - for (auto &j: toFree) - { - // continue garbage collection while there are still - // objects without owners - continueCollect = continueCollect or !hasOwners(j); - if(freeObject(j)) - { - // if an object has been freed, remove it from - // the garbage collection schedule - freeProg[i].erase(j); - nothingFreed = false; - } - } - } while (continueCollect); - // free temporaries - for (unsigned int i = 0; i < object_.size(); ++i) - { - if ((object_[i].storage == Storage::temporary) - and hasCreatedObject(i)) - { - freeObject(i); - } - } - // any remaining objects in step i garbage collection schedule - // is scheduled for step i + 1 - if (i + 1 < p.size()) - { - for (auto &j: freeProg[i]) - { - freeProg[i + 1].insert(j); - } - } - // print used memory after garbage collection if necessary - if (!isDryRun()) - { - sizeAfter = getTotalSize(); - if (sizeBefore != sizeAfter) - { - LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) - << std::endl; - } - else - { - LOG(Message) << "Nothing to free" << std::endl; - } - } - } - - return memPeak; -} - -Environment::Size Environment::executeProgram(const std::vector &p) -{ - std::vector pAddress; - - for (auto &n: p) - { - pAddress.push_back(getModuleAddress(n)); - } - - return executeProgram(pAddress); -} - // general memory management /////////////////////////////////////////////////// void Environment::addObject(const std::string name, const int moduleAddress) { @@ -490,6 +156,17 @@ void Environment::addObject(const std::string name, const int moduleAddress) } } +void Environment::setObjectModule(const unsigned int objAddress, + const int modAddress) +{ + object_[objAddress].module = modAddress; +} + +unsigned int Environment::getMaxAddress(void) const +{ + return object_.size(); +} + unsigned int Environment::getObjectAddress(const std::string name) const { if (hasObject(name)) @@ -555,7 +232,24 @@ Environment::Size Environment::getObjectSize(const std::string name) const return getObjectSize(getObjectAddress(name)); } -unsigned int Environment::getObjectModule(const unsigned int address) const +Environment::Storage Environment::getObjectStorage(const unsigned int address) const +{ + if (hasObject(address)) + { + return object_[address].storage; + } + else + { + HADRON_ERROR("no object with address " + std::to_string(address)); + } +} + +Environment::Storage Environment::getObjectStorage(const std::string name) const +{ + return getObjectStorage(getObjectAddress(name)); +} + +int Environment::getObjectModule(const unsigned int address) const { if (hasObject(address)) { @@ -567,7 +261,7 @@ unsigned int Environment::getObjectModule(const unsigned int address) const } } -unsigned int Environment::getObjectModule(const std::string name) const +int Environment::getObjectModule(const std::string name) const { return getObjectModule(getObjectAddress(name)); } @@ -696,7 +390,7 @@ bool Environment::freeObject(const unsigned int address) { if (!hasOwners(address)) { - if (!isDryRun() and hasCreatedObject(address)) + if (hasCreatedObject(address)) { LOG(Message) << "Destroying object '" << object_[address].name << "'" << std::endl; @@ -732,14 +426,9 @@ void Environment::freeAll(void) } } -void Environment::printContent(void) +// print environment content /////////////////////////////////////////////////// +void Environment::printContent(void) const { - LOG(Debug) << "Modules: " << std::endl; - for (unsigned int i = 0; i < module_.size(); ++i) - { - LOG(Debug) << std::setw(4) << i << ": " - << getModuleName(i) << std::endl; - } LOG(Debug) << "Objects: " << std::endl; for (unsigned int i = 0; i < object_.size(); ++i) { diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 58e035ac..9d482923 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -31,20 +31,12 @@ See the full license in the file "LICENSE" in the top level distribution directo #define Hadrons_Environment_hpp_ #include -#include - -#ifndef SITE_SIZE_TYPE -#define SITE_SIZE_TYPE unsigned int -#endif BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Global environment * ******************************************************************************/ -// forward declaration of Module -class ModuleBase; - class Object { public: @@ -66,26 +58,22 @@ private: std::unique_ptr objPt_{nullptr}; }; +#define DEFINE_ENV_ALIAS \ +inline Environment & env(void) const\ +{\ + return Environment::getInstance();\ +} + class Environment { SINGLETON(Environment); public: typedef SITE_SIZE_TYPE Size; - typedef std::unique_ptr ModPt; typedef std::unique_ptr GridPt; typedef std::unique_ptr GridRbPt; typedef std::unique_ptr RngPt; - typedef std::unique_ptr LatticePt; enum class Storage {object, cache, temporary}; private: - struct ModuleInfo - { - const std::type_info *type{nullptr}; - std::string name; - ModPt data{nullptr}; - std::vector input; - size_t maxAllocated; - }; struct ObjInfo { Size size{0}; @@ -98,53 +86,17 @@ private: std::unique_ptr data{nullptr}; }; public: - // dry run - void dryRun(const bool isDry); - bool isDryRun(void) const; - void memoryProfile(const bool doMemoryProfile); - bool doMemoryProfile(void) const; - // trajectory number - void setTrajectory(const unsigned int traj); - unsigned int getTrajectory(void) const; // grids void createGrid(const unsigned int Ls); GridCartesian * getGrid(const unsigned int Ls = 1) const; GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; std::vector getDim(void) const; int getDim(const unsigned int mu) const; + unsigned long int getLocalVolume(void) const; unsigned int getNd(void) const; // random number generator void setSeed(const std::vector &seed); GridParallelRNG * get4dRng(void) const; - // module management - void pushModule(ModPt &pt); - template - void createModule(const std::string name); - template - void createModule(const std::string name, - const typename M::Par &par); - void createModule(const std::string name, - const std::string type, - XmlReader &reader); - unsigned int getNModule(void) const; - ModuleBase * getModule(const unsigned int address) const; - ModuleBase * getModule(const std::string name) const; - template - M * getModule(const unsigned int address) const; - template - M * getModule(const std::string name) const; - unsigned int getModuleAddress(const std::string name) const; - std::string getModuleName(const unsigned int address) const; - std::string getModuleType(const unsigned int address) const; - std::string getModuleType(const std::string name) const; - std::string getModuleNamespace(const unsigned int address) const; - std::string getModuleNamespace(const std::string name) const; - bool hasModule(const unsigned int address) const; - bool hasModule(const std::string name) const; - Graph makeModuleGraph(void) const; - void checkGraph(void) const; - Size executeProgram(const std::vector &p); - Size executeProgram(const std::vector &p); // general memory management void addObject(const std::string name, const int moduleAddress = -1); @@ -153,18 +105,23 @@ public: const Storage storage, const unsigned int Ls, P &&pt); + void setObjectModule(const unsigned int objAddress, + const int modAddress); template T * getObject(const unsigned int address) const; template T * getObject(const std::string name) const; + unsigned int getMaxAddress(void) const; unsigned int getObjectAddress(const std::string name) const; std::string getObjectName(const unsigned int address) const; std::string getObjectType(const unsigned int address) const; std::string getObjectType(const std::string name) const; Size getObjectSize(const unsigned int address) const; Size getObjectSize(const std::string name) const; - unsigned int getObjectModule(const unsigned int address) const; - unsigned int getObjectModule(const std::string name) const; + Storage getObjectStorage(const unsigned int address) const; + Storage getObjectStorage(const std::string name) const; + int getObjectModule(const unsigned int address) const; + int getObjectModule(const std::string name) const; unsigned int getObjectLs(const unsigned int address) const; unsigned int getObjectLs(const std::string name) const; bool hasObject(const unsigned int address) const; @@ -187,11 +144,11 @@ public: bool freeObject(const unsigned int address); bool freeObject(const std::string name); void freeAll(void); - void printContent(void); + // print environment content + void printContent(void) const; private: // general - bool dryRun_{false}, memoryProfile_{false}; - unsigned int traj_, locVol_; + unsigned long int locVol_; // grids std::vector dim_; GridPt grid4d_; @@ -201,12 +158,6 @@ private: unsigned int nd_; // random number generator RngPt rng4d_; - // module and related maps - std::vector module_; - std::map moduleAddress_; - std::string currentModule_{""}; - // lattice store - std::map lattice_; // object store std::vector object_; std::map objectAddress_; @@ -243,46 +194,7 @@ void Holder::reset(T *pt) /****************************************************************************** * Environment template implementation * ******************************************************************************/ -// module management /////////////////////////////////////////////////////////// -template -void Environment::createModule(const std::string name) -{ - ModPt pt(new M(name)); - - pushModule(pt); -} - -template -void Environment::createModule(const std::string name, - const typename M::Par &par) -{ - ModPt pt(new M(name)); - - static_cast(pt.get())->setPar(par); - pushModule(pt); -} - -template -M * Environment::getModule(const unsigned int address) const -{ - if (auto *pt = dynamic_cast(getModule(address))) - { - return pt; - } - else - { - HADRON_ERROR("module '" + module_[address].name - + "' does not have type " + typeid(M).name() - + "(object type: " + getModuleType(address) + ")"); - } -} - -template -M * Environment::getModule(const std::string name) const -{ - return getModule(getModuleAddress(name)); -} - +// general memory management /////////////////////////////////////////////////// template void Environment::createObject(const std::string name, const Environment::Storage storage, diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 371256e8..1f0ce201 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -35,6 +35,10 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include +#ifndef SITE_SIZE_TYPE +#define SITE_SIZE_TYPE unsigned int +#endif + #define BEGIN_HADRONS_NAMESPACE \ namespace Grid {\ using namespace QCD;\ diff --git a/extras/Hadrons/Makefile.am b/extras/Hadrons/Makefile.am index 9cb23600..826cb158 100644 --- a/extras/Hadrons/Makefile.am +++ b/extras/Hadrons/Makefile.am @@ -8,7 +8,8 @@ libHadrons_a_SOURCES = \ Application.cc \ Environment.cc \ Global.cc \ - Module.cc + Module.cc \ + VirtualMachine.cc libHadrons_adir = $(pkgincludedir)/Hadrons nobase_libHadrons_a_HEADERS = \ $(modules_hpp) \ @@ -20,7 +21,8 @@ nobase_libHadrons_a_HEADERS = \ Graph.hpp \ Module.hpp \ Modules.hpp \ - ModuleFactory.hpp + ModuleFactory.hpp \ + VirtualMachine.hpp HadronsXmlRun_SOURCES = HadronsXmlRun.cc HadronsXmlRun_LDADD = libHadrons.a -lGrid diff --git a/extras/Hadrons/Module.cc b/extras/Hadrons/Module.cc index 2549a931..bf596bfc 100644 --- a/extras/Hadrons/Module.cc +++ b/extras/Hadrons/Module.cc @@ -39,7 +39,6 @@ using namespace Hadrons; // constructor ///////////////////////////////////////////////////////////////// ModuleBase::ModuleBase(const std::string name) : name_(name) -, env_(Environment::getInstance()) {} // access ////////////////////////////////////////////////////////////////////// @@ -48,11 +47,6 @@ std::string ModuleBase::getName(void) const return name_; } -Environment & ModuleBase::env(void) const -{ - return env_; -} - // get factory registration name if available std::string ModuleBase::getRegisteredName(void) { @@ -64,7 +58,7 @@ std::string ModuleBase::getRegisteredName(void) void ModuleBase::operator()(void) { setup(); - if (!env().isDryRun()) + if (!vm().isDryRun()) { execute(); } diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 017a9172..d1910c9b 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -31,7 +31,7 @@ See the full license in the file "LICENSE" in the top level distribution directo #define Hadrons_Module_hpp_ #include -#include +#include BEGIN_HADRONS_NAMESPACE @@ -148,7 +148,6 @@ public: virtual ~ModuleBase(void) = default; // access std::string getName(void) const; - Environment &env(void) const; // get factory registration name if available virtual std::string getRegisteredName(void); // dependencies/products @@ -163,9 +162,12 @@ protected: // setup virtual void setup(void) {}; virtual void execute(void) = 0; + // environment shortcut + DEFINE_ENV_ALIAS; + // virtual machine shortcut + DEFINE_VM_ALIAS; private: std::string name_; - Environment &env_; }; // derived class, templating the parameter class diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 31640b7c..7c0012d2 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -211,7 +211,7 @@ void TMeson::execute(void) Gamma gSrc(gammaList[i].second); std::string ns; - ns = env().getModuleNamespace(env().getObjectModule(par().sink)); + ns = vm().getModuleNamespace(env().getObjectModule(par().sink)); if (ns == "MSource") { PropagatorField1 &sink = envGet(PropagatorField1, par().sink); diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc new file mode 100644 index 00000000..f09e2710 --- /dev/null +++ b/extras/Hadrons/VirtualMachine.cc @@ -0,0 +1,388 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/VirtualMachine.cc + +Copyright (C) 2017 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#include +#include + +using namespace Grid; +using namespace QCD; +using namespace Hadrons; + +/****************************************************************************** + * VirtualMachine implementation * + ******************************************************************************/ +// dry run ///////////////////////////////////////////////////////////////////// +void VirtualMachine::dryRun(const bool isDry) +{ + dryRun_ = isDry; +} + +bool VirtualMachine::isDryRun(void) const +{ + return dryRun_; +} + +void VirtualMachine::memoryProfile(const bool doMemoryProfile) +{ + memoryProfile_ = doMemoryProfile; +} + +bool VirtualMachine::doMemoryProfile(void) const +{ + return memoryProfile_; +} + +// trajectory counter ////////////////////////////////////////////////////////// +void VirtualMachine::setTrajectory(const unsigned int traj) +{ + traj_ = traj; +} + +unsigned int VirtualMachine::getTrajectory(void) const +{ + return traj_; +} + +// module management /////////////////////////////////////////////////////////// +void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) +{ + std::string name = pt->getName(); + + if (!hasModule(name)) + { + std::vector inputAddress; + unsigned int address; + ModuleInfo m; + + m.data = std::move(pt); + m.type = typeIdPt(*m.data.get()); + m.name = name; + auto input = m.data->getInput(); + for (auto &in: input) + { + if (!env().hasObject(in)) + { + env().addObject(in , -1); + } + m.input.push_back(env().getObjectAddress(in)); + } + auto output = m.data->getOutput(); + module_.push_back(std::move(m)); + address = static_cast(module_.size() - 1); + moduleAddress_[name] = address; + for (auto &out: output) + { + if (!env().hasObject(out)) + { + env().addObject(out, address); + } + else + { + if (env().getObjectModule(env().getObjectAddress(out)) < 0) + { + env().setObjectModule(env().getObjectAddress(out), address); + } + else + { + HADRON_ERROR("object '" + out + + "' is already produced by module '" + + module_[env().getObjectModule(out)].name + + "' (while pushing module '" + name + "')"); + } + } + } + } + else + { + HADRON_ERROR("module '" + name + "' already exists"); + } +} + +unsigned int VirtualMachine::getNModule(void) const +{ + return module_.size(); +} + +void VirtualMachine::createModule(const std::string name, const std::string type, + XmlReader &reader) +{ + auto &factory = ModuleFactory::getInstance(); + auto pt = factory.create(type, name); + + pt->parseParameters(reader, "options"); + pushModule(pt); +} + +ModuleBase * VirtualMachine::getModule(const unsigned int address) const +{ + if (hasModule(address)) + { + return module_[address].data.get(); + } + else + { + HADRON_ERROR("no module with address " + std::to_string(address)); + } +} + +ModuleBase * VirtualMachine::getModule(const std::string name) const +{ + return getModule(getModuleAddress(name)); +} + +unsigned int VirtualMachine::getModuleAddress(const std::string name) const +{ + if (hasModule(name)) + { + return moduleAddress_.at(name); + } + else + { + HADRON_ERROR("no module with name '" + name + "'"); + } +} + +std::string VirtualMachine::getModuleName(const unsigned int address) const +{ + if (hasModule(address)) + { + return module_[address].name; + } + else + { + HADRON_ERROR("no module with address " + std::to_string(address)); + } +} + +std::string VirtualMachine::getModuleType(const unsigned int address) const +{ + if (hasModule(address)) + { + return typeName(module_[address].type); + } + else + { + HADRON_ERROR("no module with address " + std::to_string(address)); + } +} + +std::string VirtualMachine::getModuleType(const std::string name) const +{ + return getModuleType(getModuleAddress(name)); +} + +std::string VirtualMachine::getModuleNamespace(const unsigned int address) const +{ + std::string type = getModuleType(address), ns; + + auto pos2 = type.rfind("::"); + auto pos1 = type.rfind("::", pos2 - 2); + + return type.substr(pos1 + 2, pos2 - pos1 - 2); +} + +std::string VirtualMachine::getModuleNamespace(const std::string name) const +{ + return getModuleNamespace(getModuleAddress(name)); +} + +bool VirtualMachine::hasModule(const unsigned int address) const +{ + return (address < module_.size()); +} + +bool VirtualMachine::hasModule(const std::string name) const +{ + return (moduleAddress_.find(name) != moduleAddress_.end()); +} + +Graph VirtualMachine::makeModuleGraph(void) const +{ + Graph moduleGraph; + + for (unsigned int i = 0; i < module_.size(); ++i) + { + moduleGraph.addVertex(i); + for (auto &j: module_[i].input) + { + moduleGraph.addEdge(env().getObjectModule(j), i); + } + } + + return moduleGraph; +} + +// void VirtualMachine::checkGraph(void) const +// { +// for (auto &o: object_) +// { +// if (o.module < 0) +// { +// HADRON_ERROR("object '" + o.name + "' does not have a creator"); +// } +// } +// } + +// general execution /////////////////////////////////////////////////////////// +#define BIG_SEP "===============" +#define SEP "---------------" +#define MEM_MSG(size)\ +sizeString((size)*env().getLocalVolume()) << " (" << sizeString(size) << "/site)" + +VirtualMachine::Size +VirtualMachine::executeProgram(const std::vector &p) +{ + Size memPeak = 0, sizeBefore, sizeAfter; + std::vector> freeProg; + bool continueCollect, nothingFreed; + + // build garbage collection schedule + LOG(Debug) << "Building garbage collection schedule..." << std::endl; + freeProg.resize(p.size()); + for (unsigned int i = 0; i < env().getMaxAddress(); ++i) + { + auto pred = [i, this](const unsigned int j) + { + auto &in = module_[j].input; + auto it = std::find(in.begin(), in.end(), i); + + return (it != in.end()) or (j == env().getObjectModule(i)); + }; + auto it = std::find_if(p.rbegin(), p.rend(), pred); + if (it != p.rend()) + { + freeProg[std::distance(it, p.rend()) - 1].insert(i); + } + } + + // program execution + LOG(Debug) << "Executing program..." << std::endl; + for (unsigned int i = 0; i < p.size(); ++i) + { + // execute module + if (!isDryRun()) + { + LOG(Message) << SEP << " Measurement step " << i+1 << "/" + << p.size() << " (module '" << module_[p[i]].name + << "') " << SEP << std::endl; + } + (*module_[p[i]].data)(); + sizeBefore = env().getTotalSize(); + // print used memory after execution + if (!isDryRun()) + { + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) + << std::endl; + } + if (sizeBefore > memPeak) + { + memPeak = sizeBefore; + } + // garbage collection for step i + if (!isDryRun()) + { + LOG(Message) << "Garbage collection..." << std::endl; + } + nothingFreed = true; + do + { + continueCollect = false; + auto toFree = freeProg[i]; + for (auto &j: toFree) + { + // continue garbage collection while there are still + // objects without owners + continueCollect = continueCollect or !env().hasOwners(j); + if(env().freeObject(j)) + { + // if an object has been freed, remove it from + // the garbage collection schedule + freeProg[i].erase(j); + nothingFreed = false; + } + } + } while (continueCollect); + // free temporaries + for (unsigned int i = 0; i < env().getMaxAddress(); ++i) + { + if ((env().getObjectStorage(i) == Environment::Storage::temporary) + and env().hasCreatedObject(i)) + { + env().freeObject(i); + } + } + // any remaining objects in step i garbage collection schedule + // is scheduled for step i + 1 + if (i + 1 < p.size()) + { + for (auto &j: freeProg[i]) + { + freeProg[i + 1].insert(j); + } + } + // print used memory after garbage collection if necessary + if (!isDryRun()) + { + sizeAfter = env().getTotalSize(); + if (sizeBefore != sizeAfter) + { + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) + << std::endl; + } + else + { + LOG(Message) << "Nothing to free" << std::endl; + } + } + } + + return memPeak; +} + +VirtualMachine::Size VirtualMachine::executeProgram(const std::vector &p) +{ + std::vector pAddress; + + for (auto &n: p) + { + pAddress.push_back(getModuleAddress(n)); + } + + return executeProgram(pAddress); +} + +// print VM content //////////////////////////////////////////////////////////// +void VirtualMachine::printContent(void) const +{ + LOG(Debug) << "Modules: " << std::endl; + for (unsigned int i = 0; i < module_.size(); ++i) + { + LOG(Debug) << std::setw(4) << i << ": " + << getModuleName(i) << std::endl; + } +} diff --git a/extras/Hadrons/VirtualMachine.hpp b/extras/Hadrons/VirtualMachine.hpp new file mode 100644 index 00000000..357fdb5b --- /dev/null +++ b/extras/Hadrons/VirtualMachine.hpp @@ -0,0 +1,164 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/VirtualMachine.hpp + +Copyright (C) 2017 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#ifndef Hadrons_VirtualMachine_hpp_ +#define Hadrons_VirtualMachine_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +#define DEFINE_VM_ALIAS \ +inline VirtualMachine & vm(void) const\ +{\ + return VirtualMachine::getInstance();\ +} + +/****************************************************************************** + * Virtual machine for module execution * + ******************************************************************************/ +// forward declaration of Module +class ModuleBase; + +class VirtualMachine +{ + SINGLETON_DEFCTOR(VirtualMachine); +public: + typedef SITE_SIZE_TYPE Size; + typedef std::unique_ptr ModPt; +private: + struct ModuleInfo + { + const std::type_info *type{nullptr}; + std::string name; + ModPt data{nullptr}; + std::vector input; + size_t maxAllocated; + }; +public: + // dry run + void dryRun(const bool isDry); + bool isDryRun(void) const; + void memoryProfile(const bool doMemoryProfile); + bool doMemoryProfile(void) const; + // trajectory counter + void setTrajectory(const unsigned int traj); + unsigned int getTrajectory(void) const; + // module management + void pushModule(ModPt &pt); + template + void createModule(const std::string name); + template + void createModule(const std::string name, + const typename M::Par &par); + void createModule(const std::string name, + const std::string type, + XmlReader &reader); + unsigned int getNModule(void) const; + ModuleBase * getModule(const unsigned int address) const; + ModuleBase * getModule(const std::string name) const; + template + M * getModule(const unsigned int address) const; + template + M * getModule(const std::string name) const; + unsigned int getModuleAddress(const std::string name) const; + std::string getModuleName(const unsigned int address) const; + std::string getModuleType(const unsigned int address) const; + std::string getModuleType(const std::string name) const; + std::string getModuleNamespace(const unsigned int address) const; + std::string getModuleNamespace(const std::string name) const; + bool hasModule(const unsigned int address) const; + bool hasModule(const std::string name) const; + Graph makeModuleGraph(void) const; + void checkGraph(void) const; + // print VM content + void printContent(void) const; + // general execution + Size executeProgram(const std::vector &p); + Size executeProgram(const std::vector &p); +private: + // environment shortcut + DEFINE_ENV_ALIAS; +private: + // general + bool dryRun_{false}, memoryProfile_{false}; + unsigned int traj_; + // module and related maps + std::vector module_; + std::map moduleAddress_; + std::string currentModule_{""}; +}; + +/****************************************************************************** + * VirtualMachine template implementation * + ******************************************************************************/ +// module management /////////////////////////////////////////////////////////// +template +void VirtualMachine::createModule(const std::string name) +{ + ModPt pt(new M(name)); + + pushModule(pt); +} + +template +void VirtualMachine::createModule(const std::string name, + const typename M::Par &par) +{ + ModPt pt(new M(name)); + + static_cast(pt.get())->setPar(par); + pushModule(pt); +} + +template +M * VirtualMachine::getModule(const unsigned int address) const +{ + if (auto *pt = dynamic_cast(getModule(address))) + { + return pt; + } + else + { + HADRON_ERROR("module '" + module_[address].name + + "' does not have type " + typeid(M).name() + + "(has type: " + getModuleType(address) + ")"); + } +} + +template +M * VirtualMachine::getModule(const std::string name) const +{ + return getModule(getModuleAddress(name)); +} + +END_HADRONS_NAMESPACE + +#endif // Hadrons_VirtualMachine_hpp_ From e78794688a676131ecf88902ae923a7d32b7cb96 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 6 Dec 2017 16:50:25 +0100 Subject: [PATCH 101/174] memory profiler improvement --- lib/allocator/AlignedAllocator.cc | 3 +- lib/allocator/AlignedAllocator.h | 79 ++++++++++++++++++------------- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/lib/allocator/AlignedAllocator.cc b/lib/allocator/AlignedAllocator.cc index 944e287f..dfdb1050 100644 --- a/lib/allocator/AlignedAllocator.cc +++ b/lib/allocator/AlignedAllocator.cc @@ -3,7 +3,8 @@ namespace Grid { -MemoryStats *MemoryProfiler::stats = nullptr; +MemoryStats *MemoryProfiler::stats = nullptr; +bool MemoryProfiler::debug = false; int PointerCache::victim; diff --git a/lib/allocator/AlignedAllocator.h b/lib/allocator/AlignedAllocator.h index bdccacec..85e2b240 100644 --- a/lib/allocator/AlignedAllocator.h +++ b/lib/allocator/AlignedAllocator.h @@ -74,8 +74,47 @@ namespace Grid { { public: static MemoryStats *stats; + static bool debug; }; + #define profilerDebugPrint \ + if (MemoryProfiler::stats)\ + {\ + auto s = MemoryProfiler::stats;\ + std::cout << "[Memory debug] Stats " << MemoryProfiler::stats << std::endl;\ + std::cout << "[Memory debug] Total : " << s->totalAllocated << "B" << std::endl;\ + std::cout << "[Memory debug] Max : " << s->maxAllocated << "B" << std::endl;\ + std::cout << "[Memory debug] Current: " << s->totalAllocated << "B" << std::endl;\ + std::cout << "[Memory debug] Freed : " << s->totalFreed << "B" << std::endl;\ + } + + #define profilerAllocate(bytes)\ + if (MemoryProfiler::stats)\ + {\ + auto s = MemoryProfiler::stats;\ + s->totalAllocated += (bytes);\ + s->currentlyAllocated += (bytes);\ + s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated);\ + }\ + if (MemoryProfiler::debug)\ + {\ + std::cout << "[Memory debug] allocating " << bytes << "B" << std::endl;\ + profilerDebugPrint;\ + } + + #define profilerFree(bytes)\ + if (MemoryProfiler::stats)\ + {\ + auto s = MemoryProfiler::stats;\ + s->totalFreed += (bytes);\ + s->currentlyAllocated -= (bytes);\ + }\ + if (MemoryProfiler::debug)\ + {\ + std::cout << "[Memory debug] freeing " << bytes << "B" << std::endl;\ + profilerDebugPrint;\ + } + void check_huge_pages(void *Buf,uint64_t BYTES); //////////////////////////////////////////////////////////////////// @@ -104,13 +143,7 @@ public: pointer allocate(size_type __n, const void* _p= 0) { size_type bytes = __n*sizeof(_Tp); - - if (auto s = MemoryProfiler::stats) - { - s->totalAllocated += bytes; - s->currentlyAllocated += bytes; - s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated); - } + profilerAllocate(bytes); _Tp *ptr = (_Tp *) PointerCache::Lookup(bytes); // if ( ptr != NULL ) @@ -141,11 +174,7 @@ public: void deallocate(pointer __p, size_type __n) { size_type bytes = __n * sizeof(_Tp); - if (auto s = MemoryProfiler::stats) - { - s->totalFreed += bytes; - s->currentlyAllocated -= bytes; - } + profilerFree(bytes); pointer __freeme = (pointer)PointerCache::Insert((void *)__p,bytes); @@ -199,12 +228,7 @@ public: { size_type bytes = __n*sizeof(_Tp); - if (auto s = MemoryProfiler::stats) - { - s->totalAllocated += bytes; - s->currentlyAllocated += bytes; - s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated); - } + profilerAllocate(bytes); #ifdef CRAY _Tp *ptr = (_Tp *) shmem_align(bytes,64); #else @@ -229,11 +253,7 @@ public: void deallocate(pointer __p, size_type __n) { size_type bytes = __n*sizeof(_Tp); - if (auto s = MemoryProfiler::stats) - { - s->totalFreed += bytes; - s->currentlyAllocated -= bytes; - } + profilerFree(bytes); shmem_free((void *)__p); } #else @@ -241,12 +261,7 @@ public: { size_type bytes = __n*sizeof(_Tp); - if (auto s = MemoryProfiler::stats) - { - s->totalAllocated += bytes; - s->currentlyAllocated += bytes; - s->maxAllocated = std::max(s->maxAllocated, s->currentlyAllocated); - } + profilerAllocate(bytes); #ifdef HAVE_MM_MALLOC_H _Tp * ptr = (_Tp *) _mm_malloc(bytes, GRID_ALLOC_ALIGN); #else @@ -265,11 +280,7 @@ public: void deallocate(pointer __p, size_type __n) { size_type bytes = __n*sizeof(_Tp); - if (auto s = MemoryProfiler::stats) - { - s->totalFreed += bytes; - s->currentlyAllocated -= bytes; - } + profilerFree(bytes); #ifdef HAVE_MM_MALLOC_H _mm_free((void *)__p); #else From 0fbf445edd90be7ac6363a77bc93c8b7325c45fe Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 6 Dec 2017 16:51:48 +0100 Subject: [PATCH 102/174] Hadrons: object creation that get properly captured by the memory profiler --- extras/Hadrons/Environment.hpp | 32 +++++++++++++++------ extras/Hadrons/Module.hpp | 27 +++++++++-------- extras/Hadrons/Modules/MAction/DWF.hpp | 5 ++-- extras/Hadrons/Modules/MAction/Wilson.hpp | 5 ++-- extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 2 +- extras/Hadrons/VirtualMachine.cc | 3 +- 6 files changed, 44 insertions(+), 30 deletions(-) diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 9d482923..5058a820 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -100,11 +100,16 @@ public: // general memory management void addObject(const std::string name, const int moduleAddress = -1); - template + template + void createDerivedObject(const std::string name, + const Environment::Storage storage, + const unsigned int Ls, + Ts && ... args); + template void createObject(const std::string name, - const Storage storage, + const Environment::Storage storage, const unsigned int Ls, - P &&pt); + Ts && ... args); void setObjectModule(const unsigned int objAddress, const int modAddress); template @@ -195,11 +200,11 @@ void Holder::reset(T *pt) * Environment template implementation * ******************************************************************************/ // general memory management /////////////////////////////////////////////////// -template -void Environment::createObject(const std::string name, +template +void Environment::createDerivedObject(const std::string name, const Environment::Storage storage, const unsigned int Ls, - P &&pt) + Ts && ... args) { if (!hasObject(name)) { @@ -210,13 +215,13 @@ void Environment::createObject(const std::string name, if (!object_[address].data) { - MemoryStats memStats; + MemoryStats memStats; MemoryProfiler::stats = &memStats; object_[address].storage = storage; object_[address].Ls = Ls; - object_[address].data.reset(new Holder(pt)); - object_[address].size = memStats.totalAllocated; + object_[address].data.reset(new Holder(new T(std::forward(args)...))); + object_[address].size = memStats.maxAllocated; object_[address].type = &typeid(T); MemoryProfiler::stats = nullptr; } @@ -226,6 +231,15 @@ void Environment::createObject(const std::string name, } } +template +void Environment::createObject(const std::string name, + const Environment::Storage storage, + const unsigned int Ls, + Ts && ... args) +{ + createDerivedObject(name, storage, Ls, std::forward(args)...); +} + template T * Environment::getObject(const unsigned int address) const { diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index d1910c9b..14d98bfb 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -98,39 +98,42 @@ static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; #define envHasType(type, name)\ env().template isObjectOfType(name) -#define envCreate(type, name, Ls, pt)\ -env().template createObject(name, Environment::Storage::object, Ls, pt) +#define envCreate(type, name, Ls, ...)\ +env().template createObject(name, Environment::Storage::object, Ls, __VA_ARGS__) + +#define envCreateDerived(base, type, name, Ls, ...)\ +env().template createDerivedObject(name, Environment::Storage::object, Ls, __VA_ARGS__) #define envCreateLat4(type, name)\ -envCreate(type, name, 1, new type(env().getGrid())) +envCreate(type, name, 1, env().getGrid()) #define envCreateLat5(type, name, Ls)\ -envCreate(type, name, Ls, new type(env().getGrid(Ls))) +envCreate(type, name, Ls, env().getGrid(Ls)) #define envCreateLat(...)\ MACRO_REDIRECT(__VA_ARGS__, envCreateLat5, envCreateLat4)(__VA_ARGS__) -#define envCache(type, name, Ls, pt)\ -env().template createObject(name, Environment::Storage::cache, Ls, pt) +#define envCache(type, name, Ls, ...)\ +env().template createObject(name, Environment::Storage::cache, Ls, __VA_ARGS__) #define envCacheLat4(type, name)\ -envCache(type, name, 1, new type(env().getGrid())) +envCache(type, name, 1, env().getGrid()) #define envCacheLat5(type, name, Ls)\ -envCache(type, name, Ls, new type(env().getGrid(Ls))) +envCache(type, name, Ls, env().getGrid(Ls)) #define envCacheLat(...)\ MACRO_REDIRECT(__VA_ARGS__, envCacheLat5, envCacheLat4)(__VA_ARGS__) -#define envTmp(type, name, Ls, pt)\ +#define envTmp(type, name, Ls, ...)\ env().template createObject(getName() + "_tmp_" + name, \ - Environment::Storage::temporary, Ls, pt) + Environment::Storage::temporary, Ls, __VA_ARGS__) #define envTmpLat4(type, name)\ -envTmp(type, name, 1, new type(env().getGrid())) +envTmp(type, name, 1, env().getGrid()) #define envTmpLat5(type, name, Ls)\ -envTmp(type, name, Ls, new type(env().getGrid(Ls))) +envTmp(type, name, Ls, env().getGrid(Ls)) #define envTmpLat(...)\ MACRO_REDIRECT(__VA_ARGS__, envTmpLat5, envTmpLat4)(__VA_ARGS__) diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 36c70073..e7d28476 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -118,9 +118,8 @@ void TDWF::setup(void) auto &grb5 = *env().getRbGrid(par().Ls); std::vector boundary = strToVec(par().boundary); typename DomainWallFermion::ImplParams implParams(boundary); - envCreate(FMat, getName(), par().Ls, - new DomainWallFermion(U, g5, grb5, g4, grb4, par().mass, - par().M5, implParams)); + envCreateDerived(FMat, DomainWallFermion, getName(), par().Ls, U, g5, + grb5, g4, grb4, par().mass, par().M5, implParams); } // execution /////////////////////////////////////////////////////////////////// diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index 7fe1f44e..591a3fed 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -111,9 +111,8 @@ void TWilson::setup(void) auto &gridRb = *env().getRbGrid(); std::vector boundary = strToVec(par().boundary); typename WilsonFermion::ImplParams implParams(boundary); - envCreate(FMat, getName(), 1, new WilsonFermion(U, grid, gridRb, - par().mass, - implParams)); + envCreateDerived(FMat, WilsonFermion, getName(), 1, U, grid, gridRb, + par().mass, implParams); } // execution /////////////////////////////////////////////////////////////////// diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index d8a4b95f..d6c21412 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -114,7 +114,7 @@ void TRBPrecCG::setup(void) schurSolver(mat, source, sol); }; - envCreate(SolverFn, getName(), Ls, new SolverFn(solver)); + envCreate(SolverFn, getName(), Ls, solver); env().addOwnership(getName(), par().action); } diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index f09e2710..ae1d5b6b 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -251,8 +251,7 @@ Graph VirtualMachine::makeModuleGraph(void) const // general execution /////////////////////////////////////////////////////////// #define BIG_SEP "===============" #define SEP "---------------" -#define MEM_MSG(size)\ -sizeString((size)*env().getLocalVolume()) << " (" << sizeString(size) << "/site)" +#define MEM_MSG(size) sizeString(size) VirtualMachine::Size VirtualMachine::executeProgram(const std::vector &p) From f9aa39e1c458652185ea81d2cfa16b9e47119e4e Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 7 Dec 2017 14:40:58 +0100 Subject: [PATCH 103/174] global memory debug through command line flag --- extras/Hadrons/Environment.hpp | 15 +++++++++++---- extras/Hadrons/Global.cc | 27 --------------------------- extras/Hadrons/Global.hpp | 3 --- lib/allocator/AlignedAllocator.cc | 25 +++++++++++++++++++++++++ lib/allocator/AlignedAllocator.h | 21 ++++++++++++++------- lib/util/Init.cc | 8 +++++++- 6 files changed, 57 insertions(+), 42 deletions(-) diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 5058a820..5177b312 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -216,14 +216,21 @@ void Environment::createDerivedObject(const std::string name, if (!object_[address].data) { MemoryStats memStats; - - MemoryProfiler::stats = &memStats; + + if (!MemoryProfiler::stats) + { + MemoryProfiler::stats = &memStats; + } + size_t initMem = MemoryProfiler::stats->currentlyAllocated; object_[address].storage = storage; object_[address].Ls = Ls; object_[address].data.reset(new Holder(new T(std::forward(args)...))); - object_[address].size = memStats.maxAllocated; + object_[address].size = MemoryProfiler::stats->maxAllocated - initMem; object_[address].type = &typeid(T); - MemoryProfiler::stats = nullptr; + if (MemoryProfiler::stats == &memStats) + { + MemoryProfiler::stats = nullptr; + } } else { diff --git a/extras/Hadrons/Global.cc b/extras/Hadrons/Global.cc index 7b0b8fb6..130ede96 100644 --- a/extras/Hadrons/Global.cc +++ b/extras/Hadrons/Global.cc @@ -39,33 +39,6 @@ HadronsLogger Hadrons::HadronsLogMessage(1,"Message"); HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative"); HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); -// pretty size formatting ////////////////////////////////////////////////////// -std::string Hadrons::sizeString(long unsigned int bytes) - -{ - constexpr unsigned int bufSize = 256; - const char *suffixes[7] = {"", "K", "M", "G", "T", "P", "E"}; - char buf[256]; - long unsigned int s = 0; - double count = bytes; - - while (count >= 1024 && s < 7) - { - s++; - count /= 1024; - } - if (count - floor(count) == 0.0) - { - snprintf(buf, bufSize, "%d %sB", (int)count, suffixes[s]); - } - else - { - snprintf(buf, bufSize, "%.1f %sB", count, suffixes[s]); - } - - return std::string(buf); -} - // type utilities ////////////////////////////////////////////////////////////// constexpr unsigned int maxNameSize = 1024u; diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 1f0ce201..4c37b961 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -138,9 +138,6 @@ public:\ private:\ name(void) = default; -// pretty size formating -std::string sizeString(long unsigned int bytes); - // type utilities template const std::type_info * typeIdPt(const T &x) diff --git a/lib/allocator/AlignedAllocator.cc b/lib/allocator/AlignedAllocator.cc index dfdb1050..10b49f4b 100644 --- a/lib/allocator/AlignedAllocator.cc +++ b/lib/allocator/AlignedAllocator.cc @@ -97,4 +97,29 @@ void check_huge_pages(void *Buf,uint64_t BYTES) #endif } +std::string sizeString(const size_t bytes) +{ + constexpr unsigned int bufSize = 256; + const char *suffixes[7] = {"", "K", "M", "G", "T", "P", "E"}; + char buf[256]; + size_t s = 0; + double count = bytes; + + while (count >= 1024 && s < 7) + { + s++; + count /= 1024; + } + if (count - floor(count) == 0.0) + { + snprintf(buf, bufSize, "%d %sB", (int)count, suffixes[s]); + } + else + { + snprintf(buf, bufSize, "%.1f %sB", count, suffixes[s]); + } + + return std::string(buf); +} + } diff --git a/lib/allocator/AlignedAllocator.h b/lib/allocator/AlignedAllocator.h index 85e2b240..3b27aec9 100644 --- a/lib/allocator/AlignedAllocator.h +++ b/lib/allocator/AlignedAllocator.h @@ -64,6 +64,8 @@ namespace Grid { }; + std::string sizeString(size_t bytes); + struct MemoryStats { size_t totalAllocated{0}, maxAllocated{0}, @@ -77,15 +79,20 @@ namespace Grid { static bool debug; }; + #define memString(bytes) std::to_string(bytes) + " (" + sizeString(bytes) + ")" #define profilerDebugPrint \ if (MemoryProfiler::stats)\ {\ auto s = MemoryProfiler::stats;\ - std::cout << "[Memory debug] Stats " << MemoryProfiler::stats << std::endl;\ - std::cout << "[Memory debug] Total : " << s->totalAllocated << "B" << std::endl;\ - std::cout << "[Memory debug] Max : " << s->maxAllocated << "B" << std::endl;\ - std::cout << "[Memory debug] Current: " << s->totalAllocated << "B" << std::endl;\ - std::cout << "[Memory debug] Freed : " << s->totalFreed << "B" << std::endl;\ + std::cout << GridLogDebug << "[Memory debug] Stats " << MemoryProfiler::stats << std::endl;\ + std::cout << GridLogDebug << "[Memory debug] total : " << memString(s->totalAllocated) \ + << std::endl;\ + std::cout << GridLogDebug << "[Memory debug] max : " << memString(s->maxAllocated) \ + << std::endl;\ + std::cout << GridLogDebug << "[Memory debug] current: " << memString(s->currentlyAllocated) \ + << std::endl;\ + std::cout << GridLogDebug << "[Memory debug] freed : " << memString(s->totalFreed) \ + << std::endl;\ } #define profilerAllocate(bytes)\ @@ -98,7 +105,7 @@ namespace Grid { }\ if (MemoryProfiler::debug)\ {\ - std::cout << "[Memory debug] allocating " << bytes << "B" << std::endl;\ + std::cout << GridLogDebug << "[Memory debug] allocating " << memString(bytes) << std::endl;\ profilerDebugPrint;\ } @@ -111,7 +118,7 @@ namespace Grid { }\ if (MemoryProfiler::debug)\ {\ - std::cout << "[Memory debug] freeing " << bytes << "B" << std::endl;\ + std::cout << GridLogDebug << "[Memory debug] freeing " << memString(bytes) << std::endl;\ profilerDebugPrint;\ } diff --git a/lib/util/Init.cc b/lib/util/Init.cc index 031f8f5a..20367293 100644 --- a/lib/util/Init.cc +++ b/lib/util/Init.cc @@ -204,7 +204,7 @@ std::string GridCmdVectorIntToString(const std::vector & vec){ // Reinit guard ///////////////////////////////////////////////////////// static int Grid_is_initialised = 0; - +static MemoryStats dbgMemStats; void Grid_init(int *argc,char ***argv) { @@ -251,6 +251,11 @@ void Grid_init(int *argc,char ***argv) assert(fp!=(FILE *)NULL); } + if( GridCmdOptionExists(*argv,*argv+*argc,"--debug-mem") ){ + MemoryProfiler::debug = true; + MemoryProfiler::stats = &dbgMemStats; + } + //////////////////////////////////// // Banner //////////////////////////////////// @@ -324,6 +329,7 @@ void Grid_init(int *argc,char ***argv) std::cout< Date: Fri, 8 Dec 2017 11:13:39 +0000 Subject: [PATCH 104/174] bug fix in sequential insertion of conserved vector current --- lib/qcd/action/fermion/WilsonFermion.cc | 8 +++++++- lib/qcd/action/fermion/WilsonFermion5D.cc | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/qcd/action/fermion/WilsonFermion.cc b/lib/qcd/action/fermion/WilsonFermion.cc index b986edd7..1a020e8a 100644 --- a/lib/qcd/action/fermion/WilsonFermion.cc +++ b/lib/qcd/action/fermion/WilsonFermion.cc @@ -395,7 +395,8 @@ void WilsonFermion::SeqConservedCurrent(PropagatorField &q_in, Lattice> ph(_grid), coor(_grid); Complex i(0.0,1.0); PropagatorField tmpFwd(_grid), tmpBwd(_grid), tmp(_grid); - int tshift = (mu == Tp) ? 1 : 0; + unsigned int tshift = (mu == Tp) ? 1 : 0; + unsigned int LLt = GridDefaultLatt()[Tp]; // Momentum projection ph = zero; @@ -434,6 +435,11 @@ void WilsonFermion::SeqConservedCurrent(PropagatorField &q_in, // Repeat for backward direction. t_mask = ((coords._odata[sU] >= (tmin + tshift)) && (coords._odata[sU] <= (tmax + tshift))); + + //if tmax = LLt-1 (last timeslice) include timeslice 0 if the time is shifted (mu=3) + unsigned int t0 = 0; + if((tmax==LLt-1) && (tshift==1)) t_mask = (t_mask || (coords._odata[sU] == t0 )); + timeSlices = Reduce(t_mask); if (timeSlices > 0) diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index 19a37c34..393ee7f3 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -794,8 +794,9 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, PropagatorField tmpFwd(FermionGrid()), tmpBwd(FermionGrid()), tmp(FermionGrid()); Complex i(0.0, 1.0); - int tshift = (mu == Tp) ? 1 : 0; + unsigned int tshift = (mu == Tp) ? 1 : 0; unsigned int LLs = q_in._grid->_rdimensions[0]; + unsigned int LLt = GridDefaultLatt()[Tp]; // Momentum projection. ph = zero; @@ -842,6 +843,11 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, // Repeat for backward direction. t_mask = ((coords._odata[sU] >= (tmin + tshift)) && (coords._odata[sU] <= (tmax + tshift))); + + //if tmax = LLt-1 (last timeslice) include timeslice 0 if the time is shifted (mu=3) + unsigned int t0 = 0; + if((tmax==LLt-1) && (tshift==1)) t_mask = (t_mask || (coords._odata[sU] == t0 )); + timeSlices = Reduce(t_mask); if (timeSlices > 0) From 64161a8743ded19a767883793d7030d6e4093699 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 12 Dec 2017 13:08:01 +0000 Subject: [PATCH 105/174] Hadrons: much simpler reference dependency --- extras/Hadrons/Environment.cc | 78 +++---------------- extras/Hadrons/Environment.hpp | 27 +++---- extras/Hadrons/Graph.hpp | 12 +-- extras/Hadrons/Module.hpp | 1 + extras/Hadrons/Modules/MAction/DWF.hpp | 9 +++ extras/Hadrons/Modules/MAction/Wilson.hpp | 9 +++ extras/Hadrons/Modules/MContraction/Meson.hpp | 9 +++ extras/Hadrons/Modules/MFermion/GaugeProp.hpp | 9 +++ extras/Hadrons/Modules/MGauge/Unit.cc | 7 ++ extras/Hadrons/Modules/MGauge/Unit.hpp | 1 + extras/Hadrons/Modules/MSink/Point.hpp | 9 +++ extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 12 ++- extras/Hadrons/Modules/MSource/Point.hpp | 9 +++ .../Modules/templates/Module.cc.template | 8 ++ .../Modules/templates/Module.hpp.template | 1 + .../templates/Module_in_NS.cc.template | 8 ++ .../templates/Module_in_NS.hpp.template | 1 + .../Modules/templates/Module_tmp.hpp.template | 1 + .../templates/Module_tmp_in_NS.hpp.template | 9 +++ extras/Hadrons/VirtualMachine.cc | 77 +++++++++--------- 20 files changed, 171 insertions(+), 126 deletions(-) diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index ea41f343..66291966 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -341,81 +341,21 @@ Environment::Size Environment::getTotalSize(void) const return size; } -void Environment::addOwnership(const unsigned int owner, - const unsigned int property) +void Environment::freeObject(const unsigned int address) { - if (hasObject(property)) + if (hasCreatedObject(address)) { - object_[property].owners.insert(owner); - } - else - { - HADRON_ERROR("no object with address " + std::to_string(property)); - } - if (hasObject(owner)) - { - object_[owner].properties.insert(property); - } - else - { - HADRON_ERROR("no object with address " + std::to_string(owner)); + LOG(Message) << "Destroying object '" << object_[address].name + << "'" << std::endl; } + object_[address].size = 0; + object_[address].type = nullptr; + object_[address].data.reset(nullptr); } -void Environment::addOwnership(const std::string owner, - const std::string property) +void Environment::freeObject(const std::string name) { - addOwnership(getObjectAddress(owner), getObjectAddress(property)); -} - -bool Environment::hasOwners(const unsigned int address) const -{ - - if (hasObject(address)) - { - return (!object_[address].owners.empty()); - } - else - { - HADRON_ERROR("no object with address " + std::to_string(address)); - } -} - -bool Environment::hasOwners(const std::string name) const -{ - return hasOwners(getObjectAddress(name)); -} - -bool Environment::freeObject(const unsigned int address) -{ - if (!hasOwners(address)) - { - if (hasCreatedObject(address)) - { - LOG(Message) << "Destroying object '" << object_[address].name - << "'" << std::endl; - } - for (auto &p: object_[address].properties) - { - object_[p].owners.erase(address); - } - object_[address].size = 0; - object_[address].type = nullptr; - object_[address].owners.clear(); - object_[address].properties.clear(); - object_[address].data.reset(nullptr); - - return true; - } - else - { - return false; - } -} - -bool Environment::freeObject(const std::string name) -{ - return freeObject(getObjectAddress(name)); + freeObject(getObjectAddress(name)); } void Environment::freeAll(void) diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 5177b312..811ee14e 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -82,7 +82,6 @@ private: const std::type_info *type{nullptr}; std::string name; int module{-1}; - std::set owners, properties; std::unique_ptr data{nullptr}; }; public: @@ -140,14 +139,8 @@ public: template bool isObjectOfType(const std::string name) const; Environment::Size getTotalSize(void) const; - void addOwnership(const unsigned int owner, - const unsigned int property); - void addOwnership(const std::string owner, - const std::string property); - bool hasOwners(const unsigned int address) const; - bool hasOwners(const std::string name) const; - bool freeObject(const unsigned int address); - bool freeObject(const std::string name); + void freeObject(const unsigned int address); + void freeObject(const std::string name); void freeAll(void); // print environment content void printContent(void) const; @@ -252,15 +245,23 @@ T * Environment::getObject(const unsigned int address) const { if (hasObject(address)) { - if (auto h = dynamic_cast *>(object_[address].data.get())) + if (hasCreatedObject(address)) { - return h->getPt(); + if (auto h = dynamic_cast *>(object_[address].data.get())) + { + return h->getPt(); + } + else + { + HADRON_ERROR("object with address " + std::to_string(address) + + " does not have type '" + typeName(&typeid(T)) + + "' (has type '" + getObjectType(address) + "')"); + } } else { HADRON_ERROR("object with address " + std::to_string(address) + - " does not have type '" + typeName(&typeid(T)) + - "' (has type '" + getObjectType(address) + "')"); + " is empty"); } } else diff --git a/extras/Hadrons/Graph.hpp b/extras/Hadrons/Graph.hpp index df255517..bb9ae679 100644 --- a/extras/Hadrons/Graph.hpp +++ b/extras/Hadrons/Graph.hpp @@ -430,7 +430,7 @@ std::vector Graph::getAdjacentVertices(const T &value) const { return ((e.first == value) or (e.second == value)); }; - auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); + auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred); while (eIt != edgeSet_.end()) { @@ -442,7 +442,7 @@ std::vector Graph::getAdjacentVertices(const T &value) const { adjacentVertex.push_back((*eIt).first); } - eIt = find_if(++eIt, edgeSet_.end(), pred); + eIt = std::find_if(++eIt, edgeSet_.end(), pred); } return adjacentVertex; @@ -458,12 +458,12 @@ std::vector Graph::getChildren(const T &value) const { return (e.first == value); }; - auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); + auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred); while (eIt != edgeSet_.end()) { child.push_back((*eIt).second); - eIt = find_if(++eIt, edgeSet_.end(), pred); + eIt = std::find_if(++eIt, edgeSet_.end(), pred); } return child; @@ -479,12 +479,12 @@ std::vector Graph::getParents(const T &value) const { return (e.second == value); }; - auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred); + auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred); while (eIt != edgeSet_.end()) { parent.push_back((*eIt).first); - eIt = find_if(++eIt, edgeSet_.end(), pred); + eIt = std::find_if(++eIt, edgeSet_.end(), pred); } return parent; diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 14d98bfb..c6b58e9f 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -155,6 +155,7 @@ public: virtual std::string getRegisteredName(void); // dependencies/products virtual std::vector getInput(void) = 0; + virtual std::vector getReference(void) = 0; virtual std::vector getOutput(void) = 0; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name) = 0; diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index e7d28476..91e4ec94 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -64,6 +64,7 @@ public: virtual ~TDWF(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -92,6 +93,14 @@ std::vector TDWF::getInput(void) return in; } +template +std::vector TDWF::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TDWF::getOutput(void) { diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index 591a3fed..1ca3bf59 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -62,6 +62,7 @@ public: virtual ~TWilson(void) = default; // dependencies/products virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -90,6 +91,14 @@ std::vector TWilson::getInput(void) return in; } +template +std::vector TWilson::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TWilson::getOutput(void) { diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 7c0012d2..7d19feb8 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -95,6 +95,7 @@ public: virtual ~TMeson(void) = default; // dependencies/products virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); virtual void parseGammaString(std::vector &gammaList); protected: @@ -122,6 +123,14 @@ std::vector TMeson::getInput(void) return input; } +template +std::vector TMeson::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TMeson::getOutput(void) { diff --git a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp index 8529825b..f860c403 100644 --- a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -84,6 +84,7 @@ public: virtual ~TGaugeProp(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -115,6 +116,14 @@ std::vector TGaugeProp::getInput(void) return in; } +template +std::vector TGaugeProp::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TGaugeProp::getOutput(void) { diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index b3a7d634..bc05a785 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -47,6 +47,13 @@ std::vector TUnit::getInput(void) return std::vector(); } +std::vector TUnit::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + std::vector TUnit::getOutput(void) { std::vector out = {getName()}; diff --git a/extras/Hadrons/Modules/MGauge/Unit.hpp b/extras/Hadrons/Modules/MGauge/Unit.hpp index c1650cc7..4b69f0ce 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.hpp +++ b/extras/Hadrons/Modules/MGauge/Unit.hpp @@ -50,6 +50,7 @@ public: virtual ~TUnit(void) = default; // dependencies/products virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup diff --git a/extras/Hadrons/Modules/MSink/Point.hpp b/extras/Hadrons/Modules/MSink/Point.hpp index 853a7c32..16b89434 100644 --- a/extras/Hadrons/Modules/MSink/Point.hpp +++ b/extras/Hadrons/Modules/MSink/Point.hpp @@ -60,6 +60,7 @@ public: virtual ~TPoint(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -93,6 +94,14 @@ std::vector TPoint::getInput(void) return in; } +template +std::vector TPoint::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TPoint::getOutput(void) { diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index d6c21412..bb4f3f62 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -61,6 +61,7 @@ public: virtual ~TRBPrecCG(void) = default; // dependencies/products virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -84,11 +85,19 @@ TRBPrecCG::TRBPrecCG(const std::string name) template std::vector TRBPrecCG::getInput(void) { - std::vector in = {par().action}; + std::vector in = {}; return in; } +template +std::vector TRBPrecCG::getReference(void) +{ + std::vector ref = {par().action}; + + return ref; +} + template std::vector TRBPrecCG::getOutput(void) { @@ -115,7 +124,6 @@ void TRBPrecCG::setup(void) schurSolver(mat, source, sol); }; envCreate(SolverFn, getName(), Ls, solver); - env().addOwnership(getName(), par().action); } // execution /////////////////////////////////////////////////////////////////// diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index b9813688..3fab41c0 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -71,6 +71,7 @@ public: virtual ~TPoint(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -100,6 +101,14 @@ std::vector TPoint::getInput(void) return in; } +template +std::vector TPoint::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TPoint::getOutput(void) { diff --git a/extras/Hadrons/Modules/templates/Module.cc.template b/extras/Hadrons/Modules/templates/Module.cc.template index 0c509d6d..29edadfb 100644 --- a/extras/Hadrons/Modules/templates/Module.cc.template +++ b/extras/Hadrons/Modules/templates/Module.cc.template @@ -19,6 +19,14 @@ std::vector T___FILEBASENAME___::getInput(void) return in; } +template +std::vector T___FILEBASENAME___::getReference(void) +{ + std::vector in = {}; + + return in; +} + std::vector T___FILEBASENAME___::getOutput(void) { std::vector out = {getName()}; diff --git a/extras/Hadrons/Modules/templates/Module.hpp.template b/extras/Hadrons/Modules/templates/Module.hpp.template index fb43260f..b59e168f 100644 --- a/extras/Hadrons/Modules/templates/Module.hpp.template +++ b/extras/Hadrons/Modules/templates/Module.hpp.template @@ -26,6 +26,7 @@ public: virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); // setup virtual void setup(void); diff --git a/extras/Hadrons/Modules/templates/Module_in_NS.cc.template b/extras/Hadrons/Modules/templates/Module_in_NS.cc.template index 8b2a0ec0..880129bd 100644 --- a/extras/Hadrons/Modules/templates/Module_in_NS.cc.template +++ b/extras/Hadrons/Modules/templates/Module_in_NS.cc.template @@ -20,6 +20,14 @@ std::vector T___FILEBASENAME___::getInput(void) return in; } +template +std::vector T___FILEBASENAME___::getReference(void) +{ + std::vector in = {}; + + return in; +} + std::vector T___FILEBASENAME___::getOutput(void) { std::vector out = {getName()}; diff --git a/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template index ea77b12a..f90cb052 100644 --- a/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template @@ -28,6 +28,7 @@ public: virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); // setup virtual void setup(void); diff --git a/extras/Hadrons/Modules/templates/Module_tmp.hpp.template b/extras/Hadrons/Modules/templates/Module_tmp.hpp.template index 2ee053a9..b4e7f87f 100644 --- a/extras/Hadrons/Modules/templates/Module_tmp.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_tmp.hpp.template @@ -27,6 +27,7 @@ public: virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); // setup virtual void setup(void); diff --git a/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template b/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template index b79c0ad3..9aef1c92 100644 --- a/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template @@ -29,6 +29,7 @@ public: virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); // setup virtual void setup(void); @@ -56,6 +57,14 @@ std::vector T___FILEBASENAME___::getInput(void) return in; } +template +std::vector T___FILEBASENAME___::getReference(void) +{ + std::vector in = {}; + + return in; +} + template std::vector T___FILEBASENAME___::getOutput(void) { diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index ae1d5b6b..7f967f66 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -82,8 +82,7 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) m.data = std::move(pt); m.type = typeIdPt(*m.data.get()); m.name = name; - auto input = m.data->getInput(); - for (auto &in: input) + for (auto &in: m.data->getInput()) { if (!env().hasObject(in)) { @@ -91,11 +90,18 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) } m.input.push_back(env().getObjectAddress(in)); } - auto output = m.data->getOutput(); + for (auto &ref: m.data->getReference()) + { + if (!env().hasObject(ref)) + { + env().addObject(ref , -1); + } + m.input.push_back(env().getObjectAddress(ref)); + } module_.push_back(std::move(m)); address = static_cast(module_.size() - 1); moduleAddress_[name] = address; - for (auto &out: output) + for (auto &out: getModule(address)->getOutput()) { if (!env().hasObject(out)) { @@ -114,6 +120,25 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) + module_[env().getObjectModule(out)].name + "' (while pushing module '" + name + "')"); } + if (getModule(address)->getReference().size() > 0) + { + auto pred = [this, out](const ModuleInfo &n) + { + auto &in = n.input; + auto it = std::find(in.begin(), in.end(), env().getObjectAddress(out)); + + return (it != in.end()); + }; + auto it = std::find_if(module_.begin(), module_.end(), pred); + while (it != module_.end()) + { + for (auto &ref: getModule(address)->getReference()) + { + it->input.push_back(env().getObjectAddress(ref)); + } + it = std::find_if(++it, module_.end(), pred); + } + } } } } @@ -225,12 +250,17 @@ Graph VirtualMachine::makeModuleGraph(void) const { Graph moduleGraph; - for (unsigned int i = 0; i < module_.size(); ++i) + // create vertices + for (unsigned int m = 0; m < module_.size(); ++m) { - moduleGraph.addVertex(i); - for (auto &j: module_[i].input) + moduleGraph.addVertex(m); + } + // create edges + for (unsigned int m = 0; m < module_.size(); ++m) + { + for (auto &in: module_[m].input) { - moduleGraph.addEdge(env().getObjectModule(j), i); + moduleGraph.addEdge(env().getObjectModule(in), m); } } @@ -258,7 +288,6 @@ VirtualMachine::executeProgram(const std::vector &p) { Size memPeak = 0, sizeBefore, sizeAfter; std::vector> freeProg; - bool continueCollect, nothingFreed; // build garbage collection schedule LOG(Debug) << "Building garbage collection schedule..." << std::endl; @@ -307,25 +336,10 @@ VirtualMachine::executeProgram(const std::vector &p) { LOG(Message) << "Garbage collection..." << std::endl; } - nothingFreed = true; - do + for (auto &j: freeProg[i]) { - continueCollect = false; - auto toFree = freeProg[i]; - for (auto &j: toFree) - { - // continue garbage collection while there are still - // objects without owners - continueCollect = continueCollect or !env().hasOwners(j); - if(env().freeObject(j)) - { - // if an object has been freed, remove it from - // the garbage collection schedule - freeProg[i].erase(j); - nothingFreed = false; - } - } - } while (continueCollect); + env().freeObject(j); + } // free temporaries for (unsigned int i = 0; i < env().getMaxAddress(); ++i) { @@ -335,15 +349,6 @@ VirtualMachine::executeProgram(const std::vector &p) env().freeObject(i); } } - // any remaining objects in step i garbage collection schedule - // is scheduled for step i + 1 - if (i + 1 < p.size()) - { - for (auto &j: freeProg[i]) - { - freeProg[i + 1].insert(j); - } - } // print used memory after garbage collection if necessary if (!isDryRun()) { From 26d7b829a076fa74df370789e9f723f8b793fa67 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 12 Dec 2017 14:04:28 +0000 Subject: [PATCH 106/174] Hadrons: error managed through expections --- extras/Hadrons/Application.cc | 8 +-- extras/Hadrons/Environment.cc | 23 +++--- extras/Hadrons/Environment.hpp | 10 +-- extras/Hadrons/Exceptions.cc | 57 +++++++++++++++ extras/Hadrons/Exceptions.hpp | 72 +++++++++++++++++++ extras/Hadrons/Factory.hpp | 2 +- extras/Hadrons/Global.hpp | 7 +- extras/Hadrons/Graph.hpp | 12 ++-- extras/Hadrons/Makefile.am | 2 + extras/Hadrons/Module.cc | 2 +- .../Modules/MContraction/WardIdentity.hpp | 2 +- extras/Hadrons/Modules/MFermion/GaugeProp.hpp | 2 +- .../Modules/MUtilities/TestSeqConserved.hpp | 2 +- extras/Hadrons/VirtualMachine.cc | 14 ++-- extras/Hadrons/VirtualMachine.hpp | 2 +- 15 files changed, 174 insertions(+), 43 deletions(-) create mode 100644 extras/Hadrons/Exceptions.cc create mode 100644 extras/Hadrons/Exceptions.hpp diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index af67dff3..aa66d36f 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -123,11 +123,11 @@ void Application::parseParameterFile(const std::string parameterFileName) setPar(par); if (!push(reader, "modules")) { - HADRON_ERROR("Cannot open node 'modules' in parameter file '" + parameterFileName + "'"); + HADRON_ERROR(Parsing, "Cannot open node 'modules' in parameter file '" + parameterFileName + "'"); } if (!push(reader, "module")) { - HADRON_ERROR("Cannot open node 'modules/module' in parameter file '" + parameterFileName + "'"); + HADRON_ERROR(Parsing, "Cannot open node 'modules/module' in parameter file '" + parameterFileName + "'"); } do { @@ -262,7 +262,7 @@ void Application::saveSchedule(const std::string filename) if (!scheduled_) { - HADRON_ERROR("Computation not scheduled"); + HADRON_ERROR(Definition, "Computation not scheduled"); } LOG(Message) << "Saving current schedule to '" << filename << "'..." << std::endl; @@ -296,7 +296,7 @@ void Application::printSchedule(void) { if (!scheduled_) { - HADRON_ERROR("Computation not scheduled"); + HADRON_ERROR(Definition, "Computation not scheduled"); } LOG(Message) << "Schedule (memory peak: " << MEM_MSG(memPeak_) << "):" << std::endl; diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 66291966..403476d0 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -35,6 +35,9 @@ using namespace Grid; using namespace QCD; using namespace Hadrons; +#define ERROR_NO_ADDRESS(address)\ +HADRON_ERROR(Definition, "no object with address " + std::to_string(address)); + /****************************************************************************** * Environment implementation * ******************************************************************************/ @@ -83,7 +86,7 @@ GridCartesian * Environment::getGrid(const unsigned int Ls) const } catch(std::out_of_range &) { - HADRON_ERROR("no grid with Ls= " << Ls); + HADRON_ERROR(Definition, "no grid with Ls= " + std::to_string(Ls)); } } @@ -102,7 +105,7 @@ GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const } catch(std::out_of_range &) { - HADRON_ERROR("no red-black 5D grid with Ls= " << Ls); + HADRON_ERROR(Definition, "no red-black 5D grid with Ls= " + std::to_string(Ls)); } } @@ -152,7 +155,7 @@ void Environment::addObject(const std::string name, const int moduleAddress) } else { - HADRON_ERROR("object '" + name + "' already exists"); + HADRON_ERROR(Definition, "object '" + name + "' already exists"); } } @@ -175,7 +178,7 @@ unsigned int Environment::getObjectAddress(const std::string name) const } else { - HADRON_ERROR("no object with name '" + name + "'"); + HADRON_ERROR(Definition, "no object with name '" + name + "'"); } } @@ -187,7 +190,7 @@ std::string Environment::getObjectName(const unsigned int address) const } else { - HADRON_ERROR("no object with address " + std::to_string(address)); + ERROR_NO_ADDRESS(address); } } @@ -206,7 +209,7 @@ std::string Environment::getObjectType(const unsigned int address) const } else { - HADRON_ERROR("no object with address " + std::to_string(address)); + ERROR_NO_ADDRESS(address); } } @@ -223,7 +226,7 @@ Environment::Size Environment::getObjectSize(const unsigned int address) const } else { - HADRON_ERROR("no object with address " + std::to_string(address)); + ERROR_NO_ADDRESS(address); } } @@ -240,7 +243,7 @@ Environment::Storage Environment::getObjectStorage(const unsigned int address) c } else { - HADRON_ERROR("no object with address " + std::to_string(address)); + ERROR_NO_ADDRESS(address); } } @@ -257,7 +260,7 @@ int Environment::getObjectModule(const unsigned int address) const } else { - HADRON_ERROR("no object with address " + std::to_string(address)); + ERROR_NO_ADDRESS(address); } } @@ -274,7 +277,7 @@ unsigned int Environment::getObjectLs(const unsigned int address) const } else { - HADRON_ERROR("no object with address " + std::to_string(address)); + ERROR_NO_ADDRESS(address); } } diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 811ee14e..60371c20 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -227,7 +227,7 @@ void Environment::createDerivedObject(const std::string name, } else { - HADRON_ERROR("object '" + name + "' already allocated"); + HADRON_ERROR(Definition, "object '" + name + "' already allocated"); } } @@ -253,20 +253,20 @@ T * Environment::getObject(const unsigned int address) const } else { - HADRON_ERROR("object with address " + std::to_string(address) + + HADRON_ERROR(Definition, "object with address " + std::to_string(address) + " does not have type '" + typeName(&typeid(T)) + "' (has type '" + getObjectType(address) + "')"); } } else { - HADRON_ERROR("object with address " + std::to_string(address) + + HADRON_ERROR(Definition, "object with address " + std::to_string(address) + " is empty"); } } else { - HADRON_ERROR("no object with address " + std::to_string(address)); + HADRON_ERROR(Definition, "no object with address " + std::to_string(address)); } } @@ -292,7 +292,7 @@ bool Environment::isObjectOfType(const unsigned int address) const } else { - HADRON_ERROR("no object with address " + std::to_string(address)); + HADRON_ERROR(Definition, "no object with address " + std::to_string(address)); } } diff --git a/extras/Hadrons/Exceptions.cc b/extras/Hadrons/Exceptions.cc new file mode 100644 index 00000000..bf532c21 --- /dev/null +++ b/extras/Hadrons/Exceptions.cc @@ -0,0 +1,57 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Exceptions.cc + +Copyright (C) 2017 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#include + +#ifndef ERR_SUFF +#define ERR_SUFF " (" + loc + ")" +#endif + +#define CONST_EXC(name, init) \ +name::name(std::string msg, std::string loc)\ +:init\ +{} + +using namespace Grid; +using namespace Hadrons; +using namespace Exceptions; + +// logic errors +CONST_EXC(Logic, logic_error(msg + ERR_SUFF)) +CONST_EXC(Definition, Logic("definition error: " + msg, loc)) +CONST_EXC(Implementation, Logic("implementation error: " + msg, loc)) +CONST_EXC(Range, Logic("range error: " + msg, loc)) +CONST_EXC(Size, Logic("size error: " + msg, loc)) +// runtime errors +CONST_EXC(Runtime, runtime_error(msg + ERR_SUFF)) +CONST_EXC(Argument, Runtime("argument error: " + msg, loc)) +CONST_EXC(Io, Runtime("IO error: " + msg, loc)) +CONST_EXC(Memory, Runtime("memory error: " + msg, loc)) +CONST_EXC(Parsing, Runtime("parsing error: " + msg, loc)) +CONST_EXC(Program, Runtime("program error: " + msg, loc)) +CONST_EXC(System, Runtime("system error: " + msg, loc)) \ No newline at end of file diff --git a/extras/Hadrons/Exceptions.hpp b/extras/Hadrons/Exceptions.hpp new file mode 100644 index 00000000..8f04ab41 --- /dev/null +++ b/extras/Hadrons/Exceptions.hpp @@ -0,0 +1,72 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Exceptions.hpp + +Copyright (C) 2017 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#ifndef Hadrons_Exceptions_hpp_ +#define Hadrons_Exceptions_hpp_ + +#include +#ifndef Hadrons_Global_hpp_ +#include +#endif + +#define SRC_LOC std::string(__FUNCTION__) + " at " + std::string(__FILE__) + ":"\ + + std::to_string(__LINE__) +#define HADRON_ERROR(exc, msg)\ +LOG(Error) << msg << std::endl;\ +throw(Exceptions::exc(msg, SRC_LOC)); + +#define DECL_EXC(name, base) \ +class name: public base\ +{\ +public:\ + name(std::string msg, std::string loc);\ +} + +BEGIN_HADRONS_NAMESPACE + +namespace Exceptions +{ + // logic errors + DECL_EXC(Logic, std::logic_error); + DECL_EXC(Definition, Logic); + DECL_EXC(Implementation, Logic); + DECL_EXC(Range, Logic); + DECL_EXC(Size, Logic); + // runtime errors + DECL_EXC(Runtime, std::runtime_error); + DECL_EXC(Argument, Runtime); + DECL_EXC(Io, Runtime); + DECL_EXC(Memory, Runtime); + DECL_EXC(Parsing, Runtime); + DECL_EXC(Program, Runtime); + DECL_EXC(System, Runtime); +} + +END_HADRONS_NAMESPACE + +#endif // Hadrons_Exceptions_hpp_ diff --git a/extras/Hadrons/Factory.hpp b/extras/Hadrons/Factory.hpp index da86acae..65ce03ca 100644 --- a/extras/Hadrons/Factory.hpp +++ b/extras/Hadrons/Factory.hpp @@ -95,7 +95,7 @@ std::unique_ptr Factory::create(const std::string type, } catch (std::out_of_range &) { - HADRON_ERROR("object of type '" + type + "' unknown"); + HADRON_ERROR(Argument, "object of type '" + type + "' unknown"); } return func(name); diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 4c37b961..c3d60bf2 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -100,11 +100,6 @@ public: }; #define LOG(channel) std::cout << HadronsLog##channel -#define HADRON_ERROR(msg)\ -LOG(Error) << msg << " (" << __FUNCTION__ << " at " << __FILE__ << ":"\ - << __LINE__ << ")" << std::endl;\ -abort(); - #define DEBUG_VAR(var) LOG(Debug) << #var << "= " << (var) << std::endl; extern HadronsLogger HadronsLogError; @@ -176,4 +171,6 @@ typedef XmlWriter CorrWriter; END_HADRONS_NAMESPACE +#include + #endif // Hadrons_Global_hpp_ diff --git a/extras/Hadrons/Graph.hpp b/extras/Hadrons/Graph.hpp index bb9ae679..a9c240fa 100644 --- a/extras/Hadrons/Graph.hpp +++ b/extras/Hadrons/Graph.hpp @@ -185,7 +185,7 @@ void Graph::removeVertex(const T &value) } else { - HADRON_ERROR("vertex " << value << " does not exists"); + HADRON_ERROR(Range, "vertex does not exists"); } // remove all edges containing the vertex @@ -214,7 +214,7 @@ void Graph::removeEdge(const Edge &e) } else { - HADRON_ERROR("edge " << e << " does not exists"); + HADRON_ERROR(Range, "edge does not exists"); } } @@ -260,7 +260,7 @@ void Graph::mark(const T &value, const bool doMark) } else { - HADRON_ERROR("vertex " << value << " does not exists"); + HADRON_ERROR(Range, "vertex does not exists"); } } @@ -298,7 +298,7 @@ bool Graph::isMarked(const T &value) const } else { - HADRON_ERROR("vertex " << value << " does not exists"); + HADRON_ERROR(Range, "vertex does not exists"); return false; } @@ -544,7 +544,7 @@ std::vector Graph::topoSort(void) { if (tmpMarked.at(v)) { - HADRON_ERROR("cannot topologically sort a cyclic graph"); + HADRON_ERROR(Range, "cannot topologically sort a cyclic graph"); } if (!isMarked(v)) { @@ -603,7 +603,7 @@ std::vector Graph::topoSort(Gen &gen) { if (tmpMarked.at(v)) { - HADRON_ERROR("cannot topologically sort a cyclic graph"); + HADRON_ERROR(Range, "cannot topologically sort a cyclic graph"); } if (!isMarked(v)) { diff --git a/extras/Hadrons/Makefile.am b/extras/Hadrons/Makefile.am index 826cb158..3d07679a 100644 --- a/extras/Hadrons/Makefile.am +++ b/extras/Hadrons/Makefile.am @@ -7,6 +7,7 @@ libHadrons_a_SOURCES = \ $(modules_cc) \ Application.cc \ Environment.cc \ + Exceptions.cc \ Global.cc \ Module.cc \ VirtualMachine.cc @@ -15,6 +16,7 @@ nobase_libHadrons_a_HEADERS = \ $(modules_hpp) \ Application.hpp \ Environment.hpp \ + Exceptions.hpp \ Factory.hpp \ GeneticScheduler.hpp \ Global.hpp \ diff --git a/extras/Hadrons/Module.cc b/extras/Hadrons/Module.cc index bf596bfc..383a5c2e 100644 --- a/extras/Hadrons/Module.cc +++ b/extras/Hadrons/Module.cc @@ -50,7 +50,7 @@ std::string ModuleBase::getName(void) const // get factory registration name if available std::string ModuleBase::getRegisteredName(void) { - HADRON_ERROR("module '" + getName() + "' has a type not registered" + HADRON_ERROR(Definition, "module '" + getName() + "' has no registered type" + " in the factory"); } diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index a298c1a1..90922c27 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -118,7 +118,7 @@ void TWardIdentity::setup(void) Ls_ = env().getObjectLs(par().q); if (Ls_ != env().getObjectLs(par().action)) { - HADRON_ERROR("Ls mismatch between quark action and propagator"); + HADRON_ERROR(Size, "Ls mismatch between quark action and propagator"); } } diff --git a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp index f860c403..4d08841d 100644 --- a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -187,7 +187,7 @@ void TGaugeProp::execute(void) { if (Ls_ != env().getObjectLs(par().source)) { - HADRON_ERROR("Ls mismatch between quark action and source"); + HADRON_ERROR(Size, "Ls mismatch between quark action and source"); } else { diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp index f8714d88..b0f2846f 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -122,7 +122,7 @@ void TTestSeqConserved::setup(void) auto Ls = env().getObjectLs(par().q); if (Ls != env().getObjectLs(par().action)) { - HADRON_ERROR("Ls mismatch between quark action and propagator"); + HADRON_ERROR(Size, "Ls mismatch between quark action and propagator"); } } diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index 7f967f66..0c3eca20 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -115,7 +115,7 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) } else { - HADRON_ERROR("object '" + out + HADRON_ERROR(Definition, "object '" + out + "' is already produced by module '" + module_[env().getObjectModule(out)].name + "' (while pushing module '" + name + "')"); @@ -144,7 +144,7 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) } else { - HADRON_ERROR("module '" + name + "' already exists"); + HADRON_ERROR(Definition, "module '" + name + "' already exists"); } } @@ -171,7 +171,7 @@ ModuleBase * VirtualMachine::getModule(const unsigned int address) const } else { - HADRON_ERROR("no module with address " + std::to_string(address)); + HADRON_ERROR(Definition, "no module with address " + std::to_string(address)); } } @@ -188,7 +188,7 @@ unsigned int VirtualMachine::getModuleAddress(const std::string name) const } else { - HADRON_ERROR("no module with name '" + name + "'"); + HADRON_ERROR(Definition, "no module with name '" + name + "'"); } } @@ -200,7 +200,7 @@ std::string VirtualMachine::getModuleName(const unsigned int address) const } else { - HADRON_ERROR("no module with address " + std::to_string(address)); + HADRON_ERROR(Definition, "no module with address " + std::to_string(address)); } } @@ -212,7 +212,7 @@ std::string VirtualMachine::getModuleType(const unsigned int address) const } else { - HADRON_ERROR("no module with address " + std::to_string(address)); + HADRON_ERROR(Definition, "no module with address " + std::to_string(address)); } } @@ -273,7 +273,7 @@ Graph VirtualMachine::makeModuleGraph(void) const // { // if (o.module < 0) // { -// HADRON_ERROR("object '" + o.name + "' does not have a creator"); +// HADRON_ERROR(Runtime, "object '" + o.name + "' does not have a creator"); // } // } // } diff --git a/extras/Hadrons/VirtualMachine.hpp b/extras/Hadrons/VirtualMachine.hpp index 357fdb5b..c5557add 100644 --- a/extras/Hadrons/VirtualMachine.hpp +++ b/extras/Hadrons/VirtualMachine.hpp @@ -147,7 +147,7 @@ M * VirtualMachine::getModule(const unsigned int address) const } else { - HADRON_ERROR("module '" + module_[address].name + HADRON_ERROR(Definition, "module '" + module_[address].name + "' does not have type " + typeid(M).name() + "(has type: " + getModuleType(address) + ")"); } From 259d504ef0325879d19d8283a4cd97a4dabd8c1d Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 12 Dec 2017 19:32:58 +0000 Subject: [PATCH 107/174] Hadrons: first full implementation of the module memory profiler --- extras/Hadrons/Application.cc | 5 +- extras/Hadrons/Environment.cc | 13 +- extras/Hadrons/Environment.hpp | 9 +- extras/Hadrons/Global.hpp | 2 +- extras/Hadrons/Module.hpp | 6 +- extras/Hadrons/Modules/MContraction/Meson.hpp | 2 +- extras/Hadrons/VirtualMachine.cc | 120 ++++++++++++++++++ extras/Hadrons/VirtualMachine.hpp | 22 +++- 8 files changed, 166 insertions(+), 13 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index aa66d36f..135e4df4 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -92,9 +92,10 @@ void Application::run(void) { parseParameterFile(parameterFileName_); } - //vm().checkGraph(); - env().printContent(); vm().printContent(); + env().printContent(); + //vm().checkGraph(); + vm().memoryProfile(); if (!scheduled_) { schedule(); diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 403476d0..6de13e86 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -369,6 +369,16 @@ void Environment::freeAll(void) } } +void Environment::protectObjects(const bool protect) +{ + protect_ = protect; +} + +bool Environment::objectsProtected(void) const +{ + return protect_; +} + // print environment content /////////////////////////////////////////////////// void Environment::printContent(void) const { @@ -376,6 +386,7 @@ void Environment::printContent(void) const for (unsigned int i = 0; i < object_.size(); ++i) { LOG(Debug) << std::setw(4) << i << ": " - << getObjectName(i) << std::endl; + << getObjectName(i) << " (" + << sizeString(getObjectSize(i)) << ")" << std::endl; } } diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 60371c20..adea13ce 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -142,11 +142,14 @@ public: void freeObject(const unsigned int address); void freeObject(const std::string name); void freeAll(void); + void protectObjects(const bool protect); + bool objectsProtected(void) const; // print environment content void printContent(void) const; private: // general unsigned long int locVol_; + bool protect_{true}; // grids std::vector dim_; GridPt grid4d_; @@ -195,8 +198,8 @@ void Holder::reset(T *pt) // general memory management /////////////////////////////////////////////////// template void Environment::createDerivedObject(const std::string name, - const Environment::Storage storage, - const unsigned int Ls, + const Environment::Storage storage, + const unsigned int Ls, Ts && ... args) { if (!hasObject(name)) @@ -206,7 +209,7 @@ void Environment::createDerivedObject(const std::string name, unsigned int address = getObjectAddress(name); - if (!object_[address].data) + if (!object_[address].data or !objectsProtected()) { MemoryStats memStats; diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index c3d60bf2..ebfe94dc 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -36,7 +36,7 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #ifndef SITE_SIZE_TYPE -#define SITE_SIZE_TYPE unsigned int +#define SITE_SIZE_TYPE size_t #endif #define BEGIN_HADRONS_NAMESPACE \ diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index c6b58e9f..25c0ac05 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -160,12 +160,12 @@ public: // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name) = 0; virtual void saveParameters(XmlWriter &writer, const std::string name) = 0; - // execution - void operator()(void); -protected: // setup virtual void setup(void) {}; virtual void execute(void) = 0; + // execution + void operator()(void); +protected: // environment shortcut DEFINE_ENV_ALIAS; // virtual machine shortcut diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 7d19feb8..3c179d44 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -134,7 +134,7 @@ std::vector TMeson::getReference(void) template std::vector TMeson::getOutput(void) { - std::vector output = {getName()}; + std::vector output = {}; return output; } diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index 0c3eca20..15e53dbf 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -390,3 +390,123 @@ void VirtualMachine::printContent(void) const << getModuleName(i) << std::endl; } } + +// memory profile ////////////////////////////////////////////////////////////// +VirtualMachine::MemoryProfile VirtualMachine::memoryProfile(void) const +{ + bool protect = env().objectsProtected(); + bool hmsg = HadronsLogMessage.isActive(); + bool gmsg = GridLogMessage.isActive(); + bool err = HadronsLogError.isActive(); + MemoryProfile profile; + auto program = makeModuleGraph().topoSort(); + + profile.module.resize(getNModule()); + env().protectObjects(false); + GridLogMessage.Active(false); + HadronsLogMessage.Active(false); + HadronsLogError.Active(false); + for (auto it = program.rbegin(); it != program.rend(); ++it) + { + auto a = *it; + + if (profile.module[a].empty()) + { + LOG(Debug) << "Profiling memory for module '" << module_[a].name << "' (" << a << ")..." << std::endl; + memoryProfile(profile, a); + env().freeAll(); + } + } + env().protectObjects(protect); + GridLogMessage.Active(gmsg); + HadronsLogMessage.Active(hmsg); + HadronsLogError.Active(err); + LOG(Debug) << "Memory profile:" << std::endl; + LOG(Debug) << "----------------" << std::endl; + for (unsigned int a = 0; a < profile.module.size(); ++a) + { + LOG(Debug) << getModuleName(a) << " (" << a << ")" << std::endl; + for (auto &o: profile.module[a]) + { + LOG(Debug) << "|__ " << env().getObjectName(o.first) << " (" + << sizeString(o.second) << ")" << std::endl; + } + LOG(Debug) << std::endl; + } + LOG(Debug) << "----------------" << std::endl; + + return profile; +} + +void VirtualMachine::resizeProfile(MemoryProfile &profile) const +{ + if (env().getMaxAddress() > profile.object.size()) + { + MemoryPrint empty; + + empty.size = 0; + empty.module = -1; + profile.object.resize(env().getMaxAddress(), empty); + } +} + +void VirtualMachine::updateProfile(MemoryProfile &profile, + const unsigned int address) const +{ + resizeProfile(profile); + for (unsigned int a = 0; a < env().getMaxAddress(); ++a) + { + if (env().hasCreatedObject(a) and (profile.object[a].module == -1)) + { + profile.object[a].size = env().getObjectSize(a); + profile.object[a].module = address; + profile.module[address][a] = profile.object[a].size; + } + } +} + +void VirtualMachine::cleanEnvironment(MemoryProfile &profile) const +{ + resizeProfile(profile); + for (unsigned int a = 0; a < env().getMaxAddress(); ++a) + { + if (env().hasCreatedObject(a) and (profile.object[a].module == -1)) + { + env().freeObject(a); + } + } +} + +void VirtualMachine::memoryProfile(MemoryProfile &profile, + const unsigned int address) const +{ + auto m = getModule(address); + + LOG(Debug) << "Setting up module '" << m->getName() << "' (" << address << ")..." << std::endl; + + try + { + m->setup(); + updateProfile(profile, address); + } + catch (Exceptions::Definition &) + { + cleanEnvironment(profile); + for (auto &in: m->getInput()) + { + memoryProfile(profile, env().getObjectModule(in)); + } + for (auto &ref: m->getReference()) + { + memoryProfile(profile, env().getObjectModule(ref)); + } + m->setup(); + updateProfile(profile, address); + } +} + +void VirtualMachine::memoryProfile(MemoryProfile &profile, + const std::string name) const +{ + memoryProfile(profile, getModuleAddress(name)); +} diff --git a/extras/Hadrons/VirtualMachine.hpp b/extras/Hadrons/VirtualMachine.hpp index c5557add..56e5a8cf 100644 --- a/extras/Hadrons/VirtualMachine.hpp +++ b/extras/Hadrons/VirtualMachine.hpp @@ -51,8 +51,18 @@ class VirtualMachine { SINGLETON_DEFCTOR(VirtualMachine); public: - typedef SITE_SIZE_TYPE Size; - typedef std::unique_ptr ModPt; + typedef SITE_SIZE_TYPE Size; + typedef std::unique_ptr ModPt; + struct MemoryPrint + { + Size size; + unsigned int module; + }; + struct MemoryProfile + { + std::vector> module; + std::vector object; + }; private: struct ModuleInfo { @@ -100,12 +110,20 @@ public: void checkGraph(void) const; // print VM content void printContent(void) const; + // memory profile + MemoryProfile memoryProfile(void) const; // general execution Size executeProgram(const std::vector &p); Size executeProgram(const std::vector &p); private: // environment shortcut DEFINE_ENV_ALIAS; + // memory profile + void resizeProfile(MemoryProfile &profile) const; + void updateProfile(MemoryProfile &profile, const unsigned int address) const; + void cleanEnvironment(MemoryProfile &profile) const; + void memoryProfile(MemoryProfile &profile, const std::string name) const; + void memoryProfile(MemoryProfile &profile, const unsigned int address) const; private: // general bool dryRun_{false}, memoryProfile_{false}; From a9c8d7dad03f1b39acb5e081c3424d03ee035e07 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 13 Dec 2017 12:13:40 +0000 Subject: [PATCH 108/174] Hadrons: code cleaning --- extras/Hadrons/VirtualMachine.cc | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index 15e53dbf..1f4772a6 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -79,21 +79,26 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) unsigned int address; ModuleInfo m; + // module registration ------------------------------------------------- m.data = std::move(pt); m.type = typeIdPt(*m.data.get()); m.name = name; + // input dependencies for (auto &in: m.data->getInput()) { if (!env().hasObject(in)) { + // if object does not exist, add it with no creator module env().addObject(in , -1); } m.input.push_back(env().getObjectAddress(in)); } + // reference dependencies for (auto &ref: m.data->getReference()) { if (!env().hasObject(ref)) { + // if object does not exist, add it with no creator module env().addObject(ref , -1); } m.input.push_back(env().getObjectAddress(ref)); @@ -101,20 +106,24 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) module_.push_back(std::move(m)); address = static_cast(module_.size() - 1); moduleAddress_[name] = address; + // connecting outputs to potential inputs ------------------------------ for (auto &out: getModule(address)->getOutput()) { if (!env().hasObject(out)) { + // output does not exists, add it env().addObject(out, address); } else { if (env().getObjectModule(env().getObjectAddress(out)) < 0) { + // output exists but without creator, correct it env().setObjectModule(env().getObjectAddress(out), address); } else { + // output already fully registered, error HADRON_ERROR(Definition, "object '" + out + "' is already produced by module '" + module_[env().getObjectModule(out)].name @@ -122,10 +131,14 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) } if (getModule(address)->getReference().size() > 0) { + // module has references, dependency should be propagated + // to children modules; find module with `out` as an input + // and add references to their input auto pred = [this, out](const ModuleInfo &n) { auto &in = n.input; - auto it = std::find(in.begin(), in.end(), env().getObjectAddress(out)); + auto it = std::find(in.begin(), in.end(), + env().getObjectAddress(out)); return (it != in.end()); }; @@ -154,7 +167,7 @@ unsigned int VirtualMachine::getNModule(void) const } void VirtualMachine::createModule(const std::string name, const std::string type, - XmlReader &reader) + XmlReader &reader) { auto &factory = ModuleFactory::getInstance(); auto pt = factory.create(type, name); @@ -267,17 +280,6 @@ Graph VirtualMachine::makeModuleGraph(void) const return moduleGraph; } -// void VirtualMachine::checkGraph(void) const -// { -// for (auto &o: object_) -// { -// if (o.module < 0) -// { -// HADRON_ERROR(Runtime, "object '" + o.name + "' does not have a creator"); -// } -// } -// } - // general execution /////////////////////////////////////////////////////////// #define BIG_SEP "===============" #define SEP "---------------" @@ -412,7 +414,8 @@ VirtualMachine::MemoryProfile VirtualMachine::memoryProfile(void) const if (profile.module[a].empty()) { - LOG(Debug) << "Profiling memory for module '" << module_[a].name << "' (" << a << ")..." << std::endl; + LOG(Debug) << "Profiling memory for module '" << module_[a].name + << "' (" << a << ")..." << std::endl; memoryProfile(profile, a); env().freeAll(); } From 61fc50d616674e198b503d177ed86adef0e2260b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 13 Dec 2017 13:44:23 +0000 Subject: [PATCH 109/174] Hadrons: better organisation of the VM --- extras/Hadrons/Application.cc | 23 +- extras/Hadrons/Application.hpp | 2 - extras/Hadrons/Module.cc | 5 +- extras/Hadrons/VirtualMachine.cc | 403 +++++++++++++++--------------- extras/Hadrons/VirtualMachine.hpp | 47 ++-- 5 files changed, 236 insertions(+), 244 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 135e4df4..24618447 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -94,8 +94,6 @@ void Application::run(void) } vm().printContent(); env().printContent(); - //vm().checkGraph(); - vm().memoryProfile(); if (!scheduled_) { schedule(); @@ -185,11 +183,11 @@ GeneticScheduler::ObjFunc memPeak = \ void Application::schedule(void) { - DEFINE_MEMPEAK; + //DEFINE_MEMPEAK; // build module dependency graph LOG(Message) << "Building module graph..." << std::endl; - auto graph = vm().makeModuleGraph(); + auto graph = vm().getModuleGraph(); LOG(Debug) << "Module graph:" << std::endl; LOG(Debug) << graph << std::endl; auto con = graph.getConnectedComponents(); @@ -276,7 +274,7 @@ void Application::saveSchedule(const std::string filename) void Application::loadSchedule(const std::string filename) { - DEFINE_MEMPEAK; + //DEFINE_MEMPEAK; TextReader reader(filename); std::vector program; @@ -290,7 +288,7 @@ void Application::loadSchedule(const std::string filename) program_.push_back(vm().getModuleAddress(name)); } scheduled_ = true; - memPeak_ = memPeak(program_); + //memPeak_ = memPeak(program_); } void Application::printSchedule(void) @@ -323,16 +321,3 @@ void Application::configLoop(void) LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; env().freeAll(); } - -// memory profile ////////////////////////////////////////////////////////////// -void Application::memoryProfile(void) -{ - auto graph = vm().makeModuleGraph(); - auto program = graph.topoSort(); - bool msg; - - msg = HadronsLogMessage.isActive(); - HadronsLogMessage.Active(false); - - HadronsLogMessage.Active(msg); -} diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index 66488206..8d2537d0 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -102,8 +102,6 @@ private: DEFINE_ENV_ALIAS; // virtual machine shortcut DEFINE_VM_ALIAS; - // memory profile - void memoryProfile(void); private: long unsigned int locVol_; std::string parameterFileName_{""}; diff --git a/extras/Hadrons/Module.cc b/extras/Hadrons/Module.cc index 383a5c2e..e5ef0fe4 100644 --- a/extras/Hadrons/Module.cc +++ b/extras/Hadrons/Module.cc @@ -58,8 +58,5 @@ std::string ModuleBase::getRegisteredName(void) void ModuleBase::operator()(void) { setup(); - if (!vm().isDryRun()) - { - execute(); - } + execute(); } diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index 1f4772a6..8667a51c 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -36,27 +36,6 @@ using namespace Hadrons; /****************************************************************************** * VirtualMachine implementation * ******************************************************************************/ -// dry run ///////////////////////////////////////////////////////////////////// -void VirtualMachine::dryRun(const bool isDry) -{ - dryRun_ = isDry; -} - -bool VirtualMachine::isDryRun(void) const -{ - return dryRun_; -} - -void VirtualMachine::memoryProfile(const bool doMemoryProfile) -{ - memoryProfile_ = doMemoryProfile; -} - -bool VirtualMachine::doMemoryProfile(void) const -{ - return memoryProfile_; -} - // trajectory counter ////////////////////////////////////////////////////////// void VirtualMachine::setTrajectory(const unsigned int traj) { @@ -259,40 +238,192 @@ bool VirtualMachine::hasModule(const std::string name) const return (moduleAddress_.find(name) != moduleAddress_.end()); } -Graph VirtualMachine::makeModuleGraph(void) const +// print VM content //////////////////////////////////////////////////////////// +void VirtualMachine::printContent(void) const { - Graph moduleGraph; + LOG(Debug) << "Modules: " << std::endl; + for (unsigned int i = 0; i < module_.size(); ++i) + { + LOG(Debug) << std::setw(4) << i << ": " + << getModuleName(i) << std::endl; + } +} + +// module graph //////////////////////////////////////////////////////////////// +Graph VirtualMachine::getModuleGraph(void) +{ + if (graphOutdated_) + { + makeModuleGraph(); + graphOutdated_ = false; + } + + return graph_; +} + +void VirtualMachine::makeModuleGraph(void) +{ + Graph graph; // create vertices for (unsigned int m = 0; m < module_.size(); ++m) { - moduleGraph.addVertex(m); + graph.addVertex(m); } // create edges for (unsigned int m = 0; m < module_.size(); ++m) { for (auto &in: module_[m].input) { - moduleGraph.addEdge(env().getObjectModule(in), m); + graph.addEdge(env().getObjectModule(in), m); } } - - return moduleGraph; + graph_ = graph; } -// general execution /////////////////////////////////////////////////////////// -#define BIG_SEP "===============" -#define SEP "---------------" -#define MEM_MSG(size) sizeString(size) - -VirtualMachine::Size -VirtualMachine::executeProgram(const std::vector &p) +// memory profile ////////////////////////////////////////////////////////////// +const VirtualMachine::MemoryProfile & VirtualMachine::getMemoryProfile(void) { - Size memPeak = 0, sizeBefore, sizeAfter; - std::vector> freeProg; + if (memoryProfileOutdated_) + { + makeMemoryProfile(); + memoryProfileOutdated_ = false; + } + + return profile_; +} + +void VirtualMachine::makeMemoryProfile(void) +{ + bool protect = env().objectsProtected(); + bool hmsg = HadronsLogMessage.isActive(); + bool gmsg = GridLogMessage.isActive(); + bool err = HadronsLogError.isActive(); + auto program = getModuleGraph().topoSort(); + + resetProfile(); + profile_.module.resize(getNModule()); + env().protectObjects(false); + GridLogMessage.Active(false); + HadronsLogMessage.Active(false); + HadronsLogError.Active(false); + for (auto it = program.rbegin(); it != program.rend(); ++it) + { + auto a = *it; + + if (profile_.module[a].empty()) + { + LOG(Debug) << "Profiling memory for module '" << module_[a].name + << "' (" << a << ")..." << std::endl; + memoryProfile(a); + env().freeAll(); + } + } + env().protectObjects(protect); + GridLogMessage.Active(gmsg); + HadronsLogMessage.Active(hmsg); + HadronsLogError.Active(err); + LOG(Debug) << "Memory profile:" << std::endl; + LOG(Debug) << "----------------" << std::endl; + for (unsigned int a = 0; a < profile_.module.size(); ++a) + { + LOG(Debug) << getModuleName(a) << " (" << a << ")" << std::endl; + for (auto &o: profile_.module[a]) + { + LOG(Debug) << "|__ " << env().getObjectName(o.first) << " (" + << sizeString(o.second) << ")" << std::endl; + } + LOG(Debug) << std::endl; + } + LOG(Debug) << "----------------" << std::endl; +} + +void VirtualMachine::resetProfile(void) +{ + profile_.module.clear(); + profile_.object.clear(); +} + +void VirtualMachine::resizeProfile(void) +{ + if (env().getMaxAddress() > profile_.object.size()) + { + MemoryPrint empty; + + empty.size = 0; + empty.module = -1; + profile_.object.resize(env().getMaxAddress(), empty); + } +} + +void VirtualMachine::updateProfile(const unsigned int address) +{ + resizeProfile(); + for (unsigned int a = 0; a < env().getMaxAddress(); ++a) + { + if (env().hasCreatedObject(a) and (profile_.object[a].module == -1)) + { + profile_.object[a].size = env().getObjectSize(a); + profile_.object[a].module = address; + profile_.module[address][a] = profile_.object[a].size; + if (env().getObjectModule(a) < 0) + { + env().setObjectModule(a, address); + } + } + } +} + +void VirtualMachine::cleanEnvironment(void) +{ + resizeProfile(); + for (unsigned int a = 0; a < env().getMaxAddress(); ++a) + { + if (env().hasCreatedObject(a) and (profile_.object[a].module == -1)) + { + env().freeObject(a); + } + } +} + +void VirtualMachine::memoryProfile(const unsigned int address) +{ + auto m = getModule(address); + + LOG(Debug) << "Setting up module '" << m->getName() + << "' (" << address << ")..." << std::endl; + try + { + m->setup(); + updateProfile(address); + } + catch (Exceptions::Definition &) + { + cleanEnvironment(); + for (auto &in: m->getInput()) + { + memoryProfile(env().getObjectModule(in)); + } + for (auto &ref: m->getReference()) + { + memoryProfile(env().getObjectModule(ref)); + } + m->setup(); + updateProfile(address); + } +} + +void VirtualMachine::memoryProfile(const std::string name) +{ + memoryProfile(getModuleAddress(name)); +} + +// garbage collector /////////////////////////////////////////////////////////// +VirtualMachine::GarbageSchedule +VirtualMachine::makeGarbageSchedule(const std::vector &p) const +{ + GarbageSchedule freeProg; - // build garbage collection schedule - LOG(Debug) << "Building garbage collection schedule..." << std::endl; freeProg.resize(p.size()); for (unsigned int i = 0; i < env().getMaxAddress(); ++i) { @@ -310,34 +441,42 @@ VirtualMachine::executeProgram(const std::vector &p) } } + return freeProg; +} + +// general execution /////////////////////////////////////////////////////////// +#define BIG_SEP "===============" +#define SEP "---------------" +#define MEM_MSG(size) sizeString(size) + +void VirtualMachine::executeProgram(const std::vector &p) const +{ + Size memPeak = 0, sizeBefore, sizeAfter; + GarbageSchedule freeProg; + + // build garbage collection schedule + LOG(Debug) << "Building garbage collection schedule..." << std::endl; + freeProg = makeGarbageSchedule(p); + // program execution LOG(Debug) << "Executing program..." << std::endl; for (unsigned int i = 0; i < p.size(); ++i) { // execute module - if (!isDryRun()) - { - LOG(Message) << SEP << " Measurement step " << i+1 << "/" - << p.size() << " (module '" << module_[p[i]].name - << "') " << SEP << std::endl; - } + LOG(Message) << SEP << " Measurement step " << i + 1 << "/" + << p.size() << " (module '" << module_[p[i]].name + << "') " << SEP << std::endl; (*module_[p[i]].data)(); sizeBefore = env().getTotalSize(); // print used memory after execution - if (!isDryRun()) - { - LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) - << std::endl; - } + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) + << std::endl; if (sizeBefore > memPeak) { memPeak = sizeBefore; } // garbage collection for step i - if (!isDryRun()) - { - LOG(Message) << "Garbage collection..." << std::endl; - } + LOG(Message) << "Garbage collection..." << std::endl; for (auto &j: freeProg[i]) { env().freeObject(j); @@ -352,25 +491,20 @@ VirtualMachine::executeProgram(const std::vector &p) } } // print used memory after garbage collection if necessary - if (!isDryRun()) + sizeAfter = env().getTotalSize(); + if (sizeBefore != sizeAfter) { - sizeAfter = env().getTotalSize(); - if (sizeBefore != sizeAfter) - { - LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) - << std::endl; - } - else - { - LOG(Message) << "Nothing to free" << std::endl; - } + LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter) + << std::endl; + } + else + { + LOG(Message) << "Nothing to free" << std::endl; } } - - return memPeak; } -VirtualMachine::Size VirtualMachine::executeProgram(const std::vector &p) +void VirtualMachine::executeProgram(const std::vector &p) const { std::vector pAddress; @@ -378,138 +512,5 @@ VirtualMachine::Size VirtualMachine::executeProgram(const std::vector profile.object.size()) - { - MemoryPrint empty; - - empty.size = 0; - empty.module = -1; - profile.object.resize(env().getMaxAddress(), empty); - } -} - -void VirtualMachine::updateProfile(MemoryProfile &profile, - const unsigned int address) const -{ - resizeProfile(profile); - for (unsigned int a = 0; a < env().getMaxAddress(); ++a) - { - if (env().hasCreatedObject(a) and (profile.object[a].module == -1)) - { - profile.object[a].size = env().getObjectSize(a); - profile.object[a].module = address; - profile.module[address][a] = profile.object[a].size; - } - } -} - -void VirtualMachine::cleanEnvironment(MemoryProfile &profile) const -{ - resizeProfile(profile); - for (unsigned int a = 0; a < env().getMaxAddress(); ++a) - { - if (env().hasCreatedObject(a) and (profile.object[a].module == -1)) - { - env().freeObject(a); - } - } -} - -void VirtualMachine::memoryProfile(MemoryProfile &profile, - const unsigned int address) const -{ - auto m = getModule(address); - - LOG(Debug) << "Setting up module '" << m->getName() << "' (" << address << ")..." << std::endl; - - try - { - m->setup(); - updateProfile(profile, address); - } - catch (Exceptions::Definition &) - { - cleanEnvironment(profile); - for (auto &in: m->getInput()) - { - memoryProfile(profile, env().getObjectModule(in)); - } - for (auto &ref: m->getReference()) - { - memoryProfile(profile, env().getObjectModule(ref)); - } - m->setup(); - updateProfile(profile, address); - } -} - -void VirtualMachine::memoryProfile(MemoryProfile &profile, - const std::string name) const -{ - memoryProfile(profile, getModuleAddress(name)); + executeProgram(pAddress); } diff --git a/extras/Hadrons/VirtualMachine.hpp b/extras/Hadrons/VirtualMachine.hpp index 56e5a8cf..88e70b55 100644 --- a/extras/Hadrons/VirtualMachine.hpp +++ b/extras/Hadrons/VirtualMachine.hpp @@ -51,8 +51,9 @@ class VirtualMachine { SINGLETON_DEFCTOR(VirtualMachine); public: - typedef SITE_SIZE_TYPE Size; - typedef std::unique_ptr ModPt; + typedef SITE_SIZE_TYPE Size; + typedef std::unique_ptr ModPt; + typedef std::vector> GarbageSchedule; struct MemoryPrint { Size size; @@ -73,11 +74,6 @@ private: size_t maxAllocated; }; public: - // dry run - void dryRun(const bool isDry); - bool isDryRun(void) const; - void memoryProfile(const bool doMemoryProfile); - bool doMemoryProfile(void) const; // trajectory counter void setTrajectory(const unsigned int traj); unsigned int getTrajectory(void) const; @@ -106,32 +102,47 @@ public: std::string getModuleNamespace(const std::string name) const; bool hasModule(const unsigned int address) const; bool hasModule(const std::string name) const; - Graph makeModuleGraph(void) const; - void checkGraph(void) const; // print VM content void printContent(void) const; + // module graph (could be a const reference if topoSort was const) + Graph getModuleGraph(void); // memory profile - MemoryProfile memoryProfile(void) const; + const MemoryProfile &getMemoryProfile(void); + // garbage collector + GarbageSchedule makeGarbageSchedule(const std::vector &p) const; + // high-water memory function + Size memoryNeeded(const std::vector &p, + const GarbageSchedule &g); + Size memoryNeeded(const std::vector &p); // general execution - Size executeProgram(const std::vector &p); - Size executeProgram(const std::vector &p); + void executeProgram(const std::vector &p) const; + void executeProgram(const std::vector &p) const; private: // environment shortcut DEFINE_ENV_ALIAS; + // module graph + void makeModuleGraph(void); // memory profile - void resizeProfile(MemoryProfile &profile) const; - void updateProfile(MemoryProfile &profile, const unsigned int address) const; - void cleanEnvironment(MemoryProfile &profile) const; - void memoryProfile(MemoryProfile &profile, const std::string name) const; - void memoryProfile(MemoryProfile &profile, const unsigned int address) const; + void makeMemoryProfile(void); + void resetProfile(void); + void resizeProfile(void); + void updateProfile(const unsigned int address); + void cleanEnvironment(void); + void memoryProfile(const std::string name); + void memoryProfile(const unsigned int address); private: // general - bool dryRun_{false}, memoryProfile_{false}; unsigned int traj_; // module and related maps std::vector module_; std::map moduleAddress_; std::string currentModule_{""}; + // module graph + bool graphOutdated_{true}; + Graph graph_; + // memory profile + bool memoryProfileOutdated_{true}; + MemoryProfile profile_; }; /****************************************************************************** From 0887566134b7cd7b1a4fb3af69180c0dd9dbed91 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 13 Dec 2017 16:36:15 +0000 Subject: [PATCH 110/174] Hadrons: scheduler back! --- extras/Hadrons/Application.cc | 110 +++-------------------- extras/Hadrons/Application.hpp | 31 +++---- extras/Hadrons/GeneticScheduler.hpp | 66 +++++++------- extras/Hadrons/VirtualMachine.cc | 134 +++++++++++++++++++++++----- extras/Hadrons/VirtualMachine.hpp | 34 ++++--- 5 files changed, 189 insertions(+), 186 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 24618447..9a3366d4 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -94,10 +94,7 @@ void Application::run(void) } vm().printContent(); env().printContent(); - if (!scheduled_) - { - schedule(); - } + schedule(); printSchedule(); configLoop(); } @@ -122,11 +119,13 @@ void Application::parseParameterFile(const std::string parameterFileName) setPar(par); if (!push(reader, "modules")) { - HADRON_ERROR(Parsing, "Cannot open node 'modules' in parameter file '" + parameterFileName + "'"); + HADRON_ERROR(Parsing, "Cannot open node 'modules' in parameter file '" + + parameterFileName + "'"); } if (!push(reader, "module")) { - HADRON_ERROR(Parsing, "Cannot open node 'modules/module' in parameter file '" + parameterFileName + "'"); + HADRON_ERROR(Parsing, "Cannot open node 'modules/module' in parameter file '" + + parameterFileName + "'"); } do { @@ -160,98 +159,13 @@ void Application::saveParameterFile(const std::string parameterFileName) } // schedule computation //////////////////////////////////////////////////////// -#define MEM_MSG(size)\ -sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" - -#define DEFINE_MEMPEAK \ -GeneticScheduler::ObjFunc memPeak = \ -[this](const std::vector &program)\ -{\ - unsigned int memPeak;\ - bool msg;\ - \ - msg = HadronsLogMessage.isActive();\ - HadronsLogMessage.Active(false);\ - vm().dryRun(true);\ - memPeak = vm().executeProgram(program);\ - vm().dryRun(false);\ - env().freeAll();\ - HadronsLogMessage.Active(msg);\ - \ - return memPeak;\ -} - void Application::schedule(void) { - //DEFINE_MEMPEAK; - - // build module dependency graph - LOG(Message) << "Building module graph..." << std::endl; - auto graph = vm().getModuleGraph(); - LOG(Debug) << "Module graph:" << std::endl; - LOG(Debug) << graph << std::endl; - auto con = graph.getConnectedComponents(); - - // constrained topological sort using a genetic algorithm - // LOG(Message) << "Scheduling computation..." << std::endl; - // LOG(Message) << " #module= " << graph.size() << std::endl; - // LOG(Message) << " population size= " << par_.genetic.popSize << std::endl; - // LOG(Message) << " max. generation= " << par_.genetic.maxGen << std::endl; - // LOG(Message) << " max. cst. generation= " << par_.genetic.maxCstGen << std::endl; - // LOG(Message) << " mutation rate= " << par_.genetic.mutationRate << std::endl; - - // unsigned int k = 0, gen, prevPeak, nCstPeak = 0; - // std::random_device rd; - // GeneticScheduler::Parameters par; - - // par.popSize = par_.genetic.popSize; - // par.mutationRate = par_.genetic.mutationRate; - // par.seed = rd(); - // memPeak_ = 0; - // CartesianCommunicator::BroadcastWorld(0, &(par.seed), sizeof(par.seed)); - for (unsigned int i = 0; i < con.size(); ++i) + if (!scheduled_ and !loadedSchedule_) { - // GeneticScheduler scheduler(con[i], memPeak, par); - - // gen = 0; - // do - // { - // LOG(Debug) << "Generation " << gen << ":" << std::endl; - // scheduler.nextGeneration(); - // if (gen != 0) - // { - // if (prevPeak == scheduler.getMinValue()) - // { - // nCstPeak++; - // } - // else - // { - // nCstPeak = 0; - // } - // } - - // prevPeak = scheduler.getMinValue(); - // if (gen % 10 == 0) - // { - // LOG(Iterative) << "Generation " << gen << ": " - // << MEM_MSG(scheduler.getMinValue()) << std::endl; - // } - - // gen++; - // } while ((gen < par_.genetic.maxGen) - // and (nCstPeak < par_.genetic.maxCstGen)); - // auto &t = scheduler.getMinSchedule(); - // if (scheduler.getMinValue() > memPeak_) - // { - // memPeak_ = scheduler.getMinValue(); - // } - auto t = con[i].topoSort(); - for (unsigned int j = 0; j < t.size(); ++j) - { - program_.push_back(t[j]); - } + program_ = vm().schedule(par_.genetic); + scheduled_ = true; } - scheduled_ = true; } void Application::saveSchedule(const std::string filename) @@ -274,8 +188,6 @@ void Application::saveSchedule(const std::string filename) void Application::loadSchedule(const std::string filename) { - //DEFINE_MEMPEAK; - TextReader reader(filename); std::vector program; @@ -287,8 +199,7 @@ void Application::loadSchedule(const std::string filename) { program_.push_back(vm().getModuleAddress(name)); } - scheduled_ = true; - //memPeak_ = memPeak(program_); + loadedSchedule_ = true; } void Application::printSchedule(void) @@ -297,7 +208,8 @@ void Application::printSchedule(void) { HADRON_ERROR(Definition, "Computation not scheduled"); } - LOG(Message) << "Schedule (memory peak: " << MEM_MSG(memPeak_) << "):" + auto peak = vm().memoryNeeded(program_); + LOG(Message) << "Schedule (memory needed: " << sizeString(peak) << "):" << std::endl; for (unsigned int i = 0; i < program_.size(); ++i) { diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index 8d2537d0..4b2ce77b 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -50,25 +50,13 @@ public: unsigned int, end, unsigned int, step); }; - class GeneticPar: Serializable - { - public: - GeneticPar(void): - popSize{20}, maxGen{1000}, maxCstGen{100}, mutationRate{.1} {}; - public: - GRID_SERIALIZABLE_CLASS_MEMBERS(GeneticPar, - unsigned int, popSize, - unsigned int, maxGen, - unsigned int, maxCstGen, - double , mutationRate); - }; class GlobalPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar, - TrajRange, trajCounter, - GeneticPar, genetic, - std::string, seed); + TrajRange, trajCounter, + VirtualMachine::GeneticPar, genetic, + std::string, seed); }; public: // constructors @@ -103,12 +91,11 @@ private: // virtual machine shortcut DEFINE_VM_ALIAS; private: - long unsigned int locVol_; - std::string parameterFileName_{""}; - GlobalPar par_; - std::vector program_; - Environment::Size memPeak_; - bool scheduled_{false}; + long unsigned int locVol_; + std::string parameterFileName_{""}; + GlobalPar par_; + VirtualMachine::Program program_; + bool scheduled_{false}, loadedSchedule_{false}; }; /****************************************************************************** @@ -119,6 +106,7 @@ template void Application::createModule(const std::string name) { vm().createModule(name); + scheduled_ = false; } template @@ -126,6 +114,7 @@ void Application::createModule(const std::string name, const typename M::Par &par) { vm().createModule(name, par); + scheduled_ = false; } END_HADRONS_NAMESPACE diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index 3b0195e7..f199f1ed 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -38,13 +38,13 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Scheduler based on a genetic algorithm * ******************************************************************************/ -template +template class GeneticScheduler { public: - typedef std::vector Gene; - typedef std::pair GenePair; - typedef std::function ObjFunc; + typedef std::vector Gene; + typedef std::pair GenePair; + typedef std::function ObjFunc; struct Parameters { double mutationRate; @@ -65,7 +65,7 @@ public: void benchmarkCrossover(const unsigned int nIt); // print population friend std::ostream & operator<<(std::ostream &out, - const GeneticScheduler &s) + const GeneticScheduler &s) { out << "["; for (auto &p: s.population_) @@ -87,19 +87,19 @@ private: void mutation(Gene &m, const Gene &c); private: - Graph &graph_; - const ObjFunc &func_; - const Parameters par_; - std::multimap population_; - std::mt19937 gen_; + Graph &graph_; + const ObjFunc &func_; + const Parameters par_; + std::multimap population_; + std::mt19937 gen_; }; /****************************************************************************** * template implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -template -GeneticScheduler::GeneticScheduler(Graph &graph, const ObjFunc &func, +template +GeneticScheduler::GeneticScheduler(Graph &graph, const ObjFunc &func, const Parameters &par) : graph_(graph) , func_(func) @@ -109,22 +109,22 @@ GeneticScheduler::GeneticScheduler(Graph &graph, const ObjFunc &func, } // access ////////////////////////////////////////////////////////////////////// -template -const typename GeneticScheduler::Gene & -GeneticScheduler::getMinSchedule(void) +template +const typename GeneticScheduler::Gene & +GeneticScheduler::getMinSchedule(void) { return population_.begin()->second; } -template -int GeneticScheduler::getMinValue(void) +template +int GeneticScheduler::getMinValue(void) { return population_.begin()->first; } // breed a new generation ////////////////////////////////////////////////////// -template -void GeneticScheduler::nextGeneration(void) +template +void GeneticScheduler::nextGeneration(void) { // random initialization of the population if necessary if (population_.size() != par_.popSize) @@ -158,8 +158,8 @@ void GeneticScheduler::nextGeneration(void) } // evolution steps ///////////////////////////////////////////////////////////// -template -void GeneticScheduler::initPopulation(void) +template +void GeneticScheduler::initPopulation(void) { population_.clear(); for (unsigned int i = 0; i < par_.popSize; ++i) @@ -170,8 +170,8 @@ void GeneticScheduler::initPopulation(void) } } -template -void GeneticScheduler::doCrossover(void) +template +void GeneticScheduler::doCrossover(void) { auto p = selectPair(); Gene &p1 = *(p.first), &p2 = *(p.second); @@ -185,8 +185,8 @@ void GeneticScheduler::doCrossover(void) } } -template -void GeneticScheduler::doMutation(void) +template +void GeneticScheduler::doMutation(void) { std::uniform_real_distribution mdis(0., 1.); std::uniform_int_distribution pdis(0, population_.size() - 1); @@ -206,8 +206,8 @@ void GeneticScheduler::doMutation(void) } // genetic operators /////////////////////////////////////////////////////////// -template -typename GeneticScheduler::GenePair GeneticScheduler::selectPair(void) +template +typename GeneticScheduler::GenePair GeneticScheduler::selectPair(void) { std::vector prob; unsigned int ind; @@ -233,8 +233,8 @@ typename GeneticScheduler::GenePair GeneticScheduler::selectPair(void) return std::make_pair(p1, p2); } -template -void GeneticScheduler::crossover(Gene &c1, Gene &c2, const Gene &p1, +template +void GeneticScheduler::crossover(Gene &c1, Gene &c2, const Gene &p1, const Gene &p2) { Gene buf; @@ -268,8 +268,8 @@ void GeneticScheduler::crossover(Gene &c1, Gene &c2, const Gene &p1, } } -template -void GeneticScheduler::mutation(Gene &m, const Gene &c) +template +void GeneticScheduler::mutation(Gene &m, const Gene &c) { Gene buf; std::uniform_int_distribution dis(0, c.size() - 1); @@ -298,8 +298,8 @@ void GeneticScheduler::mutation(Gene &m, const Gene &c) } } -template -void GeneticScheduler::benchmarkCrossover(const unsigned int nIt) +template +void GeneticScheduler::benchmarkCrossover(const unsigned int nIt) { Gene p1, p2, c1, c2; double neg = 0., eq = 0., pos = 0., total; diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index 8667a51c..8a6bd149 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -27,6 +27,7 @@ See the full license in the file "LICENSE" in the top level distribution directo /* END LEGAL */ #include +#include #include using namespace Grid; @@ -133,6 +134,8 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) } } } + graphOutdated_ = true; + memoryProfileOutdated_ = true; } else { @@ -364,6 +367,7 @@ void VirtualMachine::updateProfile(const unsigned int address) if (env().hasCreatedObject(a) and (profile_.object[a].module == -1)) { profile_.object[a].size = env().getObjectSize(a); + profile_.object[a].storage = env().getObjectStorage(a); profile_.object[a].module = address; profile_.module[address][a] = profile_.object[a].size; if (env().getObjectModule(a) < 0) @@ -419,37 +423,130 @@ void VirtualMachine::memoryProfile(const std::string name) } // garbage collector /////////////////////////////////////////////////////////// -VirtualMachine::GarbageSchedule -VirtualMachine::makeGarbageSchedule(const std::vector &p) const +VirtualMachine::GarbageSchedule +VirtualMachine::makeGarbageSchedule(const Program &p) const { GarbageSchedule freeProg; freeProg.resize(p.size()); - for (unsigned int i = 0; i < env().getMaxAddress(); ++i) + for (unsigned int a = 0; a < env().getMaxAddress(); ++a) { - auto pred = [i, this](const unsigned int j) + if (env().getObjectStorage(a) == Environment::Storage::temporary) { - auto &in = module_[j].input; - auto it = std::find(in.begin(), in.end(), i); - - return (it != in.end()) or (j == env().getObjectModule(i)); - }; - auto it = std::find_if(p.rbegin(), p.rend(), pred); - if (it != p.rend()) + auto it = std::find(p.begin(), p.end(), env().getObjectModule(a)); + + if (it != p.end()) + { + freeProg[std::distance(p.begin(), it)].insert(a); + } + } + else if (env().getObjectStorage(a) == Environment::Storage::object) { - freeProg[std::distance(it, p.rend()) - 1].insert(i); + auto pred = [a, this](const unsigned int b) + { + auto &in = module_[b].input; + auto it = std::find(in.begin(), in.end(), a); + + return (it != in.end()) or (b == env().getObjectModule(a)); + }; + auto it = std::find_if(p.rbegin(), p.rend(), pred); + if (it != p.rend()) + { + freeProg[std::distance(it, p.rend()) - 1].insert(a); + } } } return freeProg; } +// high-water memory function ////////////////////////////////////////////////// +VirtualMachine::Size VirtualMachine::memoryNeeded(const Program &p) +{ + const MemoryProfile &profile = getMemoryProfile(); + GarbageSchedule freep = makeGarbageSchedule(p); + Size current = 0, max = 0; + + for (unsigned int i = 0; i < p.size(); ++i) + { + for (auto &o: profile.module[p[i]]) + { + current += o.second; + } + max = std::max(current, max); + for (auto &o: freep[i]) + { + current -= profile.object[o].size; + } + } + + return max; +} + +// genetic scheduler /////////////////////////////////////////////////////////// +VirtualMachine::Program VirtualMachine::schedule(const GeneticPar &par) +{ + typedef GeneticScheduler Scheduler; + + auto graph = getModuleGraph(); + + //constrained topological sort using a genetic algorithm + LOG(Message) << "Scheduling computation..." << std::endl; + LOG(Message) << " #module= " << graph.size() << std::endl; + LOG(Message) << " population size= " << par.popSize << std::endl; + LOG(Message) << " max. generation= " << par.maxGen << std::endl; + LOG(Message) << " max. cst. generation= " << par.maxCstGen << std::endl; + LOG(Message) << " mutation rate= " << par.mutationRate << std::endl; + + unsigned int k = 0, gen, prevPeak, nCstPeak = 0; + std::random_device rd; + Scheduler::Parameters gpar; + + gpar.popSize = par.popSize; + gpar.mutationRate = par.mutationRate; + gpar.seed = rd(); + CartesianCommunicator::BroadcastWorld(0, &(gpar.seed), sizeof(gpar.seed)); + Scheduler::ObjFunc memPeak = [this](const Program &p)->Size + { + return memoryNeeded(p); + }; + Scheduler scheduler(graph, memPeak, gpar); + gen = 0; + do + { + LOG(Debug) << "Generation " << gen << ":" << std::endl; + scheduler.nextGeneration(); + if (gen != 0) + { + if (prevPeak == scheduler.getMinValue()) + { + nCstPeak++; + } + else + { + nCstPeak = 0; + } + } + + prevPeak = scheduler.getMinValue(); + if (gen % 10 == 0) + { + LOG(Iterative) << "Generation " << gen << ": " + << sizeString(scheduler.getMinValue()) << std::endl; + } + + gen++; + } while ((gen < par.maxGen) and (nCstPeak < par.maxCstGen)); + + return scheduler.getMinSchedule(); +} + // general execution /////////////////////////////////////////////////////////// #define BIG_SEP "===============" #define SEP "---------------" #define MEM_MSG(size) sizeString(size) -void VirtualMachine::executeProgram(const std::vector &p) const +void VirtualMachine::executeProgram(const Program &p) const { Size memPeak = 0, sizeBefore, sizeAfter; GarbageSchedule freeProg; @@ -481,15 +578,6 @@ void VirtualMachine::executeProgram(const std::vector &p) const { env().freeObject(j); } - // free temporaries - for (unsigned int i = 0; i < env().getMaxAddress(); ++i) - { - if ((env().getObjectStorage(i) == Environment::Storage::temporary) - and env().hasCreatedObject(i)) - { - env().freeObject(i); - } - } // print used memory after garbage collection if necessary sizeAfter = env().getTotalSize(); if (sizeBefore != sizeAfter) @@ -506,7 +594,7 @@ void VirtualMachine::executeProgram(const std::vector &p) const void VirtualMachine::executeProgram(const std::vector &p) const { - std::vector pAddress; + Program pAddress; for (auto &n: p) { diff --git a/extras/Hadrons/VirtualMachine.hpp b/extras/Hadrons/VirtualMachine.hpp index 88e70b55..a411c108 100644 --- a/extras/Hadrons/VirtualMachine.hpp +++ b/extras/Hadrons/VirtualMachine.hpp @@ -51,19 +51,33 @@ class VirtualMachine { SINGLETON_DEFCTOR(VirtualMachine); public: - typedef SITE_SIZE_TYPE Size; - typedef std::unique_ptr ModPt; - typedef std::vector> GarbageSchedule; + typedef SITE_SIZE_TYPE Size; + typedef std::unique_ptr ModPt; + typedef std::vector> GarbageSchedule; + typedef std::vector Program; struct MemoryPrint { - Size size; - unsigned int module; + Size size; + Environment::Storage storage; + unsigned int module; }; struct MemoryProfile { std::vector> module; std::vector object; }; + class GeneticPar: Serializable + { + public: + GeneticPar(void): + popSize{20}, maxGen{1000}, maxCstGen{100}, mutationRate{.1} {}; + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(GeneticPar, + unsigned int, popSize, + unsigned int, maxGen, + unsigned int, maxCstGen, + double , mutationRate); + }; private: struct ModuleInfo { @@ -109,13 +123,13 @@ public: // memory profile const MemoryProfile &getMemoryProfile(void); // garbage collector - GarbageSchedule makeGarbageSchedule(const std::vector &p) const; + GarbageSchedule makeGarbageSchedule(const Program &p) const; // high-water memory function - Size memoryNeeded(const std::vector &p, - const GarbageSchedule &g); - Size memoryNeeded(const std::vector &p); + Size memoryNeeded(const Program &p); + // genetic scheduler + Program schedule(const GeneticPar &par); // general execution - void executeProgram(const std::vector &p) const; + void executeProgram(const Program &p) const; void executeProgram(const std::vector &p) const; private: // environment shortcut From 842754bea9f8c4ba42c9295854342c6857f061bf Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 13 Dec 2017 19:41:41 +0000 Subject: [PATCH 111/174] Hadrons: most modules ported to the new interface, compiles but untested --- extras/Hadrons/Module.hpp | 4 +- extras/Hadrons/Modules.hpp | 38 +++++------ extras/Hadrons/Modules/MAction/DWF.hpp | 11 ++-- extras/Hadrons/Modules/MAction/Wilson.hpp | 1 + .../Hadrons/Modules/MContraction/Baryon.hpp | 32 +++++++--- .../Hadrons/Modules/MContraction/DiscLoop.hpp | 17 +++-- .../Hadrons/Modules/MContraction/Gamma3pt.hpp | 21 +++++-- extras/Hadrons/Modules/MContraction/Meson.hpp | 11 ++-- .../Modules/MContraction/WardIdentity.hpp | 36 ++++++++--- .../Modules/MContraction/WeakHamiltonian.hpp | 1 + .../MContraction/WeakHamiltonianEye.cc | 41 ++++++++---- .../MContraction/WeakHamiltonianNonEye.cc | 44 ++++++++----- .../MContraction/WeakNeutral4ptDisc.cc | 39 ++++++++---- extras/Hadrons/Modules/MFermion/GaugeProp.hpp | 16 ++--- extras/Hadrons/Modules/MGauge/Load.cc | 19 ++++-- extras/Hadrons/Modules/MGauge/Load.hpp | 1 + extras/Hadrons/Modules/MGauge/Random.cc | 16 ++++- extras/Hadrons/Modules/MGauge/Random.hpp | 1 + extras/Hadrons/Modules/MGauge/StochEm.cc | 29 +++++---- extras/Hadrons/Modules/MGauge/StochEm.hpp | 1 + extras/Hadrons/Modules/MGauge/Unit.cc | 1 + extras/Hadrons/Modules/MLoop/NoiseLoop.hpp | 18 ++++-- extras/Hadrons/Modules/MSink/Point.hpp | 13 ++-- extras/Hadrons/Modules/MSink/Smear.hpp | 23 ++++--- extras/Hadrons/Modules/MSource/Point.hpp | 11 ++-- .../Hadrons/Modules/MSource/SeqConserved.hpp | 17 +++-- extras/Hadrons/Modules/MSource/SeqGamma.hpp | 53 +++++++++++----- extras/Hadrons/Modules/MSource/Wall.hpp | 49 ++++++++++----- extras/Hadrons/Modules/MSource/Z2.hpp | 38 ++++++++--- .../Modules/MUtilities/TestSeqConserved.hpp | 44 ++++++++----- .../Modules/MUtilities/TestSeqGamma.hpp | 28 ++++++--- extras/Hadrons/modules.inc | 63 +++++++++---------- tests/hadrons/Test_hadrons.hpp | 40 ++++++------ 33 files changed, 504 insertions(+), 273 deletions(-) diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 25c0ac05..390573d8 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -92,8 +92,8 @@ static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance; #define envGet(type, name)\ *env().template getObject(name) -#define envGetTmp(type, name)\ -*env().template getObject(getName() + "_tmp_" + name) +#define envGetTmp(type, var)\ +type &var = *env().template getObject(getName() + "_tmp_" + #var) #define envHasType(type, name)\ env().template isObjectOfType(name) diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index bb574a14..61a20058 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -30,31 +30,31 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include -// #include -// #include -// #include +#include +#include +#include #include -// #include -// #include -// #include -// #include -// #include +#include +#include +#include +#include +#include #include -// #include -// #include -// #include +#include +#include +#include #include -// #include +#include // #include // #include // #include #include -// #include +#include #include #include -// #include -// #include -// #include -// #include -// #include -// #include +#include +#include +#include +#include +#include +#include diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 91e4ec94..0cb9a4cb 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -119,12 +119,13 @@ void TDWF::setup(void) << std::endl; LOG(Message) << "Fermion boundary conditions: " << par().boundary << std::endl; + env().createGrid(par().Ls); - auto &U = envGet(LatticeGaugeField, par().gauge); - auto &g4 = *env().getGrid(); - auto &grb4 = *env().getRbGrid(); - auto &g5 = *env().getGrid(par().Ls); - auto &grb5 = *env().getRbGrid(par().Ls); + auto &U = envGet(LatticeGaugeField, par().gauge); + auto &g4 = *env().getGrid(); + auto &grb4 = *env().getRbGrid(); + auto &g5 = *env().getGrid(par().Ls); + auto &grb5 = *env().getRbGrid(par().Ls); std::vector boundary = strToVec(par().boundary); typename DomainWallFermion::ImplParams implParams(boundary); envCreateDerived(FMat, DomainWallFermion, getName(), par().Ls, U, g5, diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index 1ca3bf59..a6b3f0d6 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -115,6 +115,7 @@ void TWilson::setup(void) << " using gauge field '" << par().gauge << "'" << std::endl; LOG(Message) << "Fermion boundary conditions: " << par().boundary << std::endl; + auto &U = envGet(LatticeGaugeField, par().gauge); auto &grid = *env().getGrid(); auto &gridRb = *env().getRbGrid(); diff --git a/extras/Hadrons/Modules/MContraction/Baryon.hpp b/extras/Hadrons/Modules/MContraction/Baryon.hpp index da927391..28f6aa51 100644 --- a/extras/Hadrons/Modules/MContraction/Baryon.hpp +++ b/extras/Hadrons/Modules/MContraction/Baryon.hpp @@ -71,8 +71,11 @@ public: virtual ~TBaryon(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: + // setup + virtual void setup(void); // execution virtual void execute(void); }; @@ -97,14 +100,29 @@ std::vector TBaryon::getInput(void) return input; } +template +std::vector TBaryon::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TBaryon::getOutput(void) { - std::vector out = {getName()}; + std::vector out = {}; return out; } +// setup /////////////////////////////////////////////////////////////////////// +template +void TBaryon::setup(void) +{ + envTmpLat(LatticeComplex, "c"); +} + // execution /////////////////////////////////////////////////////////////////// template void TBaryon::execute(void) @@ -113,12 +131,12 @@ void TBaryon::execute(void) << " quarks '" << par().q1 << "', '" << par().q2 << "', and '" << par().q3 << "'" << std::endl; - CorrWriter writer(par().output); - PropagatorField1 &q1 = *env().template getObject(par().q1); - PropagatorField2 &q2 = *env().template getObject(par().q2); - PropagatorField3 &q3 = *env().template getObject(par().q2); - LatticeComplex c(env().getGrid()); - Result result; + CorrWriter writer(par().output); + auto &q1 = envGet(PropagatorField1, par().q1); + auto &q2 = envGet(PropagatorField2, par().q2); + auto &q3 = envGet(PropagatorField3, par().q2); + envGetTmp(LatticeComplex, c); + Result result; // FIXME: do contractions diff --git a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp index f8da3943..c0fbe296 100644 --- a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp +++ b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp @@ -67,6 +67,7 @@ public: virtual ~TDiscLoop(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -95,10 +96,18 @@ std::vector TDiscLoop::getInput(void) return in; } +template +std::vector TDiscLoop::getReference(void) +{ + std::vector out = {}; + + return out; +} + template std::vector TDiscLoop::getOutput(void) { - std::vector out = {getName()}; + std::vector out = {}; return out; } @@ -107,7 +116,7 @@ std::vector TDiscLoop::getOutput(void) template void TDiscLoop::setup(void) { - + envTmpLat(LatticeComplex, "c"); } // execution /////////////////////////////////////////////////////////////////// @@ -119,12 +128,12 @@ void TDiscLoop::execute(void) << " insertion." << std::endl; CorrWriter writer(par().output); - PropagatorField &q_loop = *env().template getObject(par().q_loop); - LatticeComplex c(env().getGrid()); + auto &q_loop = envGet(PropagatorField, par().q_loop); Gamma gamma(par().gamma); std::vector buf; Result result; + envGetTmp(LatticeComplex, c); c = trace(gamma*q_loop); sliceSum(c, buf, Tp); diff --git a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp index a8653186..4a6baf3e 100644 --- a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp +++ b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp @@ -98,6 +98,7 @@ public: virtual ~TGamma3pt(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -126,10 +127,18 @@ std::vector TGamma3pt::getInput(void) return in; } +template +std::vector TGamma3pt::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TGamma3pt::getOutput(void) { - std::vector out = {getName()}; + std::vector out = {}; return out; } @@ -138,7 +147,7 @@ std::vector TGamma3pt::getOutput(void) template void TGamma3pt::setup(void) { - + envTmpLat(LatticeComplex, "c"); } // execution /////////////////////////////////////////////////////////////////// @@ -153,10 +162,9 @@ void TGamma3pt::execute(void) // Initialise variables. q2 and q3 are normal propagators, q1 may be // sink smeared. CorrWriter writer(par().output); - SlicedPropagator1 &q1 = *env().template getObject(par().q1); - PropagatorField2 &q2 = *env().template getObject(par().q2); - PropagatorField3 &q3 = *env().template getObject(par().q3); - LatticeComplex c(env().getGrid()); + auto &q1 = envGet(SlicedPropagator1, par().q1); + auto &q2 = envGet(PropagatorField2, par().q2); + auto &q3 = envGet(PropagatorField2, par().q3); Gamma g5(Gamma::Algebra::Gamma5); Gamma gamma(par().gamma); std::vector buf; @@ -165,6 +173,7 @@ void TGamma3pt::execute(void) // Extract relevant timeslice of sinked propagator q1, then contract & // sum over all spacial positions of gamma insertion. SitePropagator1 q1Snk = q1[par().tSnk]; + envGetTmp(LatticeComplex, c); c = trace(g5*q1Snk*adj(q2)*(g5*gamma)*q3); sliceSum(c, buf, Tp); diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 3c179d44..1fd86d3a 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -161,6 +161,7 @@ void TMeson::parseGammaString(std::vector &gammaList) // Parse individual contractions from input string. gammaList = strToVec(par().gammas); } + envTmpLat(LatticeComplex, "c"); } // execution /////////////////////////////////////////////////////////////////// @@ -192,8 +193,8 @@ void TMeson::execute(void) if (envHasType(SlicedPropagator1, par().q1) and envHasType(SlicedPropagator2, par().q2)) { - SlicedPropagator1 &q1 = envGet(SlicedPropagator1, par().q1); - SlicedPropagator2 &q2 = envGet(SlicedPropagator2, par().q2); + auto &q1 = envGet(SlicedPropagator1, par().q1); + auto &q2 = envGet(SlicedPropagator2, par().q2); LOG(Message) << "(propagator already sinked)" << std::endl; for (unsigned int i = 0; i < result.size(); ++i) @@ -209,10 +210,10 @@ void TMeson::execute(void) } else { - PropagatorField1 &q1 = envGet(PropagatorField1, par().q1); - PropagatorField2 &q2 = envGet(PropagatorField2, par().q2); - LatticeComplex c(env().getGrid()); + auto &q1 = envGet(PropagatorField1, par().q1); + auto &q2 = envGet(PropagatorField2, par().q2); + envGetTmp(LatticeComplex, c); LOG(Message) << "(using sink '" << par().sink << "')" << std::endl; for (unsigned int i = 0; i < result.size(); ++i) { diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index 90922c27..c92c7243 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -73,6 +73,7 @@ public: virtual ~TWardIdentity(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -103,10 +104,18 @@ std::vector TWardIdentity::getInput(void) return in; } +template +std::vector TWardIdentity::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TWardIdentity::getOutput(void) { - std::vector out = {getName()}; + std::vector out = {}; return out; } @@ -120,6 +129,15 @@ void TWardIdentity::setup(void) { HADRON_ERROR(Size, "Ls mismatch between quark action and propagator"); } + envTmpLat(PropagatorField, "tmp"); + envTmpLat(PropagatorField, "vector_WI"); + if (par().test_axial) + { + envTmpLat(PropagatorField, "psi"); + envTmpLat(LatticeComplex, "PP"); + envTmpLat(LatticeComplex, "axial_defect"); + envTmpLat(LatticeComplex, "PJ5q"); + } } // execution /////////////////////////////////////////////////////////////////// @@ -129,12 +147,13 @@ void TWardIdentity::execute(void) LOG(Message) << "Performing Ward Identity checks for quark '" << par().q << "'." << std::endl; - PropagatorField tmp(env().getGrid()), vector_WI(env().getGrid()); - PropagatorField &q = *env().template getObject(par().q); - FMat &act = *(env().template getObject(par().action)); - Gamma g5(Gamma::Algebra::Gamma5); + auto &q = envGet(PropagatorField, par().q); + auto &act = envGet(FMat, par().action); + Gamma g5(Gamma::Algebra::Gamma5); // Compute D_mu V_mu, D here is backward derivative. + envGetTmp(PropagatorField, tmp); + envGetTmp(PropagatorField, vector_WI); vector_WI = zero; for (unsigned int mu = 0; mu < Nd; ++mu) { @@ -149,9 +168,10 @@ void TWardIdentity::execute(void) if (par().test_axial) { - PropagatorField psi(env().getGrid()); - LatticeComplex PP(env().getGrid()), axial_defect(env().getGrid()), - PJ5q(env().getGrid()); + envGetTmp(PropagatorField, psi); + envGetTmp(LatticeComplex, PP); + envGetTmp(LatticeComplex, axial_defect); + envGetTmp(LatticeComplex, PJ5q); std::vector axial_buf; // Compute , D is backwards derivative. diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp index 7df40370..2b53c87a 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp @@ -99,6 +99,7 @@ public:\ virtual ~T##modname(void) = default;\ /* dependency relation */ \ virtual std::vector getInput(void);\ + virtual std::vector getReference(void);\ virtual std::vector getOutput(void);\ public:\ std::vector VA_label = {"V", "A"};\ diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc index 314b080a..7a73a7e3 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc @@ -74,9 +74,16 @@ std::vector TWeakHamiltonianEye::getInput(void) return in; } +std::vector TWeakHamiltonianEye::getReference(void) +{ + std::vector out = {}; + + return out; +} + std::vector TWeakHamiltonianEye::getOutput(void) { - std::vector out = {getName()}; + std::vector out = {}; return out; } @@ -84,7 +91,15 @@ std::vector TWeakHamiltonianEye::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void TWeakHamiltonianEye::setup(void) { + unsigned int ndim = env().getNd(); + envTmpLat(LatticeComplex, "expbuf"); + envTmpLat(PropagatorField, "tmp1"); + envTmpLat(LatticeComplex, "tmp2"); + envTmp(std::vector, "S_body", 1, ndim, PropagatorField(env().getGrid())); + envTmp(std::vector, "S_loop", 1, ndim, PropagatorField(env().getGrid())); + envTmp(std::vector, "E_body", 1, ndim, LatticeComplex(env().getGrid())); + envTmp(std::vector, "E_loop", 1, ndim, LatticeComplex(env().getGrid())); } // execution /////////////////////////////////////////////////////////////////// @@ -96,22 +111,22 @@ void TWeakHamiltonianEye::execute(void) << "'." << std::endl; CorrWriter writer(par().output); - SlicedPropagator &q1 = *env().template getObject(par().q1); - PropagatorField &q2 = *env().template getObject(par().q2); - PropagatorField &q3 = *env().template getObject(par().q3); - PropagatorField &q4 = *env().template getObject(par().q4); - Gamma g5 = Gamma(Gamma::Algebra::Gamma5); - LatticeComplex expbuf(env().getGrid()); + auto &q1 = envGet(SlicedPropagator, par().q1); + auto &q2 = envGet(PropagatorField, par().q2); + auto &q3 = envGet(PropagatorField, par().q3); + auto &q4 = envGet(PropagatorField, par().q4); + Gamma g5 = Gamma(Gamma::Algebra::Gamma5); std::vector corrbuf; std::vector result(n_eye_diag); unsigned int ndim = env().getNd(); - PropagatorField tmp1(env().getGrid()); - LatticeComplex tmp2(env().getGrid()); - std::vector S_body(ndim, tmp1); - std::vector S_loop(ndim, tmp1); - std::vector E_body(ndim, tmp2); - std::vector E_loop(ndim, tmp2); + envGetTmp(LatticeComplex, expbuf); + envGetTmp(PropagatorField, tmp1); + envGetTmp(LatticeComplex, tmp2); + envGetTmp(std::vector, S_body); + envGetTmp(std::vector, S_loop); + envGetTmp(std::vector, E_body); + envGetTmp(std::vector, E_loop); // Get sink timeslice of q1. SitePropagator q1Snk = q1[par().tSnk]; diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc index 2c4df68a..c333713d 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc @@ -74,9 +74,15 @@ std::vector TWeakHamiltonianNonEye::getInput(void) return in; } +std::vector TWeakHamiltonianNonEye::getReference(void) +{ + std::vector out = {}; + + return out; +} std::vector TWeakHamiltonianNonEye::getOutput(void) { - std::vector out = {getName()}; + std::vector out = {}; return out; } @@ -84,7 +90,15 @@ std::vector TWeakHamiltonianNonEye::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void TWeakHamiltonianNonEye::setup(void) { + unsigned int ndim = env().getNd(); + envTmpLat(LatticeComplex, "expbuf"); + envTmpLat(PropagatorField, "tmp1"); + envTmpLat(LatticeComplex, "tmp2"); + envTmp(std::vector, "C_i_side_loop", 1, ndim, PropagatorField(env().getGrid())); + envTmp(std::vector, "C_f_side_loop", 1, ndim, PropagatorField(env().getGrid())); + envTmp(std::vector, "W_i_side_loop", 1, ndim, LatticeComplex(env().getGrid())); + envTmp(std::vector, "W_f_side_loop", 1, ndim, LatticeComplex(env().getGrid())); } // execution /////////////////////////////////////////////////////////////////// @@ -95,23 +109,23 @@ void TWeakHamiltonianNonEye::execute(void) << par().q2 << ", '" << par().q3 << "' and '" << par().q4 << "'." << std::endl; - CorrWriter writer(par().output); - PropagatorField &q1 = *env().template getObject(par().q1); - PropagatorField &q2 = *env().template getObject(par().q2); - PropagatorField &q3 = *env().template getObject(par().q3); - PropagatorField &q4 = *env().template getObject(par().q4); - Gamma g5 = Gamma(Gamma::Algebra::Gamma5); - LatticeComplex expbuf(env().getGrid()); + CorrWriter writer(par().output); + auto &q1 = envGet(PropagatorField, par().q1); + auto &q2 = envGet(PropagatorField, par().q2); + auto &q3 = envGet(PropagatorField, par().q3); + auto &q4 = envGet(PropagatorField, par().q4); + Gamma g5 = Gamma(Gamma::Algebra::Gamma5); std::vector corrbuf; std::vector result(n_noneye_diag); - unsigned int ndim = env().getNd(); + unsigned int ndim = env().getNd(); - PropagatorField tmp1(env().getGrid()); - LatticeComplex tmp2(env().getGrid()); - std::vector C_i_side_loop(ndim, tmp1); - std::vector C_f_side_loop(ndim, tmp1); - std::vector W_i_side_loop(ndim, tmp2); - std::vector W_f_side_loop(ndim, tmp2); + envGetTmp(LatticeComplex, expbuf); + envGetTmp(PropagatorField, tmp1); + envGetTmp(LatticeComplex, tmp2); + envGetTmp(std::vector, C_i_side_loop); + envGetTmp(std::vector, C_f_side_loop); + envGetTmp(std::vector, W_i_side_loop); + envGetTmp(std::vector, W_f_side_loop); // Setup for C-type contractions. for (int mu = 0; mu < ndim; ++mu) diff --git a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc index 6685f292..e0f07f6c 100644 --- a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc +++ b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc @@ -76,9 +76,16 @@ std::vector TWeakNeutral4ptDisc::getInput(void) return in; } +std::vector TWeakNeutral4ptDisc::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + std::vector TWeakNeutral4ptDisc::getOutput(void) { - std::vector out = {getName()}; + std::vector out = {}; return out; } @@ -86,7 +93,13 @@ std::vector TWeakNeutral4ptDisc::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void TWeakNeutral4ptDisc::setup(void) { + unsigned int ndim = env().getNd(); + envTmpLat(LatticeComplex, "expbuf"); + envTmpLat(PropagatorField, "tmp"); + envTmpLat(LatticeComplex, "curr"); + envTmp(std::vector, "meson", 1, ndim, PropagatorField(env().getGrid())); + envTmp(std::vector, "loop", 1, ndim, PropagatorField(env().getGrid())); } // execution /////////////////////////////////////////////////////////////////// @@ -97,21 +110,21 @@ void TWeakNeutral4ptDisc::execute(void) << par().q2 << ", '" << par().q3 << "' and '" << par().q4 << "'." << std::endl; - CorrWriter writer(par().output); - PropagatorField &q1 = *env().template getObject(par().q1); - PropagatorField &q2 = *env().template getObject(par().q2); - PropagatorField &q3 = *env().template getObject(par().q3); - PropagatorField &q4 = *env().template getObject(par().q4); - Gamma g5 = Gamma(Gamma::Algebra::Gamma5); - LatticeComplex expbuf(env().getGrid()); + CorrWriter writer(par().output); + auto &q1 = envGet(PropagatorField, par().q1); + auto &q2 = envGet(PropagatorField, par().q2); + auto &q3 = envGet(PropagatorField, par().q3); + auto &q4 = envGet(PropagatorField, par().q4); + Gamma g5 = Gamma(Gamma::Algebra::Gamma5); std::vector corrbuf; std::vector result(n_neut_disc_diag); - unsigned int ndim = env().getNd(); + unsigned int ndim = env().getNd(); - PropagatorField tmp(env().getGrid()); - std::vector meson(ndim, tmp); - std::vector loop(ndim, tmp); - LatticeComplex curr(env().getGrid()); + envGetTmp(LatticeComplex, expbuf); + envGetTmp(PropagatorField, tmp); + envGetTmp(LatticeComplex, curr); + envGetTmp(std::vector, meson); + envGetTmp(std::vector, loop); // Setup for type 1 contractions. for (int mu = 0; mu < ndim; ++mu) diff --git a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp index 4d08841d..e77df287 100644 --- a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -154,21 +154,21 @@ void TGaugeProp::execute(void) LOG(Message) << "Computing quark propagator '" << getName() << "'" << std::endl; - FermionField &source = envGetTmp(FermionField, "source"); - FermionField &sol = envGetTmp(FermionField, "sol"); - FermionField &tmp = envGetTmp(FermionField, "tmp"); - std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); - PropagatorField &prop = envGet(PropagatorField, propName); - PropagatorField &fullSrc = envGet(PropagatorField, par().source); - SolverFn &solver = envGet(SolverFn, par().solver); + std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); + auto &prop = envGet(PropagatorField, propName); + auto &fullSrc = envGet(PropagatorField, par().source); + auto &solver = envGet(SolverFn, par().solver); + envGetTmp(FermionField, source); + envGetTmp(FermionField, sol); + envGetTmp(FermionField, tmp); LOG(Message) << "Inverting using solver '" << par().solver << "' on source '" << par().source << "'" << std::endl; for (unsigned int s = 0; s < Ns; ++s) for (unsigned int c = 0; c < Nc; ++c) { LOG(Message) << "Inversion for spin= " << s << ", color= " << c - << std::endl; + << std::endl; // source conversion for 4D sources if (!env().isObject5d(par().source)) { diff --git a/extras/Hadrons/Modules/MGauge/Load.cc b/extras/Hadrons/Modules/MGauge/Load.cc index 062e7e98..c2fd49de 100644 --- a/extras/Hadrons/Modules/MGauge/Load.cc +++ b/extras/Hadrons/Modules/MGauge/Load.cc @@ -49,6 +49,13 @@ std::vector TLoad::getInput(void) return in; } +std::vector TLoad::getReference(void) +{ + std::vector ref; + + return ref; +} + std::vector TLoad::getOutput(void) { std::vector out = {getName()}; @@ -59,19 +66,19 @@ std::vector TLoad::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void TLoad::setup(void) { - env().registerLattice(getName()); + envCreateLat(LatticeGaugeField, getName()); } // execution /////////////////////////////////////////////////////////////////// void TLoad::execute(void) { - FieldMetaData header; - std::string fileName = par().file + "." - + std::to_string(env().getTrajectory()); - + FieldMetaData header; + std::string fileName = par().file + "." + + std::to_string(vm().getTrajectory()); LOG(Message) << "Loading NERSC configuration from file '" << fileName << "'" << std::endl; - LatticeGaugeField &U = *env().createLattice(getName()); + + auto &U = envGet(LatticeGaugeField, getName()); NerscIO::readConfiguration(U, header, fileName); LOG(Message) << "NERSC header:" << std::endl; dump_meta_data(header, LOG(Message)); diff --git a/extras/Hadrons/Modules/MGauge/Load.hpp b/extras/Hadrons/Modules/MGauge/Load.hpp index a338af79..a967d714 100644 --- a/extras/Hadrons/Modules/MGauge/Load.hpp +++ b/extras/Hadrons/Modules/MGauge/Load.hpp @@ -57,6 +57,7 @@ public: virtual ~TLoad(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup diff --git a/extras/Hadrons/Modules/MGauge/Random.cc b/extras/Hadrons/Modules/MGauge/Random.cc index c10fdfc3..fdb0d145 100644 --- a/extras/Hadrons/Modules/MGauge/Random.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -44,7 +44,16 @@ TRandom::TRandom(const std::string name) // dependencies/products /////////////////////////////////////////////////////// std::vector TRandom::getInput(void) { - return std::vector(); + std::vector in; + + return in; +} + +std::vector TRandom::getReference(void) +{ + std::vector ref; + + return ref; } std::vector TRandom::getOutput(void) @@ -57,13 +66,14 @@ std::vector TRandom::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void TRandom::setup(void) { - env().registerLattice(getName()); + envCreateLat(LatticeGaugeField, getName()); } // execution /////////////////////////////////////////////////////////////////// void TRandom::execute(void) { LOG(Message) << "Generating random gauge configuration" << std::endl; - LatticeGaugeField &U = *env().createLattice(getName()); + + auto &U = envGet(LatticeGaugeField, getName()); SU3::HotConfiguration(*env().get4dRng(), U); } diff --git a/extras/Hadrons/Modules/MGauge/Random.hpp b/extras/Hadrons/Modules/MGauge/Random.hpp index a07130e4..30525113 100644 --- a/extras/Hadrons/Modules/MGauge/Random.hpp +++ b/extras/Hadrons/Modules/MGauge/Random.hpp @@ -50,6 +50,7 @@ public: virtual ~TRandom(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup diff --git a/extras/Hadrons/Modules/MGauge/StochEm.cc b/extras/Hadrons/Modules/MGauge/StochEm.cc index c7a9fc4f..a878ae2f 100644 --- a/extras/Hadrons/Modules/MGauge/StochEm.cc +++ b/extras/Hadrons/Modules/MGauge/StochEm.cc @@ -47,6 +47,13 @@ std::vector TStochEm::getInput(void) return in; } +std::vector TStochEm::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + std::vector TStochEm::getOutput(void) { std::vector out = {getName()}; @@ -57,32 +64,28 @@ std::vector TStochEm::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void TStochEm::setup(void) { - if (!env().hasRegisteredObject("_" + getName() + "_weight")) + if (!env().hasCreatedObject("_" + getName() + "_weight")) { - env().registerLattice("_" + getName() + "_weight"); + envCacheLat(EmComp, "_" + getName() + "_weight"); } - env().registerLattice(getName()); + envCreateLat(EmField, getName()); } // execution /////////////////////////////////////////////////////////////////// void TStochEm::execute(void) { + LOG(Message) << "Generating stochatic EM potential..." << std::endl; + PhotonR photon(par().gauge, par().zmScheme); - EmField &a = *env().createLattice(getName()); - EmComp *w; + auto &a = envGet(EmField, getName()); + auto &w = envGet(EmComp, "_" + getName() + "_weight"); if (!env().hasCreatedObject("_" + getName() + "_weight")) { LOG(Message) << "Caching stochatic EM potential weight (gauge: " << par().gauge << ", zero-mode scheme: " << par().zmScheme << ")..." << std::endl; - w = env().createLattice("_" + getName() + "_weight"); - photon.StochasticWeight(*w); + photon.StochasticWeight(w); } - else - { - w = env().getObject("_" + getName() + "_weight"); - } - LOG(Message) << "Generating stochatic EM potential..." << std::endl; - photon.StochasticField(a, *env().get4dRng(), *w); + photon.StochasticField(a, *env().get4dRng(), w); } diff --git a/extras/Hadrons/Modules/MGauge/StochEm.hpp b/extras/Hadrons/Modules/MGauge/StochEm.hpp index bacb5172..efc2e39b 100644 --- a/extras/Hadrons/Modules/MGauge/StochEm.hpp +++ b/extras/Hadrons/Modules/MGauge/StochEm.hpp @@ -59,6 +59,7 @@ public: virtual ~TStochEm(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index bc05a785..af31f124 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -71,6 +71,7 @@ void TUnit::setup(void) void TUnit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; + auto &U = envGet(LatticeGaugeField, getName()); SU3::ColdConfiguration(*env().get4dRng(), U); } diff --git a/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp b/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp index 1f40dd48..0feb5efb 100644 --- a/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp +++ b/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp @@ -73,6 +73,7 @@ public: virtual ~TNoiseLoop(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -101,6 +102,15 @@ std::vector TNoiseLoop::getInput(void) return in; } + +template +std::vector TNoiseLoop::getReference(void) +{ + std::vector out = {}; + + return out; +} + template std::vector TNoiseLoop::getOutput(void) { @@ -113,16 +123,16 @@ std::vector TNoiseLoop::getOutput(void) template void TNoiseLoop::setup(void) { - env().template registerLattice(getName()); + envCreateLat(PropagatorField, getName()); } // execution /////////////////////////////////////////////////////////////////// template void TNoiseLoop::execute(void) { - PropagatorField &loop = *env().template createLattice(getName()); - PropagatorField &q = *env().template getObject(par().q); - PropagatorField &eta = *env().template getObject(par().eta); + auto &loop = envGet(PropagatorField, getName()); + auto &q = envGet(PropagatorField, par().q); + auto &eta = envGet(PropagatorField, par().eta); loop = q*adj(eta); } diff --git a/extras/Hadrons/Modules/MSink/Point.hpp b/extras/Hadrons/Modules/MSink/Point.hpp index 16b89434..42cae4f6 100644 --- a/extras/Hadrons/Modules/MSink/Point.hpp +++ b/extras/Hadrons/Modules/MSink/Point.hpp @@ -122,18 +122,19 @@ void TPoint::setup(void) // execution /////////////////////////////////////////////////////////////////// template void TPoint::execute(void) -{ - std::vector p = strToVec(par().mom); - LatticeComplex &ph = envGet(LatticeComplex, momphName_); - Complex i(0.0,1.0); - +{ LOG(Message) << "Setting up point sink function for momentum [" << par().mom << "]" << std::endl; + auto &ph = envGet(LatticeComplex, momphName_); + if (!hasPhase_) { - LatticeComplex &coor = envGetTmp(LatticeComplex, "coor"); + Complex i(0.0,1.0); + std::vector p; + envGetTmp(LatticeComplex, coor); + p = strToVec(par().mom); ph = zero; for(unsigned int mu = 0; mu < env().getNd(); mu++) { diff --git a/extras/Hadrons/Modules/MSink/Smear.hpp b/extras/Hadrons/Modules/MSink/Smear.hpp index b51d2f49..03cc861a 100644 --- a/extras/Hadrons/Modules/MSink/Smear.hpp +++ b/extras/Hadrons/Modules/MSink/Smear.hpp @@ -61,6 +61,7 @@ public: virtual ~TSmear(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -89,6 +90,14 @@ std::vector TSmear::getInput(void) return in; } +template +std::vector TSmear::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TSmear::getOutput(void) { @@ -101,9 +110,7 @@ std::vector TSmear::getOutput(void) template void TSmear::setup(void) { - unsigned int nt = env().getDim(Tp); - unsigned int size = nt * sizeof(SitePropagator); - env().registerObject(getName(), size); + envCreate(SlicedPropagator, getName(), 1, env().getDim(Tp)); } // execution /////////////////////////////////////////////////////////////////// @@ -114,11 +121,11 @@ void TSmear::execute(void) << "' using sink function '" << par().sink << "'." << std::endl; - SinkFn &sink = *env().template getObject(par().sink); - PropagatorField &q = *env().template getObject(par().q); - SlicedPropagator *out = new SlicedPropagator(env().getDim(Tp)); - *out = sink(q); - env().setObject(getName(), out); + auto &sink = envGet(SinkFn, par().sink); + auto &q = envGet(PropagatorField, par().q); + auto &out = envGet(SlicedPropagator, getName()); + + out = sink(q); } END_MODULE_NAMESPACE diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index 3fab41c0..6470c77f 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -128,12 +128,13 @@ void TPoint::setup(void) template void TPoint::execute(void) { - std::vector position = strToVec(par().position); - SitePropagator id; - LOG(Message) << "Creating point source at position [" << par().position - << "]" << std::endl; - PropagatorField &src = envGet(PropagatorField, getName()); + << "]" << std::endl; + + std::vector position = strToVec(par().position); + auto &src = envGet(PropagatorField, getName()); + SitePropagator id; + id = 1.; src = zero; pokeSite(id, src, position); diff --git a/extras/Hadrons/Modules/MSource/SeqConserved.hpp b/extras/Hadrons/Modules/MSource/SeqConserved.hpp index e8f91be1..9ccbee1b 100644 --- a/extras/Hadrons/Modules/MSource/SeqConserved.hpp +++ b/extras/Hadrons/Modules/MSource/SeqConserved.hpp @@ -82,6 +82,7 @@ public: virtual ~TSeqConserved(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -110,6 +111,14 @@ std::vector TSeqConserved::getInput(void) return in; } +template +std::vector TSeqConserved::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TSeqConserved::getOutput(void) { @@ -123,7 +132,7 @@ template void TSeqConserved::setup(void) { auto Ls_ = env().getObjectLs(par().action); - env().template registerLattice(getName(), Ls_); + envCreateLat(PropagatorField, getName(), Ls_); } // execution /////////////////////////////////////////////////////////////////// @@ -143,9 +152,9 @@ void TSeqConserved::execute(void) << par().mu << ") for " << par().tA << " <= t <= " << par().tB << std::endl; } - PropagatorField &src = *env().template createLattice(getName()); - PropagatorField &q = *env().template getObject(par().q); - FMat &mat = *(env().template getObject(par().action)); + auto &src = envGet(PropagatorField, getName()); + auto &q = envGet(PropagatorField, par().q); + auto &mat = envGet(FMat, par().action); std::vector mom = strToVec(par().mom); mat.SeqConservedCurrent(q, src, par().curr_type, par().mu, diff --git a/extras/Hadrons/Modules/MSource/SeqGamma.hpp b/extras/Hadrons/Modules/MSource/SeqGamma.hpp index 8f67f8fa..d2b3c958 100644 --- a/extras/Hadrons/Modules/MSource/SeqGamma.hpp +++ b/extras/Hadrons/Modules/MSource/SeqGamma.hpp @@ -80,12 +80,16 @@ public: virtual ~TSeqGamma(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup virtual void setup(void); // execution virtual void execute(void); +private: + bool hasPhase_{false}; + std::string momphName_, tName_; }; MODULE_REGISTER_NS(SeqGamma, TSeqGamma, MSource); @@ -97,6 +101,8 @@ MODULE_REGISTER_NS(SeqGamma, TSeqGamma, MSource); template TSeqGamma::TSeqGamma(const std::string name) : Module(name) +, momphName_ (name + "_momph") +, tName_ (name + "_t") {} // dependencies/products /////////////////////////////////////////////////////// @@ -108,6 +114,14 @@ std::vector TSeqGamma::getInput(void) return in; } +template +std::vector TSeqGamma::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TSeqGamma::getOutput(void) { @@ -120,7 +134,10 @@ std::vector TSeqGamma::getOutput(void) template void TSeqGamma::setup(void) { - env().template registerLattice(getName()); + envCreateLat(PropagatorField, getName()); + envCacheLat(Lattice>, tName_); + envCacheLat(LatticeComplex, momphName_); + envTmpLat(LatticeComplex, "coor"); } // execution /////////////////////////////////////////////////////////////////// @@ -138,23 +155,29 @@ void TSeqGamma::execute(void) << " sequential source for " << par().tA << " <= t <= " << par().tB << std::endl; } - PropagatorField &src = *env().template createLattice(getName()); - PropagatorField &q = *env().template getObject(par().q); - Lattice> t(env().getGrid()); - LatticeComplex ph(env().getGrid()), coor(env().getGrid()); - Gamma g(par().gamma); - std::vector p; - Complex i(0.0,1.0); + auto &src = envGet(PropagatorField, getName()); + auto &q = envGet(PropagatorField, par().q); + auto &ph = envGet(LatticeComplex, momphName_); + auto &t = envGet(Lattice>, tName_); + Gamma g(par().gamma); - p = strToVec(par().mom); - ph = zero; - for(unsigned int mu = 0; mu < env().getNd(); mu++) + if (!hasPhase_) { - LatticeCoordinate(coor, mu); - ph = ph + p[mu]*coor*((1./(env().getGrid()->_fdimensions[mu]))); + Complex i(0.0,1.0); + std::vector p; + + envGetTmp(LatticeComplex, coor); + p = strToVec(par().mom); + ph = zero; + for(unsigned int mu = 0; mu < env().getNd(); mu++) + { + LatticeCoordinate(coor, mu); + ph = ph + (p[mu]/env().getGrid()->_fdimensions[mu])*coor; + } + ph = exp((Real)(2*M_PI)*i*ph); + LatticeCoordinate(t, Tp); + hasPhase_ = true; } - ph = exp((Real)(2*M_PI)*i*ph); - LatticeCoordinate(t, Tp); src = where((t >= par().tA) and (t <= par().tB), ph*(g*q), 0.*q); } diff --git a/extras/Hadrons/Modules/MSource/Wall.hpp b/extras/Hadrons/Modules/MSource/Wall.hpp index 57dee06d..d9814d9e 100644 --- a/extras/Hadrons/Modules/MSource/Wall.hpp +++ b/extras/Hadrons/Modules/MSource/Wall.hpp @@ -72,12 +72,16 @@ public: virtual ~TWall(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup virtual void setup(void); // execution virtual void execute(void); +private: + bool hasPhase_{false}; + std::string momphName_, tName_; }; MODULE_REGISTER_NS(Wall, TWall, MSource); @@ -89,17 +93,27 @@ MODULE_REGISTER_NS(Wall, TWall, MSource); template TWall::TWall(const std::string name) : Module(name) +, momphName_ (name + "_momph") +, tName_ (name + "_t") {} // dependencies/products /////////////////////////////////////////////////////// template std::vector TWall::getInput(void) { - std::vector in; + std::vector in = {}; return in; } +template +std::vector TWall::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TWall::getOutput(void) { @@ -112,7 +126,7 @@ std::vector TWall::getOutput(void) template void TWall::setup(void) { - env().template registerLattice(getName()); + envCreateLat(PropagatorField, getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -122,21 +136,28 @@ void TWall::execute(void) LOG(Message) << "Generating wall source at t = " << par().tW << " with momentum " << par().mom << std::endl; - PropagatorField &src = *env().template createLattice(getName()); - Lattice> t(env().getGrid()); - LatticeComplex ph(env().getGrid()), coor(env().getGrid()); - std::vector p; - Complex i(0.0,1.0); + auto &src = envGet(PropagatorField, getName()); + auto &ph = envGet(LatticeComplex, momphName_); + auto &t = envGet(Lattice>, tName_); - p = strToVec(par().mom); - ph = zero; - for(unsigned int mu = 0; mu < Nd; mu++) + if (!hasPhase_) { - LatticeCoordinate(coor, mu); - ph = ph + p[mu]*coor*((1./(env().getGrid()->_fdimensions[mu]))); + Complex i(0.0,1.0); + std::vector p; + + envGetTmp(LatticeComplex, coor); + p = strToVec(par().mom); + ph = zero; + for(unsigned int mu = 0; mu < env().getNd(); mu++) + { + LatticeCoordinate(coor, mu); + ph = ph + (p[mu]/env().getGrid()->_fdimensions[mu])*coor; + } + ph = exp((Real)(2*M_PI)*i*ph); + LatticeCoordinate(t, Tp); + hasPhase_ = true; } - ph = exp((Real)(2*M_PI)*i*ph); - LatticeCoordinate(t, Tp); + src = 1.; src = where((t == par().tW), src*ph, 0.*src); } diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index e2cc4f34..2e864ff0 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -75,12 +75,16 @@ public: virtual ~TZ2(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup virtual void setup(void); // execution virtual void execute(void); +private: + bool hasT_{false}; + std::string tName_; }; MODULE_REGISTER_NS(Z2, TZ2, MSource); @@ -93,6 +97,7 @@ MODULE_REGISTER_NS(ScalarZ2, TZ2, MSource); template TZ2::TZ2(const std::string name) : Module(name) +, tName_ (name + "_t") {} // dependencies/products /////////////////////////////////////////////////////// @@ -104,6 +109,14 @@ std::vector TZ2::getInput(void) return in; } +template +std::vector TZ2::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TZ2::getOutput(void) { @@ -116,29 +129,36 @@ std::vector TZ2::getOutput(void) template void TZ2::setup(void) { - env().template registerLattice(getName()); + envCreateLat(PropagatorField, getName()); + envCacheLat(Lattice>, tName_); + envTmpLat(LatticeComplex, "eta"); } // execution /////////////////////////////////////////////////////////////////// template void TZ2::execute(void) { - Lattice> t(env().getGrid()); - LatticeComplex eta(env().getGrid()); - Complex shift(1., 1.); - if (par().tA == par().tB) { LOG(Message) << "Generating Z_2 wall source at t= " << par().tA - << std::endl; + << std::endl; } else { LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= " - << par().tB << std::endl; + << par().tB << std::endl; } - PropagatorField &src = *env().template createLattice(getName()); - LatticeCoordinate(t, Tp); + + auto &src = envGet(PropagatorField, getName()); + auto &t = envGet(Lattice>, getName()); + Complex shift(1., 1.); + + if (!hasT_) + { + LatticeCoordinate(t, Tp); + hasT_ = true; + } + envGetTmp(LatticeComplex, eta); bernoulli(*env().get4dRng(), eta); eta = (2.*eta - shift)*(1./::sqrt(2.)); eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta); diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp index b0f2846f..081d2911 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -79,6 +79,7 @@ public: virtual ~TTestSeqConserved(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -107,6 +108,14 @@ std::vector TTestSeqConserved::getInput(void) return in; } +template +std::vector TTestSeqConserved::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TTestSeqConserved::getOutput(void) { @@ -124,36 +133,37 @@ void TTestSeqConserved::setup(void) { HADRON_ERROR(Size, "Ls mismatch between quark action and propagator"); } + envTmpLat(PropagatorField, "tmp"); + envTmpLat(LatticeComplex, "c"); } // execution /////////////////////////////////////////////////////////////////// template void TTestSeqConserved::execute(void) { - PropagatorField tmp(env().getGrid()); - PropagatorField &q = *env().template getObject(par().q); - PropagatorField &qSeq = *env().template getObject(par().qSeq); - FMat &act = *(env().template getObject(par().action)); - Gamma g5(Gamma::Algebra::Gamma5); - Gamma::Algebra gA = (par().curr == Current::Axial) ? - Gamma::Algebra::Gamma5 : - Gamma::Algebra::Identity; - Gamma g(gA); - SitePropagator qSite; - Complex test_S, test_V, check_S, check_V; - std::vector check_buf; - LatticeComplex c(env().getGrid()); - // Check sequential insertion of current gives same result as conserved // current sink upon contraction. Assume q uses a point source. - std::vector siteCoord; + + auto &q = envGet(PropagatorField, par().q); + auto &qSeq = envGet(PropagatorField, par().qSeq); + auto &act = envGet(FMat, par().action); + Gamma g5(Gamma::Algebra::Gamma5); + Gamma::Algebra gA = (par().curr == Current::Axial) ? + Gamma::Algebra::Gamma5 : + Gamma::Algebra::Identity; + Gamma g(gA); + SitePropagator qSite; + Complex test_S, test_V, check_S, check_V; + std::vector check_buf; + std::vector siteCoord; + + envGetTmp(PropagatorField, tmp); + envGetTmp(LatticeComplex, c); siteCoord = strToVec(par().origin); peekSite(qSite, qSeq, siteCoord); test_S = trace(qSite*g); test_V = trace(qSite*g*Gamma::gmu[par().mu]); - act.ContractConservedCurrent(q, q, tmp, par().curr, par().mu); - c = trace(tmp*g); sliceSum(c, check_buf, Tp); check_S = TensorRemove(check_buf[par().t_J]); diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp index 9736ab54..30bd4b69 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp @@ -63,6 +63,7 @@ public: virtual ~TTestSeqGamma(void) = default; // dependency relation virtual std::vector getInput(void); + virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -91,6 +92,14 @@ std::vector TTestSeqGamma::getInput(void) return in; } +template +std::vector TTestSeqGamma::getReference(void) +{ + std::vector ref = {}; + + return ref; +} + template std::vector TTestSeqGamma::getOutput(void) { @@ -103,26 +112,27 @@ std::vector TTestSeqGamma::getOutput(void) template void TTestSeqGamma::setup(void) { - + envTmpLat(LatticeComplex, "c"); } // execution /////////////////////////////////////////////////////////////////// template void TTestSeqGamma::execute(void) { - PropagatorField &q = *env().template getObject(par().q); - PropagatorField &qSeq = *env().template getObject(par().qSeq); - LatticeComplex c(env().getGrid()); - Gamma g5(Gamma::Algebra::Gamma5); - Gamma g(par().gamma); - SitePropagator qSite; - Complex test, check; + auto &q = envGet(PropagatorField, par().q); + auto &qSeq = envGet(PropagatorField, par().qSeq); + Gamma g5(Gamma::Algebra::Gamma5); + Gamma g(par().gamma); + SitePropagator qSite; + Complex test, check; std::vector check_buf; + std::vector siteCoord; // Check sequential insertion of gamma matrix gives same result as // insertion of gamma at sink upon contraction. Assume q uses a point // source. - std::vector siteCoord; + + envGetTmp(LatticeComplex, c); siteCoord = strToVec(par().origin); peekSite(qSite, qSeq, siteCoord); test = trace(g*qSite); diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 5ce2435f..2f4d183e 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -1,45 +1,38 @@ modules_cc =\ - Modules/MGauge/Unit.cc - # Modules/MContraction/WeakHamiltonianEye.cc \ - # Modules/MContraction/WeakHamiltonianNonEye.cc \ - # Modules/MContraction/WeakNeutral4ptDisc.cc \ - # Modules/MGauge/Load.cc \ - # Modules/MGauge/Random.cc \ - # Modules/MGauge/StochEm.cc \ - # Modules/MScalar/ChargedProp.cc \ - # Modules/MScalar/FreeProp.cc + Modules/MGauge/Unit.cc \ + Modules/MContraction/WeakHamiltonianEye.cc \ + Modules/MContraction/WeakHamiltonianNonEye.cc \ + Modules/MContraction/WeakNeutral4ptDisc.cc \ + Modules/MGauge/Load.cc \ + Modules/MGauge/Random.cc \ + Modules/MGauge/StochEm.cc modules_hpp =\ Modules/MAction/DWF.hpp \ Modules/MAction/Wilson.hpp \ Modules/MSink/Point.hpp \ Modules/MSource/Point.hpp \ + Modules/MGauge/Load.hpp \ + Modules/MGauge/Random.hpp \ + Modules/MGauge/StochEm.hpp \ Modules/MGauge/Unit.hpp \ Modules/MSolver/RBPrecCG.hpp \ Modules/MFermion/GaugeProp.hpp \ - Modules/MContraction/Meson.hpp - - # Modules/MContraction/Baryon.hpp \ - # Modules/MContraction/DiscLoop.hpp \ - # Modules/MContraction/Gamma3pt.hpp \ - # Modules/MContraction/WardIdentity.hpp \ - # Modules/MContraction/WeakHamiltonian.hpp \ - # Modules/MContraction/WeakHamiltonianEye.hpp \ - # Modules/MContraction/WeakHamiltonianNonEye.hpp \ - # Modules/MContraction/WeakNeutral4ptDisc.hpp \ - # Modules/MFermion/GaugeProp.hpp \ - # Modules/MGauge/Load.hpp \ - # Modules/MGauge/Random.hpp \ - # Modules/MGauge/StochEm.hpp \ - # Modules/MLoop/NoiseLoop.hpp \ - # Modules/MScalar/ChargedProp.hpp \ - # Modules/MScalar/FreeProp.hpp \ - # Modules/MScalar/Scalar.hpp \ - # Modules/MSink/Smear.hpp \ - # Modules/MSolver/RBPrecCG.hpp \ - # Modules/MSource/SeqConserved.hpp \ - # Modules/MSource/SeqGamma.hpp \ - # Modules/MSource/Wall.hpp \ - # Modules/MSource/Z2.hpp \ - # Modules/MUtilities/TestSeqConserved.hpp \ - # Modules/MUtilities/TestSeqGamma.hpp + Modules/MContraction/Baryon.hpp \ + Modules/MContraction/DiscLoop.hpp \ + Modules/MContraction/Gamma3pt.hpp \ + Modules/MContraction/Meson.hpp \ + Modules/MContraction/WardIdentity.hpp \ + Modules/MContraction/WeakHamiltonian.hpp \ + Modules/MContraction/WeakHamiltonianEye.hpp \ + Modules/MContraction/WeakHamiltonianNonEye.hpp \ + Modules/MContraction/WeakNeutral4ptDisc.hpp \ + Modules/MLoop/NoiseLoop.hpp \ + Modules/MSink/Smear.hpp \ + Modules/MSolver/RBPrecCG.hpp \ + Modules/MSource/SeqConserved.hpp \ + Modules/MSource/SeqGamma.hpp \ + Modules/MSource/Wall.hpp \ + Modules/MSource/Z2.hpp \ + Modules/MUtilities/TestSeqConserved.hpp \ + Modules/MUtilities/TestSeqGamma.hpp diff --git a/tests/hadrons/Test_hadrons.hpp b/tests/hadrons/Test_hadrons.hpp index 9bd3ee0a..0265f5a6 100644 --- a/tests/hadrons/Test_hadrons.hpp +++ b/tests/hadrons/Test_hadrons.hpp @@ -118,7 +118,7 @@ inline void makeWilsonAction(Application &application, std::string actionName, std::string &gaugeField, double mass, std::string boundary = "1 1 1 -1") { - if (!(Environment::getInstance().hasModule(actionName))) + if (!(VirtualMachine::getInstance().hasModule(actionName))) { MAction::Wilson::Par actionPar; actionPar.gauge = gaugeField; @@ -144,7 +144,7 @@ inline void makeDWFAction(Application &application, std::string actionName, std::string &gaugeField, double mass, double M5, unsigned int Ls, std::string boundary = "1 1 1 -1") { - if (!(Environment::getInstance().hasModule(actionName))) + if (!(VirtualMachine::getInstance().hasModule(actionName))) { MAction::DWF::Par actionPar; actionPar.gauge = gaugeField; @@ -173,7 +173,7 @@ inline void makeDWFAction(Application &application, std::string actionName, inline void makeRBPrecCGSolver(Application &application, std::string &solverName, std::string &actionName, double residual = 1e-8) { - if (!(Environment::getInstance().hasModule(solverName))) + if (!(VirtualMachine::getInstance().hasModule(solverName))) { MSolver::RBPrecCG::Par solverPar; solverPar.action = actionName; @@ -195,7 +195,7 @@ inline void makePointSource(Application &application, std::string srcName, std::string pos) { // If the source already exists, don't make the module again. - if (!(Environment::getInstance().hasModule(srcName))) + if (!(VirtualMachine::getInstance().hasModule(srcName))) { MSource::Point::Par pointPar; pointPar.position = pos; @@ -219,7 +219,7 @@ inline void makeSequentialSource(Application &application, std::string srcName, std::string mom = ZERO_MOM) { // If the source already exists, don't make the module again. - if (!(Environment::getInstance().hasModule(srcName))) + if (!(VirtualMachine::getInstance().hasModule(srcName))) { MSource::SeqGamma::Par seqPar; seqPar.q = qSrc; @@ -255,7 +255,7 @@ inline void makeConservedSequentialSource(Application &application, std::string mom = ZERO_MOM) { // If the source already exists, don't make the module again. - if (!(Environment::getInstance().hasModule(srcName))) + if (!(VirtualMachine::getInstance().hasModule(srcName))) { MSource::SeqConserved::Par seqPar; seqPar.q = qSrc; @@ -280,7 +280,7 @@ inline void makeConservedSequentialSource(Application &application, inline void makeNoiseSource(Application &application, std::string &srcName, unsigned int tA, unsigned int tB) { - if (!(Environment::getInstance().hasModule(srcName))) + if (!(VirtualMachine::getInstance().hasModule(srcName))) { MSource::Z2::Par noisePar; noisePar.tA = tA; @@ -302,7 +302,7 @@ inline void makeWallSource(Application &application, std::string &srcName, unsigned int tW, std::string mom = ZERO_MOM) { // If the source already exists, don't make the module again. - if (!(Environment::getInstance().hasModule(srcName))) + if (!(VirtualMachine::getInstance().hasModule(srcName))) { MSource::Wall::Par wallPar; wallPar.tW = tW; @@ -324,7 +324,7 @@ inline void makePointSink(Application &application, std::string &sinkFnct, std::string mom = ZERO_MOM) { // If the sink function already exists, don't make it again. - if (!(Environment::getInstance().hasModule(sinkFnct))) + if (!(VirtualMachine::getInstance().hasModule(sinkFnct))) { MSink::Point::Par pointPar; pointPar.mom = mom; @@ -345,7 +345,7 @@ inline void sinkSmear(Application &application, std::string &sinkFnct, std::string &propName, std::string &smearedProp) { // If the propagator has already been smeared, don't smear it again. - if (!(Environment::getInstance().hasModule(smearedProp))) + if (!(VirtualMachine::getInstance().hasModule(smearedProp))) { MSink::Smear::Par smearPar; smearPar.q = propName; @@ -367,7 +367,7 @@ inline void makePropagator(Application &application, std::string &propName, std::string &srcName, std::string &solver) { // If the propagator already exists, don't make the module again. - if (!(Environment::getInstance().hasModule(propName))) + if (!(VirtualMachine::getInstance().hasModule(propName))) { MFermion::GaugeProp::Par quarkPar; quarkPar.source = srcName; @@ -390,7 +390,7 @@ inline void makeLoop(Application &application, std::string &propName, std::string &srcName, std::string &resName) { // If the loop propagator already exists, don't make the module again. - if (!(Environment::getInstance().hasModule(propName))) + if (!(VirtualMachine::getInstance().hasModule(propName))) { MLoop::NoiseLoop::Par loopPar; loopPar.q = resName; @@ -421,7 +421,7 @@ inline void mesonContraction(Application &application, std::string &sink, std::string gammas = "") { - if (!(Environment::getInstance().hasModule(modName))) + if (!(VirtualMachine::getInstance().hasModule(modName))) { MContraction::Meson::Par mesPar; mesPar.output = output; @@ -453,7 +453,7 @@ inline void gamma3ptContraction(Application &application, unsigned int npt, Gamma::Algebra gamma = Gamma::Algebra::Identity) { std::string modName = std::to_string(npt) + "pt_" + label; - if (!(Environment::getInstance().hasModule(modName))) + if (!(VirtualMachine::getInstance().hasModule(modName))) { MContraction::Gamma3pt::Par gamma3ptPar; gamma3ptPar.output = std::to_string(npt) + "pt/" + label; @@ -487,7 +487,7 @@ inline void weakContraction##top(Application &application, unsigned int npt,\ std::string &label, unsigned int tSnk = 0)\ {\ std::string modName = std::to_string(npt) + "pt_" + label;\ - if (!(Environment::getInstance().hasModule(modName)))\ + if (!(VirtualMachine::getInstance().hasModule(modName)))\ {\ MContraction::WeakHamiltonian##top::Par weakPar;\ weakPar.output = std::to_string(npt) + "pt/" + label;\ @@ -521,7 +521,7 @@ inline void disc0Contraction(Application &application, std::string &label) { std::string modName = "4pt_" + label; - if (!(Environment::getInstance().hasModule(modName))) + if (!(VirtualMachine::getInstance().hasModule(modName))) { MContraction::WeakNeutral4ptDisc::Par disc0Par; disc0Par.output = "4pt/" + label; @@ -547,7 +547,7 @@ inline void discLoopContraction(Application &application, std::string &q_loop, std::string &modName, Gamma::Algebra gamma = Gamma::Algebra::Identity) { - if (!(Environment::getInstance().hasModule(modName))) + if (!(VirtualMachine::getInstance().hasModule(modName))) { MContraction::DiscLoop::Par discPar; discPar.output = "disc/" + modName; @@ -574,7 +574,7 @@ inline void makeWITest(Application &application, std::string &modName, std::string &propName, std::string &actionName, double mass, unsigned int Ls = 1, bool test_axial = false) { - if (!(Environment::getInstance().hasModule(modName))) + if (!(VirtualMachine::getInstance().hasModule(modName))) { MContraction::WardIdentity::Par wiPar; if (Ls > 1) @@ -613,7 +613,7 @@ inline void makeSeqCurrComparison(Application &application, std::string &modName std::string &actionName, std::string &origin, unsigned int t_J, unsigned int mu, Current curr) { - if (!(Environment::getInstance().hasModule(modName))) + if (!(VirtualMachine::getInstance().hasModule(modName))) { MUtilities::TestSeqConserved::Par seqPar; seqPar.q = propName; @@ -646,7 +646,7 @@ inline void makeSeqGamComparison(Application &application, std::string &modName, std::string &origin, Gamma::Algebra gamma, unsigned int t_g) { - if (!(Environment::getInstance().hasModule(modName))) + if (!(VirtualMachine::getInstance().hasModule(modName))) { MUtilities::TestSeqGamma::Par seqPar; seqPar.q = propName; From 591a38c487acc0f0abc7dd099e09f26f661f913c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 14 Dec 2017 19:42:16 +0000 Subject: [PATCH 112/174] Hadrons: VM fixes --- extras/Hadrons/Modules/MSource/Z2.hpp | 2 +- extras/Hadrons/VirtualMachine.cc | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index 2e864ff0..39840319 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -150,7 +150,7 @@ void TZ2::execute(void) } auto &src = envGet(PropagatorField, getName()); - auto &t = envGet(Lattice>, getName()); + auto &t = envGet(Lattice>, tName_); Complex shift(1., 1.); if (!hasT_) diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index 8a6bd149..8b2ea516 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -83,6 +83,24 @@ void VirtualMachine::pushModule(VirtualMachine::ModPt &pt) } m.input.push_back(env().getObjectAddress(ref)); } + auto inCopy = m.input; + // if module has inputs with references, they need to be added as + // an input + for (auto &in: inCopy) + { + int inm = env().getObjectModule(in); + + if (inm > 0) + { + if (getModule(inm)->getReference().size() > 0) + { + for (auto &rin: getModule(inm)->getReference()) + { + m.input.push_back(env().getObjectAddress(rin)); + } + } + } + } module_.push_back(std::move(m)); address = static_cast(module_.size() - 1); moduleAddress_[name] = address; From bcf6f3890c38420eba6449f5190fc688b006fbf7 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 14 Dec 2017 21:14:10 +0000 Subject: [PATCH 113/174] Hadrons: more fixes after test --- extras/Hadrons/Modules/MContraction/Meson.hpp | 12 ++++++++++-- extras/Hadrons/VirtualMachine.cc | 4 ++-- extras/Hadrons/VirtualMachine.hpp | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 1fd86d3a..3b250a3b 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -99,6 +99,8 @@ public: virtual std::vector getOutput(void); virtual void parseGammaString(std::vector &gammaList); protected: + // execution + virtual void setup(void); // execution virtual void execute(void); }; @@ -160,8 +162,14 @@ void TMeson::parseGammaString(std::vector &gammaList) { // Parse individual contractions from input string. gammaList = strToVec(par().gammas); - } - envTmpLat(LatticeComplex, "c"); + } +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TMeson::setup(void) +{ + envTmpLat(LatticeComplex, "c"); } // execution /////////////////////////////////////////////////////////////////// diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index 8b2ea516..e0035bc1 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -579,8 +579,8 @@ void VirtualMachine::executeProgram(const Program &p) const { // execute module LOG(Message) << SEP << " Measurement step " << i + 1 << "/" - << p.size() << " (module '" << module_[p[i]].name - << "') " << SEP << std::endl; + << p.size() << " (module '" << module_[p[i]].name + << "') " << SEP << std::endl; (*module_[p[i]].data)(); sizeBefore = env().getTotalSize(); // print used memory after execution diff --git a/extras/Hadrons/VirtualMachine.hpp b/extras/Hadrons/VirtualMachine.hpp index a411c108..3af7d914 100644 --- a/extras/Hadrons/VirtualMachine.hpp +++ b/extras/Hadrons/VirtualMachine.hpp @@ -59,7 +59,7 @@ public: { Size size; Environment::Storage storage; - unsigned int module; + int module; }; struct MemoryProfile { From e2fe97277bc0dcc65700645f16c547fe3d6b429e Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 19 Dec 2017 20:28:04 +0000 Subject: [PATCH 114/174] Hadrons: getReference use is rare, empty by default --- extras/Hadrons/Module.hpp | 5 ++++- extras/Hadrons/Modules/MAction/DWF.hpp | 9 --------- extras/Hadrons/Modules/MAction/Wilson.hpp | 9 --------- extras/Hadrons/Modules/MContraction/Baryon.hpp | 9 --------- extras/Hadrons/Modules/MContraction/DiscLoop.hpp | 9 --------- extras/Hadrons/Modules/MContraction/Gamma3pt.hpp | 9 --------- extras/Hadrons/Modules/MContraction/Meson.hpp | 9 --------- extras/Hadrons/Modules/MContraction/WardIdentity.hpp | 9 --------- .../Hadrons/Modules/MContraction/WeakHamiltonian.hpp | 1 - .../Hadrons/Modules/MContraction/WeakHamiltonianEye.cc | 7 ------- .../Modules/MContraction/WeakHamiltonianNonEye.cc | 6 ------ .../Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc | 7 ------- extras/Hadrons/Modules/MFermion/GaugeProp.hpp | 9 --------- extras/Hadrons/Modules/MGauge/Load.cc | 7 ------- extras/Hadrons/Modules/MGauge/Load.hpp | 1 - extras/Hadrons/Modules/MGauge/Random.cc | 7 ------- extras/Hadrons/Modules/MGauge/Random.hpp | 1 - extras/Hadrons/Modules/MGauge/StochEm.cc | 7 ------- extras/Hadrons/Modules/MGauge/StochEm.hpp | 1 - extras/Hadrons/Modules/MGauge/Unit.cc | 7 ------- extras/Hadrons/Modules/MGauge/Unit.hpp | 1 - extras/Hadrons/Modules/MLoop/NoiseLoop.hpp | 10 ---------- extras/Hadrons/Modules/MSink/Point.hpp | 9 --------- extras/Hadrons/Modules/MSink/Smear.hpp | 9 --------- extras/Hadrons/Modules/MSource/Point.hpp | 9 --------- extras/Hadrons/Modules/MSource/SeqConserved.hpp | 9 --------- extras/Hadrons/Modules/MSource/SeqGamma.hpp | 9 --------- extras/Hadrons/Modules/MSource/Wall.hpp | 9 --------- extras/Hadrons/Modules/MSource/Z2.hpp | 9 --------- extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp | 9 --------- extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp | 9 --------- extras/Hadrons/Modules/templates/Module.cc.template | 8 -------- extras/Hadrons/Modules/templates/Module.hpp.template | 1 - .../Hadrons/Modules/templates/Module_in_NS.cc.template | 8 -------- .../Modules/templates/Module_in_NS.hpp.template | 1 - .../Hadrons/Modules/templates/Module_tmp.hpp.template | 1 - .../Modules/templates/Module_tmp_in_NS.hpp.template | 9 --------- 37 files changed, 4 insertions(+), 245 deletions(-) diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 390573d8..b71f779d 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -155,7 +155,10 @@ public: virtual std::string getRegisteredName(void); // dependencies/products virtual std::vector getInput(void) = 0; - virtual std::vector getReference(void) = 0; + virtual std::vector getReference(void) + { + return std::vector(0); + }; virtual std::vector getOutput(void) = 0; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name) = 0; diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index 0cb9a4cb..d99f1165 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -64,7 +64,6 @@ public: virtual ~TDWF(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -93,14 +92,6 @@ std::vector TDWF::getInput(void) return in; } -template -std::vector TDWF::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TDWF::getOutput(void) { diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index a6b3f0d6..8ef755bb 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -62,7 +62,6 @@ public: virtual ~TWilson(void) = default; // dependencies/products virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -91,14 +90,6 @@ std::vector TWilson::getInput(void) return in; } -template -std::vector TWilson::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TWilson::getOutput(void) { diff --git a/extras/Hadrons/Modules/MContraction/Baryon.hpp b/extras/Hadrons/Modules/MContraction/Baryon.hpp index 28f6aa51..1ef2e257 100644 --- a/extras/Hadrons/Modules/MContraction/Baryon.hpp +++ b/extras/Hadrons/Modules/MContraction/Baryon.hpp @@ -71,7 +71,6 @@ public: virtual ~TBaryon(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -100,14 +99,6 @@ std::vector TBaryon::getInput(void) return input; } -template -std::vector TBaryon::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TBaryon::getOutput(void) { diff --git a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp index c0fbe296..ef50061c 100644 --- a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp +++ b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp @@ -67,7 +67,6 @@ public: virtual ~TDiscLoop(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -96,14 +95,6 @@ std::vector TDiscLoop::getInput(void) return in; } -template -std::vector TDiscLoop::getReference(void) -{ - std::vector out = {}; - - return out; -} - template std::vector TDiscLoop::getOutput(void) { diff --git a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp index 4a6baf3e..fb9a9d4b 100644 --- a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp +++ b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp @@ -98,7 +98,6 @@ public: virtual ~TGamma3pt(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -127,14 +126,6 @@ std::vector TGamma3pt::getInput(void) return in; } -template -std::vector TGamma3pt::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TGamma3pt::getOutput(void) { diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 3b250a3b..46bbdb2e 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -95,7 +95,6 @@ public: virtual ~TMeson(void) = default; // dependencies/products virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); virtual void parseGammaString(std::vector &gammaList); protected: @@ -125,14 +124,6 @@ std::vector TMeson::getInput(void) return input; } -template -std::vector TMeson::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TMeson::getOutput(void) { diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index c92c7243..556450a8 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -73,7 +73,6 @@ public: virtual ~TWardIdentity(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -104,14 +103,6 @@ std::vector TWardIdentity::getInput(void) return in; } -template -std::vector TWardIdentity::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TWardIdentity::getOutput(void) { diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp index 2b53c87a..7df40370 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp @@ -99,7 +99,6 @@ public:\ virtual ~T##modname(void) = default;\ /* dependency relation */ \ virtual std::vector getInput(void);\ - virtual std::vector getReference(void);\ virtual std::vector getOutput(void);\ public:\ std::vector VA_label = {"V", "A"};\ diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc index 7a73a7e3..43dfa609 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc @@ -74,13 +74,6 @@ std::vector TWeakHamiltonianEye::getInput(void) return in; } -std::vector TWeakHamiltonianEye::getReference(void) -{ - std::vector out = {}; - - return out; -} - std::vector TWeakHamiltonianEye::getOutput(void) { std::vector out = {}; diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc index c333713d..8a7113e3 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc @@ -74,12 +74,6 @@ std::vector TWeakHamiltonianNonEye::getInput(void) return in; } -std::vector TWeakHamiltonianNonEye::getReference(void) -{ - std::vector out = {}; - - return out; -} std::vector TWeakHamiltonianNonEye::getOutput(void) { std::vector out = {}; diff --git a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc index e0f07f6c..18423f3e 100644 --- a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc +++ b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc @@ -76,13 +76,6 @@ std::vector TWeakNeutral4ptDisc::getInput(void) return in; } -std::vector TWeakNeutral4ptDisc::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - std::vector TWeakNeutral4ptDisc::getOutput(void) { std::vector out = {}; diff --git a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp index e77df287..05b3d17a 100644 --- a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -84,7 +84,6 @@ public: virtual ~TGaugeProp(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -116,14 +115,6 @@ std::vector TGaugeProp::getInput(void) return in; } -template -std::vector TGaugeProp::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TGaugeProp::getOutput(void) { diff --git a/extras/Hadrons/Modules/MGauge/Load.cc b/extras/Hadrons/Modules/MGauge/Load.cc index c2fd49de..b168a010 100644 --- a/extras/Hadrons/Modules/MGauge/Load.cc +++ b/extras/Hadrons/Modules/MGauge/Load.cc @@ -49,13 +49,6 @@ std::vector TLoad::getInput(void) return in; } -std::vector TLoad::getReference(void) -{ - std::vector ref; - - return ref; -} - std::vector TLoad::getOutput(void) { std::vector out = {getName()}; diff --git a/extras/Hadrons/Modules/MGauge/Load.hpp b/extras/Hadrons/Modules/MGauge/Load.hpp index a967d714..a338af79 100644 --- a/extras/Hadrons/Modules/MGauge/Load.hpp +++ b/extras/Hadrons/Modules/MGauge/Load.hpp @@ -57,7 +57,6 @@ public: virtual ~TLoad(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup diff --git a/extras/Hadrons/Modules/MGauge/Random.cc b/extras/Hadrons/Modules/MGauge/Random.cc index fdb0d145..97afd338 100644 --- a/extras/Hadrons/Modules/MGauge/Random.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -49,13 +49,6 @@ std::vector TRandom::getInput(void) return in; } -std::vector TRandom::getReference(void) -{ - std::vector ref; - - return ref; -} - std::vector TRandom::getOutput(void) { std::vector out = {getName()}; diff --git a/extras/Hadrons/Modules/MGauge/Random.hpp b/extras/Hadrons/Modules/MGauge/Random.hpp index 30525113..a07130e4 100644 --- a/extras/Hadrons/Modules/MGauge/Random.hpp +++ b/extras/Hadrons/Modules/MGauge/Random.hpp @@ -50,7 +50,6 @@ public: virtual ~TRandom(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup diff --git a/extras/Hadrons/Modules/MGauge/StochEm.cc b/extras/Hadrons/Modules/MGauge/StochEm.cc index a878ae2f..c5318573 100644 --- a/extras/Hadrons/Modules/MGauge/StochEm.cc +++ b/extras/Hadrons/Modules/MGauge/StochEm.cc @@ -47,13 +47,6 @@ std::vector TStochEm::getInput(void) return in; } -std::vector TStochEm::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - std::vector TStochEm::getOutput(void) { std::vector out = {getName()}; diff --git a/extras/Hadrons/Modules/MGauge/StochEm.hpp b/extras/Hadrons/Modules/MGauge/StochEm.hpp index efc2e39b..bacb5172 100644 --- a/extras/Hadrons/Modules/MGauge/StochEm.hpp +++ b/extras/Hadrons/Modules/MGauge/StochEm.hpp @@ -59,7 +59,6 @@ public: virtual ~TStochEm(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index af31f124..8bee1ecc 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -47,13 +47,6 @@ std::vector TUnit::getInput(void) return std::vector(); } -std::vector TUnit::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - std::vector TUnit::getOutput(void) { std::vector out = {getName()}; diff --git a/extras/Hadrons/Modules/MGauge/Unit.hpp b/extras/Hadrons/Modules/MGauge/Unit.hpp index 4b69f0ce..c1650cc7 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.hpp +++ b/extras/Hadrons/Modules/MGauge/Unit.hpp @@ -50,7 +50,6 @@ public: virtual ~TUnit(void) = default; // dependencies/products virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup diff --git a/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp b/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp index 0feb5efb..512c731a 100644 --- a/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp +++ b/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp @@ -73,7 +73,6 @@ public: virtual ~TNoiseLoop(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -102,15 +101,6 @@ std::vector TNoiseLoop::getInput(void) return in; } - -template -std::vector TNoiseLoop::getReference(void) -{ - std::vector out = {}; - - return out; -} - template std::vector TNoiseLoop::getOutput(void) { diff --git a/extras/Hadrons/Modules/MSink/Point.hpp b/extras/Hadrons/Modules/MSink/Point.hpp index 42cae4f6..43be3009 100644 --- a/extras/Hadrons/Modules/MSink/Point.hpp +++ b/extras/Hadrons/Modules/MSink/Point.hpp @@ -60,7 +60,6 @@ public: virtual ~TPoint(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -94,14 +93,6 @@ std::vector TPoint::getInput(void) return in; } -template -std::vector TPoint::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TPoint::getOutput(void) { diff --git a/extras/Hadrons/Modules/MSink/Smear.hpp b/extras/Hadrons/Modules/MSink/Smear.hpp index 03cc861a..e85ab263 100644 --- a/extras/Hadrons/Modules/MSink/Smear.hpp +++ b/extras/Hadrons/Modules/MSink/Smear.hpp @@ -61,7 +61,6 @@ public: virtual ~TSmear(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -90,14 +89,6 @@ std::vector TSmear::getInput(void) return in; } -template -std::vector TSmear::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TSmear::getOutput(void) { diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index 6470c77f..1d8241cf 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -71,7 +71,6 @@ public: virtual ~TPoint(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -101,14 +100,6 @@ std::vector TPoint::getInput(void) return in; } -template -std::vector TPoint::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TPoint::getOutput(void) { diff --git a/extras/Hadrons/Modules/MSource/SeqConserved.hpp b/extras/Hadrons/Modules/MSource/SeqConserved.hpp index 9ccbee1b..3e8ef457 100644 --- a/extras/Hadrons/Modules/MSource/SeqConserved.hpp +++ b/extras/Hadrons/Modules/MSource/SeqConserved.hpp @@ -82,7 +82,6 @@ public: virtual ~TSeqConserved(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -111,14 +110,6 @@ std::vector TSeqConserved::getInput(void) return in; } -template -std::vector TSeqConserved::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TSeqConserved::getOutput(void) { diff --git a/extras/Hadrons/Modules/MSource/SeqGamma.hpp b/extras/Hadrons/Modules/MSource/SeqGamma.hpp index d2b3c958..abad5ace 100644 --- a/extras/Hadrons/Modules/MSource/SeqGamma.hpp +++ b/extras/Hadrons/Modules/MSource/SeqGamma.hpp @@ -80,7 +80,6 @@ public: virtual ~TSeqGamma(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -114,14 +113,6 @@ std::vector TSeqGamma::getInput(void) return in; } -template -std::vector TSeqGamma::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TSeqGamma::getOutput(void) { diff --git a/extras/Hadrons/Modules/MSource/Wall.hpp b/extras/Hadrons/Modules/MSource/Wall.hpp index d9814d9e..9d5f1f46 100644 --- a/extras/Hadrons/Modules/MSource/Wall.hpp +++ b/extras/Hadrons/Modules/MSource/Wall.hpp @@ -72,7 +72,6 @@ public: virtual ~TWall(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -106,14 +105,6 @@ std::vector TWall::getInput(void) return in; } -template -std::vector TWall::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TWall::getOutput(void) { diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index 39840319..3593cb34 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -75,7 +75,6 @@ public: virtual ~TZ2(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -109,14 +108,6 @@ std::vector TZ2::getInput(void) return in; } -template -std::vector TZ2::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TZ2::getOutput(void) { diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp index 081d2911..0647884c 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -79,7 +79,6 @@ public: virtual ~TTestSeqConserved(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -108,14 +107,6 @@ std::vector TTestSeqConserved::getInput(void) return in; } -template -std::vector TTestSeqConserved::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TTestSeqConserved::getOutput(void) { diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp index 30bd4b69..fd53eab8 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp @@ -63,7 +63,6 @@ public: virtual ~TTestSeqGamma(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); protected: // setup @@ -92,14 +91,6 @@ std::vector TTestSeqGamma::getInput(void) return in; } -template -std::vector TTestSeqGamma::getReference(void) -{ - std::vector ref = {}; - - return ref; -} - template std::vector TTestSeqGamma::getOutput(void) { diff --git a/extras/Hadrons/Modules/templates/Module.cc.template b/extras/Hadrons/Modules/templates/Module.cc.template index 29edadfb..0c509d6d 100644 --- a/extras/Hadrons/Modules/templates/Module.cc.template +++ b/extras/Hadrons/Modules/templates/Module.cc.template @@ -19,14 +19,6 @@ std::vector T___FILEBASENAME___::getInput(void) return in; } -template -std::vector T___FILEBASENAME___::getReference(void) -{ - std::vector in = {}; - - return in; -} - std::vector T___FILEBASENAME___::getOutput(void) { std::vector out = {getName()}; diff --git a/extras/Hadrons/Modules/templates/Module.hpp.template b/extras/Hadrons/Modules/templates/Module.hpp.template index b59e168f..fb43260f 100644 --- a/extras/Hadrons/Modules/templates/Module.hpp.template +++ b/extras/Hadrons/Modules/templates/Module.hpp.template @@ -26,7 +26,6 @@ public: virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); // setup virtual void setup(void); diff --git a/extras/Hadrons/Modules/templates/Module_in_NS.cc.template b/extras/Hadrons/Modules/templates/Module_in_NS.cc.template index 880129bd..8b2a0ec0 100644 --- a/extras/Hadrons/Modules/templates/Module_in_NS.cc.template +++ b/extras/Hadrons/Modules/templates/Module_in_NS.cc.template @@ -20,14 +20,6 @@ std::vector T___FILEBASENAME___::getInput(void) return in; } -template -std::vector T___FILEBASENAME___::getReference(void) -{ - std::vector in = {}; - - return in; -} - std::vector T___FILEBASENAME___::getOutput(void) { std::vector out = {getName()}; diff --git a/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template index f90cb052..ea77b12a 100644 --- a/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_in_NS.hpp.template @@ -28,7 +28,6 @@ public: virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); // setup virtual void setup(void); diff --git a/extras/Hadrons/Modules/templates/Module_tmp.hpp.template b/extras/Hadrons/Modules/templates/Module_tmp.hpp.template index b4e7f87f..2ee053a9 100644 --- a/extras/Hadrons/Modules/templates/Module_tmp.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_tmp.hpp.template @@ -27,7 +27,6 @@ public: virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); // setup virtual void setup(void); diff --git a/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template b/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template index 9aef1c92..b79c0ad3 100644 --- a/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template +++ b/extras/Hadrons/Modules/templates/Module_tmp_in_NS.hpp.template @@ -29,7 +29,6 @@ public: virtual ~T___FILEBASENAME___(void) = default; // dependency relation virtual std::vector getInput(void); - virtual std::vector getReference(void); virtual std::vector getOutput(void); // setup virtual void setup(void); @@ -57,14 +56,6 @@ std::vector T___FILEBASENAME___::getInput(void) return in; } -template -std::vector T___FILEBASENAME___::getReference(void) -{ - std::vector in = {}; - - return in; -} - template std::vector T___FILEBASENAME___::getOutput(void) { From 65d4f17976ec7920aeccb880a50ad852e7fe7290 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 19 Dec 2017 20:28:32 +0000 Subject: [PATCH 115/174] Hadrons: no errors when trying to recreate a cache --- extras/Hadrons/Environment.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index adea13ce..7f1bc26d 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -228,7 +228,11 @@ void Environment::createDerivedObject(const std::string name, MemoryProfiler::stats = nullptr; } } - else + // object already exists, no error if it is a cache, error otherwise + else if ((object_[address].storage != Storage::cache) or + (object_[address].storage != storage) or + (object_[address].name != name) or + (object_[address].type != &typeid(T))) { HADRON_ERROR(Definition, "object '" + name + "' already allocated"); } From 67c3fa0f5f2adda473b7543121a7ad6041547259 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Thu, 21 Dec 2017 11:39:07 +0000 Subject: [PATCH 116/174] Hadrons: all modules are now ported, more tests need to be done --- extras/Hadrons/Modules.hpp | 40 ++--- extras/Hadrons/Modules/MScalar/ChargedProp.cc | 153 +++++++++--------- .../Hadrons/Modules/MScalar/ChargedProp.hpp | 6 +- extras/Hadrons/Modules/MScalar/FreeProp.cc | 27 ++-- extras/Hadrons/Modules/MScalar/FreeProp.hpp | 1 + extras/Hadrons/make_module_list.sh | 30 ++++ extras/Hadrons/modules.inc | 49 +++--- 7 files changed, 165 insertions(+), 141 deletions(-) diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 61a20058..cf381d0f 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -28,33 +28,33 @@ See the full license in the file "LICENSE" in the top level distribution directo *************************************************************************************/ /* END LEGAL */ -#include -#include #include -#include -#include #include -#include #include -#include #include +#include #include +#include +#include +#include #include -#include -#include -#include -#include -#include -// #include -// #include -// #include -#include -#include -#include -#include -#include #include +#include #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include diff --git a/extras/Hadrons/Modules/MScalar/ChargedProp.cc b/extras/Hadrons/Modules/MScalar/ChargedProp.cc index cd8dc244..6cb75a28 100644 --- a/extras/Hadrons/Modules/MScalar/ChargedProp.cc +++ b/extras/Hadrons/Modules/MScalar/ChargedProp.cc @@ -37,90 +37,44 @@ void TChargedProp::setup(void) { phaseName_.push_back("_shiftphase_" + std::to_string(mu)); } - GFSrcName_ = "_" + getName() + "_DinvSrc"; - if (!env().hasRegisteredObject(freeMomPropName_)) + GFSrcName_ = getName() + "_DinvSrc"; + fftName_ = getName() + "_fft"; + + freeMomPropDone_ = env().hasCreatedObject(freeMomPropName_); + GFSrcDone_ = env().hasCreatedObject(GFSrcName_); + phasesDone_ = env().hasCreatedObject(phaseName_[0]); + envCacheLat(ScalarField, freeMomPropName_); + for (unsigned int mu = 0; mu < env().getNd(); ++mu) { - env().registerLattice(freeMomPropName_); + envCacheLat(ScalarField, phaseName_[mu]); } - if (!env().hasRegisteredObject(phaseName_[0])) - { - for (unsigned int mu = 0; mu < env().getNd(); ++mu) - { - env().registerLattice(phaseName_[mu]); - } - } - if (!env().hasRegisteredObject(GFSrcName_)) - { - env().registerLattice(GFSrcName_); - } - env().registerLattice(getName()); + envCacheLat(ScalarField, GFSrcName_); + envCreateLat(ScalarField, getName()); + envTmpLat(ScalarField, "buf"); + envTmpLat(ScalarField, "result"); + envTmpLat(ScalarField, "Amu"); + envCache(FFT, fftName_, 1, env().getGrid()); } // execution /////////////////////////////////////////////////////////////////// void TChargedProp::execute(void) { // CACHING ANALYTIC EXPRESSIONS - ScalarField &source = *env().getObject(par().source); - Complex ci(0.0,1.0); - FFT fft(env().getGrid()); - - // cache free scalar propagator - if (!env().hasCreatedObject(freeMomPropName_)) - { - LOG(Message) << "Caching momentum space free scalar propagator" - << " (mass= " << par().mass << ")..." << std::endl; - freeMomProp_ = env().createLattice(freeMomPropName_); - SIMPL::MomentumSpacePropagator(*freeMomProp_, par().mass); - } - else - { - freeMomProp_ = env().getObject(freeMomPropName_); - } - // cache G*F*src - if (!env().hasCreatedObject(GFSrcName_)) - - { - GFSrc_ = env().createLattice(GFSrcName_); - fft.FFT_all_dim(*GFSrc_, source, FFT::forward); - *GFSrc_ = (*freeMomProp_)*(*GFSrc_); - } - else - { - GFSrc_ = env().getObject(GFSrcName_); - } - // cache phases - if (!env().hasCreatedObject(phaseName_[0])) - { - std::vector &l = env().getGrid()->_fdimensions; - - LOG(Message) << "Caching shift phases..." << std::endl; - for (unsigned int mu = 0; mu < env().getNd(); ++mu) - { - Real twoPiL = M_PI*2./l[mu]; - - phase_.push_back(env().createLattice(phaseName_[mu])); - LatticeCoordinate(*(phase_[mu]), mu); - *(phase_[mu]) = exp(ci*twoPiL*(*(phase_[mu]))); - } - } - else - { - for (unsigned int mu = 0; mu < env().getNd(); ++mu) - { - phase_.push_back(env().getObject(phaseName_[mu])); - } - } + makeCaches(); // PROPAGATOR CALCULATION LOG(Message) << "Computing charged scalar propagator" << " (mass= " << par().mass << ", charge= " << par().charge << ")..." << std::endl; - ScalarField &prop = *env().createLattice(getName()); - ScalarField buf(env().getGrid()); - ScalarField &GFSrc = *GFSrc_, &G = *freeMomProp_; - double q = par().charge; - + auto &prop = envGet(ScalarField, getName()); + auto &GFSrc = envGet(ScalarField, GFSrcName_); + auto &G = envGet(ScalarField, freeMomPropName_); + auto &fft = envGet(FFT, fftName_); + double q = par().charge; + envGetTmp(ScalarField, result); + envGetTmp(ScalarField, buf); + // G*F*Src prop = GFSrc; @@ -146,7 +100,7 @@ void TChargedProp::execute(void) if (!par().output.empty()) { std::string filename = par().output + "." + - std::to_string(env().getTrajectory()); + std::to_string(vm().getTrajectory()); LOG(Message) << "Saving zero-momentum projection to '" << filename << "'..." << std::endl; @@ -166,15 +120,55 @@ void TChargedProp::execute(void) } } +void TChargedProp::makeCaches(void) +{ + auto &freeMomProp = envGet(ScalarField, freeMomPropName_); + auto &GFSrc = envGet(ScalarField, GFSrcName_); + auto &fft = envGet(FFT, fftName_); + + if (!freeMomPropDone_) + { + LOG(Message) << "Caching momentum space free scalar propagator" + << " (mass= " << par().mass << ")..." << std::endl; + SIMPL::MomentumSpacePropagator(freeMomProp, par().mass); + } + if (!GFSrcDone_) + { + FFT fft(env().getGrid()); + auto &source = envGet(ScalarField, par().source); + + LOG(Message) << "Caching G*F*src..." << std::endl; + fft.FFT_all_dim(GFSrc, source, FFT::forward); + GFSrc = freeMomProp*GFSrc; + } + if (!phasesDone_) + { + std::vector &l = env().getGrid()->_fdimensions; + Complex ci(0.0,1.0); + + LOG(Message) << "Caching shift phases..." << std::endl; + for (unsigned int mu = 0; mu < env().getNd(); ++mu) + { + Real twoPiL = M_PI*2./l[mu]; + auto &phmu = envGet(ScalarField, phaseName_[mu]); + + LatticeCoordinate(phmu, mu); + phmu = exp(ci*twoPiL*phmu); + phase_.push_back(&phmu); + } + } +} + void TChargedProp::momD1(ScalarField &s, FFT &fft) { - EmField &A = *env().getObject(par().emField); - ScalarField buf(env().getGrid()), result(env().getGrid()), - Amu(env().getGrid()); + auto &A = envGet(EmField, par().emField); Complex ci(0.0,1.0); - result = zero; + envGetTmp(ScalarField, buf); + envGetTmp(ScalarField, result); + envGetTmp(ScalarField, Amu); + result = zero; for (unsigned int mu = 0; mu < env().getNd(); ++mu) { Amu = peekLorentz(A, mu); @@ -198,12 +192,13 @@ void TChargedProp::momD1(ScalarField &s, FFT &fft) void TChargedProp::momD2(ScalarField &s, FFT &fft) { - EmField &A = *env().getObject(par().emField); - ScalarField buf(env().getGrid()), result(env().getGrid()), - Amu(env().getGrid()); + auto &A = envGet(EmField, par().emField); + + envGetTmp(ScalarField, buf); + envGetTmp(ScalarField, result); + envGetTmp(ScalarField, Amu); result = zero; - for (unsigned int mu = 0; mu < env().getNd(); ++mu) { Amu = peekLorentz(A, mu); diff --git a/extras/Hadrons/Modules/MScalar/ChargedProp.hpp b/extras/Hadrons/Modules/MScalar/ChargedProp.hpp index ab6a0184..cfcce28e 100644 --- a/extras/Hadrons/Modules/MScalar/ChargedProp.hpp +++ b/extras/Hadrons/Modules/MScalar/ChargedProp.hpp @@ -43,14 +43,14 @@ protected: // execution virtual void execute(void); private: + void makeCaches(void); void momD1(ScalarField &s, FFT &fft); void momD2(ScalarField &s, FFT &fft); private: - std::string freeMomPropName_, GFSrcName_; + bool freeMomPropDone_, GFSrcDone_, phasesDone_; + std::string freeMomPropName_, GFSrcName_, fftName_; std::vector phaseName_; - ScalarField *freeMomProp_, *GFSrc_; std::vector phase_; - EmField *A; }; MODULE_REGISTER_NS(ChargedProp, TChargedProp, MScalar); diff --git a/extras/Hadrons/Modules/MScalar/FreeProp.cc b/extras/Hadrons/Modules/MScalar/FreeProp.cc index 674867e3..924db288 100644 --- a/extras/Hadrons/Modules/MScalar/FreeProp.cc +++ b/extras/Hadrons/Modules/MScalar/FreeProp.cc @@ -33,38 +33,31 @@ void TFreeProp::setup(void) { freeMomPropName_ = FREEMOMPROP(par().mass); - if (!env().hasRegisteredObject(freeMomPropName_)) - { - env().registerLattice(freeMomPropName_); - } - env().registerLattice(getName()); + freePropDone_ = env().hasCreatedObject(freeMomPropName_); + envCacheLat(ScalarField, freeMomPropName_); + envCreateLat(ScalarField, getName()); } // execution /////////////////////////////////////////////////////////////////// void TFreeProp::execute(void) { - ScalarField &prop = *env().createLattice(getName()); - ScalarField &source = *env().getObject(par().source); - ScalarField *freeMomProp; + auto &freeMomProp = envGet(ScalarField, freeMomPropName_); + auto &prop = envGet(ScalarField, getName()); + auto &source = envGet(ScalarField, par().source); - if (!env().hasCreatedObject(freeMomPropName_)) + if (!freePropDone_) { LOG(Message) << "Caching momentum space free scalar propagator" << " (mass= " << par().mass << ")..." << std::endl; - freeMomProp = env().createLattice(freeMomPropName_); - SIMPL::MomentumSpacePropagator(*freeMomProp, par().mass); - } - else - { - freeMomProp = env().getObject(freeMomPropName_); + SIMPL::MomentumSpacePropagator(freeMomProp, par().mass); } LOG(Message) << "Computing free scalar propagator..." << std::endl; - SIMPL::FreePropagator(source, prop, *freeMomProp); + SIMPL::FreePropagator(source, prop, freeMomProp); if (!par().output.empty()) { TextWriter writer(par().output + "." + - std::to_string(env().getTrajectory())); + std::to_string(vm().getTrajectory())); std::vector buf; std::vector result; diff --git a/extras/Hadrons/Modules/MScalar/FreeProp.hpp b/extras/Hadrons/Modules/MScalar/FreeProp.hpp index 38372a0c..6b956134 100644 --- a/extras/Hadrons/Modules/MScalar/FreeProp.hpp +++ b/extras/Hadrons/Modules/MScalar/FreeProp.hpp @@ -40,6 +40,7 @@ protected: virtual void execute(void); private: std::string freeMomPropName_; + bool freePropDone_; }; MODULE_REGISTER_NS(FreeProp, TFreeProp, MScalar); diff --git a/extras/Hadrons/make_module_list.sh b/extras/Hadrons/make_module_list.sh index ddc56ff6..8c6fa4da 100755 --- a/extras/Hadrons/make_module_list.sh +++ b/extras/Hadrons/make_module_list.sh @@ -7,6 +7,36 @@ echo 'modules_hpp =\' >> modules.inc find Modules -name '*.hpp' -type f -print | sed 's/^/ /;$q;s/$/ \\/' >> modules.inc echo '' >> modules.inc rm -f Modules.hpp +echo "/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules.hpp + +Copyright (C) 2015 +Copyright (C) 2016 +Copyright (C) 2017 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file \"LICENSE\" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +" > Modules.hpp for f in `find Modules -name '*.hpp'`; do echo "#include " >> Modules.hpp done diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 2f4d183e..199bb5cd 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -1,38 +1,43 @@ modules_cc =\ - Modules/MGauge/Unit.cc \ Modules/MContraction/WeakHamiltonianEye.cc \ - Modules/MContraction/WeakHamiltonianNonEye.cc \ Modules/MContraction/WeakNeutral4ptDisc.cc \ + Modules/MContraction/WeakHamiltonianNonEye.cc \ Modules/MGauge/Load.cc \ + Modules/MGauge/Unit.cc \ + Modules/MGauge/StochEm.cc \ Modules/MGauge/Random.cc \ - Modules/MGauge/StochEm.cc + Modules/MScalar/FreeProp.cc \ + Modules/MScalar/ChargedProp.cc modules_hpp =\ - Modules/MAction/DWF.hpp \ - Modules/MAction/Wilson.hpp \ - Modules/MSink/Point.hpp \ - Modules/MSource/Point.hpp \ - Modules/MGauge/Load.hpp \ - Modules/MGauge/Random.hpp \ - Modules/MGauge/StochEm.hpp \ - Modules/MGauge/Unit.hpp \ - Modules/MSolver/RBPrecCG.hpp \ - Modules/MFermion/GaugeProp.hpp \ Modules/MContraction/Baryon.hpp \ - Modules/MContraction/DiscLoop.hpp \ - Modules/MContraction/Gamma3pt.hpp \ Modules/MContraction/Meson.hpp \ - Modules/MContraction/WardIdentity.hpp \ Modules/MContraction/WeakHamiltonian.hpp \ - Modules/MContraction/WeakHamiltonianEye.hpp \ Modules/MContraction/WeakHamiltonianNonEye.hpp \ + Modules/MContraction/DiscLoop.hpp \ Modules/MContraction/WeakNeutral4ptDisc.hpp \ - Modules/MLoop/NoiseLoop.hpp \ - Modules/MSink/Smear.hpp \ - Modules/MSolver/RBPrecCG.hpp \ - Modules/MSource/SeqConserved.hpp \ + Modules/MContraction/Gamma3pt.hpp \ + Modules/MContraction/WardIdentity.hpp \ + Modules/MContraction/WeakHamiltonianEye.hpp \ + Modules/MFermion/GaugeProp.hpp \ Modules/MSource/SeqGamma.hpp \ + Modules/MSource/Point.hpp \ Modules/MSource/Wall.hpp \ Modules/MSource/Z2.hpp \ + Modules/MSource/SeqConserved.hpp \ + Modules/MSink/Smear.hpp \ + Modules/MSink/Point.hpp \ + Modules/MSolver/RBPrecCG.hpp \ + Modules/MGauge/Load.hpp \ + Modules/MGauge/Unit.hpp \ + Modules/MGauge/Random.hpp \ + Modules/MGauge/StochEm.hpp \ + Modules/MUtilities/TestSeqGamma.hpp \ Modules/MUtilities/TestSeqConserved.hpp \ - Modules/MUtilities/TestSeqGamma.hpp + Modules/MLoop/NoiseLoop.hpp \ + Modules/MScalar/FreeProp.hpp \ + Modules/MScalar/Scalar.hpp \ + Modules/MScalar/ChargedProp.hpp \ + Modules/MAction/DWF.hpp \ + Modules/MAction/Wilson.hpp + From 4ce63af7d5945b89043797b4de1613f0fbaf4798 Mon Sep 17 00:00:00 2001 From: pretidav Date: Fri, 22 Dec 2017 19:02:07 +0100 Subject: [PATCH 117/174] Working on Hadrons with Hirep. (QCD is set for SU4) --- extras/Hadrons/Modules.hpp | 42 ++--- .../Hadrons/Modules/MAction/WilsonClover.hpp | 142 +++++++++++++++ extras/Hadrons/Modules/MFermion/GaugeProp.hpp | 13 +- extras/Hadrons/Modules/MGauge/FundtoHirep.cc | 75 ++++++++ extras/Hadrons/Modules/MGauge/FundtoHirep.hpp | 77 ++++++++ extras/Hadrons/modules.inc | 51 +++--- lib/qcd/QCD.h | 18 +- lib/qcd/action/fermion/WilsonFermion.h | 3 +- tests/hadrons/Test_hadrons_2AS_spectrum.cc | 168 ++++++++++++++++++ tests/lanczos/Test_WCMultiRep_lanczos.cc | 108 +++++++++++ 10 files changed, 637 insertions(+), 60 deletions(-) create mode 100644 extras/Hadrons/Modules/MAction/WilsonClover.hpp create mode 100644 extras/Hadrons/Modules/MGauge/FundtoHirep.cc create mode 100644 extras/Hadrons/Modules/MGauge/FundtoHirep.hpp create mode 100644 tests/hadrons/Test_hadrons_2AS_spectrum.cc create mode 100644 tests/lanczos/Test_WCMultiRep_lanczos.cc diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index c27254aa..262795e8 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -1,25 +1,27 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/extras/Hadrons/Modules/MAction/WilsonClover.hpp b/extras/Hadrons/Modules/MAction/WilsonClover.hpp new file mode 100644 index 00000000..44b1f0b7 --- /dev/null +++ b/extras/Hadrons/Modules/MAction/WilsonClover.hpp @@ -0,0 +1,142 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MAction/Wilson.hpp + +Copyright (C) 2015 +Copyright (C) 2016 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#ifndef Hadrons_MAction_WilsonClover_hpp_ +#define Hadrons_MAction_WilsonClover_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * TWilson quark action * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MAction) + +class WilsonCloverPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonCloverPar, + std::string, gauge, + double , mass, + double , csw_r, + double , csw_t, + WilsonAnisotropyCoefficients ,clover_anisotropy, + std::string, boundary + ); +}; + +template +class TWilsonClover: public Module +{ +public: + FGS_TYPE_ALIASES(FImpl,); +public: + // constructor + TWilsonClover(const std::string name); + // destructor + virtual ~TWilsonClover(void) = default; + // dependencies/products + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_NS(WilsonClover, TWilsonClover, MAction); + +/****************************************************************************** + * TWilsonClover template implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TWilsonClover::TWilsonClover(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TWilsonClover::getInput(void) +{ + std::vector in = {par().gauge}; + + return in; +} + +template +std::vector TWilsonClover::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TWilsonClover::setup(void) +{ + unsigned int size; + + size = 2*env().template lattice4dSize(); + env().registerObject(getName(), size); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TWilsonClover::execute() +{ + LOG(Message) << "Setting up TWilsonClover fermion matrix with m= " << par().mass + << " using gauge field '" << par().gauge << "'" << std::endl; + LOG(Message) << "Fermion boundary conditions: " << par().boundary + << std::endl; + LOG(Message) << "clover term csw_r= " << par().csw_r + << " csw_t= " << par().csw_t + << std::endl; + auto &U = *env().template getObject(par().gauge); + auto &grid = *env().getGrid(); + auto &gridRb = *env().getRbGrid(); + std::vector boundary = strToVec(par().boundary); + typename WilsonCloverFermion::ImplParams implParams(boundary); + FMat *fMatPt = new WilsonCloverFermion(U, grid, gridRb, par().mass, + par().csw_r, + par().csw_t, + par().clover_anisotropy, + implParams); + env().setObject(getName(), fMatPt); +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_WilsonClover_hpp_ diff --git a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp index b4f9edcc..4e802710 100644 --- a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -43,7 +43,6 @@ private: }; MODULE_REGISTER_NS(GaugeProp, TGaugeProp, MFermion); - /****************************************************************************** * TGaugeProp implementation * ******************************************************************************/ @@ -103,7 +102,7 @@ void TGaugeProp::execute(void) LOG(Message) << "Inverting using solver '" << par().solver << "' on source '" << par().source << "'" << std::endl; for (unsigned int s = 0; s < Ns; ++s) - for (unsigned int c = 0; c < Nc; ++c) + for (unsigned int c = 0; c < FImpl::Dimension; ++c) { LOG(Message) << "Inversion for spin= " << s << ", color= " << c << std::endl; @@ -112,12 +111,12 @@ void TGaugeProp::execute(void) { if (Ls_ == 1) { - PropToFerm(source, fullSrc, s, c); + PropToFerm(source, fullSrc, s, c); } else { source = zero; - PropToFerm(tmp, fullSrc, s, c); + PropToFerm(tmp, fullSrc, s, c); InsertSlice(tmp, source, 0, 0); InsertSlice(tmp, source, Ls_-1, 0); axpby_ssp_pplus(source, 0., source, 1., source, 0, 0); @@ -133,12 +132,12 @@ void TGaugeProp::execute(void) } else { - PropToFerm(source, fullSrc, s, c); + PropToFerm(source, fullSrc, s, c); } } sol = zero; solver(sol, source); - FermToProp(prop, sol, s, c); + FermToProp(prop, sol, s, c); // create 4D propagators from 5D one if necessary if (Ls_ > 1) { @@ -148,7 +147,7 @@ void TGaugeProp::execute(void) axpby_ssp_pminus(sol, 0., sol, 1., sol, 0, 0); axpby_ssp_pplus(sol, 1., sol, 1., sol, 0, Ls_-1); ExtractSlice(tmp, sol, 0, 0); - FermToProp(p4d, tmp, s, c); + FermToProp(p4d, tmp, s, c); } } } diff --git a/extras/Hadrons/Modules/MGauge/FundtoHirep.cc b/extras/Hadrons/Modules/MGauge/FundtoHirep.cc new file mode 100644 index 00000000..f15a3b7c --- /dev/null +++ b/extras/Hadrons/Modules/MGauge/FundtoHirep.cc @@ -0,0 +1,75 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MGauge/FundtoHirep.cc + +Copyright (C) 2015 +Copyright (C) 2016 + + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#include + +using namespace Grid; +using namespace Hadrons; +using namespace MGauge; + +// constructor ///////////////////////////////////////////////////////////////// +template +TFundtoHirep::TFundtoHirep(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TFundtoHirep::getInput(void) +{ + std::vector in; + return in; +} + +template +std::vector TFundtoHirep::getOutput(void) +{ + std::vector out = {getName()}; + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TFundtoHirep::setup(void) +{ + env().template registerLattice(getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TFundtoHirep::execute(void) +{ + auto &U = *env().template getObject(par().gaugeconf); + LOG(Message) << "Transforming Representation" << std::endl; + + Rep TargetRepresentation(U._grid); + TargetRepresentation.update_representation(U); + + typename Rep::LatticeField &URep = *env().template createLattice(getName()); + URep = TargetRepresentation.U; +} diff --git a/extras/Hadrons/Modules/MGauge/FundtoHirep.hpp b/extras/Hadrons/Modules/MGauge/FundtoHirep.hpp new file mode 100644 index 00000000..6f072783 --- /dev/null +++ b/extras/Hadrons/Modules/MGauge/FundtoHirep.hpp @@ -0,0 +1,77 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MGauge/FundtoHirep.hpp + +Copyright (C) 2015 +Copyright (C) 2016 + +Author: David Preti + Guido Cossu + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#ifndef Hadrons_MGauge_FundtoHirep_hpp_ +#define Hadrons_MGauge_FundtoHirep_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Load a NERSC configuration * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MGauge) + +class FundtoHirepPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(FundtoHirepPar, + std::string, gaugeconf); +}; + +template +class TFundtoHirep: public Module +{ +public: + // constructor + TFundtoHirep(const std::string name); + // destructor + virtual ~TFundtoHirep(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + void setup(void); + // execution + void execute(void); +}; + +//MODULE_REGISTER_NS(FundtoAdjoint, TFundtoHirep, MGauge); +//MODULE_REGISTER_NS(FundtoTwoIndexSym, TFundtoHirep, MGauge); +//MODULE_REGISTER_NS(FundtoTwoIndexAsym, TFundtoHirep, MGauge); + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MGauge_FundtoHirep_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 669b08ba..089341c1 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -1,38 +1,41 @@ modules_cc =\ + Modules/MScalar/ChargedProp.cc \ + Modules/MScalar/FreeProp.cc \ Modules/MContraction/WeakHamiltonianEye.cc \ Modules/MContraction/WeakHamiltonianNonEye.cc \ Modules/MContraction/WeakNeutral4ptDisc.cc \ - Modules/MGauge/Load.cc \ - Modules/MGauge/Random.cc \ Modules/MGauge/StochEm.cc \ Modules/MGauge/Unit.cc \ - Modules/MScalar/ChargedProp.cc \ - Modules/MScalar/FreeProp.cc + Modules/MGauge/Load.cc \ + Modules/MGauge/FundtoHirep.cc \ + Modules/MGauge/Random.cc modules_hpp =\ - Modules/MAction/DWF.hpp \ - Modules/MAction/Wilson.hpp \ - Modules/MContraction/Baryon.hpp \ - Modules/MContraction/DiscLoop.hpp \ - Modules/MContraction/Gamma3pt.hpp \ - Modules/MContraction/Meson.hpp \ - Modules/MContraction/WeakHamiltonian.hpp \ - Modules/MContraction/WeakHamiltonianEye.hpp \ - Modules/MContraction/WeakHamiltonianNonEye.hpp \ - Modules/MContraction/WeakNeutral4ptDisc.hpp \ - Modules/MFermion/GaugeProp.hpp \ - Modules/MGauge/Load.hpp \ - Modules/MGauge/Random.hpp \ - Modules/MGauge/StochEm.hpp \ - Modules/MGauge/Unit.hpp \ Modules/MLoop/NoiseLoop.hpp \ Modules/MScalar/ChargedProp.hpp \ - Modules/MScalar/FreeProp.hpp \ Modules/MScalar/Scalar.hpp \ + Modules/MScalar/FreeProp.hpp \ + Modules/MSource/Wall.hpp \ + Modules/MSource/SeqGamma.hpp \ + Modules/MSource/Point.hpp \ + Modules/MSource/Z2.hpp \ + Modules/MFermion/GaugeProp.hpp \ + Modules/MContraction/Meson.hpp \ + Modules/MContraction/WeakHamiltonianNonEye.hpp \ + Modules/MContraction/WeakHamiltonianEye.hpp \ + Modules/MContraction/DiscLoop.hpp \ + Modules/MContraction/Baryon.hpp \ + Modules/MContraction/Gamma3pt.hpp \ + Modules/MContraction/WeakNeutral4ptDisc.hpp \ + Modules/MContraction/WeakHamiltonian.hpp \ Modules/MSink/Point.hpp \ Modules/MSolver/RBPrecCG.hpp \ - Modules/MSource/Point.hpp \ - Modules/MSource/SeqGamma.hpp \ - Modules/MSource/Wall.hpp \ - Modules/MSource/Z2.hpp + Modules/MGauge/StochEm.hpp \ + Modules/MGauge/FundtoHirep.hpp \ + Modules/MGauge/Unit.hpp \ + Modules/MGauge/Load.hpp \ + Modules/MGauge/Random.hpp \ + Modules/MAction/WilsonClover.hpp \ + Modules/MAction/DWF.hpp \ + Modules/MAction/Wilson.hpp diff --git a/lib/qcd/QCD.h b/lib/qcd/QCD.h index 9913a071..2caea7e9 100644 --- a/lib/qcd/QCD.h +++ b/lib/qcd/QCD.h @@ -49,7 +49,7 @@ namespace QCD { static const int Zm = 6; static const int Tm = 7; - static const int Nc=3; + static const int Nc=4; static const int Ns=4; static const int Nd=4; static const int Nhs=2; // half spinor @@ -421,15 +421,16 @@ namespace QCD { ////////////////////////////////////////////// // Fermion <-> propagator assignements ////////////////////////////////////////////// - template - void FermToProp(Prop &p, const Ferm &f, const int s, const int c) + //template + template + void FermToProp(typename Fimpl::PropagatorField &p, const typename Fimpl::FermionField &f, const int s, const int c) { - for(int j = 0; j < Ns; ++j) + for(int j = 0; j < Ns; ++j) { auto pjs = peekSpin(p, j, s); auto fj = peekSpin(f, j); - for(int i = 0; i < Nc; ++i) + for(int i = 0; i < Fimpl::Dimension; ++i) { pokeColour(pjs, peekColour(fj, i), i, c); } @@ -437,15 +438,16 @@ namespace QCD { } } - template - void PropToFerm(Ferm &f, const Prop &p, const int s, const int c) + //template + template + void PropToFerm(typename Fimpl::FermionField &f, const typename Fimpl::PropagatorField &p, const int s, const int c) { for(int j = 0; j < Ns; ++j) { auto pjs = peekSpin(p, j, s); auto fj = peekSpin(f, j); - for(int i = 0; i < Nc; ++i) + for(int i = 0; i < Fimpl::Dimension; ++i) { pokeColour(fj, peekColour(pjs, i, c), i); } diff --git a/lib/qcd/action/fermion/WilsonFermion.h b/lib/qcd/action/fermion/WilsonFermion.h index ca5eba8b..0aea4b68 100644 --- a/lib/qcd/action/fermion/WilsonFermion.h +++ b/lib/qcd/action/fermion/WilsonFermion.h @@ -44,7 +44,8 @@ class WilsonFermionStatic { static const int npoint = 8; }; -struct WilsonAnisotropyCoefficients{ + struct WilsonAnisotropyCoefficients: Serializable + { GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonAnisotropyCoefficients, bool, isAnisotropic, int, t_direction, diff --git a/tests/hadrons/Test_hadrons_2AS_spectrum.cc b/tests/hadrons/Test_hadrons_2AS_spectrum.cc new file mode 100644 index 00000000..2f519834 --- /dev/null +++ b/tests/hadrons/Test_hadrons_2AS_spectrum.cc @@ -0,0 +1,168 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: tests/hadrons/Test_hadrons_spectrum.cc + + Copyright (C) 2015 + + Author: Antonin Portelli + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution + directory. + *******************************************************************************/ + +#include + +using namespace Grid; +using namespace Hadrons; + + + BEGIN_HADRONS_NAMESPACE + BEGIN_MODULE_NAMESPACE(MFermion) + MODULE_REGISTER_NS(GaugeProp2AS, TGaugeProp, MFermion); + END_MODULE_NAMESPACE + BEGIN_MODULE_NAMESPACE(MSource) + MODULE_REGISTER_NS(Point2AS, TPoint, MSource); + END_MODULE_NAMESPACE + BEGIN_MODULE_NAMESPACE(MContraction) + MODULE_REGISTER_NS(Meson2AS, ARG(TMeson), MContraction); +// MODULE_REGISTER_NS(BaryonMultirep, ARG(TBaryon), MContraction); + END_MODULE_NAMESPACE + BEGIN_MODULE_NAMESPACE(MSink) + MODULE_REGISTER_NS(ScalarPoint2AS, TPoint, MSink); + END_MODULE_NAMESPACE + BEGIN_MODULE_NAMESPACE(MSolver) + MODULE_REGISTER_NS(RBPrecCG2AS, TRBPrecCG, MSolver); + END_MODULE_NAMESPACE + BEGIN_MODULE_NAMESPACE(MAction) + MODULE_REGISTER_NS(WilsonClover2AS, TWilsonClover, MAction); + END_MODULE_NAMESPACE + END_HADRONS_NAMESPACE + + +int main(int argc, char *argv[]) +{ + // initialization ////////////////////////////////////////////////////////// + Grid_init(&argc, &argv); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); + LOG(Message) << "Grid initialized" << std::endl; + // run setup /////////////////////////////////////////////////////////////// + Application application; + std::vector flavour = {"l", "s"}; + std::vector mass = {-0.01, -0.04}; + double csw = 1.0; + // global parameters + Application::GlobalPar globalPar; + globalPar.trajCounter.start = 1500; + globalPar.trajCounter.end = 1520; + globalPar.trajCounter.step = 20; + globalPar.seed = "1 2 3 4"; + application.setPar(globalPar); + // gauge field + application.createModule("gauge"); + MSource::Point2AS::Par ptPar; + ptPar.position = "0 0 0 0"; + application.createModule("pt", ptPar); + // sink + MSink::ScalarPoint2AS::Par sinkPar; + sinkPar.mom = "0 0 0"; + application.createModule("sink", sinkPar); + + // set fermion boundary conditions to be periodic space, antiperiodic time. + std::string boundary = "1 1 1 -1"; + + for (unsigned int i = 0; i < flavour.size(); ++i) + { + // actions + MAction::WilsonClover2AS::Par actionPar; + actionPar.gauge = "gauge"; + actionPar.mass = mass[i]; + actionPar.csw_r = csw; + actionPar.csw_t = csw; + actionPar.clover_anisotropy.isAnisotropic= false; + actionPar.clover_anisotropy.t_direction = Nd-1 ; + actionPar.clover_anisotropy.xi_0 = 1.0 ; + actionPar.clover_anisotropy.nu = 1.0 ; + actionPar.boundary = boundary; + application.createModule("WilsonClover2AS_" + flavour[i], actionPar); + + // solvers + MSolver::RBPrecCG2AS::Par solverPar; + solverPar.action = "WilsonClover2AS_" + flavour[i]; + solverPar.residual = 1.0e-8; + application.createModule("CG_" + flavour[i], + solverPar); + + // propagators + MFermion::GaugeProp2AS::Par quarkPar; + quarkPar.solver = "CG_" + flavour[i]; + quarkPar.source = "pt"; + application.createModule("Qpt_" + flavour[i], quarkPar); + quarkPar.source = "z2"; + application.createModule("QZ2_" + flavour[i], quarkPar); + } + for (unsigned int i = 0; i < flavour.size(); ++i) + for (unsigned int j = i; j < flavour.size(); ++j) + { + MContraction::Meson2AS::Par mesPar; + + mesPar.output = "mesons2AS/pt_" + flavour[i] + flavour[j]; + mesPar.q1 = "Qpt_" + flavour[i]; + mesPar.q2 = "Qpt_" + flavour[j]; + mesPar.gammas = "all"; + mesPar.sink = "sink"; + application.createModule("meson_pt_" + + flavour[i] + flavour[j], + mesPar); + + // mesPar.output = "mesons2AS/Z2_" + flavour[i] + flavour[j]; + // mesPar.q1 = "QZ2_" + flavour[i]; + // mesPar.q2 = "QZ2_" + flavour[j]; + // mesPar.gammas = "all"; + // mesPar.sink = "sink"; + // application.createModule("meson_Z2_" + // + flavour[i] + flavour[j], + // mesPar); + } + for (unsigned int i = 0; i < flavour.size(); ++i) + for (unsigned int j = i; j < flavour.size(); ++j) + for (unsigned int k = j; k < flavour.size(); ++k) + { + MContraction::Baryon::Par barPar; + + barPar.output = "baryons/pt_" + flavour[i] + flavour[j] + flavour[k]; + barPar.q1 = "Qpt_" + flavour[i]; + barPar.q2 = "Qpt_" + flavour[j]; + barPar.q3 = "Qpt_" + flavour[k]; + application.createModule( + "baryon_pt_" + flavour[i] + flavour[j] + flavour[k], barPar); + } + + // execution + application.saveParameterFile("spectrum.xml"); + application.run(); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} diff --git a/tests/lanczos/Test_WCMultiRep_lanczos.cc b/tests/lanczos/Test_WCMultiRep_lanczos.cc new file mode 100644 index 00000000..e8549234 --- /dev/null +++ b/tests/lanczos/Test_WCMultiRep_lanczos.cc @@ -0,0 +1,108 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./tests/Test_dwf_lanczos.cc + +Copyright (C) 2015 + +Author: Peter Boyle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution +directory +*************************************************************************************/ +/* END LEGAL */ +#include + +using namespace std; +using namespace Grid; +using namespace Grid::QCD; + +typedef WilsonFermionR FermionOp; +typedef typename WilsonFermionR::FermionField FermionField; + + +RealD AllZero(RealD x) { return 0.; } + +int main(int argc, char** argv) { + Grid_init(&argc, &argv); + + GridCartesian* UGrid = SpaceTimeGrid::makeFourDimGrid( + GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()), + GridDefaultMpi()); + GridRedBlackCartesian* UrbGrid = + SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); + GridCartesian* FGrid = UGrid; + GridRedBlackCartesian* FrbGrid = UrbGrid; + printf("UGrid=%p UrbGrid=%p FGrid=%p FrbGrid=%p\n", UGrid, UrbGrid, FGrid, + FrbGrid); + + std::vector seeds4({1, 2, 3, 4}); + std::vector seeds5({5, 6, 7, 8}); + GridParallelRNG RNG5(FGrid); + RNG5.SeedFixedIntegers(seeds5); + GridParallelRNG RNG4(UGrid); + RNG4.SeedFixedIntegers(seeds4); + GridParallelRNG RNG5rb(FrbGrid); + RNG5.SeedFixedIntegers(seeds5); + + LatticeGaugeField Umu(UGrid); + SU3::HotConfiguration(RNG4, Umu); + +/* + std::vector U(4, UGrid); + for (int mu = 0; mu < Nd; mu++) { + U[mu] = PeekIndex(Umu, mu); + } +*/ + + RealD mass = -0.1; + RealD M5 = 1.8; + RealD mob_b = 1.5; + FermionOp WilsonOperator(Umu,*FGrid,*FrbGrid,mass); + MdagMLinearOperator HermOp(WilsonOperator); /// <----- + //SchurDiagTwoOperator HermOp(WilsonOperator); + + const int Nstop = 20; + const int Nk = 60; + const int Np = 60; + const int Nm = Nk + Np; + const int MaxIt = 10000; + RealD resid = 1.0e-6; + + std::vector Coeffs{0, 1.}; + Polynomial PolyX(Coeffs); + Chebyshev Cheb(0.0, 10., 12); + ImplicitlyRestartedLanczos IRL(HermOp, PolyX, Nstop, Nk, Nm, + resid, MaxIt); + + std::vector eval(Nm); + FermionField src(FGrid); + gaussian(RNG5, src); + std::vector evec(Nm, FGrid); + for (int i = 0; i < 1; i++) { + std::cout << i << " / " << Nm << " grid pointer " << evec[i]._grid + << std::endl; + }; + + int Nconv; + IRL.calc(eval, evec, src, Nconv); + + std::cout << eval << std::endl; + + Grid_finalize(); +} From 185da83454961773a4666d4fff45724abb426f5b Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 26 Dec 2017 14:05:17 +0100 Subject: [PATCH 118/174] Hadrons: new MIO module namespace, NERSC loader moved there --- extras/Hadrons/Modules.hpp | 9 +++--- .../{MGauge/Load.cc => MIO/LoadNersc.cc} | 25 +++++++--------- .../{MGauge/Load.hpp => MIO/LoadNersc.hpp} | 30 ++++++++----------- extras/Hadrons/modules.inc | 8 ++--- 4 files changed, 32 insertions(+), 40 deletions(-) rename extras/Hadrons/Modules/{MGauge/Load.cc => MIO/LoadNersc.cc} (81%) rename extras/Hadrons/Modules/{MGauge/Load.hpp => MIO/LoadNersc.hpp} (75%) diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index cf381d0f..3ae2f9a7 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -2,13 +2,12 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: extras/Hadrons/Modules.hpp +Source file: Modules.hpp -Copyright (C) 2015 -Copyright (C) 2016 -Copyright (C) 2017 +Copyright (C) 2015-2018 Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,7 +45,6 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include -#include #include #include #include @@ -58,3 +56,4 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include +#include diff --git a/extras/Hadrons/Modules/MGauge/Load.cc b/extras/Hadrons/Modules/MIO/LoadNersc.cc similarity index 81% rename from extras/Hadrons/Modules/MGauge/Load.cc rename to extras/Hadrons/Modules/MIO/LoadNersc.cc index b168a010..2c35d2e1 100644 --- a/extras/Hadrons/Modules/MGauge/Load.cc +++ b/extras/Hadrons/Modules/MIO/LoadNersc.cc @@ -2,12 +2,10 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: extras/Hadrons/Modules/MGauge/Load.cc +Source file: LoadNersc.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 -Author: Antonin Portelli This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,30 +24,29 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ - -#include +#include using namespace Grid; using namespace Hadrons; -using namespace MGauge; +using namespace MIO; /****************************************************************************** -* TLoad implementation * +* TLoadNersc implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// -TLoad::TLoad(const std::string name) -: Module(name) +TLoadNersc::TLoadNersc(const std::string name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// -std::vector TLoad::getInput(void) +std::vector TLoadNersc::getInput(void) { std::vector in; return in; } -std::vector TLoad::getOutput(void) +std::vector TLoadNersc::getOutput(void) { std::vector out = {getName()}; @@ -57,13 +54,13 @@ std::vector TLoad::getOutput(void) } // setup /////////////////////////////////////////////////////////////////////// -void TLoad::setup(void) +void TLoadNersc::setup(void) { envCreateLat(LatticeGaugeField, getName()); } // execution /////////////////////////////////////////////////////////////////// -void TLoad::execute(void) +void TLoadNersc::execute(void) { FieldMetaData header; std::string fileName = par().file + "." diff --git a/extras/Hadrons/Modules/MGauge/Load.hpp b/extras/Hadrons/Modules/MIO/LoadNersc.hpp similarity index 75% rename from extras/Hadrons/Modules/MGauge/Load.hpp rename to extras/Hadrons/Modules/MIO/LoadNersc.hpp index a338af79..5bd251c3 100644 --- a/extras/Hadrons/Modules/MGauge/Load.hpp +++ b/extras/Hadrons/Modules/MIO/LoadNersc.hpp @@ -2,12 +2,10 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: extras/Hadrons/Modules/MGauge/Load.hpp +Source file: LoadNersc.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 -Author: Antonin Portelli This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,9 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc., See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ - -#ifndef Hadrons_MGauge_Load_hpp_ -#define Hadrons_MGauge_Load_hpp_ +#ifndef Hadrons_MIO_LoadNersc_hpp_ +#define Hadrons_MIO_LoadNersc_hpp_ #include #include @@ -37,38 +34,37 @@ See the full license in the file "LICENSE" in the top level distribution directo BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * Load a NERSC configuration * + * Load a NERSC configuration * ******************************************************************************/ -BEGIN_MODULE_NAMESPACE(MGauge) +BEGIN_MODULE_NAMESPACE(MIO) -class LoadPar: Serializable +class LoadNerscPar: Serializable { public: - GRID_SERIALIZABLE_CLASS_MEMBERS(LoadPar, + GRID_SERIALIZABLE_CLASS_MEMBERS(LoadNerscPar, std::string, file); }; -class TLoad: public Module +class TLoadNersc: public Module { public: // constructor - TLoad(const std::string name); + TLoadNersc(const std::string name); // destructor - virtual ~TLoad(void) = default; + virtual ~TLoadNersc(void) = default; // dependency relation virtual std::vector getInput(void); virtual std::vector getOutput(void); -protected: // setup virtual void setup(void); // execution virtual void execute(void); }; -MODULE_REGISTER_NS(Load, TLoad, MGauge); +MODULE_REGISTER_NS(LoadNersc, TLoadNersc, MIO); END_MODULE_NAMESPACE END_HADRONS_NAMESPACE -#endif // Hadrons_MGauge_Load_hpp_ +#endif // Hadrons_MIO_LoadNersc_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 199bb5cd..85fa0971 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -2,12 +2,12 @@ modules_cc =\ Modules/MContraction/WeakHamiltonianEye.cc \ Modules/MContraction/WeakNeutral4ptDisc.cc \ Modules/MContraction/WeakHamiltonianNonEye.cc \ - Modules/MGauge/Load.cc \ Modules/MGauge/Unit.cc \ Modules/MGauge/StochEm.cc \ Modules/MGauge/Random.cc \ Modules/MScalar/FreeProp.cc \ - Modules/MScalar/ChargedProp.cc + Modules/MScalar/ChargedProp.cc \ + Modules/MIO/LoadNersc.cc modules_hpp =\ Modules/MContraction/Baryon.hpp \ @@ -28,7 +28,6 @@ modules_hpp =\ Modules/MSink/Smear.hpp \ Modules/MSink/Point.hpp \ Modules/MSolver/RBPrecCG.hpp \ - Modules/MGauge/Load.hpp \ Modules/MGauge/Unit.hpp \ Modules/MGauge/Random.hpp \ Modules/MGauge/StochEm.hpp \ @@ -39,5 +38,6 @@ modules_hpp =\ Modules/MScalar/Scalar.hpp \ Modules/MScalar/ChargedProp.hpp \ Modules/MAction/DWF.hpp \ - Modules/MAction/Wilson.hpp + Modules/MAction/Wilson.hpp \ + Modules/MIO/LoadNersc.hpp From 8b30c5956c7e78250303a1a80e6fd0cd79a7682a Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 26 Dec 2017 14:16:47 +0100 Subject: [PATCH 119/174] Hadrons: copyright update --- extras/Hadrons/Application.cc | 3 +- extras/Hadrons/Application.hpp | 3 +- extras/Hadrons/Environment.cc | 3 +- extras/Hadrons/Environment.hpp | 3 +- extras/Hadrons/Exceptions.cc | 4 +-- extras/Hadrons/Exceptions.hpp | 2 +- extras/Hadrons/Factory.hpp | 3 +- extras/Hadrons/GeneticScheduler.hpp | 3 +- extras/Hadrons/Global.cc | 3 +- extras/Hadrons/Global.hpp | 4 +-- extras/Hadrons/Graph.hpp | 3 +- extras/Hadrons/HadronsXmlRun.cc | 3 +- extras/Hadrons/HadronsXmlSchedule.cc | 3 +- extras/Hadrons/Module.cc | 3 +- extras/Hadrons/Module.hpp | 3 +- extras/Hadrons/ModuleFactory.hpp | 3 +- extras/Hadrons/Modules.hpp | 2 +- extras/Hadrons/Modules/MAction/DWF.hpp | 4 +-- extras/Hadrons/Modules/MAction/Wilson.hpp | 4 +-- .../Hadrons/Modules/MContraction/Baryon.hpp | 4 +-- .../Hadrons/Modules/MContraction/DiscLoop.hpp | 5 ++-- .../Hadrons/Modules/MContraction/Gamma3pt.hpp | 5 ++-- extras/Hadrons/Modules/MContraction/Meson.hpp | 6 ++-- .../Modules/MContraction/WardIdentity.hpp | 5 ++-- .../Modules/MContraction/WeakHamiltonian.hpp | 5 ++-- .../MContraction/WeakHamiltonianEye.cc | 5 ++-- .../MContraction/WeakHamiltonianEye.hpp | 5 ++-- .../MContraction/WeakHamiltonianNonEye.cc | 5 ++-- .../MContraction/WeakHamiltonianNonEye.hpp | 5 ++-- .../MContraction/WeakNeutral4ptDisc.cc | 5 ++-- .../MContraction/WeakNeutral4ptDisc.hpp | 5 ++-- extras/Hadrons/Modules/MFermion/GaugeProp.hpp | 6 ++-- extras/Hadrons/Modules/MGauge/Random.cc | 3 +- extras/Hadrons/Modules/MGauge/Random.hpp | 3 +- extras/Hadrons/Modules/MGauge/StochEm.cc | 4 +-- extras/Hadrons/Modules/MGauge/StochEm.hpp | 4 +-- extras/Hadrons/Modules/MGauge/Unit.cc | 3 +- extras/Hadrons/Modules/MGauge/Unit.hpp | 3 +- extras/Hadrons/Modules/MIO/LoadNersc.cc | 3 +- extras/Hadrons/Modules/MIO/LoadNersc.hpp | 3 +- extras/Hadrons/Modules/MLoop/NoiseLoop.hpp | 5 ++-- extras/Hadrons/Modules/MScalar/ChargedProp.cc | 28 +++++++++++++++++++ .../Hadrons/Modules/MScalar/ChargedProp.hpp | 27 ++++++++++++++++++ extras/Hadrons/Modules/MScalar/FreeProp.cc | 27 ++++++++++++++++++ extras/Hadrons/Modules/MScalar/FreeProp.hpp | 27 ++++++++++++++++++ extras/Hadrons/Modules/MScalar/Scalar.hpp | 27 ++++++++++++++++++ extras/Hadrons/Modules/MSink/Point.hpp | 3 +- extras/Hadrons/Modules/MSink/Smear.hpp | 5 ++-- extras/Hadrons/Modules/MSolver/RBPrecCG.hpp | 3 +- extras/Hadrons/Modules/MSource/Point.hpp | 4 +-- .../Hadrons/Modules/MSource/SeqConserved.hpp | 7 +++-- extras/Hadrons/Modules/MSource/SeqGamma.hpp | 5 ++-- extras/Hadrons/Modules/MSource/Wall.hpp | 5 ++-- extras/Hadrons/Modules/MSource/Z2.hpp | 3 +- .../Modules/MUtilities/TestSeqConserved.hpp | 5 ++-- .../Modules/MUtilities/TestSeqGamma.hpp | 5 ++-- extras/Hadrons/VirtualMachine.cc | 2 +- extras/Hadrons/VirtualMachine.hpp | 2 +- scripts/copyright | 5 ++-- 59 files changed, 238 insertions(+), 108 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 9a3366d4..6d5d6776 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Application.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index 4b2ce77b..8cd15433 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Application.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 6de13e86..82b0dda1 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Environment.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 7f1bc26d..e9bfffe1 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Environment.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Exceptions.cc b/extras/Hadrons/Exceptions.cc index bf532c21..eedc03b1 100644 --- a/extras/Hadrons/Exceptions.cc +++ b/extras/Hadrons/Exceptions.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Exceptions.cc -Copyright (C) 2017 +Copyright (C) 2015-2018 Author: Antonin Portelli @@ -54,4 +54,4 @@ CONST_EXC(Io, Runtime("IO error: " + msg, loc)) CONST_EXC(Memory, Runtime("memory error: " + msg, loc)) CONST_EXC(Parsing, Runtime("parsing error: " + msg, loc)) CONST_EXC(Program, Runtime("program error: " + msg, loc)) -CONST_EXC(System, Runtime("system error: " + msg, loc)) \ No newline at end of file +CONST_EXC(System, Runtime("system error: " + msg, loc)) diff --git a/extras/Hadrons/Exceptions.hpp b/extras/Hadrons/Exceptions.hpp index 8f04ab41..ab588e5e 100644 --- a/extras/Hadrons/Exceptions.hpp +++ b/extras/Hadrons/Exceptions.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Exceptions.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Factory.hpp b/extras/Hadrons/Factory.hpp index 65ce03ca..705a639e 100644 --- a/extras/Hadrons/Factory.hpp +++ b/extras/Hadrons/Factory.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Factory.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/GeneticScheduler.hpp b/extras/Hadrons/GeneticScheduler.hpp index f199f1ed..9a6476c3 100644 --- a/extras/Hadrons/GeneticScheduler.hpp +++ b/extras/Hadrons/GeneticScheduler.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/GeneticScheduler.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Global.cc b/extras/Hadrons/Global.cc index 130ede96..fc41424c 100644 --- a/extras/Hadrons/Global.cc +++ b/extras/Hadrons/Global.cc @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Global.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index ebfe94dc..1b4e5f9a 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Global.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Graph.hpp b/extras/Hadrons/Graph.hpp index a9c240fa..67694aa8 100644 --- a/extras/Hadrons/Graph.hpp +++ b/extras/Hadrons/Graph.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Graph.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/HadronsXmlRun.cc b/extras/Hadrons/HadronsXmlRun.cc index 0dff8f9a..07eb096e 100644 --- a/extras/Hadrons/HadronsXmlRun.cc +++ b/extras/Hadrons/HadronsXmlRun.cc @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/HadronsXmlRun.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/HadronsXmlSchedule.cc b/extras/Hadrons/HadronsXmlSchedule.cc index a8ca9a63..6b167690 100644 --- a/extras/Hadrons/HadronsXmlSchedule.cc +++ b/extras/Hadrons/HadronsXmlSchedule.cc @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/HadronsXmlSchedule.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Module.cc b/extras/Hadrons/Module.cc index e5ef0fe4..54978f93 100644 --- a/extras/Hadrons/Module.cc +++ b/extras/Hadrons/Module.cc @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Module.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index b71f779d..2ba425e4 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Module.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/ModuleFactory.hpp b/extras/Hadrons/ModuleFactory.hpp index 48ab305c..d5c703fa 100644 --- a/extras/Hadrons/ModuleFactory.hpp +++ b/extras/Hadrons/ModuleFactory.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/ModuleFactory.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 3ae2f9a7..7f7c5dc7 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -2,7 +2,7 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: Modules.hpp +Source file: extras/Hadrons/Modules.hpp Copyright (C) 2015-2018 diff --git a/extras/Hadrons/Modules/MAction/DWF.hpp b/extras/Hadrons/Modules/MAction/DWF.hpp index d99f1165..4dfd06cf 100644 --- a/extras/Hadrons/Modules/MAction/DWF.hpp +++ b/extras/Hadrons/Modules/MAction/DWF.hpp @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MAction/DWF.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MAction/Wilson.hpp b/extras/Hadrons/Modules/MAction/Wilson.hpp index 8ef755bb..6467b3ee 100644 --- a/extras/Hadrons/Modules/MAction/Wilson.hpp +++ b/extras/Hadrons/Modules/MAction/Wilson.hpp @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MAction/Wilson.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/Baryon.hpp b/extras/Hadrons/Modules/MContraction/Baryon.hpp index 1ef2e257..625c7108 100644 --- a/extras/Hadrons/Modules/MContraction/Baryon.hpp +++ b/extras/Hadrons/Modules/MContraction/Baryon.hpp @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/Baryon.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp index ef50061c..3d08f0eb 100644 --- a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp +++ b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/DiscLoop.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp index fb9a9d4b..68701aeb 100644 --- a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp +++ b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/Gamma3pt.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 46bbdb2e..5cf504e3 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -4,12 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/Meson.hpp -Copyright (C) 2015 -Copyright (C) 2016 -Copyright (C) 2017 +Copyright (C) 2015-2018 Author: Antonin Portelli - Andrew Lawson +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp index 556450a8..2801d88c 100644 --- a/extras/Hadrons/Modules/MContraction/WardIdentity.hpp +++ b/extras/Hadrons/Modules/MContraction/WardIdentity.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/WardIdentity.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp index 7df40370..9d8ada98 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc index 43dfa609..b79c09e7 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp index 3a2b9309..24f39f6c 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc index 8a7113e3..e66b6ee7 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp index eb5abe3c..c4cd66f1 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc index 18423f3e..e0a00472 100644 --- a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc +++ b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp index f26d4636..5de2a751 100644 --- a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp +++ b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp index 05b3d17a..33787a0b 100644 --- a/extras/Hadrons/Modules/MFermion/GaugeProp.hpp +++ b/extras/Hadrons/Modules/MFermion/GaugeProp.hpp @@ -4,12 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MFermion/GaugeProp.hpp -Copyright (C) 2015 -Copyright (C) 2016 -Copyright (C) 2017 +Copyright (C) 2015-2018 Author: Antonin Portelli - Andrew Lawson +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MGauge/Random.cc b/extras/Hadrons/Modules/MGauge/Random.cc index 97afd338..962fc243 100644 --- a/extras/Hadrons/Modules/MGauge/Random.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MGauge/Random.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Modules/MGauge/Random.hpp b/extras/Hadrons/Modules/MGauge/Random.hpp index a07130e4..51a08dbb 100644 --- a/extras/Hadrons/Modules/MGauge/Random.hpp +++ b/extras/Hadrons/Modules/MGauge/Random.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MGauge/Random.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Modules/MGauge/StochEm.cc b/extras/Hadrons/Modules/MGauge/StochEm.cc index c5318573..21b7f626 100644 --- a/extras/Hadrons/Modules/MGauge/StochEm.cc +++ b/extras/Hadrons/Modules/MGauge/StochEm.cc @@ -4,9 +4,9 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MGauge/StochEm.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 +Author: Antonin Portelli This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MGauge/StochEm.hpp b/extras/Hadrons/Modules/MGauge/StochEm.hpp index bacb5172..87b70880 100644 --- a/extras/Hadrons/Modules/MGauge/StochEm.hpp +++ b/extras/Hadrons/Modules/MGauge/StochEm.hpp @@ -4,9 +4,9 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MGauge/StochEm.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 +Author: Antonin Portelli This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index 8bee1ecc..38b5f3aa 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MGauge/Unit.cc -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Modules/MGauge/Unit.hpp b/extras/Hadrons/Modules/MGauge/Unit.hpp index c1650cc7..d6ce5a6b 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.hpp +++ b/extras/Hadrons/Modules/MGauge/Unit.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MGauge/Unit.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Modules/MIO/LoadNersc.cc b/extras/Hadrons/Modules/MIO/LoadNersc.cc index 2c35d2e1..f20606fc 100644 --- a/extras/Hadrons/Modules/MIO/LoadNersc.cc +++ b/extras/Hadrons/Modules/MIO/LoadNersc.cc @@ -2,10 +2,11 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: LoadNersc.cc +Source file: extras/Hadrons/Modules/MIO/LoadNersc.cc Copyright (C) 2015-2018 +Author: Antonin Portelli This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MIO/LoadNersc.hpp b/extras/Hadrons/Modules/MIO/LoadNersc.hpp index 5bd251c3..d6742e1e 100644 --- a/extras/Hadrons/Modules/MIO/LoadNersc.hpp +++ b/extras/Hadrons/Modules/MIO/LoadNersc.hpp @@ -2,10 +2,11 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: LoadNersc.hpp +Source file: extras/Hadrons/Modules/MIO/LoadNersc.hpp Copyright (C) 2015-2018 +Author: Antonin Portelli This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp b/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp index 512c731a..e61bf163 100644 --- a/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp +++ b/extras/Hadrons/Modules/MLoop/NoiseLoop.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MLoop/NoiseLoop.hpp -Copyright (C) 2016 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MScalar/ChargedProp.cc b/extras/Hadrons/Modules/MScalar/ChargedProp.cc index 6cb75a28..da82617f 100644 --- a/extras/Hadrons/Modules/MScalar/ChargedProp.cc +++ b/extras/Hadrons/Modules/MScalar/ChargedProp.cc @@ -1,3 +1,31 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MScalar/ChargedProp.cc + +Copyright (C) 2015-2018 + +Author: Antonin Portelli +Author: James Harrison + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #include #include diff --git a/extras/Hadrons/Modules/MScalar/ChargedProp.hpp b/extras/Hadrons/Modules/MScalar/ChargedProp.hpp index cfcce28e..4d43aec2 100644 --- a/extras/Hadrons/Modules/MScalar/ChargedProp.hpp +++ b/extras/Hadrons/Modules/MScalar/ChargedProp.hpp @@ -1,3 +1,30 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MScalar/ChargedProp.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_MScalar_ChargedProp_hpp_ #define Hadrons_MScalar_ChargedProp_hpp_ diff --git a/extras/Hadrons/Modules/MScalar/FreeProp.cc b/extras/Hadrons/Modules/MScalar/FreeProp.cc index 924db288..ee86b9db 100644 --- a/extras/Hadrons/Modules/MScalar/FreeProp.cc +++ b/extras/Hadrons/Modules/MScalar/FreeProp.cc @@ -1,3 +1,30 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MScalar/FreeProp.cc + +Copyright (C) 2015-2018 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #include #include diff --git a/extras/Hadrons/Modules/MScalar/FreeProp.hpp b/extras/Hadrons/Modules/MScalar/FreeProp.hpp index 6b956134..df17f44e 100644 --- a/extras/Hadrons/Modules/MScalar/FreeProp.hpp +++ b/extras/Hadrons/Modules/MScalar/FreeProp.hpp @@ -1,3 +1,30 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MScalar/FreeProp.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_MScalar_FreeProp_hpp_ #define Hadrons_MScalar_FreeProp_hpp_ diff --git a/extras/Hadrons/Modules/MScalar/Scalar.hpp b/extras/Hadrons/Modules/MScalar/Scalar.hpp index db702ff2..7272f1b3 100644 --- a/extras/Hadrons/Modules/MScalar/Scalar.hpp +++ b/extras/Hadrons/Modules/MScalar/Scalar.hpp @@ -1,3 +1,30 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MScalar/Scalar.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_Scalar_hpp_ #define Hadrons_Scalar_hpp_ diff --git a/extras/Hadrons/Modules/MSink/Point.hpp b/extras/Hadrons/Modules/MSink/Point.hpp index 43be3009..c5f6eff0 100644 --- a/extras/Hadrons/Modules/MSink/Point.hpp +++ b/extras/Hadrons/Modules/MSink/Point.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MSink/Point.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MSink/Smear.hpp b/extras/Hadrons/Modules/MSink/Smear.hpp index e85ab263..e72dece0 100644 --- a/extras/Hadrons/Modules/MSink/Smear.hpp +++ b/extras/Hadrons/Modules/MSink/Smear.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MSink/Smear.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp index bb4f3f62..54c0f2d8 100644 --- a/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp +++ b/extras/Hadrons/Modules/MSolver/RBPrecCG.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MSolver/RBPrecCG.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Modules/MSource/Point.hpp b/extras/Hadrons/Modules/MSource/Point.hpp index 1d8241cf..ac6df252 100644 --- a/extras/Hadrons/Modules/MSource/Point.hpp +++ b/extras/Hadrons/Modules/MSource/Point.hpp @@ -4,10 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MSource/Point.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MSource/SeqConserved.hpp b/extras/Hadrons/Modules/MSource/SeqConserved.hpp index 3e8ef457..ee8d8d56 100644 --- a/extras/Hadrons/Modules/MSource/SeqConserved.hpp +++ b/extras/Hadrons/Modules/MSource/SeqConserved.hpp @@ -2,11 +2,12 @@ Grid physics library, www.github.com/paboyle/Grid -Source file: extras/Hadrons/Modules/MContraction/SeqConserved.hpp +Source file: extras/Hadrons/Modules/MSource/SeqConserved.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MSource/SeqGamma.hpp b/extras/Hadrons/Modules/MSource/SeqGamma.hpp index abad5ace..40eda29f 100644 --- a/extras/Hadrons/Modules/MSource/SeqGamma.hpp +++ b/extras/Hadrons/Modules/MSource/SeqGamma.hpp @@ -4,11 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MSource/SeqGamma.hpp -Copyright (C) 2015 -Copyright (C) 2016 -Copyright (C) 2017 +Copyright (C) 2015-2018 Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MSource/Wall.hpp b/extras/Hadrons/Modules/MSource/Wall.hpp index 9d5f1f46..5853b11a 100644 --- a/extras/Hadrons/Modules/MSource/Wall.hpp +++ b/extras/Hadrons/Modules/MSource/Wall.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MSource/Wall.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MSource/Z2.hpp b/extras/Hadrons/Modules/MSource/Z2.hpp index 3593cb34..4414e37f 100644 --- a/extras/Hadrons/Modules/MSource/Z2.hpp +++ b/extras/Hadrons/Modules/MSource/Z2.hpp @@ -4,8 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MSource/Z2.hpp -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp index 0647884c..6ee1e3c2 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MUtilities/TestSeqConserved.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp index fd53eab8..df35d887 100644 --- a/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp +++ b/extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp @@ -4,9 +4,10 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/Modules/MUtilities/TestSeqGamma.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 -Author: Andrew Lawson +Author: Antonin Portelli +Author: Lanny91 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index e0035bc1..d47bafb7 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/VirtualMachine.cc -Copyright (C) 2017 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/extras/Hadrons/VirtualMachine.hpp b/extras/Hadrons/VirtualMachine.hpp index 3af7d914..19a74f94 100644 --- a/extras/Hadrons/VirtualMachine.hpp +++ b/extras/Hadrons/VirtualMachine.hpp @@ -4,7 +4,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: extras/Hadrons/VirtualMachine.hpp -Copyright (C) 2017 +Copyright (C) 2015-2018 Author: Antonin Portelli diff --git a/scripts/copyright b/scripts/copyright index cc9ed6e5..a461b54c 100755 --- a/scripts/copyright +++ b/scripts/copyright @@ -11,8 +11,7 @@ Grid physics library, www.github.com/paboyle/Grid Source file: $1 -Copyright (C) 2015 -Copyright (C) 2016 +Copyright (C) 2015-2018 EOF @@ -60,4 +59,4 @@ shift done - +rm message tmp.fil From e8ac75055c0566fc56663240e07d2d8340ad5799 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 27 Dec 2017 14:24:29 +0100 Subject: [PATCH 120/174] Hadrons: binary configuration loader --- extras/Hadrons/Global.hpp | 6 +- extras/Hadrons/Modules.hpp | 1 + extras/Hadrons/Modules/MIO/LoadBinary.hpp | 140 ++++++++++++++++++++++ extras/Hadrons/modules.inc | 3 +- 4 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 extras/Hadrons/Modules/MIO/LoadBinary.hpp diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 1b4e5f9a..c68edafd 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -61,6 +61,9 @@ using Grid::operator<<; #ifndef SIMPL #define SIMPL ScalarImplCR #endif +#ifndef GIMPL +#define GIMPL GimplTypesR +#endif BEGIN_HADRONS_NAMESPACE @@ -84,7 +87,8 @@ typedef std::function SolverFn##suffix; #define SINK_TYPE_ALIASES(suffix)\ -typedef std::function SinkFn##suffix; +typedef std::function SinkFn##suffix; #define FGS_TYPE_ALIASES(FImpl, suffix)\ FERM_TYPE_ALIASES(FImpl, suffix)\ diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 7f7c5dc7..e50d2b0b 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -57,3 +57,4 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include +#include diff --git a/extras/Hadrons/Modules/MIO/LoadBinary.hpp b/extras/Hadrons/Modules/MIO/LoadBinary.hpp new file mode 100644 index 00000000..5e45dfd8 --- /dev/null +++ b/extras/Hadrons/Modules/MIO/LoadBinary.hpp @@ -0,0 +1,140 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MIO/LoadBinary.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#ifndef Hadrons_MIO_LoadBinary_hpp_ +#define Hadrons_MIO_LoadBinary_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Load a binary configurations * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MIO) + +class LoadBinaryPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(LoadBinaryPar, + std::string, file, + std::string, format); +}; + +template +class TLoadBinary: public Module +{ +public: + typedef typename Impl::Field Field; + typedef typename Impl::Simd Simd; + typedef typename Field::vector_object vobj; + typedef typename vobj::scalar_object sobj; + typedef typename sobj::DoublePrecision sobj_double; + typedef BinarySimpleMunger Munger; +public: + // constructor + TLoadBinary(const std::string name); + // destructor + virtual ~TLoadBinary(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_NS(LoadBinary, TLoadBinary, MIO); +MODULE_REGISTER_NS(LoadBinaryScalarSU2, TLoadBinary>, MIO); +MODULE_REGISTER_NS(LoadBinaryScalarSU3, TLoadBinary>, MIO); +MODULE_REGISTER_NS(LoadBinaryScalarSU4, TLoadBinary>, MIO); +MODULE_REGISTER_NS(LoadBinaryScalarSU5, TLoadBinary>, MIO); +MODULE_REGISTER_NS(LoadBinaryScalarSU6, TLoadBinary>, MIO); + +/****************************************************************************** + * TLoadBinary implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TLoadBinary::TLoadBinary(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TLoadBinary::getInput(void) +{ + std::vector in; + + return in; +} + +template +std::vector TLoadBinary::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TLoadBinary::setup(void) +{ + envCreateLat(Field, getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TLoadBinary::execute(void) +{ + Munger munge; + uint32_t nersc_csum, scidac_csuma, scidac_csumb; + auto &U = envGet(Field, getName()); + std::string filename = par().file + "." + + std::to_string(vm().getTrajectory()); + + LOG(Message) << "Loading " << par().format + << "binary configuration from file '" << filename + << "'" << std::endl; + BinaryIO::readLatticeObject(U, filename, munge, 0, + par().format, nersc_csum, + scidac_csuma, scidac_csumb); + LOG(Message) << "Checksums:" << std::endl; + LOG(Message) << " NERSC " << nersc_csum << std::endl; + LOG(Message) << " SciDAC A " << scidac_csuma << std::endl; + LOG(Message) << " SciDAC B " << scidac_csumb << std::endl; +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MIO_LoadBinary_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 85fa0971..6e1ef6dc 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -39,5 +39,6 @@ modules_hpp =\ Modules/MScalar/ChargedProp.hpp \ Modules/MAction/DWF.hpp \ Modules/MAction/Wilson.hpp \ - Modules/MIO/LoadNersc.hpp + Modules/MIO/LoadNersc.hpp \ + Modules/MIO/LoadBinary.hpp From 0d612039ed4c16c5dc0234bc243a631f6e7173b8 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 29 Dec 2017 16:58:23 +0100 Subject: [PATCH 121/174] Hadrons: prettier Grid logging (non-intrusive) --- extras/Hadrons/Application.cc | 1 + extras/Hadrons/Global.cc | 15 +++++++++++++++ extras/Hadrons/Global.hpp | 2 ++ extras/Hadrons/HadronsXmlRun.cc | 6 ------ extras/Hadrons/HadronsXmlSchedule.cc | 6 ------ lib/log/Log.h | 9 ++++++++- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 6d5d6776..7ba98ade 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -42,6 +42,7 @@ using namespace Hadrons; // constructors //////////////////////////////////////////////////////////////// Application::Application(void) { + initLogger(); LOG(Message) << "Modules available:" << std::endl; auto list = ModuleFactory::getInstance().getBuilderList(); for (auto &m: list) diff --git a/extras/Hadrons/Global.cc b/extras/Hadrons/Global.cc index fc41424c..942a4243 100644 --- a/extras/Hadrons/Global.cc +++ b/extras/Hadrons/Global.cc @@ -38,6 +38,21 @@ HadronsLogger Hadrons::HadronsLogMessage(1,"Message"); HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative"); HadronsLogger Hadrons::HadronsLogDebug(1,"Debug"); +void Hadrons::initLogger(void) +{ + auto w = std::string("Hadrons").length(); + GridLogError.setTopWidth(w); + GridLogWarning.setTopWidth(w); + GridLogMessage.setTopWidth(w); + GridLogIterative.setTopWidth(w); + GridLogDebug.setTopWidth(w); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); +} + // type utilities ////////////////////////////////////////////////////////////// constexpr unsigned int maxNameSize = 1024u; diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index c68edafd..274e1934 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -112,6 +112,8 @@ extern HadronsLogger HadronsLogMessage; extern HadronsLogger HadronsLogIterative; extern HadronsLogger HadronsLogDebug; +void initLogger(void); + // singleton pattern #define SINGLETON(name)\ public:\ diff --git a/extras/Hadrons/HadronsXmlRun.cc b/extras/Hadrons/HadronsXmlRun.cc index 07eb096e..680f234b 100644 --- a/extras/Hadrons/HadronsXmlRun.cc +++ b/extras/Hadrons/HadronsXmlRun.cc @@ -54,12 +54,6 @@ int main(int argc, char *argv[]) // initialization Grid_init(&argc, &argv); - HadronsLogError.Active(GridLogError.isActive()); - HadronsLogWarning.Active(GridLogWarning.isActive()); - HadronsLogMessage.Active(GridLogMessage.isActive()); - HadronsLogIterative.Active(GridLogIterative.isActive()); - HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << std::endl; // execution Application application(parameterFileName); diff --git a/extras/Hadrons/HadronsXmlSchedule.cc b/extras/Hadrons/HadronsXmlSchedule.cc index 6b167690..55f3b231 100644 --- a/extras/Hadrons/HadronsXmlSchedule.cc +++ b/extras/Hadrons/HadronsXmlSchedule.cc @@ -48,12 +48,6 @@ int main(int argc, char *argv[]) // initialization Grid_init(&argc, &argv); - HadronsLogError.Active(GridLogError.isActive()); - HadronsLogWarning.Active(GridLogWarning.isActive()); - HadronsLogMessage.Active(GridLogMessage.isActive()); - HadronsLogIterative.Active(GridLogIterative.isActive()); - HadronsLogDebug.Active(GridLogDebug.isActive()); - LOG(Message) << "Grid initialized" << std::endl; // execution Application application; diff --git a/lib/log/Log.h b/lib/log/Log.h index ddff4c1d..011a7250 100644 --- a/lib/log/Log.h +++ b/lib/log/Log.h @@ -86,6 +86,7 @@ protected: Colours &Painter; int active; int timing_mode; + int topWidth{-1}; static int timestamp; std::string name, topName; std::string COLOUR; @@ -124,11 +125,17 @@ public: Reset(); } } + void setTopWidth(const int w) {topWidth = w;} friend std::ostream& operator<< (std::ostream& stream, Logger& log){ if ( log.active ) { - stream << log.background()<< std::left << log.topName << log.background()<< " : "; + stream << log.background()<< std::left; + if (log.topWidth > 0) + { + stream << std::setw(log.topWidth); + } + stream << log.topName << log.background()<< " : "; stream << log.colour() << std::left << log.name << log.background() << " : "; if ( log.timestamp ) { log.StopWatch->Stop(); From dd62f2f371cce3236f4e38dfd8502b0a68fa01ba Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 29 Dec 2017 16:58:44 +0100 Subject: [PATCH 122/174] Hadrons: log message fix --- extras/Hadrons/Modules/MIO/LoadBinary.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/Hadrons/Modules/MIO/LoadBinary.hpp b/extras/Hadrons/Modules/MIO/LoadBinary.hpp index 5e45dfd8..d9a8b5f8 100644 --- a/extras/Hadrons/Modules/MIO/LoadBinary.hpp +++ b/extras/Hadrons/Modules/MIO/LoadBinary.hpp @@ -122,7 +122,7 @@ void TLoadBinary::execute(void) + std::to_string(vm().getTrajectory()); LOG(Message) << "Loading " << par().format - << "binary configuration from file '" << filename + << " binary configuration from file '" << filename << "'" << std::endl; BinaryIO::readLatticeObject(U, filename, munge, 0, par().format, nersc_csum, From 9028e278e4ededffb45b4d2e510c79860d536584 Mon Sep 17 00:00:00 2001 From: David Preti Date: Sat, 6 Jan 2018 15:57:38 +0100 Subject: [PATCH 123/174] Trying to fix a bug with SU4 mesons (still under investigation) --- extras/Hadrons/Modules/MGauge/Load.cc | 3 +- extras/Hadrons/Modules/MGauge/Random.cc | 2 +- extras/Hadrons/Modules/MGauge/Unit.cc | 2 +- tests/hadrons/Test_hadrons_wilsonFund.cc | 160 +++++++++++++++++++++++ 4 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 tests/hadrons/Test_hadrons_wilsonFund.cc diff --git a/extras/Hadrons/Modules/MGauge/Load.cc b/extras/Hadrons/Modules/MGauge/Load.cc index 062e7e98..97be9539 100644 --- a/extras/Hadrons/Modules/MGauge/Load.cc +++ b/extras/Hadrons/Modules/MGauge/Load.cc @@ -66,7 +66,8 @@ void TLoad::setup(void) void TLoad::execute(void) { FieldMetaData header; - std::string fileName = par().file + "." + + std::string fileName = par().file + "ckpoint_lat." + std::to_string(env().getTrajectory()); LOG(Message) << "Loading NERSC configuration from file '" << fileName diff --git a/extras/Hadrons/Modules/MGauge/Random.cc b/extras/Hadrons/Modules/MGauge/Random.cc index c10fdfc3..5c063361 100644 --- a/extras/Hadrons/Modules/MGauge/Random.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -65,5 +65,5 @@ void TRandom::execute(void) { LOG(Message) << "Generating random gauge configuration" << std::endl; LatticeGaugeField &U = *env().createLattice(getName()); - SU3::HotConfiguration(*env().get4dRng(), U); + SU4::HotConfiguration(*env().get4dRng(), U); } diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index 18d75c59..12696ee9 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -65,5 +65,5 @@ void TUnit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; LatticeGaugeField &U = *env().createLattice(getName()); - SU3::ColdConfiguration(*env().get4dRng(), U); + SU4::ColdConfiguration(*env().get4dRng(), U); } diff --git a/tests/hadrons/Test_hadrons_wilsonFund.cc b/tests/hadrons/Test_hadrons_wilsonFund.cc new file mode 100644 index 00000000..aff8a670 --- /dev/null +++ b/tests/hadrons/Test_hadrons_wilsonFund.cc @@ -0,0 +1,160 @@ +/******************************************************************************* + Grid physics library, www.github.com/paboyle/Grid + + Source file: tests/hadrons/Test_hadrons_spectrum.cc + + Copyright (C) 2015 + + Author: Antonin Portelli + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution + directory. + *******************************************************************************/ + +#include + +using namespace Grid; +using namespace Hadrons; + +int main(int argc, char *argv[]) +{ + // initialization ////////////////////////////////////////////////////////// + Grid_init(&argc, &argv); + HadronsLogError.Active(GridLogError.isActive()); + HadronsLogWarning.Active(GridLogWarning.isActive()); + HadronsLogMessage.Active(GridLogMessage.isActive()); + HadronsLogIterative.Active(GridLogIterative.isActive()); + HadronsLogDebug.Active(GridLogDebug.isActive()); + LOG(Message) << "Grid initialized" << std::endl; + + // run setup /////////////////////////////////////////////////////////////// + Application application; + std::vector flavour = {"l"}; + std::vector mass = {-0.1}; + double csw = 0.0; + + // global parameters + Application::GlobalPar globalPar; + + globalPar.trajCounter.start = 1; + globalPar.trajCounter.end = 2; + globalPar.trajCounter.step = 1; + + globalPar.trajCounter.start = 309; + globalPar.trajCounter.end = 310; + globalPar.trajCounter.step = 1; + globalPar.seed = "1 2 3 4"; + application.setPar(globalPar); + // gauge field + application.createModule("gauge"); + //application.createModule("gauge"); + + // sources + //MSource::Z2::Par z2Par; + //z2Par.tA = 0; + //z2Par.tB = 0; + //application.createModule("z2", z2Par); + MSource::Point::Par ptPar; + ptPar.position = "0 0 0 0"; + application.createModule("pt", ptPar); + // sink + MSink::Point::Par sinkPar; + sinkPar.mom = "0 0 0"; + application.createModule("sink", sinkPar); + + // set fermion boundary conditions to be periodic space, antiperiodic time. + std::string boundary = "1 1 1 -1"; + + for (unsigned int i = 0; i < flavour.size(); ++i) + { + // actions + MAction::WilsonClover::Par actionPar; + actionPar.gauge = "gauge"; + actionPar.mass = mass[i]; + actionPar.boundary = boundary; + actionPar.csw_r = csw; + actionPar.csw_t = csw; + + // !!!!! Check if Anisotropy works !!!!! + actionPar.clover_anisotropy.isAnisotropic= false; + actionPar.clover_anisotropy.t_direction = 3 ; // Explicit for D=4 + actionPar.clover_anisotropy.xi_0 = 1.0 ; + actionPar.clover_anisotropy.nu = 1.0 ; + + application.createModule("WilsonClover_" + flavour[i], actionPar); + + // solvers + MSolver::RBPrecCG::Par solverPar; + solverPar.action = "WilsonClover_" + flavour[i]; + solverPar.residual = 1.0e-8; + application.createModule("CG_" + flavour[i], + solverPar); + + // propagators + MFermion::GaugeProp::Par quarkPar; + quarkPar.solver = "CG_" + flavour[i]; + quarkPar.source = "pt"; + application.createModule("Qpt_" + flavour[i], quarkPar); + // quarkPar.source = "z2"; + // application.createModule("QZ2_" + flavour[i], quarkPar); + } + for (unsigned int i = 0; i < flavour.size(); ++i) + for (unsigned int j = i; j < flavour.size(); ++j) + { + MContraction::Meson::Par mesPar; + + mesPar.output = "Fund_mesons/pt_" + flavour[i] + flavour[j]; + mesPar.q1 = "Qpt_" + flavour[i]; + mesPar.q2 = "Qpt_" + flavour[j]; + mesPar.gammas = "all"; + mesPar.sink = "sink"; + application.createModule("meson_pt_" + + flavour[i] + flavour[j], + mesPar); + // mesPar.output = "mesons/Z2_" + flavour[i] + flavour[j]; + // mesPar.q1 = "QZ2_" + flavour[i]; + // mesPar.q2 = "QZ2_" + flavour[j]; + // mesPar.gammas = "all"; + // mesPar.sink = "sink"; + // application.createModule("meson_Z2_" + // + flavour[i] + flavour[j], + // mesPar); + } + for (unsigned int i = 0; i < flavour.size(); ++i) + for (unsigned int j = i; j < flavour.size(); ++j) + for (unsigned int k = j; k < flavour.size(); ++k) + { + MContraction::Baryon::Par barPar; + + barPar.output = "Fund_baryons/pt_" + flavour[i] + flavour[j] + flavour[k]; + barPar.q1 = "Qpt_" + flavour[i]; + barPar.q2 = "Qpt_" + flavour[j]; + barPar.q3 = "Qpt_" + flavour[k]; + application.createModule( + "baryon_pt_" + flavour[i] + flavour[j] + flavour[k], barPar); + } + + // execution + application.saveParameterFile("WilsonClover_spectrum.xml"); + application.run(); + + // epilogue + LOG(Message) << "Grid is finalizing now" << std::endl; + Grid_finalize(); + + return EXIT_SUCCESS; +} From 1a0163f45c43a304271bb9e8a99052c012b4b736 Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:26:11 +0000 Subject: [PATCH 124/174] Updated to do list --- TODO | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index 83bfda5e..95ccf1df 100644 --- a/TODO +++ b/TODO @@ -4,17 +4,17 @@ TODO: Large item work list: 1)- BG/Q port and check ; Andrew says ok. -2)- Christoph's local basis expansion Lanczos --- 3a)- RNG I/O in ILDG/SciDAC (minor) -3b)- Precision conversion and sort out localConvert <-- partial/easy 3c)- Consistent linear solver flop count/rate -- PARTIAL, time but no flop/s yet 4)- Physical propagator interface -5)- Conserved currents 6)- Multigrid Wilson and DWF, compare to other Multigrid implementations 7)- HDCR resume - +---------------------------- Recent DONE +-- Precision conversion and sort out localConvert <-- partial/easy +-- Conserved currents (Andrew) +-- Split grid +-- Christoph's local basis expansion Lanczos -- MultiRHS with spread out extra dim -- Go through filesystem with SciDAC I/O ; <-- DONE ; bmark cori -- Lanczos Remove DenseVector, DenseMatrix; Use Eigen instead. <-- DONE -- GaugeFix into central location <-- DONE From 7b3ed160aa22c11cfb8e5acbd7e4414a4d718305 Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:26:48 +0000 Subject: [PATCH 125/174] Rationalise MPI options --- configure.ac | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/configure.ac b/configure.ac index 496f7fd7..468d9d5f 100644 --- a/configure.ac +++ b/configure.ac @@ -337,15 +337,11 @@ case ${ac_PRECISION} in esac ###################### Shared memory allocation technique under MPI3 -AC_ARG_ENABLE([shm],[AC_HELP_STRING([--enable-shm=shmget|shmopen|hugetlbfs], +AC_ARG_ENABLE([shm],[AC_HELP_STRING([--enable-shm=shmopen|hugetlbfs], [Select SHM allocation technique])],[ac_SHM=${enable_shm}],[ac_SHM=shmopen]) case ${ac_SHM} in - shmget) - AC_DEFINE([GRID_MPI3_SHMGET],[1],[GRID_MPI3_SHMGET] ) - ;; - shmopen) AC_DEFINE([GRID_MPI3_SHMOPEN],[1],[GRID_MPI3_SHMOPEN] ) ;; @@ -367,7 +363,7 @@ AC_ARG_ENABLE([shmpath],[AC_HELP_STRING([--enable-shmpath=path], AC_DEFINE_UNQUOTED([GRID_SHM_PATH],["$ac_SHMPATH"],[Path to a hugetlbfs filesystem for MMAPing]) ############### communication type selection -AC_ARG_ENABLE([comms],[AC_HELP_STRING([--enable-comms=none|mpi|mpi-auto|mpi3|mpi3-auto|shmem], +AC_ARG_ENABLE([comms],[AC_HELP_STRING([--enable-comms=none|mpi|mpi-auto], [Select communications])],[ac_COMMS=${enable_comms}],[ac_COMMS=none]) case ${ac_COMMS} in @@ -375,22 +371,10 @@ case ${ac_COMMS} in AC_DEFINE([GRID_COMMS_NONE],[1],[GRID_COMMS_NONE] ) comms_type='none' ;; - mpi3*) + mpi*) AC_DEFINE([GRID_COMMS_MPI3],[1],[GRID_COMMS_MPI3] ) comms_type='mpi3' ;; - mpit) - AC_DEFINE([GRID_COMMS_MPIT],[1],[GRID_COMMS_MPIT] ) - comms_type='mpit' - ;; - mpi*) - AC_DEFINE([GRID_COMMS_MPI],[1],[GRID_COMMS_MPI] ) - comms_type='mpi' - ;; - shmem) - AC_DEFINE([GRID_COMMS_SHMEM],[1],[GRID_COMMS_SHMEM] ) - comms_type='shmem' - ;; *) AC_MSG_ERROR([${ac_COMMS} unsupported --enable-comms option]); ;; From 9b32d51cd1a7ec710239ed280a94a3d836117e7a Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:27:14 +0000 Subject: [PATCH 126/174] Simplify comms layer proliferatoin --- benchmarks/Benchmark_comms.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/benchmarks/Benchmark_comms.cc b/benchmarks/Benchmark_comms.cc index a270e3fa..29ccf96c 100644 --- a/benchmarks/Benchmark_comms.cc +++ b/benchmarks/Benchmark_comms.cc @@ -106,7 +106,7 @@ int main (int argc, char ** argv) for(int i=0;i requests; + std::vector requests; ncomm=0; for(int mu=0;mu<4;mu++){ @@ -202,7 +202,7 @@ int main (int argc, char ** argv) int recv_from_rank; { - std::vector requests; + std::vector requests; Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); Grid.SendToRecvFromBegin(requests, (void *)&xbuf[mu][0], @@ -215,7 +215,7 @@ int main (int argc, char ** argv) comm_proc = mpi_layout[mu]-1; { - std::vector requests; + std::vector requests; Grid.ShiftedRanks(mu,comm_proc,xmit_to_rank,recv_from_rank); Grid.SendToRecvFromBegin(requests, (void *)&xbuf[mu+4][0], @@ -290,7 +290,7 @@ int main (int argc, char ** argv) dbytes=0; ncomm=0; - std::vector requests; + std::vector requests; for(int mu=0;mu<4;mu++){ @@ -383,7 +383,7 @@ int main (int argc, char ** argv) for(int i=0;i requests; + std::vector requests; dbytes=0; ncomm=0; for(int mu=0;mu<4;mu++){ @@ -481,7 +481,7 @@ int main (int argc, char ** argv) for(int i=0;i requests; + std::vector requests; dbytes=0; ncomm=0; From 7eeab7f995332ae2a2ce60c318beb77c449fe0db Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:27:43 +0000 Subject: [PATCH 127/174] Simplify comms layers --- lib/communicator/Communicator.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/communicator/Communicator.h b/lib/communicator/Communicator.h index 09ce50dc..d4ec5a13 100644 --- a/lib/communicator/Communicator.h +++ b/lib/communicator/Communicator.h @@ -28,6 +28,7 @@ Author: Peter Boyle #ifndef GRID_COMMUNICATOR_H #define GRID_COMMUNICATOR_H +#include #include #endif From 6ecf2807237f7b476c495cc97d42cd2c9a1c5c72 Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:28:04 +0000 Subject: [PATCH 128/174] Simplify comms layer proliferation --- lib/qcd/action/fermion/WilsonCompressor.h | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/qcd/action/fermion/WilsonCompressor.h b/lib/qcd/action/fermion/WilsonCompressor.h index cc5c3c63..b47700ac 100644 --- a/lib/qcd/action/fermion/WilsonCompressor.h +++ b/lib/qcd/action/fermion/WilsonCompressor.h @@ -265,7 +265,6 @@ public: if ( timer3 ) std::cout << GridLogMessage << " timer3 (commsMergeShm) " < same_node; std::vector surface_list; From 0a68470f9a2042af2c5bc443bc3fdb33bfc58e77 Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:28:30 +0000 Subject: [PATCH 129/174] Simplify comms layers --- lib/stencil/Stencil.h | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/stencil/Stencil.h b/lib/stencil/Stencil.h index 887d8a7c..69c010f4 100644 --- a/lib/stencil/Stencil.h +++ b/lib/stencil/Stencil.h @@ -105,7 +105,6 @@ template class CartesianStencil { // Stencil runs along coordinate axes only; NO diagonal fill in. public: - typedef CartesianCommunicator::CommsRequest_t CommsRequest_t; typedef typename cobj::vector_type vector_type; typedef typename cobj::scalar_type scalar_type; typedef typename cobj::scalar_object scalar_object; From b91282ad46630f006c9c678b33ec0d9448cec8d6 Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:28:52 +0000 Subject: [PATCH 130/174] Simplify comms layer proliferation --- lib/util/Init.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/util/Init.cc b/lib/util/Init.cc index 031f8f5a..4f99e491 100644 --- a/lib/util/Init.cc +++ b/lib/util/Init.cc @@ -220,11 +220,11 @@ void Grid_init(int *argc,char ***argv) arg= GridCmdOptionPayload(*argv,*argv+*argc,"--shm"); GridCmdOptionInt(arg,MB); uint64_t MB64 = MB; - CartesianCommunicator::MAX_MPI_SHM_BYTES = MB64*1024LL*1024LL; + GlobalSharedMemory::MAX_MPI_SHM_BYTES = MB64*1024LL*1024LL; } if( GridCmdOptionExists(*argv,*argv+*argc,"--shm-hugepages") ){ - CartesianCommunicator::Hugepages = 1; + GlobalSharedMemory::Hugepages = 1; } @@ -392,8 +392,8 @@ void Grid_init(int *argc,char ***argv) Grid_default_latt, Grid_default_mpi); - std::cout << GridLogMessage << "Requesting "<< CartesianCommunicator::MAX_MPI_SHM_BYTES <<" byte stencil comms buffers "< Date: Mon, 8 Jan 2018 11:29:20 +0000 Subject: [PATCH 131/174] Simplify proliferation of comms layers --- scripts/filelist | 2 +- tests/solver/Test_dwf_mrhs_cg_mpi.cc | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/filelist b/scripts/filelist index 8d4b8e1a..74f8e334 100755 --- a/scripts/filelist +++ b/scripts/filelist @@ -6,7 +6,7 @@ home=`pwd` cd $home/lib HFILES=`find . -type f -name '*.h' -not -name '*Hdf5*' -not -path '*/gamma-gen/*' -not -path '*/Old/*' -not -path '*/Eigen/*'` HFILES="$HFILES" -CCFILES=`find . -type f -name '*.cc' -not -path '*/gamma-gen/*' -not -name '*Communicator*.cc' -not -name '*Hdf5*'` +CCFILES=`find . -type f -name '*.cc' -not -path '*/gamma-gen/*' -not -name '*Communicator*.cc' -not -name '*SharedMemory*.cc' -not -name '*Hdf5*'` HPPFILES=`find . -type f -name '*.hpp'` echo HFILES=$HFILES $HPPFILES > Make.inc echo >> Make.inc diff --git a/tests/solver/Test_dwf_mrhs_cg_mpi.cc b/tests/solver/Test_dwf_mrhs_cg_mpi.cc index 7e11d8d1..aa36ebbc 100644 --- a/tests/solver/Test_dwf_mrhs_cg_mpi.cc +++ b/tests/solver/Test_dwf_mrhs_cg_mpi.cc @@ -72,14 +72,17 @@ int main (int argc, char ** argv) int nrhs = 1; int me; for(int i=0;i Date: Mon, 8 Jan 2018 11:30:22 +0000 Subject: [PATCH 132/174] Simplify comms layer proliferation --- lib/Makefile.am | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/Makefile.am b/lib/Makefile.am index 6dd7899e..dc33e7cf 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,28 +1,18 @@ extra_sources= extra_headers= -if BUILD_COMMS_MPI - extra_sources+=communicator/Communicator_mpi.cc - extra_sources+=communicator/Communicator_base.cc -endif if BUILD_COMMS_MPI3 extra_sources+=communicator/Communicator_mpi3.cc extra_sources+=communicator/Communicator_base.cc -endif - -if BUILD_COMMS_MPIT - extra_sources+=communicator/Communicator_mpit.cc - extra_sources+=communicator/Communicator_base.cc -endif - -if BUILD_COMMS_SHMEM - extra_sources+=communicator/Communicator_shmem.cc - extra_sources+=communicator/Communicator_base.cc + extra_sources+=communicator/SharedMemoryMPI.cc + extra_sources+=communicator/SharedMemory.cc endif if BUILD_COMMS_NONE extra_sources+=communicator/Communicator_none.cc extra_sources+=communicator/Communicator_base.cc + extra_sources+=communicator/SharedMemoryNone.cc + extra_sources+=communicator/SharedMemory.cc endif if BUILD_HDF5 From 0091eec23a08fd94ed5711d887019d2359e3503a Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:31:32 +0000 Subject: [PATCH 133/174] Simplify communicator cases --- lib/communicator/Communicator_base.h | 112 ++++----------------------- 1 file changed, 13 insertions(+), 99 deletions(-) diff --git a/lib/communicator/Communicator_base.h b/lib/communicator/Communicator_base.h index 548515cd..a9b99c17 100644 --- a/lib/communicator/Communicator_base.h +++ b/lib/communicator/Communicator_base.h @@ -32,117 +32,33 @@ Author: Peter Boyle /////////////////////////////////// // Processor layout information /////////////////////////////////// -#ifdef GRID_COMMS_MPI -#include -#endif -#ifdef GRID_COMMS_MPI3 -#include -#endif -#ifdef GRID_COMMS_MPIT -#include -#endif -#ifdef GRID_COMMS_SHMEM -#include -#endif +#include namespace Grid { -class CartesianCommunicator { - public: +class CartesianCommunicator : public SharedMemory { +public: //////////////////////////////////////////// - // Isend/Irecv/Wait, or Sendrecv blocking + // Policies //////////////////////////////////////////// enum CommunicatorPolicy_t { CommunicatorPolicyConcurrent, CommunicatorPolicySequential }; static CommunicatorPolicy_t CommunicatorPolicy; static void SetCommunicatorPolicy(CommunicatorPolicy_t policy ) { CommunicatorPolicy = policy; } - - /////////////////////////////////////////// - // Up to 65536 ranks per node adequate for now - // 128MB shared memory for comms enought for 48^4 local vol comms - // Give external control (command line override?) of this - /////////////////////////////////////////// - static const int MAXLOG2RANKSPERNODE = 16; - static uint64_t MAX_MPI_SHM_BYTES; static int nCommThreads; - // use explicit huge pages - static int Hugepages; + //////////////////////////////////////////// // Communicator should know nothing of the physics grid, only processor grid. + //////////////////////////////////////////// int _Nprocessors; // How many in all std::vector _processors; // Which dimensions get relayed out over processors lanes. int _processor; // linear processor rank std::vector _processor_coor; // linear processor coordinate - unsigned long _ndimension; - -#if defined (GRID_COMMS_MPI) || defined (GRID_COMMS_MPI3) || defined (GRID_COMMS_MPIT) - static MPI_Comm communicator_world; - - MPI_Comm communicator; - std::vector communicator_halo; - - typedef MPI_Request CommsRequest_t; - -#else - typedef int CommsRequest_t; -#endif - - - //////////////////////////////////////////////////////////////////// - // Helper functionality for SHM Windows common to all other impls - //////////////////////////////////////////////////////////////////// - // Longer term; drop this in favour of a master / slave model with - // cartesian communicator on a subset of ranks, slave ranks controlled - // by group leader with data xfer via shared memory - //////////////////////////////////////////////////////////////////// -#ifdef GRID_COMMS_MPI3 - - static int ShmRank; - static int ShmSize; - static int GroupRank; - static int GroupSize; - static int WorldRank; - static int WorldSize; - - std::vector WorldDims; - std::vector GroupDims; - std::vector ShmDims; - - std::vector GroupCoor; - std::vector ShmCoor; - std::vector WorldCoor; - - static std::vector GroupRanks; - static std::vector MyGroup; - static int ShmSetup; - static MPI_Win ShmWindow; - static MPI_Comm ShmComm; - - std::vector LexicographicToWorldRank; - - static std::vector ShmCommBufs; - -#else - static void ShmInitGeneric(void); - static commVector ShmBufStorageVector; -#endif - - ///////////////////////////////// - // Grid information and queries - // Implemented in Communicator_base.C - ///////////////////////////////// - static void * ShmCommBuf; - - - size_t heap_top; - size_t heap_bytes; - - void *ShmBufferSelf(void); - void *ShmBuffer(int rank); - void *ShmBufferTranslate(int rank,void * local_p); - void *ShmBufferMalloc(size_t bytes); - void ShmBufferFreeAll(void) ; + unsigned long _ndimension; + static Grid_MPI_Comm communicator_world; + Grid_MPI_Comm communicator; + std::vector communicator_halo; //////////////////////////////////////////////// // Must call in Grid startup @@ -158,13 +74,13 @@ class CartesianCommunicator { virtual ~CartesianCommunicator(); private: -#if defined (GRID_COMMS_MPI) || defined (GRID_COMMS_MPIT) || defined (GRID_COMMS_MPI3) + //////////////////////////////////////////////// // Private initialise from an MPI communicator // Can use after an MPI_Comm_split, but hidden from user so private //////////////////////////////////////////////// - void InitFromMPICommunicator(const std::vector &processors, MPI_Comm communicator_base); -#endif + void InitFromMPICommunicator(const std::vector &processors, Grid_MPI_Comm communicator_base); + public: //////////////////////////////////////////////////////////////////////////////////////// @@ -181,8 +97,6 @@ class CartesianCommunicator { const std::vector & ThisProcessorCoor(void) ; const std::vector & ProcessorGrid(void) ; int ProcessorCount(void) ; - int NodeCount(void) ; - int RankCount(void) ; //////////////////////////////////////////////////////////////////////////////// // very VERY rarely (Log, serial RNG) we need world without a grid From 357badce5ed7efac2df4c3f5bc5cf71815334c3a Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:32:16 +0000 Subject: [PATCH 134/174] Simplify communicator case proliferation --- lib/communicator/Communicator_base.cc | 288 -------------------------- 1 file changed, 288 deletions(-) diff --git a/lib/communicator/Communicator_base.cc b/lib/communicator/Communicator_base.cc index 3e561405..edbf26af 100644 --- a/lib/communicator/Communicator_base.cc +++ b/lib/communicator/Communicator_base.cc @@ -36,33 +36,9 @@ namespace Grid { /////////////////////////////////////////////////////////////// // Info that is setup once and indept of cartesian layout /////////////////////////////////////////////////////////////// -void * CartesianCommunicator::ShmCommBuf; -uint64_t CartesianCommunicator::MAX_MPI_SHM_BYTES = 1024LL*1024LL*1024LL; CartesianCommunicator::CommunicatorPolicy_t CartesianCommunicator::CommunicatorPolicy= CartesianCommunicator::CommunicatorPolicyConcurrent; int CartesianCommunicator::nCommThreads = -1; -int CartesianCommunicator::Hugepages = 0; - -///////////////////////////////// -// Alloc, free shmem region -///////////////////////////////// -void *CartesianCommunicator::ShmBufferMalloc(size_t bytes){ - // bytes = (bytes+sizeof(vRealD))&(~(sizeof(vRealD)-1));// align up bytes - void *ptr = (void *)heap_top; - heap_top += bytes; - heap_bytes+= bytes; - if (heap_bytes >= MAX_MPI_SHM_BYTES) { - std::cout<< " ShmBufferMalloc exceeded shared heap size -- try increasing with --shm flag" < row(_ndimension,1); - assert(dim>=0 && dim<_ndimension); - - // Split the communicator - row[dim] = _processors[dim]; - - int me; - CartesianCommunicator Comm(row,*this,me); - Comm.AllToAll(in,out,words,bytes); -} -void CartesianCommunicator::AllToAll(void *in,void *out,uint64_t words,uint64_t bytes) -{ - // MPI is a pain and uses "int" arguments - // 64*64*64*128*16 == 500Million elements of data. - // When 24*4 bytes multiples get 50x 10^9 >>> 2x10^9 Y2K bug. - // (Turns up on 32^3 x 64 Gparity too) - MPI_Datatype object; - int iwords; - int ibytes; - iwords = words; - ibytes = bytes; - assert(words == iwords); // safe to cast to int ? - assert(bytes == ibytes); // safe to cast to int ? - MPI_Type_contiguous(ibytes,MPI_BYTE,&object); - MPI_Type_commit(&object); - MPI_Alltoall(in,iwords,object,out,iwords,object,communicator); - MPI_Type_free(&object); -} -#endif - -#if defined( GRID_COMMS_MPI) || defined (GRID_COMMS_MPIT) -CartesianCommunicator::CartesianCommunicator(const std::vector &processors,const CartesianCommunicator &parent,int &srank) -{ - _ndimension = processors.size(); - - int parent_ndimension = parent._ndimension; assert(_ndimension >= parent._ndimension); - std::vector parent_processor_coor(_ndimension,0); - std::vector parent_processors (_ndimension,1); - - // Can make 5d grid from 4d etc... - int pad = _ndimension-parent_ndimension; - for(int d=0;d ccoor(_ndimension); // coor within subcommunicator - std::vector scoor(_ndimension); // coor of split within parent - std::vector ssize(_ndimension); // coor of split within parent - - for(int d=0;d<_ndimension;d++){ - ccoor[d] = parent_processor_coor[d] % processors[d]; - scoor[d] = parent_processor_coor[d] / processors[d]; - ssize[d] = parent_processors[d] / processors[d]; - } - int crank; // rank within subcomm ; srank is rank of subcomm within blocks of subcomms - // Mpi uses the reverse Lexico convention to us - Lexicographic::IndexFromCoorReversed(ccoor,crank,processors); - Lexicographic::IndexFromCoorReversed(scoor,srank,ssize); - - MPI_Comm comm_split; - if ( Nchild > 1 ) { - - if(0){ - std::cout << GridLogMessage<<"Child communicator of "<< std::hex << parent.communicator << std::dec< &processors, MPI_Comm communicator_base) -{ - _ndimension = processors.size(); - _processor_coor.resize(_ndimension); - - ///////////////////////////////// - // Count the requested nodes - ///////////////////////////////// - _Nprocessors=1; - _processors = processors; - for(int i=0;i<_ndimension;i++){ - _Nprocessors*=_processors[i]; - } - - std::vector periodic(_ndimension,1); - MPI_Cart_create(communicator_base, _ndimension,&_processors[0],&periodic[0],0,&communicator); - MPI_Comm_rank(communicator,&_processor); - MPI_Cart_coords(communicator,_processor,_ndimension,&_processor_coor[0]); - - if ( 0 && (communicator_base != communicator_world) ) { - std::cout << "InitFromMPICommunicator Cartesian communicator created with a non-world communicator"< &processors) -{ - InitFromMPICommunicator(processors,communicator_world); -} - -#endif - -#if !defined( GRID_COMMS_MPI3) -int CartesianCommunicator::NodeCount(void) { return ProcessorCount();}; -int CartesianCommunicator::RankCount(void) { return ProcessorCount();}; -#endif - -#if !defined( GRID_COMMS_MPI3) && !defined (GRID_COMMS_MPIT) -double CartesianCommunicator::StencilSendToRecvFrom( void *xmit, - int xmit_to_rank, - void *recv, - int recv_from_rank, - int bytes, int dir) -{ - std::vector list; - // Discard the "dir" - SendToRecvFromBegin (list,xmit,xmit_to_rank,recv,recv_from_rank,bytes); - SendToRecvFromComplete(list); - return 2.0*bytes; -} -double CartesianCommunicator::StencilSendToRecvFromBegin(std::vector &list, - void *xmit, - int xmit_to_rank, - void *recv, - int recv_from_rank, - int bytes, int dir) -{ - // Discard the "dir" - SendToRecvFromBegin(list,xmit,xmit_to_rank,recv,recv_from_rank,bytes); - return 2.0*bytes; -} -void CartesianCommunicator::StencilSendToRecvFromComplete(std::vector &waitall,int dir) -{ - SendToRecvFromComplete(waitall); -} -#endif - -#if !defined( GRID_COMMS_MPI3) - -void CartesianCommunicator::StencilBarrier(void){}; - -commVector CartesianCommunicator::ShmBufStorageVector; - -void *CartesianCommunicator::ShmBufferSelf(void) { return ShmCommBuf; } - -void *CartesianCommunicator::ShmBuffer(int rank) { - return NULL; -} -void *CartesianCommunicator::ShmBufferTranslate(int rank,void * local_p) { - return NULL; -} -void CartesianCommunicator::ShmInitGeneric(void){ -#if 1 - int mmap_flag =0; -#ifdef MAP_ANONYMOUS - mmap_flag = mmap_flag| MAP_SHARED | MAP_ANONYMOUS; -#endif -#ifdef MAP_ANON - mmap_flag = mmap_flag| MAP_SHARED | MAP_ANON; -#endif -#ifdef MAP_HUGETLB - if ( Hugepages ) mmap_flag |= MAP_HUGETLB; -#endif - ShmCommBuf =(void *) mmap(NULL, MAX_MPI_SHM_BYTES, PROT_READ | PROT_WRITE, mmap_flag, -1, 0); - if (ShmCommBuf == (void *)MAP_FAILED) { - perror("mmap failed "); - exit(EXIT_FAILURE); - } -#ifdef MADV_HUGEPAGE - if (!Hugepages ) madvise(ShmCommBuf,MAX_MPI_SHM_BYTES,MADV_HUGEPAGE); -#endif -#else - ShmBufStorageVector.resize(MAX_MPI_SHM_BYTES); - ShmCommBuf=(void *)&ShmBufStorageVector[0]; -#endif - bzero(ShmCommBuf,MAX_MPI_SHM_BYTES); -} - -#endif } From 9947cfbf14de0bc323c0a791f21267aadf9488ab Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:33:01 +0000 Subject: [PATCH 135/174] Simplify number of communicator cases --- lib/communicator/Communicator_mpi3.cc | 751 ++++++++------------------ 1 file changed, 213 insertions(+), 538 deletions(-) diff --git a/lib/communicator/Communicator_mpi3.cc b/lib/communicator/Communicator_mpi3.cc index e41749d4..ef47d617 100644 --- a/lib/communicator/Communicator_mpi3.cc +++ b/lib/communicator/Communicator_mpi3.cc @@ -26,89 +26,20 @@ Author: Peter Boyle *************************************************************************************/ /* END LEGAL */ #include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_NUMAIF_H -#include -#endif - +#include namespace Grid { -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Info that is setup once and indept of cartesian layout -/////////////////////////////////////////////////////////////////////////////////////////////////// -int CartesianCommunicator::ShmSetup = 0; +Grid_MPI_Comm CartesianCommunicator::communicator_world; -int CartesianCommunicator::ShmRank; -int CartesianCommunicator::ShmSize; -int CartesianCommunicator::GroupRank; -int CartesianCommunicator::GroupSize; -int CartesianCommunicator::WorldRank; -int CartesianCommunicator::WorldSize; - -MPI_Comm CartesianCommunicator::communicator_world; -MPI_Comm CartesianCommunicator::ShmComm; -MPI_Win CartesianCommunicator::ShmWindow; - -std::vector CartesianCommunicator::GroupRanks; -std::vector CartesianCommunicator::MyGroup; -std::vector CartesianCommunicator::ShmCommBufs; - -int CartesianCommunicator::NodeCount(void) { return GroupSize;}; -int CartesianCommunicator::RankCount(void) { return WorldSize;}; - - -#undef FORCE_COMMS -void *CartesianCommunicator::ShmBufferSelf(void) +//////////////////////////////////////////// +// First initialise of comms system +//////////////////////////////////////////// +void CartesianCommunicator::Init(int *argc, char ***argv) { - return ShmCommBufs[ShmRank]; -} -void *CartesianCommunicator::ShmBuffer(int rank) -{ - int gpeer = GroupRanks[rank]; -#ifdef FORCE_COMMS - return NULL; -#endif - if (gpeer == MPI_UNDEFINED){ - return NULL; - } else { - return ShmCommBufs[gpeer]; - } -} -void *CartesianCommunicator::ShmBufferTranslate(int rank,void * local_p) -{ - static int count =0; - int gpeer = GroupRanks[rank]; - assert(gpeer!=ShmRank); // never send to self - assert(rank!=WorldRank);// never send to self -#ifdef FORCE_COMMS - return NULL; -#endif - if (gpeer == MPI_UNDEFINED){ - return NULL; - } else { - uint64_t offset = (uint64_t)local_p - (uint64_t)ShmCommBufs[ShmRank]; - uint64_t remote = (uint64_t)ShmCommBufs[gpeer]+offset; - return (void *) remote; - } -} - -void CartesianCommunicator::Init(int *argc, char ***argv) { int flag; int provided; - // mtrace(); MPI_Initialized(&flag); // needed to coexist with other libs apparently if ( !flag ) { @@ -119,487 +50,202 @@ void CartesianCommunicator::Init(int *argc, char ***argv) { Grid_quiesce_nodes(); MPI_Comm_dup (MPI_COMM_WORLD,&communicator_world); - MPI_Comm_rank(communicator_world,&WorldRank); - MPI_Comm_size(communicator_world,&WorldSize); - if ( WorldRank == 0 ) { - std::cout << GridLogMessage<< "Initialising MPI "<< WorldRank <<"/"< world_ranks(WorldSize); - GroupRanks.resize(WorldSize); - for(int r=0;r()); - int myleader = MyGroup[0]; - - std::vector leaders_1hot(WorldSize,0); - std::vector leaders_group(GroupSize,0); - leaders_1hot [ myleader ] = 1; - - /////////////////////////////////////////////////////////////////// - // global sum leaders over comm world - /////////////////////////////////////////////////////////////////// - int ierr=MPI_Allreduce(MPI_IN_PLACE,&leaders_1hot[0],WorldSize,MPI_INT,MPI_SUM,communicator_world); - assert(ierr==0); - /////////////////////////////////////////////////////////////////// - // find the group leaders world rank - /////////////////////////////////////////////////////////////////// - int group=0; - for(int l=0;l shmids(ShmSize); - - if ( ShmRank == 0 ) { - for(int r=0;r coor = _processor_coor; // my coord - assert(std::abs(shift) <_processors[dim]); - - coor[dim] = (_processor_coor[dim] + shift + _processors[dim])%_processors[dim]; - Lexicographic::IndexFromCoor(coor,source,_processors); - source = LexicographicToWorldRank[source]; - - coor[dim] = (_processor_coor[dim] - shift + _processors[dim])%_processors[dim]; - Lexicographic::IndexFromCoor(coor,dest,_processors); - dest = LexicographicToWorldRank[dest]; - -}// rank is world rank. - + int ierr=MPI_Cart_shift(communicator,dim,shift,&source,&dest); + assert(ierr==0); +} int CartesianCommunicator::RankFromProcessorCoor(std::vector &coor) { int rank; - Lexicographic::IndexFromCoor(coor,rank,_processors); - rank = LexicographicToWorldRank[rank]; + int ierr=MPI_Cart_rank (communicator, &coor[0], &rank); + assert(ierr==0); return rank; -}// rank is world rank - +} void CartesianCommunicator::ProcessorCoorFromRank(int rank, std::vector &coor) { - int lr=-1; - for(int r=0;r &processors) +{ + MPI_Comm optimal_comm; + GlobalSharedMemory::OptimalCommunicator (processors,optimal_comm); // Remap using the shared memory optimising routine + InitFromMPICommunicator(processors,optimal_comm); + SetCommunicator(optimal_comm); } ////////////////////////////////// // Try to subdivide communicator ////////////////////////////////// -/* - * Use default in MPI compile - */ -CartesianCommunicator::CartesianCommunicator(const std::vector &processors,const CartesianCommunicator &parent,int &srank) - : CartesianCommunicator(processors) +CartesianCommunicator::CartesianCommunicator(const std::vector &processors,const CartesianCommunicator &parent,int &srank) { - std::cout << "Attempts to split MPI3 communicators will fail until implemented" <= parent._ndimension); + std::vector parent_processor_coor(_ndimension,0); + std::vector parent_processors (_ndimension,1); + + // Can make 5d grid from 4d etc... + int pad = _ndimension-parent_ndimension; + for(int d=0;d ccoor(_ndimension); // coor within subcommunicator + std::vector scoor(_ndimension); // coor of split within parent + std::vector ssize(_ndimension); // coor of split within parent + + for(int d=0;d<_ndimension;d++){ + ccoor[d] = parent_processor_coor[d] % processors[d]; + scoor[d] = parent_processor_coor[d] / processors[d]; + ssize[d] = parent_processors[d] / processors[d]; + } + + // rank within subcomm ; srank is rank of subcomm within blocks of subcomms + int crank; + // Mpi uses the reverse Lexico convention to us; so reversed routines called + Lexicographic::IndexFromCoorReversed(ccoor,crank,processors); // processors is the split grid dimensions + Lexicographic::IndexFromCoorReversed(scoor,srank,ssize); // ssize is the number of split grids + + MPI_Comm comm_split; + if ( Nchild > 1 ) { + + if(0){ + std::cout << GridLogMessage<<"Child communicator of "<< std::hex << parent.communicator << std::dec< &processors) -{ - int ierr; - communicator=communicator_world; - +void CartesianCommunicator::InitFromMPICommunicator(const std::vector &processors, MPI_Comm communicator_base) +{ _ndimension = processors.size(); + _processor_coor.resize(_ndimension); + + ///////////////////////////////// + // Count the requested nodes + ///////////////////////////////// + _Nprocessors=1; + _processors = processors; + for(int i=0;i<_ndimension;i++){ + _Nprocessors*=_processors[i]; + } + + std::vector periodic(_ndimension,1); + MPI_Cart_create(communicator_base, _ndimension,&_processors[0],&periodic[0],0,&communicator); + MPI_Comm_rank(communicator,&_processor); + MPI_Cart_coords(communicator,_processor,_ndimension,&_processor_coor[0]); + + if ( 0 && (communicator_base != communicator_world) ) { + std::cout << "InitFromMPICommunicator Cartesian communicator created with a non-world communicator"< WorldDims = processors; - - ShmDims.resize (_ndimension,1); - GroupDims.resize(_ndimension); - ShmCoor.resize (_ndimension); - GroupCoor.resize(_ndimension); - WorldCoor.resize(_ndimension); - - int dim = 0; - for(int l2=0;l2 coor(_ndimension); - ProcessorCoorFromRank(wr,coor); // from world rank - int ck = RankFromProcessorCoor(coor); - assert(ck==wr); - - if ( wr == WorldRank ) { - for(int j=0;j mcoor = coor; - this->Broadcast(0,(void *)&mcoor[0],mcoor.size()*sizeof(int)); - for(int d = 0 ; d< _ndimension; d++) { - assert(coor[d] == mcoor[d]); - } - } -}; CartesianCommunicator::~CartesianCommunicator() { int MPI_is_finalised; @@ -734,19 +380,15 @@ double CartesianCommunicator::StencilSendToRecvFromBegin(std::vector row(_ndimension,1); + assert(dim>=0 && dim<_ndimension); + + // Split the communicator + row[dim] = _processors[dim]; + + int me; + CartesianCommunicator Comm(row,*this,me); + Comm.AllToAll(in,out,words,bytes); +} +void CartesianCommunicator::AllToAll(void *in,void *out,uint64_t words,uint64_t bytes) +{ + // MPI is a pain and uses "int" arguments + // 64*64*64*128*16 == 500Million elements of data. + // When 24*4 bytes multiples get 50x 10^9 >>> 2x10^9 Y2K bug. + // (Turns up on 32^3 x 64 Gparity too) + MPI_Datatype object; + int iwords; + int ibytes; + iwords = words; + ibytes = bytes; + assert(words == iwords); // safe to cast to int ? + assert(bytes == ibytes); // safe to cast to int ? + MPI_Type_contiguous(ibytes,MPI_BYTE,&object); + MPI_Type_commit(&object); + MPI_Alltoall(in,iwords,object,out,iwords,object,communicator); + MPI_Type_free(&object); +} + + + } From 0b85f1bfc8d6ceec46150ae1c75dc048f20629a3 Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:33:47 +0000 Subject: [PATCH 136/174] Simplify the communicator proliferation: mpi and none. --- lib/communicator/Communicator_none.cc | 43 +++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/communicator/Communicator_none.cc b/lib/communicator/Communicator_none.cc index 26b330a7..c3763d53 100644 --- a/lib/communicator/Communicator_none.cc +++ b/lib/communicator/Communicator_none.cc @@ -32,14 +32,22 @@ namespace Grid { /////////////////////////////////////////////////////////////////////////////////////////////////// // Info that is setup once and indept of cartesian layout /////////////////////////////////////////////////////////////////////////////////////////////////// +Grid_MPI_Comm CartesianCommunicator::communicator_world; void CartesianCommunicator::Init(int *argc, char *** arv) { - ShmInitGeneric(); + GlobalSharedMemory::Init(communicator_world); + GlobalSharedMemory::SharedMemoryAllocate( + GlobalSharedMemory::MAX_MPI_SHM_BYTES, + GlobalSharedMemory::Hugepages); } CartesianCommunicator::CartesianCommunicator(const std::vector &processors,const CartesianCommunicator &parent,int &srank) - : CartesianCommunicator(processors) { srank=0;} + : CartesianCommunicator(processors) +{ + srank=0; + SetCommunicator(communicator_world); +} CartesianCommunicator::CartesianCommunicator(const std::vector &processors) { @@ -54,6 +62,7 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors) assert(_processors[d]==1); _processor_coor[d] = 0; } + SetCommunicator(communicator_world); } CartesianCommunicator::~CartesianCommunicator(){} @@ -121,6 +130,36 @@ void CartesianCommunicator::ShiftedRanks(int dim,int shift,int &source,int &dest dest=0; } +double CartesianCommunicator::StencilSendToRecvFrom( void *xmit, + int xmit_to_rank, + void *recv, + int recv_from_rank, + int bytes, int dir) +{ + std::vector list; + // Discard the "dir" + SendToRecvFromBegin (list,xmit,xmit_to_rank,recv,recv_from_rank,bytes); + SendToRecvFromComplete(list); + return 2.0*bytes; +} +double CartesianCommunicator::StencilSendToRecvFromBegin(std::vector &list, + void *xmit, + int xmit_to_rank, + void *recv, + int recv_from_rank, + int bytes, int dir) +{ + // Discard the "dir" + SendToRecvFromBegin(list,xmit,xmit_to_rank,recv,recv_from_rank,bytes); + return 2.0*bytes; +} +void CartesianCommunicator::StencilSendToRecvFromComplete(std::vector &waitall,int dir) +{ + SendToRecvFromComplete(waitall); +} + +void CartesianCommunicator::StencilBarrier(void){}; + } From 44f65526e01369c193a8754e97ec959ed8d0a1d4 Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 8 Jan 2018 11:35:43 +0000 Subject: [PATCH 137/174] Simplify communicators --- lib/communicator/Communicator_mpi.cc | 222 ----- lib/communicator/Communicator_mpi3_leader.cc | 988 ------------------- lib/communicator/Communicator_mpit.cc | 273 ----- lib/communicator/Communicator_shmem.cc | 357 ------- lib/communicator/SharedMemory.cc | 54 + lib/communicator/SharedMemory.h | 158 +++ lib/communicator/SharedMemoryMPI.cc | 415 ++++++++ lib/communicator/SharedMemoryNone.cc | 150 +++ 8 files changed, 777 insertions(+), 1840 deletions(-) delete mode 100644 lib/communicator/Communicator_mpi.cc delete mode 100644 lib/communicator/Communicator_mpi3_leader.cc delete mode 100644 lib/communicator/Communicator_mpit.cc delete mode 100644 lib/communicator/Communicator_shmem.cc create mode 100644 lib/communicator/SharedMemory.cc create mode 100644 lib/communicator/SharedMemory.h create mode 100644 lib/communicator/SharedMemoryMPI.cc create mode 100644 lib/communicator/SharedMemoryNone.cc diff --git a/lib/communicator/Communicator_mpi.cc b/lib/communicator/Communicator_mpi.cc deleted file mode 100644 index 2075e4bf..00000000 --- a/lib/communicator/Communicator_mpi.cc +++ /dev/null @@ -1,222 +0,0 @@ - /************************************************************************************* - - Grid physics library, www.github.com/paboyle/Grid - - Source file: ./lib/communicator/Communicator_mpi.cc - - Copyright (C) 2015 - -Author: Peter Boyle - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - See the full license in the file "LICENSE" in the top level distribution directory - *************************************************************************************/ - /* END LEGAL */ -#include -#include -#include -#include - -namespace Grid { - - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Info that is setup once and indept of cartesian layout -/////////////////////////////////////////////////////////////////////////////////////////////////// -MPI_Comm CartesianCommunicator::communicator_world; - -// Should error check all MPI calls. -void CartesianCommunicator::Init(int *argc, char ***argv) { - int flag; - int provided; - MPI_Initialized(&flag); // needed to coexist with other libs apparently - if ( !flag ) { - MPI_Init_thread(argc,argv,MPI_THREAD_MULTIPLE,&provided); - if ( provided != MPI_THREAD_MULTIPLE ) { - QCD::WilsonKernelsStatic::Comms = QCD::WilsonKernelsStatic::CommsThenCompute; - } - } - MPI_Comm_dup (MPI_COMM_WORLD,&communicator_world); - ShmInitGeneric(); -} - -CartesianCommunicator::~CartesianCommunicator() -{ - int MPI_is_finalised; - MPI_Finalized(&MPI_is_finalised); - if (communicator && !MPI_is_finalised) - MPI_Comm_free(&communicator); -} - -void CartesianCommunicator::GlobalSum(uint32_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSum(uint64_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT64_T,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalXOR(uint32_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_BXOR,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalXOR(uint64_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT64_T,MPI_BXOR,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSum(float &f){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&f,1,MPI_FLOAT,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSumVector(float *f,int N) -{ - int ierr=MPI_Allreduce(MPI_IN_PLACE,f,N,MPI_FLOAT,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSum(double &d) -{ - int ierr = MPI_Allreduce(MPI_IN_PLACE,&d,1,MPI_DOUBLE,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSumVector(double *d,int N) -{ - int ierr = MPI_Allreduce(MPI_IN_PLACE,d,N,MPI_DOUBLE,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::ShiftedRanks(int dim,int shift,int &source,int &dest) -{ - int ierr=MPI_Cart_shift(communicator,dim,shift,&source,&dest); - assert(ierr==0); -} -int CartesianCommunicator::RankFromProcessorCoor(std::vector &coor) -{ - int rank; - int ierr=MPI_Cart_rank (communicator, &coor[0], &rank); - assert(ierr==0); - return rank; -} -void CartesianCommunicator::ProcessorCoorFromRank(int rank, std::vector &coor) -{ - coor.resize(_ndimension); - int ierr=MPI_Cart_coords (communicator, rank, _ndimension,&coor[0]); - assert(ierr==0); -} - -// Basic Halo comms primitive -void CartesianCommunicator::SendToRecvFrom(void *xmit, - int dest, - void *recv, - int from, - int bytes) -{ - std::vector reqs(0); - SendToRecvFromBegin(reqs,xmit,dest,recv,from,bytes); - SendToRecvFromComplete(reqs); -} - -void CartesianCommunicator::SendRecvPacket(void *xmit, - void *recv, - int sender, - int receiver, - int bytes) -{ - MPI_Status stat; - assert(sender != receiver); - int tag = sender; - if ( _processor == sender ) { - MPI_Send(xmit, bytes, MPI_CHAR,receiver,tag,communicator); - } - if ( _processor == receiver ) { - MPI_Recv(recv, bytes, MPI_CHAR,sender,tag,communicator,&stat); - } -} - -// Basic Halo comms primitive -void CartesianCommunicator::SendToRecvFromBegin(std::vector &list, - void *xmit, - int dest, - void *recv, - int from, - int bytes) -{ - int myrank = _processor; - int ierr; - if ( CommunicatorPolicy == CommunicatorPolicyConcurrent ) { - MPI_Request xrq; - MPI_Request rrq; - - ierr =MPI_Irecv(recv, bytes, MPI_CHAR,from,from,communicator,&rrq); - ierr|=MPI_Isend(xmit, bytes, MPI_CHAR,dest,_processor,communicator,&xrq); - - assert(ierr==0); - list.push_back(xrq); - list.push_back(rrq); - } else { - // Give the CPU to MPI immediately; can use threads to overlap optionally - ierr=MPI_Sendrecv(xmit,bytes,MPI_CHAR,dest,myrank, - recv,bytes,MPI_CHAR,from, from, - communicator,MPI_STATUS_IGNORE); - assert(ierr==0); - } -} -void CartesianCommunicator::SendToRecvFromComplete(std::vector &list) -{ - if ( CommunicatorPolicy == CommunicatorPolicyConcurrent ) { - int nreq=list.size(); - std::vector status(nreq); - int ierr = MPI_Waitall(nreq,&list[0],&status[0]); - assert(ierr==0); - } -} - -void CartesianCommunicator::Barrier(void) -{ - int ierr = MPI_Barrier(communicator); - assert(ierr==0); -} - -void CartesianCommunicator::Broadcast(int root,void* data, int bytes) -{ - int ierr=MPI_Bcast(data, - bytes, - MPI_BYTE, - root, - communicator); - assert(ierr==0); -} - /////////////////////////////////////////////////////// - // Should only be used prior to Grid Init finished. - // Check for this? - /////////////////////////////////////////////////////// -int CartesianCommunicator::RankWorld(void){ - int r; - MPI_Comm_rank(communicator_world,&r); - return r; -} -void CartesianCommunicator::BroadcastWorld(int root,void* data, int bytes) -{ - int ierr= MPI_Bcast(data, - bytes, - MPI_BYTE, - root, - communicator_world); - assert(ierr==0); -} - - - -} - diff --git a/lib/communicator/Communicator_mpi3_leader.cc b/lib/communicator/Communicator_mpi3_leader.cc deleted file mode 100644 index 6e26bd3e..00000000 --- a/lib/communicator/Communicator_mpi3_leader.cc +++ /dev/null @@ -1,988 +0,0 @@ - /************************************************************************************* - - Grid physics library, www.github.com/paboyle/Grid - - Source file: ./lib/communicator/Communicator_mpi.cc - - Copyright (C) 2015 - -Author: Peter Boyle - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - See the full license in the file "LICENSE" in the top level distribution directory - *************************************************************************************/ - /* END LEGAL */ -#include "Grid.h" -#include -//#include - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/// Workarounds: -/// i) bloody mac os doesn't implement unnamed semaphores since it is "optional" posix. -/// darwin dispatch semaphores don't seem to be multiprocess. -/// -/// ii) openmpi under --mca shmem posix works with two squadrons per node; -/// openmpi under default mca settings (I think --mca shmem mmap) on MacOS makes two squadrons map the SAME -/// memory as each other, despite their living on different communicators. This appears to be a bug in OpenMPI. -/// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#include -#include -#include -#include -typedef sem_t *Grid_semaphore; - - -#error /*THis is deprecated*/ - -#if 0 -#define SEM_INIT(S) S = sem_open(sem_name,0,0600,0); assert ( S != SEM_FAILED ); -#define SEM_INIT_EXCL(S) sem_unlink(sem_name); S = sem_open(sem_name,O_CREAT|O_EXCL,0600,0); assert ( S != SEM_FAILED ); -#define SEM_POST(S) assert ( sem_post(S) == 0 ); -#define SEM_WAIT(S) assert ( sem_wait(S) == 0 ); -#else -#define SEM_INIT(S) ; -#define SEM_INIT_EXCL(S) ; -#define SEM_POST(S) ; -#define SEM_WAIT(S) ; -#endif -#include - -namespace Grid { - -enum { COMMAND_ISEND, COMMAND_IRECV, COMMAND_WAITALL, COMMAND_SENDRECV }; - -struct Descriptor { - uint64_t buf; - size_t bytes; - int rank; - int tag; - int command; - uint64_t xbuf; - uint64_t rbuf; - int xtag; - int rtag; - int src; - int dest; - MPI_Request request; -}; - -const int pool = 48; - -class SlaveState { -public: - volatile int head; - volatile int start; - volatile int tail; - volatile Descriptor Descrs[pool]; -}; - -class Slave { -public: - Grid_semaphore sem_head; - Grid_semaphore sem_tail; - SlaveState *state; - MPI_Comm squadron; - uint64_t base; - int universe_rank; - int vertical_rank; - char sem_name [NAME_MAX]; - //////////////////////////////////////////////////////////// - // Descriptor circular pointers - //////////////////////////////////////////////////////////// - Slave() {}; - - void Init(SlaveState * _state,MPI_Comm _squadron,int _universe_rank,int _vertical_rank); - - void SemInit(void) { - sprintf(sem_name,"/Grid_mpi3_sem_head_%d",universe_rank); - SEM_INIT(sem_head); - sprintf(sem_name,"/Grid_mpi3_sem_tail_%d",universe_rank); - SEM_INIT(sem_tail); - } - void SemInitExcl(void) { - sprintf(sem_name,"/Grid_mpi3_sem_head_%d",universe_rank); - SEM_INIT_EXCL(sem_head); - sprintf(sem_name,"/Grid_mpi3_sem_tail_%d",universe_rank); - SEM_INIT_EXCL(sem_tail); - } - void WakeUpDMA(void) { - SEM_POST(sem_head); - }; - void WakeUpCompute(void) { - SEM_POST(sem_tail); - }; - void WaitForCommand(void) { - SEM_WAIT(sem_head); - }; - void WaitForComplete(void) { - SEM_WAIT(sem_tail); - }; - void EventLoop (void) { - // std::cout<< " Entering event loop "<head,0,0); - int s=state->start; - if ( s != state->head ) { - _mm_mwait(0,0); - } -#endif - Event(); - } - } - - int Event (void) ; - - uint64_t QueueCommand(int command,void *buf, int bytes, int hashtag, MPI_Comm comm,int u_rank) ; - void QueueSendRecv(void *xbuf, void *rbuf, int bytes, int xtag, int rtag, MPI_Comm comm,int dest,int src) ; - - void WaitAll() { - // std::cout << "Queueing WAIT command "<tail != state->head ); - } -}; - -//////////////////////////////////////////////////////////////////////// -// One instance of a data mover. -// Master and Slave must agree on location in shared memory -//////////////////////////////////////////////////////////////////////// - -class MPIoffloadEngine { -public: - - static std::vector Slaves; - - static int ShmSetup; - - static int UniverseRank; - static int UniverseSize; - - static MPI_Comm communicator_universe; - static MPI_Comm communicator_cached; - - static MPI_Comm HorizontalComm; - static int HorizontalRank; - static int HorizontalSize; - - static MPI_Comm VerticalComm; - static MPI_Win VerticalWindow; - static int VerticalSize; - static int VerticalRank; - - static std::vector VerticalShmBufs; - static std::vector > UniverseRanks; - static std::vector UserCommunicatorToWorldRanks; - - static MPI_Group WorldGroup, CachedGroup; - - static void CommunicatorInit (MPI_Comm &communicator_world, - MPI_Comm &ShmComm, - void * &ShmCommBuf); - - static void MapCommRankToWorldRank(int &hashtag, int & comm_world_peer,int tag, MPI_Comm comm,int commrank); - - ///////////////////////////////////////////////////////// - // routines for master proc must handle any communicator - ///////////////////////////////////////////////////////// - - static void QueueSend(int slave,void *buf, int bytes, int tag, MPI_Comm comm,int rank) { - // std::cout<< " Queueing send "<< bytes<< " slave "<< slave << " to comm "<= units ) { - mywork = myoff = 0; - } else { - mywork = (nwork+me)/units; - myoff = basework * me; - if ( me > backfill ) - myoff+= (me-backfill); - } - return; - }; - - static void QueueRoundRobinSendRecv(void *xbuf, void *rbuf, int bytes, int xtag, int rtag, MPI_Comm comm,int dest,int src) { - uint8_t * cxbuf = (uint8_t *) xbuf; - uint8_t * crbuf = (uint8_t *) rbuf; - static int rrp=0; - int procs = VerticalSize-1; - int myoff=0; - int mywork=bytes; - QueueSendRecv(rrp+1,&cxbuf[myoff],&crbuf[myoff],mywork,xtag,rtag,comm,dest,src); - rrp = rrp+1; - if ( rrp == (VerticalSize-1) ) rrp = 0; - } - - static void QueueMultiplexedSendRecv(void *xbuf, void *rbuf, int bytes, int xtag, int rtag, MPI_Comm comm,int dest,int src) { - uint8_t * cxbuf = (uint8_t *) xbuf; - uint8_t * crbuf = (uint8_t *) rbuf; - int mywork, myoff, procs; - procs = VerticalSize-1; - for(int s=0;s MPIoffloadEngine::Slaves; - -int MPIoffloadEngine::UniverseRank; -int MPIoffloadEngine::UniverseSize; - -MPI_Comm MPIoffloadEngine::communicator_universe; -MPI_Comm MPIoffloadEngine::communicator_cached; -MPI_Group MPIoffloadEngine::WorldGroup; -MPI_Group MPIoffloadEngine::CachedGroup; - -MPI_Comm MPIoffloadEngine::HorizontalComm; -int MPIoffloadEngine::HorizontalRank; -int MPIoffloadEngine::HorizontalSize; - -MPI_Comm MPIoffloadEngine::VerticalComm; -int MPIoffloadEngine::VerticalSize; -int MPIoffloadEngine::VerticalRank; -MPI_Win MPIoffloadEngine::VerticalWindow; -std::vector MPIoffloadEngine::VerticalShmBufs; -std::vector > MPIoffloadEngine::UniverseRanks; -std::vector MPIoffloadEngine::UserCommunicatorToWorldRanks; - -int CartesianCommunicator::NodeCount(void) { return HorizontalSize;}; -int MPIoffloadEngine::ShmSetup = 0; - -void MPIoffloadEngine::CommunicatorInit (MPI_Comm &communicator_world, - MPI_Comm &ShmComm, - void * &ShmCommBuf) -{ - int flag; - assert(ShmSetup==0); - - ////////////////////////////////////////////////////////////////////// - // Universe is all nodes prior to squadron grouping - ////////////////////////////////////////////////////////////////////// - MPI_Comm_dup (MPI_COMM_WORLD,&communicator_universe); - MPI_Comm_rank(communicator_universe,&UniverseRank); - MPI_Comm_size(communicator_universe,&UniverseSize); - - ///////////////////////////////////////////////////////////////////// - // Split into groups that can share memory (Verticals) - ///////////////////////////////////////////////////////////////////// -#undef MPI_SHARED_MEM_DEBUG -#ifdef MPI_SHARED_MEM_DEBUG - MPI_Comm_split(communicator_universe,(UniverseRank/4),UniverseRank,&VerticalComm); -#else - MPI_Comm_split_type(communicator_universe, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL,&VerticalComm); -#endif - MPI_Comm_rank(VerticalComm ,&VerticalRank); - MPI_Comm_size(VerticalComm ,&VerticalSize); - - ////////////////////////////////////////////////////////////////////// - // Split into horizontal groups by rank in squadron - ////////////////////////////////////////////////////////////////////// - MPI_Comm_split(communicator_universe,VerticalRank,UniverseRank,&HorizontalComm); - MPI_Comm_rank(HorizontalComm,&HorizontalRank); - MPI_Comm_size(HorizontalComm,&HorizontalSize); - assert(HorizontalSize*VerticalSize==UniverseSize); - - //////////////////////////////////////////////////////////////////////////////// - // What is my place in the world - //////////////////////////////////////////////////////////////////////////////// - int WorldRank=0; - if(VerticalRank==0) WorldRank = HorizontalRank; - int ierr=MPI_Allreduce(MPI_IN_PLACE,&WorldRank,1,MPI_INT,MPI_SUM,VerticalComm); - assert(ierr==0); - - //////////////////////////////////////////////////////////////////////////////// - // Where is the world in the universe? - //////////////////////////////////////////////////////////////////////////////// - UniverseRanks = std::vector >(HorizontalSize,std::vector(VerticalSize,0)); - UniverseRanks[WorldRank][VerticalRank] = UniverseRank; - for(int w=0;w0 ) size = sizeof(SlaveState); - - sprintf(shm_name,"/Grid_mpi3_shm_%d_%d",WorldRank,r); - - shm_unlink(shm_name); - - int fd=shm_open(shm_name,O_RDWR|O_CREAT,0600); - if ( fd < 0 ) { - perror("failed shm_open"); - assert(0); - } - - ftruncate(fd, size); - - VerticalShmBufs[r] = mmap(NULL,size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if ( VerticalShmBufs[r] == MAP_FAILED ) { - perror("failed mmap"); - assert(0); - } - - /* - for(uint64_t page=0;page0 ) size = sizeof(SlaveState); - - sprintf(shm_name,"/Grid_mpi3_shm_%d_%d",WorldRank,r); - - int fd=shm_open(shm_name,O_RDWR|O_CREAT,0600); - if ( fd<0 ) { - perror("failed shm_open"); - assert(0); - } - VerticalShmBufs[r] = mmap(NULL,size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - - uint64_t * check = (uint64_t *) VerticalShmBufs[r]; - assert(check[0]== WorldRank); - assert(check[1]== r); - // std::cerr<<"SHM "<"<"< cached_ranks(size); - - for(int r=0;r"<>0 )&0xFFFF)^((icomm>>16)&0xFFFF) - ^ ((icomm>>32)&0xFFFF)^((icomm>>48)&0xFFFF); - - // hashtag = (comm_hash<<15) | tag; - hashtag = tag; - -}; - -void Slave::Init(SlaveState * _state,MPI_Comm _squadron,int _universe_rank,int _vertical_rank) -{ - squadron=_squadron; - universe_rank=_universe_rank; - vertical_rank=_vertical_rank; - state =_state; - // std::cout << "state "<<_state<<" comm "<<_squadron<<" universe_rank"<head = state->tail = state->start = 0; - base = (uint64_t)MPIoffloadEngine::VerticalShmBufs[0]; - int rank; MPI_Comm_rank(_squadron,&rank); -} -#define PERI_PLUS(A) ( (A+1)%pool ) -int Slave::Event (void) { - - static int tail_last; - static int head_last; - static int start_last; - int ierr; - MPI_Status stat; - static int i=0; - - //////////////////////////////////////////////////// - // Try to advance the start pointers - //////////////////////////////////////////////////// - int s=state->start; - if ( s != state->head ) { - switch ( state->Descrs[s].command ) { - case COMMAND_ISEND: - ierr = MPI_Isend((void *)(state->Descrs[s].buf+base), - state->Descrs[s].bytes, - MPI_CHAR, - state->Descrs[s].rank, - state->Descrs[s].tag, - MPIoffloadEngine::communicator_universe, - (MPI_Request *)&state->Descrs[s].request); - assert(ierr==0); - state->start = PERI_PLUS(s); - return 1; - break; - - case COMMAND_IRECV: - ierr=MPI_Irecv((void *)(state->Descrs[s].buf+base), - state->Descrs[s].bytes, - MPI_CHAR, - state->Descrs[s].rank, - state->Descrs[s].tag, - MPIoffloadEngine::communicator_universe, - (MPI_Request *)&state->Descrs[s].request); - - // std::cout<< " Request is "<Descrs[s].request<Descrs[0].request<start = PERI_PLUS(s); - return 1; - break; - - case COMMAND_SENDRECV: - - // fprintf(stderr,"Sendrecv ->%d %d : <-%d %d \n",state->Descrs[s].dest, state->Descrs[s].xtag+i*10,state->Descrs[s].src, state->Descrs[s].rtag+i*10); - - ierr=MPI_Sendrecv((void *)(state->Descrs[s].xbuf+base), state->Descrs[s].bytes, MPI_CHAR, state->Descrs[s].dest, state->Descrs[s].xtag+i*10, - (void *)(state->Descrs[s].rbuf+base), state->Descrs[s].bytes, MPI_CHAR, state->Descrs[s].src , state->Descrs[s].rtag+i*10, - MPIoffloadEngine::communicator_universe,MPI_STATUS_IGNORE); - - assert(ierr==0); - - // fprintf(stderr,"Sendrecv done %d %d\n",ierr,i); - // MPI_Barrier(MPIoffloadEngine::HorizontalComm); - // fprintf(stderr,"Barrier\n"); - i++; - - state->start = PERI_PLUS(s); - - return 1; - break; - - case COMMAND_WAITALL: - - for(int t=state->tail;t!=s; t=PERI_PLUS(t) ){ - if ( state->Descrs[t].command != COMMAND_SENDRECV ) { - MPI_Wait((MPI_Request *)&state->Descrs[t].request,MPI_STATUS_IGNORE); - } - }; - s=PERI_PLUS(s); - state->start = s; - state->tail = s; - - WakeUpCompute(); - - return 1; - break; - - default: - assert(0); - break; - } - } - return 0; -} - ////////////////////////////////////////////////////////////////////////////// - // External interaction with the queue - ////////////////////////////////////////////////////////////////////////////// - -void Slave::QueueSendRecv(void *xbuf, void *rbuf, int bytes, int xtag, int rtag, MPI_Comm comm,int dest,int src) -{ - int head =state->head; - int next = PERI_PLUS(head); - - // Set up descriptor - int worldrank; - int hashtag; - MPI_Comm communicator; - MPI_Request request; - uint64_t relative; - - relative = (uint64_t)xbuf - base; - state->Descrs[head].xbuf = relative; - - relative= (uint64_t)rbuf - base; - state->Descrs[head].rbuf = relative; - - state->Descrs[head].bytes = bytes; - - MPIoffloadEngine::MapCommRankToWorldRank(hashtag,worldrank,xtag,comm,dest); - state->Descrs[head].dest = MPIoffloadEngine::UniverseRanks[worldrank][vertical_rank]; - state->Descrs[head].xtag = hashtag; - - MPIoffloadEngine::MapCommRankToWorldRank(hashtag,worldrank,rtag,comm,src); - state->Descrs[head].src = MPIoffloadEngine::UniverseRanks[worldrank][vertical_rank]; - state->Descrs[head].rtag = hashtag; - - state->Descrs[head].command= COMMAND_SENDRECV; - - // Block until FIFO has space - while( state->tail==next ); - - // Msync on weak order architectures - - // Advance pointer - state->head = next; - -}; -uint64_t Slave::QueueCommand(int command,void *buf, int bytes, int tag, MPI_Comm comm,int commrank) -{ - ///////////////////////////////////////// - // Spin; if FIFO is full until not full - ///////////////////////////////////////// - int head =state->head; - int next = PERI_PLUS(head); - - // Set up descriptor - int worldrank; - int hashtag; - MPI_Comm communicator; - MPI_Request request; - - MPIoffloadEngine::MapCommRankToWorldRank(hashtag,worldrank,tag,comm,commrank); - - uint64_t relative= (uint64_t)buf - base; - state->Descrs[head].buf = relative; - state->Descrs[head].bytes = bytes; - state->Descrs[head].rank = MPIoffloadEngine::UniverseRanks[worldrank][vertical_rank]; - state->Descrs[head].tag = hashtag; - state->Descrs[head].command= command; - - /* - if ( command == COMMAND_ISEND ) { - std::cout << "QueueSend from "<< universe_rank <<" to commrank " << commrank - << " to worldrank " << worldrank <tail==next ); - - // Msync on weak order architectures - // Advance pointer - state->head = next; - - return 0; -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Info that is setup once and indept of cartesian layout -/////////////////////////////////////////////////////////////////////////////////////////////////// - -MPI_Comm CartesianCommunicator::communicator_world; - -void CartesianCommunicator::Init(int *argc, char ***argv) -{ - int flag; - MPI_Initialized(&flag); // needed to coexist with other libs apparently - if ( !flag ) { - MPI_Init(argc,argv); - } - communicator_world = MPI_COMM_WORLD; - MPI_Comm ShmComm; - MPIoffloadEngine::CommunicatorInit (communicator_world,ShmComm,ShmCommBuf); -} -void CartesianCommunicator::ShiftedRanks(int dim,int shift,int &source,int &dest) -{ - int ierr=MPI_Cart_shift(communicator,dim,shift,&source,&dest); - assert(ierr==0); -} -int CartesianCommunicator::RankFromProcessorCoor(std::vector &coor) -{ - int rank; - int ierr=MPI_Cart_rank (communicator, &coor[0], &rank); - assert(ierr==0); - return rank; -} -void CartesianCommunicator::ProcessorCoorFromRank(int rank, std::vector &coor) -{ - coor.resize(_ndimension); - int ierr=MPI_Cart_coords (communicator, rank, _ndimension,&coor[0]); - assert(ierr==0); -} - -CartesianCommunicator::CartesianCommunicator(const std::vector &processors) -{ - _ndimension = processors.size(); - std::vector periodic(_ndimension,1); - - _Nprocessors=1; - _processors = processors; - - for(int i=0;i<_ndimension;i++){ - _Nprocessors*=_processors[i]; - } - - int Size; - MPI_Comm_size(communicator_world,&Size); - assert(Size==_Nprocessors); - - _processor_coor.resize(_ndimension); - MPI_Cart_create(communicator_world, _ndimension,&_processors[0],&periodic[0],1,&communicator); - MPI_Comm_rank (communicator,&_processor); - MPI_Cart_coords(communicator,_processor,_ndimension,&_processor_coor[0]); -}; - -void CartesianCommunicator::GlobalSum(uint32_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSum(uint64_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT64_T,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSum(float &f){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&f,1,MPI_FLOAT,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSumVector(float *f,int N) -{ - int ierr=MPI_Allreduce(MPI_IN_PLACE,f,N,MPI_FLOAT,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSum(double &d) -{ - int ierr = MPI_Allreduce(MPI_IN_PLACE,&d,1,MPI_DOUBLE,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSumVector(double *d,int N) -{ - int ierr = MPI_Allreduce(MPI_IN_PLACE,d,N,MPI_DOUBLE,MPI_SUM,communicator); - assert(ierr==0); -} - -// Basic Halo comms primitive -void CartesianCommunicator::SendToRecvFrom(void *xmit, - int dest, - void *recv, - int from, - int bytes) -{ - std::vector reqs(0); - SendToRecvFromBegin(reqs,xmit,dest,recv,from,bytes); - SendToRecvFromComplete(reqs); -} - -void CartesianCommunicator::SendRecvPacket(void *xmit, - void *recv, - int sender, - int receiver, - int bytes) -{ - MPI_Status stat; - assert(sender != receiver); - int tag = sender; - if ( _processor == sender ) { - MPI_Send(xmit, bytes, MPI_CHAR,receiver,tag,communicator); - } - if ( _processor == receiver ) { - MPI_Recv(recv, bytes, MPI_CHAR,sender,tag,communicator,&stat); - } -} - -// Basic Halo comms primitive -void CartesianCommunicator::SendToRecvFromBegin(std::vector &list, - void *xmit, - int dest, - void *recv, - int from, - int bytes) -{ - MPI_Request xrq; - MPI_Request rrq; - int rank = _processor; - int ierr; - ierr =MPI_Isend(xmit, bytes, MPI_CHAR,dest,_processor,communicator,&xrq); - ierr|=MPI_Irecv(recv, bytes, MPI_CHAR,from,from,communicator,&rrq); - - assert(ierr==0); - - list.push_back(xrq); - list.push_back(rrq); -} - -void CartesianCommunicator::StencilSendToRecvFromBegin(std::vector &list, - void *xmit, - int dest, - void *recv, - int from, - int bytes) -{ - uint64_t xmit_i = (uint64_t) xmit; - uint64_t recv_i = (uint64_t) recv; - uint64_t shm = (uint64_t) ShmCommBuf; - // assert xmit and recv lie in shared memory region - assert( (xmit_i >= shm) && (xmit_i+bytes <= shm+MAX_MPI_SHM_BYTES) ); - assert( (recv_i >= shm) && (recv_i+bytes <= shm+MAX_MPI_SHM_BYTES) ); - assert(from!=_processor); - assert(dest!=_processor); - - MPIoffloadEngine::QueueMultiplexedSendRecv(xmit,recv,bytes,_processor,from,communicator,dest,from); - - //MPIoffloadEngine::QueueRoundRobinSendRecv(xmit,recv,bytes,_processor,from,communicator,dest,from); - - //MPIoffloadEngine::QueueMultiplexedSend(xmit,bytes,_processor,communicator,dest); - //MPIoffloadEngine::QueueMultiplexedRecv(recv,bytes,from,communicator,from); -} - -void CartesianCommunicator::StencilSendToRecvFromComplete(std::vector &list) -{ - MPIoffloadEngine::WaitAll(); - //this->Barrier(); -} - -void CartesianCommunicator::StencilBarrier(void) { } - -void CartesianCommunicator::SendToRecvFromComplete(std::vector &list) -{ - int nreq=list.size(); - std::vector status(nreq); - int ierr = MPI_Waitall(nreq,&list[0],&status[0]); - assert(ierr==0); -} - -void CartesianCommunicator::Barrier(void) -{ - int ierr = MPI_Barrier(communicator); - assert(ierr==0); -} - -void CartesianCommunicator::Broadcast(int root,void* data, int bytes) -{ - int ierr=MPI_Bcast(data, - bytes, - MPI_BYTE, - root, - communicator); - assert(ierr==0); -} - -void CartesianCommunicator::BroadcastWorld(int root,void* data, int bytes) -{ - int ierr= MPI_Bcast(data, - bytes, - MPI_BYTE, - root, - communicator_world); - assert(ierr==0); -} - -void *CartesianCommunicator::ShmBufferSelf(void) { return ShmCommBuf; } - -void *CartesianCommunicator::ShmBuffer(int rank) { - return NULL; -} -void *CartesianCommunicator::ShmBufferTranslate(int rank,void * local_p) { - return NULL; -} - - -}; - diff --git a/lib/communicator/Communicator_mpit.cc b/lib/communicator/Communicator_mpit.cc deleted file mode 100644 index bceea0d8..00000000 --- a/lib/communicator/Communicator_mpit.cc +++ /dev/null @@ -1,273 +0,0 @@ - /************************************************************************************* - - Grid physics library, www.github.com/paboyle/Grid - - Source file: ./lib/communicator/Communicator_mpi.cc - - Copyright (C) 2015 - -Author: Peter Boyle - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - See the full license in the file "LICENSE" in the top level distribution directory - *************************************************************************************/ - /* END LEGAL */ -#include -#include -#include -#include - -namespace Grid { - - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Info that is setup once and indept of cartesian layout -/////////////////////////////////////////////////////////////////////////////////////////////////// -MPI_Comm CartesianCommunicator::communicator_world; - -// Should error check all MPI calls. -void CartesianCommunicator::Init(int *argc, char ***argv) { - int flag; - int provided; - MPI_Initialized(&flag); // needed to coexist with other libs apparently - if ( !flag ) { - MPI_Init_thread(argc,argv,MPI_THREAD_MULTIPLE,&provided); - if ( provided != MPI_THREAD_MULTIPLE ) { - QCD::WilsonKernelsStatic::Comms = QCD::WilsonKernelsStatic::CommsThenCompute; - } - } - MPI_Comm_dup (MPI_COMM_WORLD,&communicator_world); - ShmInitGeneric(); -} - -CartesianCommunicator::~CartesianCommunicator() -{ - int MPI_is_finalised; - MPI_Finalized(&MPI_is_finalised); - if (communicator && !MPI_is_finalised){ - MPI_Comm_free(&communicator); - for(int i=0;i< communicator_halo.size();i++){ - MPI_Comm_free(&communicator_halo[i]); - } - } -} - -void CartesianCommunicator::GlobalSum(uint32_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSum(uint64_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT64_T,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalXOR(uint32_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_BXOR,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalXOR(uint64_t &u){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT64_T,MPI_BXOR,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSum(float &f){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&f,1,MPI_FLOAT,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSumVector(float *f,int N) -{ - int ierr=MPI_Allreduce(MPI_IN_PLACE,f,N,MPI_FLOAT,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSum(double &d) -{ - int ierr = MPI_Allreduce(MPI_IN_PLACE,&d,1,MPI_DOUBLE,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::GlobalSumVector(double *d,int N) -{ - int ierr = MPI_Allreduce(MPI_IN_PLACE,d,N,MPI_DOUBLE,MPI_SUM,communicator); - assert(ierr==0); -} -void CartesianCommunicator::ShiftedRanks(int dim,int shift,int &source,int &dest) -{ - int ierr=MPI_Cart_shift(communicator,dim,shift,&source,&dest); - assert(ierr==0); -} -int CartesianCommunicator::RankFromProcessorCoor(std::vector &coor) -{ - int rank; - int ierr=MPI_Cart_rank (communicator, &coor[0], &rank); - assert(ierr==0); - return rank; -} -void CartesianCommunicator::ProcessorCoorFromRank(int rank, std::vector &coor) -{ - coor.resize(_ndimension); - int ierr=MPI_Cart_coords (communicator, rank, _ndimension,&coor[0]); - assert(ierr==0); -} - -// Basic Halo comms primitive -void CartesianCommunicator::SendToRecvFrom(void *xmit, - int dest, - void *recv, - int from, - int bytes) -{ - std::vector reqs(0); - SendToRecvFromBegin(reqs,xmit,dest,recv,from,bytes); - SendToRecvFromComplete(reqs); -} - -void CartesianCommunicator::SendRecvPacket(void *xmit, - void *recv, - int sender, - int receiver, - int bytes) -{ - MPI_Status stat; - assert(sender != receiver); - int tag = sender; - if ( _processor == sender ) { - MPI_Send(xmit, bytes, MPI_CHAR,receiver,tag,communicator); - } - if ( _processor == receiver ) { - MPI_Recv(recv, bytes, MPI_CHAR,sender,tag,communicator,&stat); - } -} - -// Basic Halo comms primitive -void CartesianCommunicator::SendToRecvFromBegin(std::vector &list, - void *xmit, - int dest, - void *recv, - int from, - int bytes) -{ - int myrank = _processor; - int ierr; - if ( CommunicatorPolicy == CommunicatorPolicyConcurrent ) { - MPI_Request xrq; - MPI_Request rrq; - - ierr =MPI_Irecv(recv, bytes, MPI_CHAR,from,from,communicator,&rrq); - ierr|=MPI_Isend(xmit, bytes, MPI_CHAR,dest,_processor,communicator,&xrq); - - assert(ierr==0); - list.push_back(xrq); - list.push_back(rrq); - } else { - // Give the CPU to MPI immediately; can use threads to overlap optionally - ierr=MPI_Sendrecv(xmit,bytes,MPI_CHAR,dest,myrank, - recv,bytes,MPI_CHAR,from, from, - communicator,MPI_STATUS_IGNORE); - assert(ierr==0); - } -} -void CartesianCommunicator::SendToRecvFromComplete(std::vector &list) -{ - if ( CommunicatorPolicy == CommunicatorPolicyConcurrent ) { - int nreq=list.size(); - std::vector status(nreq); - int ierr = MPI_Waitall(nreq,&list[0],&status[0]); - assert(ierr==0); - } -} - -void CartesianCommunicator::Barrier(void) -{ - int ierr = MPI_Barrier(communicator); - assert(ierr==0); -} - -void CartesianCommunicator::Broadcast(int root,void* data, int bytes) -{ - int ierr=MPI_Bcast(data, - bytes, - MPI_BYTE, - root, - communicator); - assert(ierr==0); -} - /////////////////////////////////////////////////////// - // Should only be used prior to Grid Init finished. - // Check for this? - /////////////////////////////////////////////////////// -int CartesianCommunicator::RankWorld(void){ - int r; - MPI_Comm_rank(communicator_world,&r); - return r; -} -void CartesianCommunicator::BroadcastWorld(int root,void* data, int bytes) -{ - int ierr= MPI_Bcast(data, - bytes, - MPI_BYTE, - root, - communicator_world); - assert(ierr==0); -} - -double CartesianCommunicator::StencilSendToRecvFromBegin(std::vector &list, - void *xmit, - int xmit_to_rank, - void *recv, - int recv_from_rank, - int bytes,int dir) -{ - int myrank = _processor; - int ierr; - int ncomm =communicator_halo.size(); - int commdir=dir%ncomm; - - // std::cout << " sending on communicator "< &waitall,int dir) -{ - int nreq=waitall.size(); - MPI_Waitall(nreq, &waitall[0], MPI_STATUSES_IGNORE); -} -double CartesianCommunicator::StencilSendToRecvFrom(void *xmit, - int xmit_to_rank, - void *recv, - int recv_from_rank, - int bytes,int dir) -{ - int myrank = _processor; - int ierr; - // std::cout << " sending on communicator "< - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - See the full license in the file "LICENSE" in the top level distribution directory - *************************************************************************************/ - /* END LEGAL */ -#include -#include -#include - -namespace Grid { - - // Should error check all MPI calls. -#define SHMEM_VET(addr) - -#define SHMEM_VET_DEBUG(addr) { \ - if ( ! shmem_addr_accessible(addr,_processor) ) {\ - std::fprintf(stderr,"%d Inaccessible shmem address %lx %s %s\n",_processor,addr,__FUNCTION__,#addr); \ - BACKTRACEFILE(); \ - }\ -} - - -/////////////////////////////////////////////////////////////////////////////////////////////////// -// Info that is setup once and indept of cartesian layout -/////////////////////////////////////////////////////////////////////////////////////////////////// - -typedef struct HandShake_t { - uint64_t seq_local; - uint64_t seq_remote; -} HandShake; - -std::array make_psync_init(void) { - std::array ret; - ret.fill(SHMEM_SYNC_VALUE); - return ret; -} -static std::array psync_init = make_psync_init(); - -static Vector< HandShake > XConnections; -static Vector< HandShake > RConnections; - -void CartesianCommunicator::Init(int *argc, char ***argv) { - shmem_init(); - XConnections.resize(shmem_n_pes()); - RConnections.resize(shmem_n_pes()); - for(int pe =0 ; pe &processors,const CartesianCommunicator &parent) - : CartesianCommunicator(processors) -{ - std::cout << "Attempts to split SHMEM communicators will fail " < &processors) -{ - _ndimension = processors.size(); - std::vector periodic(_ndimension,1); - - _Nprocessors=1; - _processors = processors; - _processor_coor.resize(_ndimension); - - _processor = shmem_my_pe(); - - Lexicographic::CoorFromIndex(_processor_coor,_processor,_processors); - - for(int i=0;i<_ndimension;i++){ - _Nprocessors*=_processors[i]; - } - - int Size = shmem_n_pes(); - - - assert(Size==_Nprocessors); -} - -void CartesianCommunicator::GlobalSum(uint32_t &u){ - static long long source ; - static long long dest ; - static long long llwrk[_SHMEM_REDUCE_MIN_WRKDATA_SIZE]; - static std::array psync = psync_init; - - // int nreduce=1; - // int pestart=0; - // int logStride=0; - - source = u; - dest = 0; - shmem_longlong_sum_to_all(&dest,&source,1,0,0,_Nprocessors,llwrk,psync.data()); - shmem_barrier_all(); // necessary? - u = dest; -} -void CartesianCommunicator::GlobalSum(uint64_t &u){ - static long long source ; - static long long dest ; - static long long llwrk[_SHMEM_REDUCE_MIN_WRKDATA_SIZE]; - static std::array psync = psync_init; - - // int nreduce=1; - // int pestart=0; - // int logStride=0; - - source = u; - dest = 0; - shmem_longlong_sum_to_all(&dest,&source,1,0,0,_Nprocessors,llwrk,psync.data()); - shmem_barrier_all(); // necessary? - u = dest; -} -void CartesianCommunicator::GlobalSum(float &f){ - static float source ; - static float dest ; - static float llwrk[_SHMEM_REDUCE_MIN_WRKDATA_SIZE]; - static std::array psync = psync_init; - - source = f; - dest =0.0; - shmem_float_sum_to_all(&dest,&source,1,0,0,_Nprocessors,llwrk,psync.data()); - shmem_barrier_all(); - f = dest; -} -void CartesianCommunicator::GlobalSumVector(float *f,int N) -{ - static float source ; - static float dest = 0 ; - static float llwrk[_SHMEM_REDUCE_MIN_WRKDATA_SIZE]; - static std::array psync = psync_init; - - if ( shmem_addr_accessible(f,_processor) ){ - shmem_float_sum_to_all(f,f,N,0,0,_Nprocessors,llwrk,psync.data()); - shmem_barrier_all(); - return; - } - - for(int i=0;i psync = psync_init; - - source = d; - dest = 0; - shmem_double_sum_to_all(&dest,&source,1,0,0,_Nprocessors,llwrk,psync.data()); - shmem_barrier_all(); - d = dest; -} -void CartesianCommunicator::GlobalSumVector(double *d,int N) -{ - static double source ; - static double dest ; - static double llwrk[_SHMEM_REDUCE_MIN_WRKDATA_SIZE]; - static std::array psync = psync_init; - - - if ( shmem_addr_accessible(d,_processor) ){ - shmem_double_sum_to_all(d,d,N,0,0,_Nprocessors,llwrk,psync.data()); - shmem_barrier_all(); - return; - } - - for(int i=0;i coor = _processor_coor; - - assert(std::abs(shift) <_processors[dim]); - - coor[dim] = (_processor_coor[dim] + shift + _processors[dim])%_processors[dim]; - Lexicographic::IndexFromCoor(coor,source,_processors); - - coor[dim] = (_processor_coor[dim] - shift + _processors[dim])%_processors[dim]; - Lexicographic::IndexFromCoor(coor,dest,_processors); - -} -int CartesianCommunicator::RankFromProcessorCoor(std::vector &coor) -{ - int rank; - Lexicographic::IndexFromCoor(coor,rank,_processors); - return rank; -} -void CartesianCommunicator::ProcessorCoorFromRank(int rank, std::vector &coor) -{ - Lexicographic::CoorFromIndex(coor,rank,_processors); -} - -// Basic Halo comms primitive -void CartesianCommunicator::SendToRecvFrom(void *xmit, - int dest, - void *recv, - int from, - int bytes) -{ - SHMEM_VET(xmit); - SHMEM_VET(recv); - std::vector reqs(0); - SendToRecvFromBegin(reqs,xmit,dest,recv,from,bytes); - SendToRecvFromComplete(reqs); -} - -void CartesianCommunicator::SendRecvPacket(void *xmit, - void *recv, - int sender, - int receiver, - int bytes) -{ - static uint64_t seq; - - assert(recv!=xmit); - volatile HandShake *RecvSeq = (volatile HandShake *) & RConnections[sender]; - volatile HandShake *SendSeq = (volatile HandShake *) & XConnections[receiver]; - - if ( _processor == sender ) { - - // Check he has posted a receive - while(SendSeq->seq_remote == SendSeq->seq_local); - - // Advance our send count - seq = ++(SendSeq->seq_local); - - // Send this packet - SHMEM_VET(recv); - shmem_putmem(recv,xmit,bytes,receiver); - shmem_fence(); - - //Notify him we're done - shmem_putmem((void *)&(RecvSeq->seq_remote),&seq,sizeof(seq),receiver); - shmem_fence(); - } - if ( _processor == receiver ) { - - // Post a receive - seq = ++(RecvSeq->seq_local); - shmem_putmem((void *)&(SendSeq->seq_remote),&seq,sizeof(seq),sender); - - // Now wait until he has advanced our reception counter - while(RecvSeq->seq_remote != RecvSeq->seq_local); - - } -} - -// Basic Halo comms primitive -void CartesianCommunicator::SendToRecvFromBegin(std::vector &list, - void *xmit, - int dest, - void *recv, - int from, - int bytes) -{ - SHMEM_VET(xmit); - SHMEM_VET(recv); - // shmem_putmem_nb(recv,xmit,bytes,dest,NULL); - shmem_putmem(recv,xmit,bytes,dest); - - if ( CommunicatorPolicy == CommunicatorPolicySequential ) shmem_barrier_all(); -} -void CartesianCommunicator::SendToRecvFromComplete(std::vector &list) -{ - // shmem_quiet(); // I'm done - if( CommunicatorPolicy == CommunicatorPolicyConcurrent ) shmem_barrier_all();// He's done too -} -void CartesianCommunicator::Barrier(void) -{ - shmem_barrier_all(); -} -void CartesianCommunicator::Broadcast(int root,void* data, int bytes) -{ - static std::array psync = psync_init; - static uint32_t word; - uint32_t *array = (uint32_t *) data; - assert( (bytes % 4)==0); - int words = bytes/4; - - if ( shmem_addr_accessible(data,_processor) ){ - shmem_broadcast32(data,data,words,root,0,0,shmem_n_pes(),psync.data()); - return; - } - - for(int w=0;w psync = psync_init; - static uint32_t word; - uint32_t *array = (uint32_t *) data; - assert( (bytes % 4)==0); - int words = bytes/4; - - for(int w=0;w + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#include + +namespace Grid { + +// static data + +uint64_t GlobalSharedMemory::MAX_MPI_SHM_BYTES = 1024LL*1024LL*1024LL; +int GlobalSharedMemory::Hugepages = 0; +int GlobalSharedMemory::ShmSetup; + +std::vector GlobalSharedMemory::WorldShmCommBufs; + +Grid_MPI_Comm GlobalSharedMemory::WorldShmComm; +int GlobalSharedMemory::WorldShmRank; +int GlobalSharedMemory::WorldShmSize; +std::vector GlobalSharedMemory::WorldShmRanks; + +Grid_MPI_Comm GlobalSharedMemory::WorldComm; +int GlobalSharedMemory::WorldSize; +int GlobalSharedMemory::WorldRank; + +int GlobalSharedMemory::WorldNodes; +int GlobalSharedMemory::WorldNode; + + +} diff --git a/lib/communicator/SharedMemory.h b/lib/communicator/SharedMemory.h new file mode 100644 index 00000000..2bb112e5 --- /dev/null +++ b/lib/communicator/SharedMemory.h @@ -0,0 +1,158 @@ +/************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./lib/communicator/SharedMemory.cc + + Copyright (C) 2015 + +Author: Peter Boyle + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + + +// TODO +// 1) move includes into SharedMemory.cc +// +// 2) split shared memory into a) optimal communicator creation from comm world +// +// b) shared memory buffers container +// -- static globally shared; init once +// -- per instance set of buffers. +// + +#pragma once + +#include + +#if defined (GRID_COMMS_MPI3) +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_NUMAIF_H +#include +#endif + +namespace Grid { + +#if defined (GRID_COMMS_MPI3) + typedef MPI_Comm Grid_MPI_Comm; + typedef MPI_Request CommsRequest_t; +#else + typedef int CommsRequest_t; + typedef int Grid_MPI_Comm; +#endif + +class GlobalSharedMemory { + private: + // Init once lock on the buffer allocation + static int ShmSetup; + static const int MAXLOG2RANKSPERNODE = 16; + + public: + static uint64_t MAX_MPI_SHM_BYTES; + static int Hugepages; + + static std::vector WorldShmCommBufs; + + static Grid_MPI_Comm WorldComm; + static int WorldRank; + static int WorldSize; + + static Grid_MPI_Comm WorldShmComm; + static int WorldShmRank; + static int WorldShmSize; + + static int WorldNodes; + static int WorldNode; + + static std::vector WorldShmRanks; + + ////////////////////////////////////////////////////////////////////////////////////// + // Create an optimal reordered communicator that makes MPI_Cart_create get it right + ////////////////////////////////////////////////////////////////////////////////////// + static void Init(Grid_MPI_Comm comm); // Typically MPI_COMM_WORLD + static void OptimalCommunicator(const std::vector &processors,Grid_MPI_Comm & optimal_comm); // Turns MPI_COMM_WORLD into right layout for Cartesian + /////////////////////////////////////////////////// + // Provide shared memory facilities off comm world + /////////////////////////////////////////////////// + static void SharedMemoryAllocate(uint64_t bytes, int flags); + static void SharedMemoryFree(void); + +}; + +////////////////////////////// +// one per communicator +////////////////////////////// +class SharedMemory +{ + private: + static const int MAXLOG2RANKSPERNODE = 16; + + size_t heap_top; + size_t heap_bytes; + size_t heap_size; + + protected: + + Grid_MPI_Comm ShmComm; // for barriers + int ShmRank; + int ShmSize; + std::vector ShmCommBufs; + std::vector ShmRanks;// Mapping comm ranks to Shm ranks + + public: + SharedMemory() {}; + /////////////////////////////////////////////////////////////////////////////////////// + // set the buffers & sizes + /////////////////////////////////////////////////////////////////////////////////////// + void SetCommunicator(Grid_MPI_Comm comm); + + //////////////////////////////////////////////////////////////////////// + // For this instance ; disjoint buffer sets between splits if split grid + //////////////////////////////////////////////////////////////////////// + void ShmBarrier(void); + + /////////////////////////////////////////////////// + // Call on any instance + /////////////////////////////////////////////////// + void SharedMemoryTest(void); + void *ShmBufferSelf(void); + void *ShmBuffer (int rank); + void *ShmBufferTranslate(int rank,void * local_p); + void *ShmBufferMalloc(size_t bytes); + void ShmBufferFreeAll(void) ; + + ////////////////////////////////////////////////////////////////////////// + // Make info on Nodes & ranks and Shared memory available + ////////////////////////////////////////////////////////////////////////// + int NodeCount(void) { return GlobalSharedMemory::WorldNodes;}; + int RankCount(void) { return GlobalSharedMemory::WorldSize;}; + +}; + +} diff --git a/lib/communicator/SharedMemoryMPI.cc b/lib/communicator/SharedMemoryMPI.cc new file mode 100644 index 00000000..af4f9702 --- /dev/null +++ b/lib/communicator/SharedMemoryMPI.cc @@ -0,0 +1,415 @@ +/************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./lib/communicator/SharedMemory.cc + + Copyright (C) 2015 + +Author: Peter Boyle + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#include + +namespace Grid { + +/*Construct from an MPI communicator*/ +void GlobalSharedMemory::Init(Grid_MPI_Comm comm) +{ + WorldComm = comm; + MPI_Comm_rank(WorldComm,&WorldRank); + MPI_Comm_size(WorldComm,&WorldSize); + // WorldComm, WorldSize, WorldRank + + ///////////////////////////////////////////////////////////////////// + // Split into groups that can share memory + ///////////////////////////////////////////////////////////////////// + MPI_Comm_split_type(comm, MPI_COMM_TYPE_SHARED, 0, MPI_INFO_NULL,&WorldShmComm); + MPI_Comm_rank(WorldShmComm ,&WorldShmRank); + MPI_Comm_size(WorldShmComm ,&WorldShmSize); + // WorldShmComm, WorldShmSize, WorldShmRank + + // WorldNodes + WorldNodes = WorldSize/WorldShmSize; + assert( (WorldNodes * WorldShmSize) == WorldSize ); + + // FIXME: Check all WorldShmSize are the same ? + + ///////////////////////////////////////////////////////////////////// + // find world ranks in our SHM group (i.e. which ranks are on our node) + ///////////////////////////////////////////////////////////////////// + MPI_Group WorldGroup, ShmGroup; + MPI_Comm_group (WorldComm, &WorldGroup); + MPI_Comm_group (WorldShmComm, &ShmGroup); + + std::vector world_ranks(WorldSize); for(int r=0;r MyGroup; + MyGroup.resize(WorldShmSize); + for(int rank=0;rank()); + int myleader = MyGroup[0]; + + std::vector leaders_1hot(WorldSize,0); + std::vector leaders_group(WorldNodes,0); + leaders_1hot [ myleader ] = 1; + + /////////////////////////////////////////////////////////////////// + // global sum leaders over comm world + /////////////////////////////////////////////////////////////////// + int ierr=MPI_Allreduce(MPI_IN_PLACE,&leaders_1hot[0],WorldSize,MPI_INT,MPI_SUM,WorldComm); + assert(ierr==0); + + /////////////////////////////////////////////////////////////////// + // find the group leaders world rank + /////////////////////////////////////////////////////////////////// + int group=0; + for(int l=0;l &processors,Grid_MPI_Comm & optimal_comm) +{ + //////////////////////////////////////////////////////////////// + // Assert power of two shm_size. + //////////////////////////////////////////////////////////////// + int log2size = -1; + for(int i=0;i<=MAXLOG2RANKSPERNODE;i++){ + if ( (0x1< processor_coor(ndimension); + std::vector WorldDims = processors; std::vector ShmDims (ndimension,1); std::vector NodeDims (ndimension); + std::vector ShmCoor (ndimension); std::vector NodeCoor (ndimension); std::vector WorldCoor(ndimension); + int dim = 0; + for(int l2=0;l2 ranks(size); for(int r=0;r= heap_size) { + std::cout<< " ShmBufferMalloc exceeded shared heap size -- try increasing with --shm flag" < + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ + +#include + +namespace Grid { + +/*Construct from an MPI communicator*/ +void GlobalSharedMemory::Init(Grid_MPI_Comm comm) +{ + WorldComm = 0; + WorldRank = 0; + WorldSize = 1; + WorldShmComm = 0 ; + WorldShmRank = 0 ; + WorldShmSize = 1 ; + WorldNodes = 1 ; + WorldNode = 0 ; + WorldShmRanks.resize(WorldSize); WorldShmRanks[0] = 0; + WorldShmCommBufs.resize(1); +} + +void GlobalSharedMemory::OptimalCommunicator(const std::vector &processors,Grid_MPI_Comm & optimal_comm) +{ + optimal_comm = WorldComm; +} + +//////////////////////////////////////////////////////////////////////////////////////////// +// Hugetlbfs mapping intended, use anonymous mmap +//////////////////////////////////////////////////////////////////////////////////////////// +void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) +{ + void * ShmCommBuf ; + MAX_MPI_SHM_BYTES=bytes; + int mmap_flag =0; +#ifdef MAP_ANONYMOUS + mmap_flag = mmap_flag| MAP_SHARED | MAP_ANONYMOUS; +#endif +#ifdef MAP_ANON + mmap_flag = mmap_flag| MAP_SHARED | MAP_ANON; +#endif +#ifdef MAP_HUGETLB + if ( flags ) mmap_flag |= MAP_HUGETLB; +#endif + ShmCommBuf =(void *) mmap(NULL, bytes, PROT_READ | PROT_WRITE, mmap_flag, -1, 0); + if (ShmCommBuf == (void *)MAP_FAILED) { + perror("mmap failed "); + exit(EXIT_FAILURE); + } +#ifdef MADV_HUGEPAGE + if (!Hugepages ) madvise(ShmCommBuf,bytes,MADV_HUGEPAGE); +#endif + bzero(ShmCommBuf,bytes); + WorldShmCommBufs[0] = ShmCommBuf; +}; + +void GlobalSharedMemory::SharedMemoryFree(void) +{ + assert(ShmSetup); + assert(0); // unimplemented +} + + //////////////////////////////////////////////////////// + // Global shared functionality finished + // Now move to per communicator functionality + //////////////////////////////////////////////////////// +void SharedMemory::SetCommunicator(Grid_MPI_Comm comm) +{ + ShmRanks.resize(1); + ShmCommBufs.resize(1); + ShmRanks[0] = 0; + ShmRank = 0; + ShmSize = 1; + ////////////////////////////////////////////////////////////////////// + // Map ShmRank to WorldShmRank and use the right buffer + ////////////////////////////////////////////////////////////////////// + ShmCommBufs[0] = GlobalSharedMemory::WorldShmCommBufs[0]; + heap_size = GlobalSharedMemory::MAX_MPI_SHM_BYTES; + ShmBufferFreeAll(); + return; +} +////////////////////////////////////////////////////////////////// +// On node barrier +////////////////////////////////////////////////////////////////// +void SharedMemory::ShmBarrier(void){ return ; } + +////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Test the shared memory is working +////////////////////////////////////////////////////////////////////////////////////////////////////////// +void SharedMemory::SharedMemoryTest(void) { return; } + +void *SharedMemory::ShmBufferSelf(void) +{ + return ShmCommBufs[ShmRank]; +} +void *SharedMemory::ShmBuffer(int rank) +{ + return NULL; +} +void *SharedMemory::ShmBufferTranslate(int rank,void * local_p) +{ + return NULL; +} + +///////////////////////////////// +// Alloc, free shmem region ; common to MPI and none? +///////////////////////////////// +void *SharedMemory::ShmBufferMalloc(size_t bytes){ + void *ptr = (void *)heap_top; + heap_top += bytes; + heap_bytes+= bytes; + if (heap_bytes >= heap_size) { + std::cout<< " ShmBufferMalloc exceeded shared heap size -- try increasing with --shm flag" < Date: Mon, 8 Jan 2018 11:36:39 +0000 Subject: [PATCH 138/174] Synthetic test of lanczos --- ..._dwf_compressed_lanczos_reorg_synthetic.cc | 330 ++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 tests/lanczos/Test_dwf_compressed_lanczos_reorg_synthetic.cc diff --git a/tests/lanczos/Test_dwf_compressed_lanczos_reorg_synthetic.cc b/tests/lanczos/Test_dwf_compressed_lanczos_reorg_synthetic.cc new file mode 100644 index 00000000..132dff4e --- /dev/null +++ b/tests/lanczos/Test_dwf_compressed_lanczos_reorg_synthetic.cc @@ -0,0 +1,330 @@ + /************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./tests/Test_dwf_compressed_lanczos_reorg.cc + + Copyright (C) 2017 + +Author: Leans heavily on Christoph Lehner's code +Author: Peter Boyle + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ + /* END LEGAL */ +/* + * Reimplement the badly named "multigrid" lanczos as compressed Lanczos using the features + * in Grid that were intended to be used to support blocked Aggregates, from + */ +#include +#include + +using namespace std; +using namespace Grid; +using namespace Grid::QCD; + +template +class ProjectedHermOp : public LinearFunction > > { +public: + typedef iVector CoarseSiteVector; + typedef Lattice CoarseField; + typedef Lattice CoarseScalar; // used for inner products on fine field + typedef Lattice FineField; + + LinearOperatorBase &_Linop; + Aggregation &_Aggregate; + + ProjectedHermOp(LinearOperatorBase& linop, Aggregation &aggregate) : + _Linop(linop), + _Aggregate(aggregate) { }; + + void operator()(const CoarseField& in, CoarseField& out) { + + GridBase *FineGrid = _Aggregate.FineGrid; + FineField fin(FineGrid); + FineField fout(FineGrid); + + _Aggregate.PromoteFromSubspace(in,fin); + _Linop.HermOp(fin,fout); + _Aggregate.ProjectToSubspace(out,fout); + } +}; + +template +class ProjectedFunctionHermOp : public LinearFunction > > { +public: + typedef iVector CoarseSiteVector; + typedef Lattice CoarseField; + typedef Lattice CoarseScalar; // used for inner products on fine field + typedef Lattice FineField; + + + OperatorFunction & _poly; + LinearOperatorBase &_Linop; + Aggregation &_Aggregate; + + ProjectedFunctionHermOp(OperatorFunction & poly,LinearOperatorBase& linop, + Aggregation &aggregate) : + _poly(poly), + _Linop(linop), + _Aggregate(aggregate) { }; + + void operator()(const CoarseField& in, CoarseField& out) { + + GridBase *FineGrid = _Aggregate.FineGrid; + + FineField fin(FineGrid) ;fin.checkerboard =_Aggregate.checkerboard; + FineField fout(FineGrid);fout.checkerboard =_Aggregate.checkerboard; + + _Aggregate.PromoteFromSubspace(in,fin); + _poly(_Linop,fin,fout); + _Aggregate.ProjectToSubspace(out,fout); + } +}; + +// Make serializable Lanczos params + +template +class CoarseFineIRL +{ +public: + typedef iVector CoarseSiteVector; + typedef Lattice CoarseScalar; // used for inner products on fine field + typedef Lattice CoarseField; + typedef Lattice FineField; + +private: + GridBase *_CoarseGrid; + GridBase *_FineGrid; + int _checkerboard; + LinearOperatorBase & _FineOp; + Aggregation _Aggregate; + +public: + CoarseFineIRL(GridBase *FineGrid, + GridBase *CoarseGrid, + LinearOperatorBase &FineOp, + int checkerboard) : + _CoarseGrid(CoarseGrid), + _FineGrid(FineGrid), + _Aggregate(CoarseGrid,FineGrid,checkerboard), + _FineOp(FineOp), + _checkerboard(checkerboard) + {}; + + template static RealD normalise(T& v) + { + RealD nn = norm2(v); + nn = ::sqrt(nn); + v = v * (1.0/nn); + return nn; + } + + void testFine(void) + { + int Nk = nbasis; + _Aggregate.subspace.resize(Nk,_FineGrid); + _Aggregate.subspace[0]=1.0; + _Aggregate.subspace[0].checkerboard=_checkerboard; + normalise(_Aggregate.subspace[0]); + PlainHermOp Op(_FineOp); + for(int k=1;k Cheby(alpha,beta,Npoly); + FunctionHermOp ChebyOp(Cheby,_FineOp); + PlainHermOp Op(_FineOp); + + int Nk = nbasis; + + std::vector eval(Nm); + + FineField src(_FineGrid); src=1.0; src.checkerboard = _checkerboard; + + ImplicitlyRestartedLanczos IRL(ChebyOp,Op,Nk,Nk,Nm,resid,MaxIt,betastp,MinRes); + _Aggregate.subspace.resize(Nm,_FineGrid); + IRL.calc(eval,_Aggregate.subspace,src,Nk,false); + _Aggregate.subspace.resize(Nk,_FineGrid); + for(int k=0;k Cheby(alpha,beta,Npoly); + ProjectedHermOp Op(_FineOp,_Aggregate); + ProjectedFunctionHermOp ChebyOp(Cheby,_FineOp,_Aggregate); + + std::vector eval(Nm); + std::vector evec(Nm,_CoarseGrid); + + CoarseField src(_CoarseGrid); src=1.0; + + ImplicitlyRestartedLanczos IRL(ChebyOp,ChebyOp,Nk,Nk,Nm,resid,MaxIt,betastp,MinRes); + IRL.calc(eval,evec,src,Nk,false); + + // We got the evalues of the Cheby operator; + // Reconstruct eigenvalues of original operator via Chebyshev inverse + for (int i=0;i, blockSize, + std::string, config, + std::vector < std::complex >, omega, + RealD, mass, + RealD, M5 + ); +}; + +int main (int argc, char ** argv) { + + Grid_init(&argc,&argv); + + CompressedLanczosParams Params; + { + Params.omega.resize(10); + Params.blockSize.resize(5); + XmlWriter writer("Params_template.xml"); + write(writer,"Params",Params); + std::cout << GridLogMessage << " Written Params_template.xml" < blockSize = Params.blockSize; + + // Grids + GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); + GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); + GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); + GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid); + + std::vector fineLatt = GridDefaultLatt(); + int dims=fineLatt.size(); + assert(blockSize.size()==dims+1); + std::vector coarseLatt(dims); + std::vector coarseLatt5d ; + + for (int d=0;d seeds4({1,2,3,4}); + GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); + SU3::HotConfiguration(RNG4, Umu); + } + std::cout << GridLogMessage << "Lattice dimensions: " << GridDefaultLatt() << " Ls: " << Ls << std::endl; + + // ZMobius EO Operator + ZMobiusFermionR Ddwf(Umu, *FGrid, *FrbGrid, *UGrid, *UrbGrid, mass, M5, Params.omega,1.,0.); + SchurDiagTwoOperator HermOp(Ddwf); + + // Eigenvector storage + LanczosParams fine =Params.FineParams; + LanczosParams coarse=Params.CoarseParams; + const int Nm1 = fine.Nm; + const int Nm2 = coarse.Nm; + + std::cout << GridLogMessage << "Keep " << fine.Nk << " full vectors" << std::endl; + std::cout << GridLogMessage << "Keep " << coarse.Nk << " total vectors" << std::endl; + assert(Nm2 >= Nm1); + + const int nbasis= 70; + CoarseFineIRL IRL(FrbGrid,CoarseGrid5rb,HermOp,Odd); + + std::cout << GridLogMessage << "Constructed CoarseFine IRL" << std::endl; + + std::cout << GridLogMessage << "Performing fine grid IRL Nk "<< nbasis<<" Nm "< Date: Mon, 8 Jan 2018 14:06:53 +0000 Subject: [PATCH 139/174] Clean up --- lib/communicator/Communicator_base.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/communicator/Communicator_base.h b/lib/communicator/Communicator_base.h index a9b99c17..359846c9 100644 --- a/lib/communicator/Communicator_base.h +++ b/lib/communicator/Communicator_base.h @@ -184,15 +184,10 @@ public: template void AllToAll(int dim,std::vector &in, std::vector &out){ assert(dim>=0); assert(dim<_ndimension); - int numnode = _processors[dim]; - // std::cerr << " AllToAll in.size() "< Date: Mon, 8 Jan 2018 15:20:26 +0000 Subject: [PATCH 140/174] Allow resize of the shared memory buffers --- TODO | 28 +++++++++++---- lib/communicator/SharedMemory.cc | 40 ++++++++++++++++++++- lib/communicator/SharedMemory.h | 10 ++++-- lib/communicator/SharedMemoryMPI.cc | 52 +++++++++------------------- lib/communicator/SharedMemoryNone.cc | 40 +++++---------------- 5 files changed, 93 insertions(+), 77 deletions(-) diff --git a/TODO b/TODO index 95ccf1df..746302ca 100644 --- a/TODO +++ b/TODO @@ -1,16 +1,32 @@ TODO: --------------- -Large item work list: +Code item work list + +a) namespaces & indentation + GRID_BEGIN_NAMESPACE(); + GRID_END_NAMESPACE(); +-- delete QCD namespace + +b) GPU branch +- start branch +- Increase Macro use in core library support; prepare for change +- Audit volume of "device" code +- Virtual function audit +- Start port once Nvidia box is up +- Cut down volume of code for first port? How? + +Physics item work list: 1)- BG/Q port and check ; Andrew says ok. -3a)- RNG I/O in ILDG/SciDAC (minor) -3c)- Consistent linear solver flop count/rate -- PARTIAL, time but no flop/s yet -4)- Physical propagator interface -6)- Multigrid Wilson and DWF, compare to other Multigrid implementations -7)- HDCR resume +2)- Consistent linear solver flop count/rate -- PARTIAL, time but no flop/s yet +3)- Physical propagator interface +4)- Multigrid Wilson and DWF, compare to other Multigrid implementations +5)- HDCR resume + ---------------------------- Recent DONE +-- RNG I/O in ILDG/SciDAC (minor) -- Precision conversion and sort out localConvert <-- partial/easy -- Conserved currents (Andrew) -- Split grid diff --git a/lib/communicator/SharedMemory.cc b/lib/communicator/SharedMemory.cc index f9d5e5bc..4682d420 100644 --- a/lib/communicator/SharedMemory.cc +++ b/lib/communicator/SharedMemory.cc @@ -34,7 +34,9 @@ namespace Grid { uint64_t GlobalSharedMemory::MAX_MPI_SHM_BYTES = 1024LL*1024LL*1024LL; int GlobalSharedMemory::Hugepages = 0; -int GlobalSharedMemory::ShmSetup; +int GlobalSharedMemory::_ShmSetup; +int GlobalSharedMemory::_ShmAlloc; +uint64_t GlobalSharedMemory::_ShmAllocBytes; std::vector GlobalSharedMemory::WorldShmCommBufs; @@ -50,5 +52,41 @@ int GlobalSharedMemory::WorldRank; int GlobalSharedMemory::WorldNodes; int GlobalSharedMemory::WorldNode; +void GlobalSharedMemory::SharedMemoryFree(void) +{ + assert(_ShmAlloc); + assert(_ShmAllocBytes>0); + for(int r=0;r= heap_size) { + std::cout<< " ShmBufferMalloc exceeded shared heap size -- try increasing with --shm flag" < &processors,Grid_MPI_Comm & optimal_comm) @@ -180,8 +182,8 @@ void GlobalSharedMemory::OptimalCommunicator(const std::vector &processors, #ifdef GRID_MPI3_SHMMMAP void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) { - GlobalSharedMemory::MAX_MPI_SHM_BYTES = bytes; - assert(ShmSetup==0); ShmSetup=1; + assert(_ShmSetup==1); + assert(_ShmAlloc==0); ////////////////////////////////////////////////////////////////////////////////////////////////////////// // allocate the shared windows for our group ////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -214,8 +216,11 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) perror("failed mmap"); assert(0); } assert(((uint64_t)ptr&0x3F)==0); + close(fd); WorldShmCommBufs[r] =ptr; } + _ShmAlloc=1; + _ShmAllocBytes = bytes; }; #endif // MMAP @@ -227,8 +232,8 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) //////////////////////////////////////////////////////////////////////////////////////////// void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) { - GlobalSharedMemory::MAX_MPI_SHM_BYTES = bytes; - assert(ShmSetup==0); ShmSetup=1; + assert(_ShmSetup==1); + assert(_ShmAlloc==0); MPI_Barrier(WorldShmComm); WorldShmCommBufs.resize(WorldShmSize); @@ -258,6 +263,7 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) assert(((uint64_t)ptr&0x3F)==0); WorldShmCommBufs[r] =ptr; + close(fd); } } @@ -277,17 +283,15 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) if ( ptr == MAP_FAILED ) { perror("failed mmap"); assert(0); } assert(((uint64_t)ptr&0x3F)==0); WorldShmCommBufs[r] =ptr; + + close(fd); } } + _ShmAlloc=1; + _ShmAllocBytes = bytes; } #endif -void GlobalSharedMemory::SharedMemoryFree(void) -{ - assert(ShmSetup); - assert(0); // unimplemented -} - //////////////////////////////////////////////////////// // Global shared functionality finished // Now move to per communicator functionality @@ -310,7 +314,8 @@ void SharedMemory::SetCommunicator(Grid_MPI_Comm comm) ////////////////////////////////////////////////////////////////////// // Map ShmRank to WorldShmRank and use the right buffer ////////////////////////////////////////////////////////////////////// - heap_size = GlobalSharedMemory::MAX_MPI_SHM_BYTES; + assert (GlobalSharedMemory::ShmAlloc()==1); + heap_size = GlobalSharedMemory::ShmAllocBytes(); for(int r=0;r= heap_size) { - std::cout<< " ShmBufferMalloc exceeded shared heap size -- try increasing with --shm flag" < &processors,Grid_MPI_Comm & optimal_comm) @@ -56,7 +58,8 @@ void GlobalSharedMemory::OptimalCommunicator(const std::vector &processors, void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) { void * ShmCommBuf ; - MAX_MPI_SHM_BYTES=bytes; + assert(_ShmSetup==1); + assert(_ShmAlloc==0); int mmap_flag =0; #ifdef MAP_ANONYMOUS mmap_flag = mmap_flag| MAP_SHARED | MAP_ANONYMOUS; @@ -77,20 +80,17 @@ void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) #endif bzero(ShmCommBuf,bytes); WorldShmCommBufs[0] = ShmCommBuf; + _ShmAllocBytes=bytes; + _ShmAlloc=1; }; -void GlobalSharedMemory::SharedMemoryFree(void) -{ - assert(ShmSetup); - assert(0); // unimplemented -} - //////////////////////////////////////////////////////// // Global shared functionality finished // Now move to per communicator functionality //////////////////////////////////////////////////////// void SharedMemory::SetCommunicator(Grid_MPI_Comm comm) { + assert(GlobalSharedMemory::ShmAlloc()==1); ShmRanks.resize(1); ShmCommBufs.resize(1); ShmRanks[0] = 0; @@ -100,7 +100,7 @@ void SharedMemory::SetCommunicator(Grid_MPI_Comm comm) // Map ShmRank to WorldShmRank and use the right buffer ////////////////////////////////////////////////////////////////////// ShmCommBufs[0] = GlobalSharedMemory::WorldShmCommBufs[0]; - heap_size = GlobalSharedMemory::MAX_MPI_SHM_BYTES; + heap_size = GlobalSharedMemory::ShmAllocBytes(); ShmBufferFreeAll(); return; } @@ -114,10 +114,6 @@ void SharedMemory::ShmBarrier(void){ return ; } ////////////////////////////////////////////////////////////////////////////////////////////////////////// void SharedMemory::SharedMemoryTest(void) { return; } -void *SharedMemory::ShmBufferSelf(void) -{ - return ShmCommBufs[ShmRank]; -} void *SharedMemory::ShmBuffer(int rank) { return NULL; @@ -127,24 +123,4 @@ void *SharedMemory::ShmBufferTranslate(int rank,void * local_p) return NULL; } -///////////////////////////////// -// Alloc, free shmem region ; common to MPI and none? -///////////////////////////////// -void *SharedMemory::ShmBufferMalloc(size_t bytes){ - void *ptr = (void *)heap_top; - heap_top += bytes; - heap_bytes+= bytes; - if (heap_bytes >= heap_size) { - std::cout<< " ShmBufferMalloc exceeded shared heap size -- try increasing with --shm flag" < Date: Wed, 10 Jan 2018 10:59:58 +0000 Subject: [PATCH 141/174] Hadrons: result file macro with trajectory number --- extras/Hadrons/Global.cc | 7 +++++++ extras/Hadrons/Global.hpp | 13 +++++++++---- extras/Hadrons/Modules/MContraction/Baryon.hpp | 2 +- extras/Hadrons/Modules/MContraction/DiscLoop.hpp | 2 +- extras/Hadrons/Modules/MContraction/Gamma3pt.hpp | 2 +- extras/Hadrons/Modules/MContraction/Meson.hpp | 2 +- .../Modules/MContraction/WeakHamiltonianEye.cc | 2 +- .../Modules/MContraction/WeakHamiltonianNonEye.cc | 2 +- .../Modules/MContraction/WeakNeutral4ptDisc.cc | 2 +- extras/Hadrons/Modules/MScalar/ChargedProp.cc | 2 +- 10 files changed, 24 insertions(+), 12 deletions(-) diff --git a/extras/Hadrons/Global.cc b/extras/Hadrons/Global.cc index 942a4243..9a90a08c 100644 --- a/extras/Hadrons/Global.cc +++ b/extras/Hadrons/Global.cc @@ -67,3 +67,10 @@ std::string Hadrons::typeName(const std::type_info *info) return name; } + +// default writers/readers ///////////////////////////////////////////////////// +#ifdef HAVE_HDF5 +const std::string Hadrons::resultFileExt = "h5"; +#else +const std::string Hadrons::resultFileExt = "xml"; +#endif diff --git a/extras/Hadrons/Global.hpp b/extras/Hadrons/Global.hpp index 274e1934..fc069ed6 100644 --- a/extras/Hadrons/Global.hpp +++ b/extras/Hadrons/Global.hpp @@ -167,14 +167,19 @@ std::string typeName(void) } // default writers/readers +extern const std::string resultFileExt; + #ifdef HAVE_HDF5 -typedef Hdf5Reader CorrReader; -typedef Hdf5Writer CorrWriter; +typedef Hdf5Reader ResultReader; +typedef Hdf5Writer ResultWriter; #else -typedef XmlReader CorrReader; -typedef XmlWriter CorrWriter; +typedef XmlReader ResultReader; +typedef XmlWriter ResultWriter; #endif +#define RESULT_FILE_NAME(name) \ +name + "." + std::to_string(vm().getTrajectory()) + "." + resultFileExt + END_HADRONS_NAMESPACE #include diff --git a/extras/Hadrons/Modules/MContraction/Baryon.hpp b/extras/Hadrons/Modules/MContraction/Baryon.hpp index 625c7108..8966d95b 100644 --- a/extras/Hadrons/Modules/MContraction/Baryon.hpp +++ b/extras/Hadrons/Modules/MContraction/Baryon.hpp @@ -122,7 +122,7 @@ void TBaryon::execute(void) << " quarks '" << par().q1 << "', '" << par().q2 << "', and '" << par().q3 << "'" << std::endl; - CorrWriter writer(par().output); + ResultWriter writer(RESULT_FILE_NAME(par().output)); auto &q1 = envGet(PropagatorField1, par().q1); auto &q2 = envGet(PropagatorField2, par().q2); auto &q3 = envGet(PropagatorField3, par().q2); diff --git a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp index 3d08f0eb..539abbbb 100644 --- a/extras/Hadrons/Modules/MContraction/DiscLoop.hpp +++ b/extras/Hadrons/Modules/MContraction/DiscLoop.hpp @@ -119,7 +119,7 @@ void TDiscLoop::execute(void) << "' using '" << par().q_loop << "' with " << par().gamma << " insertion." << std::endl; - CorrWriter writer(par().output); + ResultWriter writer(RESULT_FILE_NAME(par().output)); auto &q_loop = envGet(PropagatorField, par().q_loop); Gamma gamma(par().gamma); std::vector buf; diff --git a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp index 68701aeb..b4327a13 100644 --- a/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp +++ b/extras/Hadrons/Modules/MContraction/Gamma3pt.hpp @@ -153,7 +153,7 @@ void TGamma3pt::execute(void) // Initialise variables. q2 and q3 are normal propagators, q1 may be // sink smeared. - CorrWriter writer(par().output); + ResultWriter writer(RESULT_FILE_NAME(par().output)); auto &q1 = envGet(SlicedPropagator1, par().q1); auto &q2 = envGet(PropagatorField2, par().q2); auto &q3 = envGet(PropagatorField2, par().q3); diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 5cf504e3..0197534d 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -172,7 +172,7 @@ void TMeson::execute(void) << " quarks '" << par().q1 << "' and '" << par().q2 << "'" << std::endl; - CorrWriter writer(par().output); + ResultWriter writer(RESULT_FILE_NAME(par().output)); std::vector buf; std::vector result; Gamma g5(Gamma::Algebra::Gamma5); diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc index b79c09e7..1d257fc7 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc @@ -104,7 +104,7 @@ void TWeakHamiltonianEye::execute(void) << par().q2 << ", '" << par().q3 << "' and '" << par().q4 << "'." << std::endl; - CorrWriter writer(par().output); + ResultWriter writer(RESULT_FILE_NAME(par().output)); auto &q1 = envGet(SlicedPropagator, par().q1); auto &q2 = envGet(PropagatorField, par().q2); auto &q3 = envGet(PropagatorField, par().q3); diff --git a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc index e66b6ee7..2ad2e7dc 100644 --- a/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc +++ b/extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc @@ -104,7 +104,7 @@ void TWeakHamiltonianNonEye::execute(void) << par().q2 << ", '" << par().q3 << "' and '" << par().q4 << "'." << std::endl; - CorrWriter writer(par().output); + ResultWriter writer(RESULT_FILE_NAME(par().output)); auto &q1 = envGet(PropagatorField, par().q1); auto &q2 = envGet(PropagatorField, par().q2); auto &q3 = envGet(PropagatorField, par().q3); diff --git a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc index e0a00472..2c94b2ba 100644 --- a/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc +++ b/extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc @@ -104,7 +104,7 @@ void TWeakNeutral4ptDisc::execute(void) << par().q2 << ", '" << par().q3 << "' and '" << par().q4 << "'." << std::endl; - CorrWriter writer(par().output); + ResultWriter writer(RESULT_FILE_NAME(par().output)); auto &q1 = envGet(PropagatorField, par().q1); auto &q2 = envGet(PropagatorField, par().q2); auto &q3 = envGet(PropagatorField, par().q3); diff --git a/extras/Hadrons/Modules/MScalar/ChargedProp.cc b/extras/Hadrons/Modules/MScalar/ChargedProp.cc index da82617f..1470f1ad 100644 --- a/extras/Hadrons/Modules/MScalar/ChargedProp.cc +++ b/extras/Hadrons/Modules/MScalar/ChargedProp.cc @@ -133,7 +133,7 @@ void TChargedProp::execute(void) LOG(Message) << "Saving zero-momentum projection to '" << filename << "'..." << std::endl; - CorrWriter writer(filename); + ResultWriter writer(RESULT_FILE_NAME(par().output)); std::vector vecBuf; std::vector result; From 29f026c3758b6e5c1cd2fcaf6f11066f015d0284 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 10 Jan 2018 11:01:03 +0000 Subject: [PATCH 142/174] Hadrons: scalar SU(N) tr(phi^n) 1-pt function --- extras/Hadrons/Modules.hpp | 30 +--- extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp | 155 ++++++++++++++++++++ extras/Hadrons/make_module_list.sh | 30 ---- extras/Hadrons/modules.inc | 1 + 4 files changed, 157 insertions(+), 59 deletions(-) create mode 100644 extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index e50d2b0b..523ac101 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -1,32 +1,3 @@ -/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: extras/Hadrons/Modules.hpp - -Copyright (C) 2015-2018 - -Author: Antonin Portelli -Author: Lanny91 - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file "LICENSE" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ - #include #include #include @@ -56,5 +27,6 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include +#include #include #include diff --git a/extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp b/extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp new file mode 100644 index 00000000..8c6bead7 --- /dev/null +++ b/extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp @@ -0,0 +1,155 @@ +#ifndef Hadrons_MScalarSUN_TrPhi_hpp_ +#define Hadrons_MScalarSUN_TrPhi_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * TrPhi * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MScalarSUN) + +class TrPhiPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(TrPhiPar, + std::string, field, + unsigned int, maxPow, + std::string, output); +}; + +template +class TTrPhi: public Module +{ +public: + typedef typename SImpl::Field Field; + typedef typename SImpl::ComplexField ComplexField; + class Result: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Result, + std::string, op, + Complex, value); + }; +public: + // constructor + TTrPhi(const std::string name); + // destructor + virtual ~TTrPhi(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +private: + // output name generator + std::string outName(const unsigned int n); +}; + +MODULE_REGISTER_NS(TrPhiSU2, TTrPhi>, MScalarSUN); +MODULE_REGISTER_NS(TrPhiSU3, TTrPhi>, MScalarSUN); +MODULE_REGISTER_NS(TrPhiSU4, TTrPhi>, MScalarSUN); +MODULE_REGISTER_NS(TrPhiSU5, TTrPhi>, MScalarSUN); +MODULE_REGISTER_NS(TrPhiSU6, TTrPhi>, MScalarSUN); + +/****************************************************************************** + * TTrPhi implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TTrPhi::TTrPhi(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TTrPhi::getInput(void) +{ + std::vector in = {par().field}; + + return in; +} + +template +std::vector TTrPhi::getOutput(void) +{ + std::vector out; + + for (unsigned int n = 2; n <= par().maxPow; n += 2) + { + out.push_back(outName(n)); + } + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TTrPhi::setup(void) +{ + if (par().maxPow < 2) + { + HADRON_ERROR(Size, "'maxPow' should be at least equal to 2"); + } + envTmpLat(Field, "phi2"); + envTmpLat(Field, "buf"); + for (unsigned int n = 2; n <= par().maxPow; n += 2) + { + envCreateLat(ComplexField, outName(n)); + } +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TTrPhi::execute(void) +{ + LOG(Message) << "Computing tr(phi^n) for n even up to " << par().maxPow + << "..." << std::endl; + + std::vector result; + auto &phi = envGet(Field, par().field); + + envGetTmp(Field, phi2); + envGetTmp(Field, buf); + buf = 1.; + phi2 = -phi*phi; + for (unsigned int n = 2; n <= par().maxPow; n += 2) + { + auto &phin = envGet(ComplexField, outName(n)); + + buf = buf*phi2; + phin = trace(buf); + if (!par().output.empty()) + { + Result r; + + r.op = "phi" + std::to_string(n); + r.value = TensorRemove(sum(phin)); + result.push_back(r); + } + } + if (result.size() > 0) + { + ResultWriter writer(RESULT_FILE_NAME(par().output)); + + write(writer, "trphi", result); + } +} + +// output name generator /////////////////////////////////////////////////////// +template +std::string TTrPhi::outName(const unsigned int n) +{ + return getName() + "_" + std::to_string(n); +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MScalarSUN_TrPhi_hpp_ diff --git a/extras/Hadrons/make_module_list.sh b/extras/Hadrons/make_module_list.sh index 8c6fa4da..ddc56ff6 100755 --- a/extras/Hadrons/make_module_list.sh +++ b/extras/Hadrons/make_module_list.sh @@ -7,36 +7,6 @@ echo 'modules_hpp =\' >> modules.inc find Modules -name '*.hpp' -type f -print | sed 's/^/ /;$q;s/$/ \\/' >> modules.inc echo '' >> modules.inc rm -f Modules.hpp -echo "/************************************************************************************* - -Grid physics library, www.github.com/paboyle/Grid - -Source file: extras/Hadrons/Modules.hpp - -Copyright (C) 2015 -Copyright (C) 2016 -Copyright (C) 2017 - -Author: Antonin Portelli - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -See the full license in the file \"LICENSE\" in the top level distribution directory -*************************************************************************************/ -/* END LEGAL */ -" > Modules.hpp for f in `find Modules -name '*.hpp'`; do echo "#include " >> Modules.hpp done diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 6e1ef6dc..00ef323f 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -39,6 +39,7 @@ modules_hpp =\ Modules/MScalar/ChargedProp.hpp \ Modules/MAction/DWF.hpp \ Modules/MAction/Wilson.hpp \ + Modules/MScalarSUN/TrPhi.hpp \ Modules/MIO/LoadNersc.hpp \ Modules/MIO/LoadBinary.hpp From b7cd7213085c7050f17c81ba2757c1d8ae63c914 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 10 Jan 2018 11:25:59 +0000 Subject: [PATCH 143/174] Hadrons: scalar SU(N) tr(mag^n) --- extras/Hadrons/Modules.hpp | 1 + extras/Hadrons/Modules/MScalarSUN/TrMag.hpp | 119 ++++++++++++++++++++ extras/Hadrons/modules.inc | 1 + 3 files changed, 121 insertions(+) create mode 100644 extras/Hadrons/Modules/MScalarSUN/TrMag.hpp diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 523ac101..1d059a79 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/extras/Hadrons/Modules/MScalarSUN/TrMag.hpp b/extras/Hadrons/Modules/MScalarSUN/TrMag.hpp new file mode 100644 index 00000000..f33784fa --- /dev/null +++ b/extras/Hadrons/Modules/MScalarSUN/TrMag.hpp @@ -0,0 +1,119 @@ +#ifndef Hadrons_MScalarSUN_TrMag_hpp_ +#define Hadrons_MScalarSUN_TrMag_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * TrMag * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MScalarSUN) + +class TrMagPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(TrMagPar, + std::string, field, + unsigned int, maxPow, + std::string, output); +}; + +template +class TTrMag: public Module +{ +public: + typedef typename SImpl::Field Field; + typedef typename SImpl::ComplexField ComplexField; + class Result: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Result, + std::string, op, + Real, value); + }; +public: + // constructor + TTrMag(const std::string name); + // destructor + virtual ~TTrMag(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_NS(TrMagSU2, TTrMag>, MScalarSUN); +MODULE_REGISTER_NS(TrMagSU3, TTrMag>, MScalarSUN); +MODULE_REGISTER_NS(TrMagSU4, TTrMag>, MScalarSUN); +MODULE_REGISTER_NS(TrMagSU5, TTrMag>, MScalarSUN); +MODULE_REGISTER_NS(TrMagSU6, TTrMag>, MScalarSUN); + +/****************************************************************************** + * TTrMag implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TTrMag::TTrMag(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TTrMag::getInput(void) +{ + std::vector in = {par().field}; + + return in; +} + +template +std::vector TTrMag::getOutput(void) +{ + std::vector out = {}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TTrMag::setup(void) +{} + +// execution /////////////////////////////////////////////////////////////////// +template +void TTrMag::execute(void) +{ + LOG(Message) << "Computing tr(mag^n) for n even up to " << par().maxPow + << "..." << std::endl; + + std::vector result; + ResultWriter writer(RESULT_FILE_NAME(par().output)); + auto &phi = envGet(Field, par().field); + + auto m2 = sum(phi), mn = m2; + + m2 = -m2*m2; + mn = 1.; + for (unsigned int n = 2; n <= par().maxPow; n += 2) + { + Result r; + + mn = mn*m2; + r.op = "tr(mag^" + std::to_string(n) + ")"; + r.value = TensorRemove(trace(mn)).real(); + result.push_back(r); + } + write(writer, "trmag", result); +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MScalarSUN_TrMag_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index 00ef323f..cea4dc2a 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -39,6 +39,7 @@ modules_hpp =\ Modules/MScalar/ChargedProp.hpp \ Modules/MAction/DWF.hpp \ Modules/MAction/Wilson.hpp \ + Modules/MScalarSUN/TrMag.hpp \ Modules/MScalarSUN/TrPhi.hpp \ Modules/MIO/LoadNersc.hpp \ Modules/MIO/LoadBinary.hpp From d9d1f43ba208fed87fae930e182e4b6cd550da6f Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 10 Jan 2018 11:29:49 +0000 Subject: [PATCH 144/174] Hadrons: code cleaning --- extras/Hadrons/Modules.hpp | 28 ++++++++++++++++ extras/Hadrons/Modules/MScalarSUN/TrMag.hpp | 31 +++++++++++++++-- extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp | 37 ++++++++++++++++++--- 3 files changed, 89 insertions(+), 7 deletions(-) diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 1d059a79..eea16839 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -1,3 +1,31 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli +Author: Lanny91 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #include #include #include diff --git a/extras/Hadrons/Modules/MScalarSUN/TrMag.hpp b/extras/Hadrons/Modules/MScalarSUN/TrMag.hpp index f33784fa..96eb794e 100644 --- a/extras/Hadrons/Modules/MScalarSUN/TrMag.hpp +++ b/extras/Hadrons/Modules/MScalarSUN/TrMag.hpp @@ -1,3 +1,30 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MScalarSUN/TrMag.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_MScalarSUN_TrMag_hpp_ #define Hadrons_MScalarSUN_TrMag_hpp_ @@ -8,7 +35,7 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * TrMag * + * Module to compute tr(mag^n) * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MScalarSUN) @@ -55,7 +82,7 @@ MODULE_REGISTER_NS(TrMagSU5, TTrMag>, MScalarSUN); MODULE_REGISTER_NS(TrMagSU6, TTrMag>, MScalarSUN); /****************************************************************************** - * TTrMag implementation * + * TTrMag implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template diff --git a/extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp b/extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp index 8c6bead7..4586663d 100644 --- a/extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp +++ b/extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp @@ -1,3 +1,30 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MScalarSUN/TrPhi.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ #ifndef Hadrons_MScalarSUN_TrPhi_hpp_ #define Hadrons_MScalarSUN_TrPhi_hpp_ @@ -8,7 +35,7 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** - * TrPhi * + * Module to compute tr(phi^n) * ******************************************************************************/ BEGIN_MODULE_NAMESPACE(MScalarSUN) @@ -32,7 +59,7 @@ public: public: GRID_SERIALIZABLE_CLASS_MEMBERS(Result, std::string, op, - Complex, value); + Real, value); }; public: // constructor @@ -58,7 +85,7 @@ MODULE_REGISTER_NS(TrPhiSU5, TTrPhi>, MScalarSUN); MODULE_REGISTER_NS(TrPhiSU6, TTrPhi>, MScalarSUN); /****************************************************************************** - * TTrPhi implementation * + * TTrPhi implementation * ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// template @@ -128,8 +155,8 @@ void TTrPhi::execute(void) { Result r; - r.op = "phi" + std::to_string(n); - r.value = TensorRemove(sum(phin)); + r.op = "tr(phi^" + std::to_string(n) + ")"; + r.value = TensorRemove(sum(phin)).real(); result.push_back(r); } } From a3affac963b85fa2f8de4296c58b31eaf737279b Mon Sep 17 00:00:00 2001 From: David Preti Date: Wed, 10 Jan 2018 14:56:54 +0100 Subject: [PATCH 145/174] SU3 restored + output filename for mesons and baryons fixed. --- extras/Hadrons/Modules/MContraction/Baryon.hpp | 4 +++- extras/Hadrons/Modules/MContraction/Meson.hpp | 4 +++- extras/Hadrons/Modules/MGauge/Random.cc | 2 +- extras/Hadrons/Modules/MGauge/Unit.cc | 2 +- lib/qcd/QCD.h | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/extras/Hadrons/Modules/MContraction/Baryon.hpp b/extras/Hadrons/Modules/MContraction/Baryon.hpp index 78bde5a2..358f7025 100644 --- a/extras/Hadrons/Modules/MContraction/Baryon.hpp +++ b/extras/Hadrons/Modules/MContraction/Baryon.hpp @@ -112,7 +112,9 @@ void TBaryon::execute(void) << " quarks '" << par().q1 << "', '" << par().q2 << "', and '" << par().q3 << "'" << std::endl; - CorrWriter writer(par().output); + std::string output_name = par().output + "." + std::to_string(env().getTrajectory()); + + CorrWriter writer(output_name); PropagatorField1 &q1 = *env().template getObject(par().q1); PropagatorField2 &q2 = *env().template getObject(par().q2); PropagatorField3 &q3 = *env().template getObject(par().q2); diff --git a/extras/Hadrons/Modules/MContraction/Meson.hpp b/extras/Hadrons/Modules/MContraction/Meson.hpp index 7810326a..5355bace 100644 --- a/extras/Hadrons/Modules/MContraction/Meson.hpp +++ b/extras/Hadrons/Modules/MContraction/Meson.hpp @@ -165,8 +165,10 @@ void TMeson::execute(void) LOG(Message) << "Computing meson contractions '" << getName() << "' using" << " quarks '" << par().q1 << "' and '" << par().q2 << "'" << std::endl; + + std::string output_name = par().output + "." + std::to_string(env().getTrajectory()); - CorrWriter writer(par().output); + CorrWriter writer(output_name); std::vector buf; std::vector result; Gamma g5(Gamma::Algebra::Gamma5); diff --git a/extras/Hadrons/Modules/MGauge/Random.cc b/extras/Hadrons/Modules/MGauge/Random.cc index 5c063361..c10fdfc3 100644 --- a/extras/Hadrons/Modules/MGauge/Random.cc +++ b/extras/Hadrons/Modules/MGauge/Random.cc @@ -65,5 +65,5 @@ void TRandom::execute(void) { LOG(Message) << "Generating random gauge configuration" << std::endl; LatticeGaugeField &U = *env().createLattice(getName()); - SU4::HotConfiguration(*env().get4dRng(), U); + SU3::HotConfiguration(*env().get4dRng(), U); } diff --git a/extras/Hadrons/Modules/MGauge/Unit.cc b/extras/Hadrons/Modules/MGauge/Unit.cc index 12696ee9..18d75c59 100644 --- a/extras/Hadrons/Modules/MGauge/Unit.cc +++ b/extras/Hadrons/Modules/MGauge/Unit.cc @@ -65,5 +65,5 @@ void TUnit::execute(void) { LOG(Message) << "Creating unit gauge configuration" << std::endl; LatticeGaugeField &U = *env().createLattice(getName()); - SU4::ColdConfiguration(*env().get4dRng(), U); + SU3::ColdConfiguration(*env().get4dRng(), U); } diff --git a/lib/qcd/QCD.h b/lib/qcd/QCD.h index 2caea7e9..9c6d54d4 100644 --- a/lib/qcd/QCD.h +++ b/lib/qcd/QCD.h @@ -49,7 +49,7 @@ namespace QCD { static const int Zm = 6; static const int Tm = 7; - static const int Nc=4; + static const int Nc=3; static const int Ns=4; static const int Nd=4; static const int Nhs=2; // half spinor From cf858deb16a393270d4b14c702031aae50257da3 Mon Sep 17 00:00:00 2001 From: pretidav Date: Wed, 10 Jan 2018 18:43:02 +0100 Subject: [PATCH 146/174] Lanczos with 2 reps fixed (tobe tested) --- tests/lanczos/Test_WCMultiRep_lanczos.cc | 128 +++++++++++++++++------ 1 file changed, 95 insertions(+), 33 deletions(-) diff --git a/tests/lanczos/Test_WCMultiRep_lanczos.cc b/tests/lanczos/Test_WCMultiRep_lanczos.cc index e8549234..98180db1 100644 --- a/tests/lanczos/Test_WCMultiRep_lanczos.cc +++ b/tests/lanczos/Test_WCMultiRep_lanczos.cc @@ -32,8 +32,17 @@ using namespace std; using namespace Grid; using namespace Grid::QCD; -typedef WilsonFermionR FermionOp; -typedef typename WilsonFermionR::FermionField FermionField; + +//typedef WilsonCloverFermionR FermionOp; +//typedef typename WilsonFermionR::FermionField FermionField; + +typedef WilsonImplR FundImplPolicy; +typedef WilsonCloverFermionR FundFermionAction; +typedef typename FundFermionAction::FermionField FundFermionField; + +typedef WilsonTwoIndexAntiSymmetricImplR ASymmImplPolicy; +typedef WilsonCloverTwoIndexAntiSymmetricFermionR ASymmFermionAction; +typedef typename ASymmFermionAction::FermionField ASymmFermionField; RealD AllZero(RealD x) { return 0.; } @@ -60,49 +69,102 @@ int main(int argc, char** argv) { GridParallelRNG RNG5rb(FrbGrid); RNG5.SeedFixedIntegers(seeds5); - LatticeGaugeField Umu(UGrid); - SU3::HotConfiguration(RNG4, Umu); + GridParallelRNG pRNG(UGrid); + GridSerialRNG sRNG; -/* - std::vector U(4, UGrid); - for (int mu = 0; mu < Nd; mu++) { - U[mu] = PeekIndex(Umu, mu); - } -*/ + FundamentalRepresentation::LatticeField Umu(UGrid); + + TwoIndexAntiSymmetricRepresentation HiRep(UGrid); + TwoIndexAntiSymmetricRepresentation::LatticeField UmuAS(UGrid); - RealD mass = -0.1; - RealD M5 = 1.8; - RealD mob_b = 1.5; - FermionOp WilsonOperator(Umu,*FGrid,*FrbGrid,mass); - MdagMLinearOperator HermOp(WilsonOperator); /// <----- - //SchurDiagTwoOperator HermOp(WilsonOperator); + + CheckpointerParameters CPparams; + + CPparams.config_prefix = "ckpoint_lat"; + CPparams.rng_prefix = "ckpoint_rng"; + CPparams.format = "IEEE64BIG"; - const int Nstop = 20; - const int Nk = 60; - const int Np = 60; +//NerscHmcCheckpointer Checkpoint(std::string("ckpoint_lat"), + // std::string("ckpoint_rng"), 1); + +NerscHmcCheckpointer Checkpoint(CPparams); + + int CNFGSTART=1; + int CNFGEND=2; + int CNFGSTEP=1; + + Real Fundmass = -0.1; + Real Fundcsw = 1.0; + Real ASmass = -0.1; + Real AScsw = 1.0; + + std::cout << "Fund: mass and csw" << Fundmass << " and " << Fundcsw << std::endl; + std::cout << "AS : mass and csw" << ASmass << " and " << AScsw << std::endl; + + const int Nstop = 30; + const int Nk = 40; + const int Np = 40; const int Nm = Nk + Np; const int MaxIt = 10000; - RealD resid = 1.0e-6; + RealD resid = 1.0e-8; - std::vector Coeffs{0, 1.}; - Polynomial PolyX(Coeffs); - Chebyshev Cheb(0.0, 10., 12); - ImplicitlyRestartedLanczos IRL(HermOp, PolyX, Nstop, Nk, Nm, + for (int cnfg=CNFGSTART;cnfg<=CNFGEND;cnfg+=CNFGSTEP){ + Checkpoint.CheckpointRestore(cnfg,Umu, sRNG, pRNG); + + //SU4::HotConfiguration(RNG4, Umu); // temporary, then read. + + HiRep.update_representation(Umu); + UmuAS = HiRep.U; + + FundFermionAction FundFermOp(Umu,*FGrid,*FrbGrid, Fundmass, Fundcsw, Fundcsw); + MdagMLinearOperator HermOpFund(FundFermOp); /// <----- + + ASymmFermionAction ASFermOp(UmuAS,*FGrid,*FrbGrid, ASmass, AScsw, AScsw); + MdagMLinearOperator HermOpAS(ASFermOp); /// <----- + + std::vector Coeffs{0, -1.}; + Polynomial FundPolyX(Coeffs); + Chebyshev FundCheb(0.0, 10., 12); + ImplicitlyRestartedLanczos IRL_Fund(HermOpFund, FundPolyX, Nstop, Nk, Nm, resid, MaxIt); + + Polynomial ASPolyX(Coeffs); + Chebyshev ASCheb(0.0, 10., 12); + ImplicitlyRestartedLanczos IRL_AS(HermOpAS, ASPolyX, Nstop, Nk, Nm, + resid, MaxIt); + + std::vector Fundeval(Nm); + std::vector ASeval(Nm); - std::vector eval(Nm); - FermionField src(FGrid); - gaussian(RNG5, src); - std::vector evec(Nm, FGrid); + FundFermionField Fundsrc(FGrid); + ASymmFermionField ASsrc(FGrid); + + gaussian(RNG5, Fundsrc); + gaussian(RNG5, ASsrc); + + std::vector Fundevec(Nm, FGrid); + std::vector ASevec(Nm, FGrid); + for (int i = 0; i < 1; i++) { - std::cout << i << " / " << Nm << " grid pointer " << evec[i]._grid + std::cout << i << " / " << Nm << "Fund: grid pointer " << Fundevec[i]._grid << std::endl; }; + for (int i = 0; i < 1; i++) { + std::cout << i << " / " << Nm << "AS: grid pointer " << ASevec[i]._grid + << std::endl; + }; + + int FundNconv, ASNconv; + IRL_Fund.calc(Fundeval, Fundevec, Fundsrc, FundNconv); + IRL_AS.calc(ASeval, ASevec, ASsrc, ASNconv); - int Nconv; - IRL.calc(eval, evec, src, Nconv); - - std::cout << eval << std::endl; + for (int i=0;i #include #include +#include #include #include #include diff --git a/extras/Hadrons/Modules/MScalarSUN/TwoPoint.hpp b/extras/Hadrons/Modules/MScalarSUN/TwoPoint.hpp new file mode 100644 index 00000000..abfbf609 --- /dev/null +++ b/extras/Hadrons/Modules/MScalarSUN/TwoPoint.hpp @@ -0,0 +1,184 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MScalarSUN/TwoPoint.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#ifndef Hadrons_MScalarSUN_TwoPoint_hpp_ +#define Hadrons_MScalarSUN_TwoPoint_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * 2-pt functions for a given set of operators * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MScalarSUN) + +class TwoPointPar: Serializable +{ +public: + GRID_SERIALIZABLE_CLASS_MEMBERS(TwoPointPar, + std::vector, op, + std::string, output); +}; + +template +class TTwoPoint: public Module +{ +public: + typedef typename SImpl::Field Field; + typedef typename SImpl::ComplexField ComplexField; + class Result: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Result, + std::string, sink, + std::string, source, + std::vector, data); + }; +public: + // constructor + TTwoPoint(const std::string name); + // destructor + virtual ~TTwoPoint(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +private: + // make 2-pt function + template + std::vector makeTwoPoint(const std::vector &sink, + const std::vector &source); +}; + +MODULE_REGISTER_NS(TwoPointSU2, TTwoPoint>, MScalarSUN); +MODULE_REGISTER_NS(TwoPointSU3, TTwoPoint>, MScalarSUN); +MODULE_REGISTER_NS(TwoPointSU4, TTwoPoint>, MScalarSUN); +MODULE_REGISTER_NS(TwoPointSU5, TTwoPoint>, MScalarSUN); +MODULE_REGISTER_NS(TwoPointSU6, TTwoPoint>, MScalarSUN); + +/****************************************************************************** + * TTwoPoint implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TTwoPoint::TTwoPoint(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TTwoPoint::getInput(void) +{ + return par().op; +} + +template +std::vector TTwoPoint::getOutput(void) +{ + std::vector out = {}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TTwoPoint::setup(void) +{ + const unsigned int nt = env().getDim().back(); + envTmp(std::vector>, "slicedOp", 1, par().op.size(), + std::vector(nt)); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TTwoPoint::execute(void) +{ + LOG(Message) << "Computing 2-point functions for operators:" << std::endl; + for (auto &o: par().op) + { + LOG(Message) << " '" << o << "'" << std::endl; + } + + ResultWriter writer(RESULT_FILE_NAME(par().output)); + const unsigned int nd = env().getDim().size(); + std::vector result; + + envGetTmp(std::vector>, slicedOp); + for (unsigned int i = 0; i < par().op.size(); ++i) + { + auto &op = envGet(ComplexField, par().op[i]); + + sliceSum(op, slicedOp[i], nd - 1); + } + for (unsigned int i = 0; i < par().op.size(); ++i) + for (unsigned int j = 0; j < par().op.size(); ++j) + { + Result r; + + r.sink = par().op[i]; + r.source = par().op[j]; + r.data = makeTwoPoint(slicedOp[i], slicedOp[j]); + result.push_back(r); + } + write(writer, "twopt", result); +} + +// make 2-pt function ////////////////////////////////////////////////////////// +template +template +std::vector TTwoPoint::makeTwoPoint( + const std::vector &sink, + const std::vector &source) +{ + assert(sink.size() == source.size()); + + unsigned int nt = sink.size(); + std::vector res(nt, 0.); + + for (unsigned int dt = 0; dt < nt; ++dt) + { + for (unsigned int t = 0; t < nt; ++t) + { + res[dt] += TensorRemove(trace(sink[(t+dt)%nt]*source[t])); + } + res[dt] *= 1./static_cast(nt); + } + + return res; +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MScalarSUN_TwoPoint_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index cea4dc2a..b1ccb8cc 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -40,6 +40,7 @@ modules_hpp =\ Modules/MAction/DWF.hpp \ Modules/MAction/Wilson.hpp \ Modules/MScalarSUN/TrMag.hpp \ + Modules/MScalarSUN/TwoPoint.hpp \ Modules/MScalarSUN/TrPhi.hpp \ Modules/MIO/LoadNersc.hpp \ Modules/MIO/LoadBinary.hpp From b7f8c5b823dbc0e0b22f7461bb7b7faf9fcc1e39 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Fri, 12 Jan 2018 14:38:27 +0000 Subject: [PATCH 148/174] Modify test to merge with the new Lanczos interface --- tests/lanczos/Test_WCMultiRep_lanczos.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/lanczos/Test_WCMultiRep_lanczos.cc b/tests/lanczos/Test_WCMultiRep_lanczos.cc index 98180db1..b6d69aee 100644 --- a/tests/lanczos/Test_WCMultiRep_lanczos.cc +++ b/tests/lanczos/Test_WCMultiRep_lanczos.cc @@ -124,13 +124,21 @@ NerscHmcCheckpointer Checkpoint(CPparams); std::vector Coeffs{0, -1.}; Polynomial FundPolyX(Coeffs); - Chebyshev FundCheb(0.0, 10., 12); - ImplicitlyRestartedLanczos IRL_Fund(HermOpFund, FundPolyX, Nstop, Nk, Nm, + //Chebyshev FundCheb(0.0, 10., 12); + + FunctionHermOp FundPolyXOp(FundPolyX,HermOpFund); + PlainHermOp FundOp (HermOpFund); + + ImplicitlyRestartedLanczos IRL_Fund(FundOp, FundPolyXOp, Nstop, Nk, Nm, resid, MaxIt); Polynomial ASPolyX(Coeffs); - Chebyshev ASCheb(0.0, 10., 12); - ImplicitlyRestartedLanczos IRL_AS(HermOpAS, ASPolyX, Nstop, Nk, Nm, + //Chebyshev ASCheb(0.0, 10., 12); + + FunctionHermOp ASPolyXOp(ASPolyX,HermOpAS); + PlainHermOp ASOp (HermOpAS); + + ImplicitlyRestartedLanczos IRL_AS(ASOp, ASPolyXOp, Nstop, Nk, Nm, resid, MaxIt); std::vector Fundeval(Nm); From b00d2d2c39f8fdc976446072faaa884e8596b777 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Wed, 17 Jan 2018 13:46:12 +0000 Subject: [PATCH 149/174] Correction of Representations compilation and small compilation error for Intel 17 --- lib/qcd/action/fermion/FermionOperatorImpl.h | 89 +++++++++++--------- lib/qcd/action/fermion/WilsonFermion.cc | 4 +- lib/qcd/action/fermion/WilsonFermion5D.cc | 4 +- lib/qcd/action/fermion/WilsonKernels.h | 8 +- lib/qcd/representations/adjoint.h | 1 + lib/qcd/representations/fundamental.h | 1 + lib/qcd/representations/two_index.h | 1 + 7 files changed, 58 insertions(+), 50 deletions(-) diff --git a/lib/qcd/action/fermion/FermionOperatorImpl.h b/lib/qcd/action/fermion/FermionOperatorImpl.h index 2b900569..c21a07ee 100644 --- a/lib/qcd/action/fermion/FermionOperatorImpl.h +++ b/lib/qcd/action/fermion/FermionOperatorImpl.h @@ -164,6 +164,7 @@ namespace QCD { public: static const int Dimension = Representation::Dimension; + static const bool isFundamental = Representation::isFundamental; static const bool LsVectorised=false; static const int Nhcs = Options::Nhcs; @@ -298,27 +299,28 @@ namespace QCD { //////////////////////////////////////////////////////////////////////////////////// // Single flavour four spinors with colour index, 5d redblack //////////////////////////////////////////////////////////////////////////////////// -template -class DomainWallVec5dImpl : public PeriodicGaugeImpl< GaugeImplTypes< S,Nrepresentation> > { +template +class DomainWallVec5dImpl : public PeriodicGaugeImpl< GaugeImplTypes< S,Representation::Dimension> > { public: - typedef PeriodicGaugeImpl > Gimpl; + typedef PeriodicGaugeImpl > Gimpl; INHERIT_GIMPL_TYPES(Gimpl); - static const int Dimension = Nrepresentation; + static const int Dimension = Representation::Dimension; + static const bool isFundamental = Representation::isFundamental; static const bool LsVectorised=true; static const int Nhcs = Options::Nhcs; typedef typename Options::_Coeff_t Coeff_t; typedef typename Options::template PrecisionMapper::LowerPrecVector SimdL; - template using iImplSpinor = iScalar, Ns> >; - template using iImplPropagator = iScalar, Ns> >; - template using iImplHalfSpinor = iScalar, Nhs> >; - template using iImplHalfCommSpinor = iScalar, Nhcs> >; - template using iImplDoubledGaugeField = iVector >, Nds>; - template using iImplGaugeField = iVector >, Nd>; - template using iImplGaugeLink = iScalar > >; + template using iImplSpinor = iScalar, Ns> >; + template using iImplPropagator = iScalar, Ns> >; + template using iImplHalfSpinor = iScalar, Nhs> >; + template using iImplHalfCommSpinor = iScalar, Nhcs> >; + template using iImplDoubledGaugeField = iVector >, Nds>; + template using iImplGaugeField = iVector >, Nd>; + template using iImplGaugeLink = iScalar > >; typedef iImplSpinor SiteSpinor; typedef iImplPropagator SitePropagator; @@ -354,8 +356,8 @@ class DomainWallVec5dImpl : public PeriodicGaugeImpl< GaugeImplTypes< S,Nrepres const SiteHalfSpinor &chi, int mu, StencilEntry *SE, StencilImpl &St) { SiteGaugeLink UU; - for (int i = 0; i < Nrepresentation; i++) { - for (int j = 0; j < Nrepresentation; j++) { + for (int i = 0; i < Dimension; i++) { + for (int j = 0; j < Dimension; j++) { vsplat(UU()()(i, j), U(mu)()(i, j)); } } @@ -367,8 +369,8 @@ class DomainWallVec5dImpl : public PeriodicGaugeImpl< GaugeImplTypes< S,Nrepres const SitePropagator &chi, int mu) { SiteGaugeLink UU; - for (int i = 0; i < Nrepresentation; i++) { - for (int j = 0; j < Nrepresentation; j++) { + for (int i = 0; i < Dimension; i++) { + for (int j = 0; j < Dimension; j++) { vsplat(UU()()(i, j), U(mu)()(i, j)); } } @@ -472,25 +474,26 @@ class DomainWallVec5dImpl : public PeriodicGaugeImpl< GaugeImplTypes< S,Nrepres //////////////////////////////////////////////////////////////////////////////////////// // Flavour doubled spinors; is Gparity the only? what about C*? //////////////////////////////////////////////////////////////////////////////////////// -template -class GparityWilsonImpl : public ConjugateGaugeImpl > { +template +class GparityWilsonImpl : public ConjugateGaugeImpl > { public: - static const int Dimension = Nrepresentation; + static const int Dimension = Representation::Dimension; + static const bool isFundamental = Representation::isFundamental; static const int Nhcs = Options::Nhcs; static const bool LsVectorised=false; - typedef ConjugateGaugeImpl< GaugeImplTypes > Gimpl; + typedef ConjugateGaugeImpl< GaugeImplTypes > Gimpl; INHERIT_GIMPL_TYPES(Gimpl); typedef typename Options::_Coeff_t Coeff_t; typedef typename Options::template PrecisionMapper::LowerPrecVector SimdL; - template using iImplSpinor = iVector, Ns>, Ngp>; - template using iImplPropagator = iVector, Ns>, Ngp>; - template using iImplHalfSpinor = iVector, Nhs>, Ngp>; - template using iImplHalfCommSpinor = iVector, Nhcs>, Ngp>; - template using iImplDoubledGaugeField = iVector >, Nds>, Ngp>; + template using iImplSpinor = iVector, Ns>, Ngp>; + template using iImplPropagator = iVector, Ns>, Ngp>; + template using iImplHalfSpinor = iVector, Nhs>, Ngp>; + template using iImplHalfCommSpinor = iVector, Nhcs>, Ngp>; + template using iImplDoubledGaugeField = iVector >, Nds>, Ngp>; typedef iImplSpinor SiteSpinor; typedef iImplPropagator SitePropagator; @@ -711,6 +714,7 @@ class StaggeredImpl : public PeriodicGaugeImpl > Gimpl; @@ -839,6 +843,7 @@ class StaggeredImpl : public PeriodicGaugeImpl > Gimpl; @@ -1033,29 +1038,29 @@ typedef WilsonImpl W typedef WilsonImpl WilsonTwoIndexAntiSymmetricImplF; // Float typedef WilsonImpl WilsonTwoIndexAntiSymmetricImplD; // Double -typedef DomainWallVec5dImpl DomainWallVec5dImplR; // Real.. whichever prec -typedef DomainWallVec5dImpl DomainWallVec5dImplF; // Float -typedef DomainWallVec5dImpl DomainWallVec5dImplD; // Double +typedef DomainWallVec5dImpl DomainWallVec5dImplR; // Real.. whichever prec +typedef DomainWallVec5dImpl DomainWallVec5dImplF; // Float +typedef DomainWallVec5dImpl DomainWallVec5dImplD; // Double -typedef DomainWallVec5dImpl DomainWallVec5dImplRL; // Real.. whichever prec -typedef DomainWallVec5dImpl DomainWallVec5dImplFH; // Float -typedef DomainWallVec5dImpl DomainWallVec5dImplDF; // Double +typedef DomainWallVec5dImpl DomainWallVec5dImplRL; // Real.. whichever prec +typedef DomainWallVec5dImpl DomainWallVec5dImplFH; // Float +typedef DomainWallVec5dImpl DomainWallVec5dImplDF; // Double -typedef DomainWallVec5dImpl ZDomainWallVec5dImplR; // Real.. whichever prec -typedef DomainWallVec5dImpl ZDomainWallVec5dImplF; // Float -typedef DomainWallVec5dImpl ZDomainWallVec5dImplD; // Double +typedef DomainWallVec5dImpl ZDomainWallVec5dImplR; // Real.. whichever prec +typedef DomainWallVec5dImpl ZDomainWallVec5dImplF; // Float +typedef DomainWallVec5dImpl ZDomainWallVec5dImplD; // Double -typedef DomainWallVec5dImpl ZDomainWallVec5dImplRL; // Real.. whichever prec -typedef DomainWallVec5dImpl ZDomainWallVec5dImplFH; // Float -typedef DomainWallVec5dImpl ZDomainWallVec5dImplDF; // Double +typedef DomainWallVec5dImpl ZDomainWallVec5dImplRL; // Real.. whichever prec +typedef DomainWallVec5dImpl ZDomainWallVec5dImplFH; // Float +typedef DomainWallVec5dImpl ZDomainWallVec5dImplDF; // Double -typedef GparityWilsonImpl GparityWilsonImplR; // Real.. whichever prec -typedef GparityWilsonImpl GparityWilsonImplF; // Float -typedef GparityWilsonImpl GparityWilsonImplD; // Double +typedef GparityWilsonImpl GparityWilsonImplR; // Real.. whichever prec +typedef GparityWilsonImpl GparityWilsonImplF; // Float +typedef GparityWilsonImpl GparityWilsonImplD; // Double -typedef GparityWilsonImpl GparityWilsonImplRL; // Real.. whichever prec -typedef GparityWilsonImpl GparityWilsonImplFH; // Float -typedef GparityWilsonImpl GparityWilsonImplDF; // Double +typedef GparityWilsonImpl GparityWilsonImplRL; // Real.. whichever prec +typedef GparityWilsonImpl GparityWilsonImplFH; // Float +typedef GparityWilsonImpl GparityWilsonImplDF; // Double typedef StaggeredImpl StaggeredImplR; // Real.. whichever prec typedef StaggeredImpl StaggeredImplF; // Float diff --git a/lib/qcd/action/fermion/WilsonFermion.cc b/lib/qcd/action/fermion/WilsonFermion.cc index 2336f4b6..dfaa6758 100644 --- a/lib/qcd/action/fermion/WilsonFermion.cc +++ b/lib/qcd/action/fermion/WilsonFermion.cc @@ -419,7 +419,7 @@ void WilsonFermion::SeqConservedCurrent(PropagatorField &q_in, conformable(_grid, q_in._grid); conformable(_grid, q_out._grid); Lattice> ph(_grid), coor(_grid); - Complex i(0.0,1.0); + ComplexD i(0.0,1.0); PropagatorField tmpFwd(_grid), tmpBwd(_grid), tmp(_grid); unsigned int tshift = (mu == Tp) ? 1 : 0; unsigned int LLt = GridDefaultLatt()[Tp]; @@ -431,7 +431,7 @@ void WilsonFermion::SeqConservedCurrent(PropagatorField &q_in, LatticeCoordinate(coor, mu); ph = ph + mom[mu]*coor*((1./(_grid->_fdimensions[mu]))); } - ph = exp((Real)(2*M_PI)*i*ph); + ph = exp((RealD)(2*M_PI)*i*ph); q_out = zero; LatticeInteger coords(_grid); diff --git a/lib/qcd/action/fermion/WilsonFermion5D.cc b/lib/qcd/action/fermion/WilsonFermion5D.cc index 393ee7f3..3e58fed6 100644 --- a/lib/qcd/action/fermion/WilsonFermion5D.cc +++ b/lib/qcd/action/fermion/WilsonFermion5D.cc @@ -793,7 +793,7 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, Lattice> ph(FermionGrid()), coor(FermionGrid()); PropagatorField tmpFwd(FermionGrid()), tmpBwd(FermionGrid()), tmp(FermionGrid()); - Complex i(0.0, 1.0); + ComplexD i(0.0, 1.0); unsigned int tshift = (mu == Tp) ? 1 : 0; unsigned int LLs = q_in._grid->_rdimensions[0]; unsigned int LLt = GridDefaultLatt()[Tp]; @@ -806,7 +806,7 @@ void WilsonFermion5D::SeqConservedCurrent(PropagatorField &q_in, LatticeCoordinate(coor, nu + 1); ph = ph + mom[nu]*coor*((1./(_FourDimGrid->_fdimensions[nu]))); } - ph = exp((Real)(2*M_PI)*i*ph); + ph = exp((RealD)(2*M_PI)*i*ph); q_out = zero; LatticeInteger coords(_FourDimGrid); diff --git a/lib/qcd/action/fermion/WilsonKernels.h b/lib/qcd/action/fermion/WilsonKernels.h index ed8d6be9..2369c98d 100644 --- a/lib/qcd/action/fermion/WilsonKernels.h +++ b/lib/qcd/action/fermion/WilsonKernels.h @@ -55,7 +55,7 @@ template class WilsonKernels : public FermionOperator , public public: template - typename std::enable_if::type + typename std::enable_if::type DhopSite(StencilImpl &st, LebesgueOrder &lo, DoubledGaugeField &U, SiteHalfSpinor * buf, int sF, int sU, int Ls, int Ns, const FermionField &in, FermionField &out,int interior=1,int exterior=1) { @@ -99,7 +99,7 @@ public: } template - typename std::enable_if<(Impl::Dimension != 3 || (Impl::Dimension == 3 && Nc != 3)) && EnableBool, void>::type + typename std::enable_if<(Impl::isFundamental==false || (Impl::isFundamental==true && Nc != 3)) && EnableBool, void>::type DhopSite(StencilImpl &st, LebesgueOrder &lo, DoubledGaugeField &U, SiteHalfSpinor * buf, int sF, int sU, int Ls, int Ns, const FermionField &in, FermionField &out,int interior=1,int exterior=1 ) { // no kernel choice @@ -116,7 +116,7 @@ public: } template - typename std::enable_if::type + typename std::enable_if::type DhopSiteDag(StencilImpl &st, LebesgueOrder &lo, DoubledGaugeField &U, SiteHalfSpinor * buf, int sF, int sU, int Ls, int Ns, const FermionField &in, FermionField &out,int interior=1,int exterior=1) { @@ -161,7 +161,7 @@ public: } template - typename std::enable_if<(Impl::Dimension != 3 || (Impl::Dimension == 3 && Nc != 3)) && EnableBool,void>::type + typename std::enable_if<(Impl::isFundamental==false || (Impl::isFundamental==true && Nc != 3)) && EnableBool,void>::type DhopSiteDag(StencilImpl &st, LebesgueOrder &lo, DoubledGaugeField &U,SiteHalfSpinor * buf, int sF, int sU, int Ls, int Ns, const FermionField &in, FermionField &out,int interior=1,int exterior=1) { diff --git a/lib/qcd/representations/adjoint.h b/lib/qcd/representations/adjoint.h index 078d12a1..052cd7a8 100644 --- a/lib/qcd/representations/adjoint.h +++ b/lib/qcd/representations/adjoint.h @@ -23,6 +23,7 @@ class AdjointRep { typedef typename SU_Adjoint::LatticeAdjMatrix LatticeMatrix; typedef typename SU_Adjoint::LatticeAdjField LatticeField; static const int Dimension = ncolour * ncolour - 1; + static const bool isFundamental = false; LatticeField U; diff --git a/lib/qcd/representations/fundamental.h b/lib/qcd/representations/fundamental.h index db52d893..9f039a07 100644 --- a/lib/qcd/representations/fundamental.h +++ b/lib/qcd/representations/fundamental.h @@ -19,6 +19,7 @@ template class FundamentalRep { public: static const int Dimension = ncolour; + static const bool isFundamental = true; // typdef to be used by the Representations class in HMC to get the // types for the higher representation fields diff --git a/lib/qcd/representations/two_index.h b/lib/qcd/representations/two_index.h index 082a52a5..2c7e8b3a 100644 --- a/lib/qcd/representations/two_index.h +++ b/lib/qcd/representations/two_index.h @@ -29,6 +29,7 @@ class TwoIndexRep { typedef typename SU_TwoIndex::LatticeTwoIndexMatrix LatticeMatrix; typedef typename SU_TwoIndex::LatticeTwoIndexField LatticeField; static const int Dimension = ncolour * (ncolour + S) / 2; + static const bool isFundamental = false; LatticeField U; From 0e5f6262260eb6d97962d0ffa17cdf40c7ec8c45 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 22 Jan 2018 19:37:47 +0000 Subject: [PATCH 150/174] Hadrons: module for scalar operator divergence --- extras/Hadrons/Modules.hpp | 1 + extras/Hadrons/Modules/MScalarSUN/Div.hpp | 166 ++++++++++++++++++++++ extras/Hadrons/modules.inc | 1 + 3 files changed, 168 insertions(+) create mode 100644 extras/Hadrons/Modules/MScalarSUN/Div.hpp diff --git a/extras/Hadrons/Modules.hpp b/extras/Hadrons/Modules.hpp index 5834fb3f..6e123660 100644 --- a/extras/Hadrons/Modules.hpp +++ b/extras/Hadrons/Modules.hpp @@ -55,6 +55,7 @@ See the full license in the file "LICENSE" in the top level distribution directo #include #include #include +#include #include #include #include diff --git a/extras/Hadrons/Modules/MScalarSUN/Div.hpp b/extras/Hadrons/Modules/MScalarSUN/Div.hpp new file mode 100644 index 00000000..6680cd79 --- /dev/null +++ b/extras/Hadrons/Modules/MScalarSUN/Div.hpp @@ -0,0 +1,166 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: extras/Hadrons/Modules/MScalarSUN/Div.hpp + +Copyright (C) 2015-2018 + +Author: Antonin Portelli + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +See the full license in the file "LICENSE" in the top level distribution directory +*************************************************************************************/ +/* END LEGAL */ +#ifndef Hadrons_MScalarSUN_Div_hpp_ +#define Hadrons_MScalarSUN_Div_hpp_ + +#include +#include +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Div * + ******************************************************************************/ +BEGIN_MODULE_NAMESPACE(MScalarSUN) + +class DivPar: Serializable +{ +public: + GRID_SERIALIZABLE_ENUM(DiffType, undef, forward, 1, backward, 2, central, 3); + GRID_SERIALIZABLE_CLASS_MEMBERS(DivPar, + std::vector, op, + DiffType, type, + std::string, output); +}; + +template +class TDiv: public Module +{ +public: + typedef typename SImpl::Field Field; + typedef typename SImpl::ComplexField ComplexField; + class Result: Serializable + { + public: + GRID_SERIALIZABLE_CLASS_MEMBERS(Result, + DivPar::DiffType, type, + Complex, value); + }; +public: + // constructor + TDiv(const std::string name); + // destructor + virtual ~TDiv(void) = default; + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +}; + +MODULE_REGISTER_NS(DivSU2, TDiv>, MScalarSUN); +MODULE_REGISTER_NS(DivSU3, TDiv>, MScalarSUN); +MODULE_REGISTER_NS(DivSU4, TDiv>, MScalarSUN); +MODULE_REGISTER_NS(DivSU5, TDiv>, MScalarSUN); +MODULE_REGISTER_NS(DivSU6, TDiv>, MScalarSUN); + +/****************************************************************************** + * TDiv implementation * + ******************************************************************************/ +// constructor ///////////////////////////////////////////////////////////////// +template +TDiv::TDiv(const std::string name) +: Module(name) +{} + +// dependencies/products /////////////////////////////////////////////////////// +template +std::vector TDiv::getInput(void) +{ + return par().op; +} + +template +std::vector TDiv::getOutput(void) +{ + std::vector out = {getName()}; + + return out; +} + +// setup /////////////////////////////////////////////////////////////////////// +template +void TDiv::setup(void) +{ + if (par().op.size() != env().getNd()) + { + HADRON_ERROR(Size, "the number of components differs from number of dimensions"); + } + envCreateLat(ComplexField, getName()); +} + +// execution /////////////////////////////////////////////////////////////////// +template +void TDiv::execute(void) +{ + const auto nd = env().getNd(); + + LOG(Message) << "Computing the " << par().type << " divergence of ["; + for (unsigned int mu = 0; mu < nd; ++mu) + { + std::cout << par().op[mu] << ((mu == nd - 1) ? "]" : ", "); + } + std::cout << std::endl; + + auto &div = envGet(ComplexField, getName()); + div = zero; + for (unsigned int mu = 0; mu < nd; ++mu) + { + auto &op = envGet(ComplexField, par().op[mu]); + switch(par().type) + { + case DivPar::DiffType::backward: + div += op - Cshift(op, mu, -1); + break; + case DivPar::DiffType::forward: + div += Cshift(op, mu, 1) - op; + break; + case DivPar::DiffType::central: + div += 0.5*(Cshift(op, mu, 1) - Cshift(op, mu, -1)); + break; + } + } + if (!par().output.empty()) + { + Result r; + ResultWriter writer(RESULT_FILE_NAME(par().output)); + + r.type = par().type; + r.value = TensorRemove(sum(div)); + write(writer, "div", r); + } +} + +END_MODULE_NAMESPACE + +END_HADRONS_NAMESPACE + +#endif // Hadrons_MScalarSUN_Div_hpp_ diff --git a/extras/Hadrons/modules.inc b/extras/Hadrons/modules.inc index b1ccb8cc..1c71301a 100644 --- a/extras/Hadrons/modules.inc +++ b/extras/Hadrons/modules.inc @@ -39,6 +39,7 @@ modules_hpp =\ Modules/MScalar/ChargedProp.hpp \ Modules/MAction/DWF.hpp \ Modules/MAction/Wilson.hpp \ + Modules/MScalarSUN/Div.hpp \ Modules/MScalarSUN/TrMag.hpp \ Modules/MScalarSUN/TwoPoint.hpp \ Modules/MScalarSUN/TrPhi.hpp \ From 6e3ce7423ef97f53987e768113e3fa4699a3e93e Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Mon, 22 Jan 2018 20:04:05 +0000 Subject: [PATCH 151/174] Hadrons: don't display module list at startup (too long) --- extras/Hadrons/Application.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 7ba98ade..39c898bc 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -43,12 +43,6 @@ using namespace Hadrons; Application::Application(void) { initLogger(); - LOG(Message) << "Modules available:" << std::endl; - auto list = ModuleFactory::getInstance().getBuilderList(); - for (auto &m: list) - { - LOG(Message) << " " << m << std::endl; - } auto dim = GridDefaultLatt(), mpi = GridDefaultMpi(), loc(dim); locVol_ = 1; for (unsigned int d = 0; d < dim.size(); ++d) From cff3bae1557f90077ec67d56c96eb72f817bb273 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Thu, 25 Jan 2018 13:46:31 +0100 Subject: [PATCH 152/174] Adding support for general Nc in the benchmark outputs --- benchmarks/Benchmark_dwf.cc | 15 ++++++---- benchmarks/Benchmark_dwf_sweep.cc | 11 ++++--- benchmarks/Benchmark_gparity.cc | 6 ++-- benchmarks/Benchmark_wilson.cc | 13 ++++++-- benchmarks/Benchmark_wilson_sweep.cc | 45 ++++++++++++++++++++++------ 5 files changed, 66 insertions(+), 24 deletions(-) diff --git a/benchmarks/Benchmark_dwf.cc b/benchmarks/Benchmark_dwf.cc index 73621bbe..1d9de772 100644 --- a/benchmarks/Benchmark_dwf.cc +++ b/benchmarks/Benchmark_dwf.cc @@ -48,7 +48,6 @@ int main (int argc, char ** argv) int threads = GridThread::GetThreads(); - std::cout< latt4 = GridDefaultLatt(); int Ls=16; @@ -57,6 +56,10 @@ int main (int argc, char ** argv) std::stringstream ss(argv[i+1]); ss >> Ls; } + GridLogLayout(); + + long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); + GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); @@ -187,7 +190,7 @@ int main (int argc, char ** argv) FGrid->Barrier(); double volume=Ls; for(int mu=0;muBarrier(); double volume=Ls; for(int mu=0;muBarrier(); double volume=Ls; for(int mu=0;mu & latt4, int Ls, int threads,int report ) GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid); + long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); std::vector seeds4({1,2,3,4}); std::vector seeds5({5,6,7,8}); @@ -196,7 +198,7 @@ void benchDw(std::vector & latt4, int Ls, int threads,int report ) if ( ! report ) { double volume=Ls; for(int mu=0;mu & latt4, int Ls, int threads,int report ) if(!report){ double volume=Ls; for(int mu=0;mu & latt4, int Ls, int threads,int report ) #define CHECK_SDW void benchsDw(std::vector & latt4, int Ls, int threads, int report ) { + long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(latt4, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi()); GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); @@ -321,7 +324,7 @@ void benchsDw(std::vector & latt4, int Ls, int threads, int report ) Counter.Report(); } else { double volume=Ls; for(int mu=0;mu & latt4, int Ls, int threads, int report ) CounterSdw.Report(); } else { double volume=Ls; for(int mu=0;muBarrier(); double volume=Ls; for(int mu=0;muBarrier(); double volume=Ls; for(int mu=0;mu latt_size = GridDefaultLatt(); std::vector simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); std::vector mpi_layout = GridDefaultMpi(); @@ -61,10 +64,15 @@ int main (int argc, char ** argv) GridRedBlackCartesian RBGrid(&Grid); int threads = GridThread::GetThreads(); - std::cout< seeds({1,2,3,4}); GridParallelRNG pRNG(&Grid); @@ -134,9 +142,10 @@ int main (int argc, char ** argv) Dw.Dhop(src,result,0); } double t1=usecond(); - double flops=1344*volume*ncall; + double flops=single_site_flops*volume*ncall; std::cout<()); WilsonFermionR Dw(Umu,Grid,RBGrid,mass,params); - + + // Full operator + bench_wilson(src,result,Dw,volume,DaggerNo); + bench_wilson(src,result,Dw,volume,DaggerYes); + std::cout << "\t"; + // EO bench_wilson(src,result,Dw,volume,DaggerNo); bench_wilson(src,result,Dw,volume,DaggerYes); std::cout << std::endl; @@ -122,9 +132,26 @@ void bench_wilson ( int const dag ) { int ncall = 1000; + long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); double t0 = usecond(); for(int i=0; i Date: Sat, 27 Jan 2018 10:59:55 +0100 Subject: [PATCH 153/174] Correcting an missing semicolumn in avx512 --- lib/simd/Grid_avx512.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simd/Grid_avx512.h b/lib/simd/Grid_avx512.h index 85d27421..cce77a58 100644 --- a/lib/simd/Grid_avx512.h +++ b/lib/simd/Grid_avx512.h @@ -556,7 +556,7 @@ namespace Optimization { v3 = _mm256_add_epi32(v1, v2); v1 = _mm256_hadd_epi32(v3, v3); v2 = _mm256_hadd_epi32(v1, v1); - u1 = _mm256_castsi256_si128(v2) // upper half + u1 = _mm256_castsi256_si128(v2); // upper half u2 = _mm256_extracti128_si256(v2, 1); // lower half ret = _mm_add_epi32(u1, u2); return _mm_cvtsi128_si32(ret); From 655a69259a76b844ab06a2e78fbe8a0441dbf774 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Sun, 28 Jan 2018 17:02:46 +0100 Subject: [PATCH 154/174] Added support for GCC compilation for Skylake AVX512 --- configure.ac | 3 +++ lib/qcd/action/fermion/CayleyFermion5Dvec.cc | 4 ++-- lib/qcd/action/fermion/DomainWallEOFAFermionvec.cc | 2 +- lib/qcd/action/fermion/MobiusEOFAFermionvec.cc | 2 +- lib/simd/Intel512avx.h | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 468d9d5f..3a6a2960 100644 --- a/configure.ac +++ b/configure.ac @@ -249,6 +249,9 @@ case ${ax_cv_cxx_compiler_vendor} in AVX512) AC_DEFINE([AVX512],[1],[AVX512 intrinsics]) SIMD_FLAGS='-mavx512f -mavx512pf -mavx512er -mavx512cd';; + SKL) + AC_DEFINE([AVX512],[1],[AVX512 intrinsics for SkyLake Xeon]) + SIMD_FLAGS='-march=skylake-avx512';; KNC) AC_DEFINE([IMCI],[1],[IMCI intrinsics for Knights Corner]) SIMD_FLAGS='';; diff --git a/lib/qcd/action/fermion/CayleyFermion5Dvec.cc b/lib/qcd/action/fermion/CayleyFermion5Dvec.cc index 653e6ab3..2b2eace7 100644 --- a/lib/qcd/action/fermion/CayleyFermion5Dvec.cc +++ b/lib/qcd/action/fermion/CayleyFermion5Dvec.cc @@ -469,7 +469,7 @@ void CayleyFermion5D::MooeeInternalAsm(const FermionField &psi, FermionFie } a0 = a0+incr; a1 = a1+incr; - a2 = a2+sizeof(Simd::scalar_type); + a2 = a2+sizeof(typename Simd::scalar_type); }} { int lexa = s1+LLs*site; @@ -701,7 +701,7 @@ void CayleyFermion5D::MooeeInternalZAsm(const FermionField &psi, FermionFi } a0 = a0+incr; a1 = a1+incr; - a2 = a2+sizeof(Simd::scalar_type); + a2 = a2+sizeof(typename Simd::scalar_type); }} { int lexa = s1+LLs*site; diff --git a/lib/qcd/action/fermion/DomainWallEOFAFermionvec.cc b/lib/qcd/action/fermion/DomainWallEOFAFermionvec.cc index 81ce448c..c95172a5 100644 --- a/lib/qcd/action/fermion/DomainWallEOFAFermionvec.cc +++ b/lib/qcd/action/fermion/DomainWallEOFAFermionvec.cc @@ -475,7 +475,7 @@ namespace QCD { } a0 = a0 + incr; a1 = a1 + incr; - a2 = a2 + sizeof(Simd::scalar_type); + a2 = a2 + sizeof(typename Simd::scalar_type); } } diff --git a/lib/qcd/action/fermion/MobiusEOFAFermionvec.cc b/lib/qcd/action/fermion/MobiusEOFAFermionvec.cc index c4eaf0f3..290ba158 100644 --- a/lib/qcd/action/fermion/MobiusEOFAFermionvec.cc +++ b/lib/qcd/action/fermion/MobiusEOFAFermionvec.cc @@ -853,7 +853,7 @@ namespace QCD { a0 = a0 + incr; a1 = a1 + incr; - a2 = a2 + sizeof(Simd::scalar_type); + a2 = a2 + sizeof(typename Simd::scalar_type); } } diff --git a/lib/simd/Intel512avx.h b/lib/simd/Intel512avx.h index 7b5964ad..def37b9b 100644 --- a/lib/simd/Intel512avx.h +++ b/lib/simd/Intel512avx.h @@ -79,7 +79,7 @@ Author: paboyle #define ZEND2f(Criir,Ciirr, tmp) "vshufps $0xb1," #Ciirr "," #Ciirr "," #tmp ";\n"\ "vsubps " #tmp "," #Ciirr "," #Criir"{%k7}" ";\n" -#define ZEND1d(Criir,Ciirr, tmp) "vshufpd $0x55," #Criir "," #Criir "," #tmp ";\n"\ +#define ZEND1d(Criir,Ciirr, tmp) "vshufpd $0x55," #Criir "," #Criir "," #tmp ";\n"\ "vaddps " #tmp "," #Criir "," #Criir"{%k6}" ";\n" #define ZEND2d(Criir,Ciirr, tmp) "vshufpd $0x55," #Ciirr "," #Ciirr "," #tmp ";\n"\ From fb24e3a7d24abb2bcdef4c85711ce0d25319a153 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Mon, 29 Jan 2018 11:11:45 +0100 Subject: [PATCH 155/174] Adding utilities for perf profiling --- benchmarks/Benchmark_wilson.cc | 24 +++++++++++- lib/util/Profiling.h | 72 ++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 lib/util/Profiling.h diff --git a/benchmarks/Benchmark_wilson.cc b/benchmarks/Benchmark_wilson.cc index d1499a76..754051f0 100644 --- a/benchmarks/Benchmark_wilson.cc +++ b/benchmarks/Benchmark_wilson.cc @@ -4,7 +4,7 @@ Source file: ./benchmarks/Benchmark_wilson.cc - Copyright (C) 2015 + Copyright (C) 2018 Author: Peter Boyle Author: paboyle @@ -32,6 +32,9 @@ using namespace std; using namespace Grid; using namespace Grid::QCD; + +#include "Grid/util/Profiling.h" + template struct scal { d internal; @@ -45,6 +48,7 @@ struct scal { }; bool overlapComms = false; +bool perfProfiling = false; int main (int argc, char ** argv) { @@ -53,6 +57,9 @@ int main (int argc, char ** argv) if( GridCmdOptionExists(argv,argv+argc,"--asynch") ){ overlapComms = true; } + if( GridCmdOptionExists(argv,argv+argc,"--perf") ){ + perfProfiling = true; + } long unsigned int single_site_flops = 8*QCD::Nc*(7+16*QCD::Nc); @@ -144,6 +151,21 @@ int main (int argc, char ** argv) double t1=usecond(); double flops=single_site_flops*volume*ncall; + if (perfProfiling){ + std::cout< + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ + /* END LEGAL */ + +#ifndef GRID_PERF_PROFILING_H +#define GRID_PERF_PROFILING_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct System +{ + static void profile(const std::string& name,std::function body) { + std::string filename = name.find(".data") == std::string::npos ? (name + ".data") : name; + + // Launch profiler + pid_t pid; + std::stringstream s; + s << getpid(); + pid = fork(); + if (pid == 0) { + auto fd=open("/dev/null",O_RDWR); + dup2(fd,1); + dup2(fd,2); + exit(execl("/usr/bin/perf","perf","record","-o",filename.c_str(),"-p",s.str().c_str(),nullptr)); + } + + // Run body + body(); + + // Kill profiler + kill(pid,SIGINT); + waitpid(pid,nullptr,0); + } + + static void profile(std::function body) { + profile("perf.data",body); + } +}; + +#endif // GRID_PERF_PROFILING_H \ No newline at end of file From cd44e851f1021db5f895a4caf409c885b35d7bd9 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 30 Jan 2018 06:04:30 +0100 Subject: [PATCH 156/174] Fixing compilation error in FundtoHirep --- extras/Hadrons/Modules/MGauge/FundtoHirep.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extras/Hadrons/Modules/MGauge/FundtoHirep.cc b/extras/Hadrons/Modules/MGauge/FundtoHirep.cc index f15a3b7c..31c5a34d 100644 --- a/extras/Hadrons/Modules/MGauge/FundtoHirep.cc +++ b/extras/Hadrons/Modules/MGauge/FundtoHirep.cc @@ -57,7 +57,7 @@ std::vector TFundtoHirep::getOutput(void) template void TFundtoHirep::setup(void) { - env().template registerLattice(getName()); + envCreateLat(typename Rep::LatticeField, getName()); } // execution /////////////////////////////////////////////////////////////////// @@ -70,6 +70,6 @@ void TFundtoHirep::execute(void) Rep TargetRepresentation(U._grid); TargetRepresentation.update_representation(U); - typename Rep::LatticeField &URep = *env().template createLattice(getName()); + auto &URep = envGet(typename Rep::LatticeField, getName()); URep = TargetRepresentation.U; } From 53bffb83d453080fe5dd16fb5601d16a94997d87 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 30 Jan 2018 12:42:36 +0100 Subject: [PATCH 157/174] Updating README with new SKL target --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13dd6996..5a92cdec 100644 --- a/README.md +++ b/README.md @@ -187,10 +187,11 @@ Alternatively, some CPU codenames can be directly used: | `` | Description | | ----------- | -------------------------------------- | | `KNL` | [Intel Xeon Phi codename Knights Landing](http://ark.intel.com/products/codename/48999/Knights-Landing) | +| `SKL` | [Intel Skylake with AVX512 extensions](https://ark.intel.com/products/codename/37572/Skylake#@server) | | `BGQ` | Blue Gene/Q | #### Notes: -- We currently support AVX512 only for the Intel compiler. Support for GCC and clang will appear in future versions of Grid when the AVX512 support within GCC and clang will be more advanced. +- We currently support AVX512 for the Intel compiler and GCC (SKL target). Support for clang will appear in future versions of Grid when the AVX512 support in the compiler will be more advanced. - For BG/Q only [bgclang](http://trac.alcf.anl.gov/projects/llvm-bgq) is supported. We do not presently plan to support more compilers for this platform. - BG/Q performances are currently rather poor. This is being investigated for future versions. - The vector size for the `GEN` target can be specified with the `configure` script option `--enable-gen-simd-width`. From f0fcdf75b5b7c6be03224a50b1157170e441b3b5 Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 30 Jan 2018 12:44:20 +0100 Subject: [PATCH 158/174] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a92cdec..86506f52 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ Alternatively, some CPU codenames can be directly used: | `BGQ` | Blue Gene/Q | #### Notes: -- We currently support AVX512 for the Intel compiler and GCC (SKL target). Support for clang will appear in future versions of Grid when the AVX512 support in the compiler will be more advanced. +- We currently support AVX512 for the Intel compiler and GCC (KNL and SKL target). Support for clang will appear in future versions of Grid when the AVX512 support in the compiler will be more advanced. - For BG/Q only [bgclang](http://trac.alcf.anl.gov/projects/llvm-bgq) is supported. We do not presently plan to support more compilers for this platform. - BG/Q performances are currently rather poor. This is being investigated for future versions. - The vector size for the `GEN` target can be specified with the `configure` script option `--enable-gen-simd-width`. From 896f3a8002b3116380e2293cf3ecca350c34ce5d Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Thu, 1 Feb 2018 18:51:51 +0000 Subject: [PATCH 159/174] Fix to MPI for Hokusai system --- lib/communicator/SharedMemoryMPI.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/communicator/SharedMemoryMPI.cc b/lib/communicator/SharedMemoryMPI.cc index d7bd7c65..2a62b7ac 100644 --- a/lib/communicator/SharedMemoryMPI.cc +++ b/lib/communicator/SharedMemoryMPI.cc @@ -182,6 +182,7 @@ void GlobalSharedMemory::OptimalCommunicator(const std::vector &processors, #ifdef GRID_MPI3_SHMMMAP void GlobalSharedMemory::SharedMemoryAllocate(uint64_t bytes, int flags) { + std::cout << "SharedMemoryAllocate "<< bytes<< " MMAP implementation "< &processors, ////////////////////////////////////////////////////////////////////////////////////////////////////// SetCommunicator(comm_split); + // Free the temp communicator + MPI_Comm_free(&comm_split); + if(0){ std::cout << " ndim " <<_ndimension<<" " << parent._ndimension << std::endl; for(int d=0;d &processors, void CartesianCommunicator::InitFromMPICommunicator(const std::vector &processors, MPI_Comm communicator_base) { + //////////////////////////////////////////////////// + // Creates communicator, and the communicator_halo + //////////////////////////////////////////////////// _ndimension = processors.size(); _processor_coor.resize(_ndimension); From 7b8b2731e702838e3b5696faca6746f5f8157d02 Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 12 Feb 2018 16:06:31 +0000 Subject: [PATCH 161/174] Conj error for complex coeffs --- lib/qcd/action/fermion/CayleyFermion5D.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/qcd/action/fermion/CayleyFermion5D.cc b/lib/qcd/action/fermion/CayleyFermion5D.cc index eace6484..e053b98c 100644 --- a/lib/qcd/action/fermion/CayleyFermion5D.cc +++ b/lib/qcd/action/fermion/CayleyFermion5D.cc @@ -73,7 +73,7 @@ void CayleyFermion5D::DminusDag(const FermionField &psi, FermionField &chi this->DW(psi,tmp_f,DaggerYes); for(int s=0;s Date: Tue, 13 Feb 2018 02:08:49 +0000 Subject: [PATCH 162/174] INterface to suit hadrons on Lanczos --- .../iterative/ImplicitlyRestartedLanczos.h | 7 + .../iterative/LocalCoherenceLanczos.h | 187 ++++++++++++------ tests/debug/Test_cayley_coarsen_support.cc | 3 +- tests/debug/Test_cayley_ldop_cr.cc | 3 +- .../Test_dwf_compressed_lanczos_reorg.cc | 14 +- 5 files changed, 143 insertions(+), 71 deletions(-) diff --git a/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h b/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h index 7b85c095..b4fca33a 100644 --- a/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h +++ b/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h @@ -181,6 +181,13 @@ enum IRLdiagonalisation { template class ImplicitlyRestartedLanczosHermOpTester : public ImplicitlyRestartedLanczosTester { public: + + static void Deflate(const std::vector &_v, + const std::vector& eval, + const Field& src_orig,Field& result) { + basisDeflate(_v,eval,src_orig,result); + } + LinearFunction &_HermOp; ImplicitlyRestartedLanczosHermOpTester(LinearFunction &HermOp) : _HermOp(HermOp) { }; int ReconstructEval(int j,RealD resid,Field &B, RealD &eval,RealD evalMaxApprox) diff --git a/lib/algorithms/iterative/LocalCoherenceLanczos.h b/lib/algorithms/iterative/LocalCoherenceLanczos.h index d5d1bbc2..c530a572 100644 --- a/lib/algorithms/iterative/LocalCoherenceLanczos.h +++ b/lib/algorithms/iterative/LocalCoherenceLanczos.h @@ -70,21 +70,24 @@ public: typedef Lattice FineField; LinearOperatorBase &_Linop; - Aggregation &_Aggregate; + std::vector &subspace; - ProjectedHermOp(LinearOperatorBase& linop, Aggregation &aggregate) : - _Linop(linop), - _Aggregate(aggregate) { }; + ProjectedHermOp(LinearOperatorBase& linop, std::vector & _subspace) : + _Linop(linop), subspace(_subspace) + { + assert(subspace.size() >0); + }; void operator()(const CoarseField& in, CoarseField& out) { + GridBase *FineGrid = subspace[0]._grid; + int checkerboard = subspace[0].checkerboard; + + FineField fin (FineGrid); fin.checkerboard= checkerboard; + FineField fout(FineGrid); fout.checkerboard = checkerboard; - GridBase *FineGrid = _Aggregate.FineGrid; - FineField fin(FineGrid); - FineField fout(FineGrid); - - _Aggregate.PromoteFromSubspace(in,fin); std::cout< & _poly; LinearOperatorBase &_Linop; - Aggregation &_Aggregate; + std::vector &subspace; - ProjectedFunctionHermOp(OperatorFunction & poly,LinearOperatorBase& linop, - Aggregation &aggregate) : + ProjectedFunctionHermOp(OperatorFunction & poly, + LinearOperatorBase& linop, + std::vector & _subspace) : _poly(poly), _Linop(linop), - _Aggregate(aggregate) { }; + subspace(_subspace) + { }; void operator()(const CoarseField& in, CoarseField& out) { - - GridBase *FineGrid = _Aggregate.FineGrid; - - FineField fin(FineGrid) ;fin.checkerboard =_Aggregate.checkerboard; - FineField fout(FineGrid);fout.checkerboard =_Aggregate.checkerboard; - _Aggregate.PromoteFromSubspace(in,fin); std::cout< & _Poly; OperatorFunction & _smoother; LinearOperatorBase &_Linop; - Aggregation &_Aggregate; - RealD _coarse_relax_tol; + RealD _coarse_relax_tol; + std::vector &_subspace; + ImplicitlyRestartedLanczosSmoothedTester(LinearFunction &Poly, OperatorFunction &smoother, LinearOperatorBase &Linop, - Aggregation &Aggregate, + std::vector &subspace, RealD coarse_relax_tol=5.0e3) - : _smoother(smoother), _Linop(Linop),_Aggregate(Aggregate), _Poly(Poly), _coarse_relax_tol(coarse_relax_tol) { }; + : _smoother(smoother), _Linop(Linop), _Poly(Poly), _subspace(subspace), + _coarse_relax_tol(coarse_relax_tol) + { }; int TestConvergence(int j,RealD eresid,CoarseField &B, RealD &eval,RealD evalMaxApprox) { CoarseField v(B); RealD eval_poly = eval; + // Apply operator _Poly(B,v); @@ -168,14 +178,13 @@ class ImplicitlyRestartedLanczosSmoothedTester : public ImplicitlyRestartedLanc } int ReconstructEval(int j,RealD eresid,CoarseField &B, RealD &eval,RealD evalMaxApprox) { - GridBase *FineGrid = _Aggregate.FineGrid; - - int checkerboard = _Aggregate.checkerboard; - + GridBase *FineGrid = _subspace[0]._grid; + int checkerboard = _subspace[0].checkerboard; FineField fB(FineGrid);fB.checkerboard =checkerboard; FineField fv(FineGrid);fv.checkerboard =checkerboard; - _Aggregate.PromoteFromSubspace(B,fv); + blockPromote(B,fv,_subspace); + _smoother(_Linop,fv,fB); RealD eval_poly = eval; @@ -217,27 +226,80 @@ protected: int _checkerboard; LinearOperatorBase & _FineOp; - // FIXME replace Aggregation with vector of fine; the code reuse is too small for - // the hassle and complexity of cross coupling. - Aggregation _Aggregate; - std::vector evals_fine; - std::vector evals_coarse; - std::vector evec_coarse; + std::vector &evals_fine; + std::vector &evals_coarse; + std::vector &subspace; + std::vector &evec_coarse; + +private: + std::vector _evals_fine; + std::vector _evals_coarse; + std::vector _subspace; + std::vector _evec_coarse; + public: + static void Deflate(std::vector subspace, + std::vector evec_coarse, + std::vector eval_coarse, + const FineField& src_orig,FineField& result) + { + int N = (int)evec_coarse.size(); + CoarseField src_coarse(evec_coarse[0]._grid); + CoarseField res_coarse(evec_coarse[0]._grid); res_coarse = zero; + blockProject(src_orig,src_coarse,subspace); + for (int i=0;i &FineOp, - int checkerboard) : + GridBase *CoarseGrid, + LinearOperatorBase &FineOp, + int checkerboard) : _CoarseGrid(CoarseGrid), _FineGrid(FineGrid), - _Aggregate(CoarseGrid,FineGrid,checkerboard), _FineOp(FineOp), - _checkerboard(checkerboard) + _checkerboard(checkerboard), + evals_fine (_evals_fine), + evals_coarse(_evals_coarse), + subspace (_subspace), + evec_coarse(_evec_coarse) { evals_fine.resize(0); evals_coarse.resize(0); }; - void Orthogonalise(void ) { _Aggregate.Orthogonalise(); } + ////////////////////////////////////////////////////////////////////////// + // Alternate constructore, external storage for use by Hadrons module + ////////////////////////////////////////////////////////////////////////// + LocalCoherenceLanczos(GridBase *FineGrid, + GridBase *CoarseGrid, + LinearOperatorBase &FineOp, + int checkerboard, + std::vector &ext_subspace, + std::vector &ext_coarse, + std::vector &ext_eval_fine, + std::vector &ext_eval_coarse + ) : + _CoarseGrid(CoarseGrid), + _FineGrid(FineGrid), + _FineOp(FineOp), + _checkerboard(checkerboard), + evals_fine (ext_eval_fine), + evals_coarse(ext_eval_coarse), + subspace (ext_subspace), + evec_coarse (ext_coarse) + { + evals_fine.resize(0); + evals_coarse.resize(0); + }; + + void Orthogonalise(void ) { + CoarseScalar InnerProd(_CoarseGrid); + blockOrthogonalise(InnerProd,subspace);std::cout << GridLogMessage <<" Gramm-Schmidt pass 1"< static RealD normalise(T& v) { @@ -246,43 +308,44 @@ public: v = v * (1.0/nn); return nn; } - + /* void fakeFine(void) { int Nk = nbasis; - _Aggregate.subspace.resize(Nk,_FineGrid); - _Aggregate.subspace[0]=1.0; - _Aggregate.subspace[0].checkerboard=_checkerboard; - normalise(_Aggregate.subspace[0]); + subspace.resize(Nk,_FineGrid); + subspace[0]=1.0; + subspace[0].checkerboard=_checkerboard; + normalise(subspace[0]); PlainHermOp Op(_FineOp); for(int k=1;k Op(_FineOp); ImplicitlyRestartedLanczosHermOpTester SimpleTester(Op); for(int k=0;k ChebySmooth(cheby_smooth); - ProjectedFunctionHermOp ChebyOp (ChebySmooth,_FineOp,_Aggregate); - ImplicitlyRestartedLanczosSmoothedTester ChebySmoothTester(ChebyOp,ChebySmooth,_FineOp,_Aggregate,relax); + ProjectedFunctionHermOp ChebyOp (ChebySmooth,_FineOp,_subspace); + ImplicitlyRestartedLanczosSmoothedTester ChebySmoothTester(ChebyOp,ChebySmooth,_FineOp,subspace,relax); for(int k=0;k Op(_FineOp); evals_fine.resize(Nm); - _Aggregate.subspace.resize(Nm,_FineGrid); + subspace.resize(Nm,_FineGrid); ImplicitlyRestartedLanczos IRL(ChebyOp,Op,Nstop,Nk,Nm,resid,MaxIt,betastp,MinRes); FineField src(_FineGrid); src=1.0; src.checkerboard = _checkerboard; int Nconv; - IRL.calc(evals_fine,_Aggregate.subspace,src,Nconv,false); + IRL.calc(evals_fine,subspace,src,Nconv,false); // Shrink down to number saved assert(Nstop>=nbasis); assert(Nconv>=nbasis); evals_fine.resize(nbasis); - _Aggregate.subspace.resize(nbasis,_FineGrid); + subspace.resize(nbasis,_FineGrid); } void calcCoarse(ChebyParams cheby_op,ChebyParams cheby_smooth,RealD relax, int Nstop, int Nk, int Nm,RealD resid, RealD MaxIt, RealD betastp, int MinRes) { Chebyshev Cheby(cheby_op); - ProjectedHermOp Op(_FineOp,_Aggregate); - ProjectedFunctionHermOp ChebyOp (Cheby,_FineOp,_Aggregate); + ProjectedHermOp Op(_FineOp,_subspace); + ProjectedFunctionHermOp ChebyOp (Cheby,_FineOp,_subspace); ////////////////////////////////////////////////////////////////////////////////////////////////// // create a smoother and see if we can get a cheap convergence test and smooth inside the IRL ////////////////////////////////////////////////////////////////////////////////////////////////// Chebyshev ChebySmooth(cheby_smooth); - ImplicitlyRestartedLanczosSmoothedTester ChebySmoothTester(ChebyOp,ChebySmooth,_FineOp,_Aggregate,relax); + ImplicitlyRestartedLanczosSmoothedTester ChebySmoothTester(ChebyOp,ChebySmooth,_FineOp,_subspace,relax); evals_coarse.resize(Nm); evec_coarse.resize(Nm,_CoarseGrid); diff --git a/tests/debug/Test_cayley_coarsen_support.cc b/tests/debug/Test_cayley_coarsen_support.cc index c6532a0d..f57823e5 100644 --- a/tests/debug/Test_cayley_coarsen_support.cc +++ b/tests/debug/Test_cayley_coarsen_support.cc @@ -111,6 +111,7 @@ int main (int argc, char ** argv) std::cout< subspace(nbasis,FGrid); @@ -119,7 +120,7 @@ int main (int argc, char ** argv) MdagMLinearOperator HermDefOp(Ddwf); typedef Aggregation Subspace; - Subspace Aggregates(Coarse5d,FGrid); + Subspace Aggregates(Coarse5d,FGrid,cb); Aggregates.CreateSubspaceRandom(RNG5); subspace=Aggregates.subspace; diff --git a/tests/debug/Test_cayley_ldop_cr.cc b/tests/debug/Test_cayley_ldop_cr.cc index cbefdd46..c6005fd0 100644 --- a/tests/debug/Test_cayley_ldop_cr.cc +++ b/tests/debug/Test_cayley_ldop_cr.cc @@ -78,6 +78,7 @@ int main (int argc, char ** argv) RealD mass=0.1; RealD M5=1.5; + int cb=0; std::cout< HermDefOp(Ddwf); - Subspace Aggregates(Coarse5d,FGrid); + Subspace Aggregates(Coarse5d,FGrid,cb); Aggregates.CreateSubspace(RNG5,HermDefOp); diff --git a/tests/lanczos/Test_dwf_compressed_lanczos_reorg.cc b/tests/lanczos/Test_dwf_compressed_lanczos_reorg.cc index 4c702a33..3dff4b90 100644 --- a/tests/lanczos/Test_dwf_compressed_lanczos_reorg.cc +++ b/tests/lanczos/Test_dwf_compressed_lanczos_reorg.cc @@ -56,12 +56,12 @@ public: void checkpointFine(std::string evecs_file,std::string evals_file) { - assert(this->_Aggregate.subspace.size()==nbasis); + assert(this->subspace.size()==nbasis); emptyUserRecord record; Grid::QCD::ScidacWriter WR; WR.open(evecs_file); for(int k=0;k_Aggregate.subspace[k],record); + WR.writeScidacFieldRecord(this->subspace[k],record); } WR.close(); @@ -72,7 +72,7 @@ public: void checkpointFineRestore(std::string evecs_file,std::string evals_file) { this->evals_fine.resize(nbasis); - this->_Aggregate.subspace.resize(nbasis,this->_FineGrid); + this->subspace.resize(nbasis,this->_FineGrid); std::cout << GridLogIRL<< "checkpointFineRestore: Reading evals from "<_Aggregate.subspace[k].checkerboard=this->_checkerboard; - RD.readScidacFieldRecord(this->_Aggregate.subspace[k],record); + this->subspace[k].checkerboard=this->_checkerboard; + RD.readScidacFieldRecord(this->subspace[k],record); } RD.close(); @@ -221,7 +221,9 @@ int main (int argc, char ** argv) { std::cout << GridLogIRL<<"Checkpointing Fine evecs"< Date: Tue, 13 Feb 2018 02:11:37 +0000 Subject: [PATCH 163/174] Move deflate to right class --- .../iterative/ImplicitlyRestartedLanczos.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h b/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h index b4fca33a..7d5a1889 100644 --- a/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h +++ b/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h @@ -182,12 +182,6 @@ template class ImplicitlyRestartedLanczosHermOpTester : public Imp { public: - static void Deflate(const std::vector &_v, - const std::vector& eval, - const Field& src_orig,Field& result) { - basisDeflate(_v,eval,src_orig,result); - } - LinearFunction &_HermOp; ImplicitlyRestartedLanczosHermOpTester(LinearFunction &HermOp) : _HermOp(HermOp) { }; int ReconstructEval(int j,RealD resid,Field &B, RealD &eval,RealD evalMaxApprox) @@ -250,6 +244,13 @@ class ImplicitlyRestartedLanczos { ///////////////////////// public: + + static void Deflate(const std::vector &_v, + const std::vector& eval, + const Field& src_orig,Field& result) { + basisDeflate(_v,eval,src_orig,result); + } + ////////////////////////////////////////////////////////////////// // PAB: ////////////////////////////////////////////////////////////////// From c96483e3bd559ab4a20c12102534c37447179b4c Mon Sep 17 00:00:00 2001 From: paboyle Date: Tue, 13 Feb 2018 11:39:07 +0000 Subject: [PATCH 164/174] Whitespace only change --- lib/algorithms/iterative/LocalCoherenceLanczos.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/algorithms/iterative/LocalCoherenceLanczos.h b/lib/algorithms/iterative/LocalCoherenceLanczos.h index c530a572..4c05f4c7 100644 --- a/lib/algorithms/iterative/LocalCoherenceLanczos.h +++ b/lib/algorithms/iterative/LocalCoherenceLanczos.h @@ -28,7 +28,9 @@ Author: paboyle /* END LEGAL */ #ifndef GRID_LOCAL_COHERENCE_IRL_H #define GRID_LOCAL_COHERENCE_IRL_H + namespace Grid { + struct LanczosParams : Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(LanczosParams, From e30a80a2340275774e464b5ce7b328f0ece84b44 Mon Sep 17 00:00:00 2001 From: Christopher Kelly Date: Thu, 15 Feb 2018 17:13:36 +0000 Subject: [PATCH 165/174] Relaxed constraints on MPI thread mode when not using multiple comms threads --- lib/communicator/Communicator_mpi3.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/communicator/Communicator_mpi3.cc b/lib/communicator/Communicator_mpi3.cc index 6732dcdf..eb0144f0 100644 --- a/lib/communicator/Communicator_mpi3.cc +++ b/lib/communicator/Communicator_mpi3.cc @@ -44,7 +44,10 @@ void CartesianCommunicator::Init(int *argc, char ***argv) MPI_Initialized(&flag); // needed to coexist with other libs apparently if ( !flag ) { MPI_Init_thread(argc,argv,MPI_THREAD_MULTIPLE,&provided); - assert (provided == MPI_THREAD_MULTIPLE); + //If only 1 comms thread we require any threading mode other than SINGLE, but for multiple comms threads we need MULTIPLE + if( (nCommThreads == 1 && provided == MPI_THREAD_SINGLE) || + (nCommThreads > 1 && provided != MPI_THREAD_MULTIPLE) ) + assert(0); } Grid_quiesce_nodes(); From 945684c470845d826fdbb8511ddf098a90779188 Mon Sep 17 00:00:00 2001 From: paboyle Date: Tue, 20 Feb 2018 14:28:38 +0000 Subject: [PATCH 166/174] updates for deflation in the RB solver --- lib/algorithms/Algorithms.h | 1 + .../iterative/ImplicitlyRestartedLanczos.h | 19 ----------- .../iterative/LocalCoherenceLanczos.h | 16 +-------- lib/algorithms/iterative/SchurRedBlack.h | 33 ++++++++++++++++--- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/lib/algorithms/Algorithms.h b/lib/algorithms/Algorithms.h index 070a1019..ef147c53 100644 --- a/lib/algorithms/Algorithms.h +++ b/lib/algorithms/Algorithms.h @@ -39,6 +39,7 @@ Author: Peter Boyle #include #include +#include #include #include #include diff --git a/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h b/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h index 7d5a1889..787cf15a 100644 --- a/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h +++ b/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h @@ -149,19 +149,6 @@ void basisSortInPlace(std::vector & _v,std::vector& sort_vals, boo basisReorderInPlace(_v,sort_vals,idx); } -// PAB: faster to compute the inner products first then fuse loops. -// If performance critical can improve. -template -void basisDeflate(const std::vector &_v,const std::vector& eval,const Field& src_orig,Field& result) { - result = zero; - assert(_v.size()==eval.size()); - int N = (int)_v.size(); - for (int i=0;i &_v, - const std::vector& eval, - const Field& src_orig,Field& result) { - basisDeflate(_v,eval,src_orig,result); - } - ////////////////////////////////////////////////////////////////// // PAB: ////////////////////////////////////////////////////////////////// diff --git a/lib/algorithms/iterative/LocalCoherenceLanczos.h b/lib/algorithms/iterative/LocalCoherenceLanczos.h index 4c05f4c7..b8348c0c 100644 --- a/lib/algorithms/iterative/LocalCoherenceLanczos.h +++ b/lib/algorithms/iterative/LocalCoherenceLanczos.h @@ -31,6 +31,7 @@ Author: paboyle namespace Grid { + struct LanczosParams : Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(LanczosParams, @@ -240,21 +241,6 @@ private: std::vector _evec_coarse; public: - static void Deflate(std::vector subspace, - std::vector evec_coarse, - std::vector eval_coarse, - const FineField& src_orig,FineField& result) - { - int N = (int)evec_coarse.size(); - CoarseField src_coarse(evec_coarse[0]._grid); - CoarseField res_coarse(evec_coarse[0]._grid); res_coarse = zero; - blockProject(src_orig,src_coarse,subspace); - for (int i=0;i - void operator() (Matrix & _Matrix,const Field &in, Field &out){ + void operator() (Matrix & _Matrix,const Field &in, Field &out){ + ZeroGuesser guess; + (*this)(_Matrix,in,out,guess); + } + template + void operator() (Matrix & _Matrix,const Field &in, Field &out, Guesser &guess){ // FIXME CGdiagonalMee not implemented virtual function // FIXME use CBfactorise to control schur decomp @@ -129,7 +134,6 @@ namespace Grid { pickCheckerboard(Odd ,src_o,in); pickCheckerboard(Even,sol_e,out); pickCheckerboard(Odd ,sol_o,out); - std::cout << GridLogMessage << " SchurRedBlackStaggeredSolve checkerboards picked" < - void operator() (Matrix & _Matrix,const Field &in, Field &out){ + void operator() (Matrix & _Matrix,const Field &in, Field &out){ + ZeroGuesser guess; + (*this)(_Matrix,in,out,guess); + } + template + void operator() (Matrix & _Matrix,const Field &in, Field &out,Guesser &guess){ // FIXME CGdiagonalMee not implemented virtual function // FIXME use CBfactorise to control schur decomp @@ -225,6 +235,7 @@ namespace Grid { // Call the red-black solver ////////////////////////////////////////////////////////////// std::cout< - void operator() (Matrix & _Matrix,const Field &in, Field &out){ + void operator() (Matrix & _Matrix,const Field &in, Field &out){ + ZeroGuesser guess; + (*this)(_Matrix,in,out,guess); + } + template + void operator() (Matrix & _Matrix,const Field &in, Field &out,Guesser &guess){ // FIXME CGdiagonalMee not implemented virtual function // FIXME use CBfactorise to control schur decomp @@ -305,6 +321,7 @@ namespace Grid { ////////////////////////////////////////////////////////////// std::cout< - void operator() (Matrix & _Matrix,const Field &in, Field &out){ + void operator() (Matrix & _Matrix,const Field &in, Field &out){ + ZeroGuesser guess; + (*this)(_Matrix,in,out,guess); + } + template + void operator() (Matrix & _Matrix,const Field &in, Field &out,Guesser &guess){ // FIXME CGdiagonalMee not implemented virtual function // FIXME use CBfactorise to control schur decomp @@ -385,6 +407,7 @@ namespace Grid { std::cout< Date: Tue, 20 Feb 2018 14:29:08 +0000 Subject: [PATCH 167/174] Deflation interface for solvers --- lib/algorithms/iterative/Deflation.h | 101 +++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 lib/algorithms/iterative/Deflation.h diff --git a/lib/algorithms/iterative/Deflation.h b/lib/algorithms/iterative/Deflation.h new file mode 100644 index 00000000..b6aa0d3d --- /dev/null +++ b/lib/algorithms/iterative/Deflation.h @@ -0,0 +1,101 @@ + /************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./lib/algorithms/iterative/ImplicitlyRestartedLanczos.h + + Copyright (C) 2015 + +Author: Peter Boyle + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + See the full license in the file "LICENSE" in the top level distribution directory + *************************************************************************************/ + /* END LEGAL */ +#ifndef GRID_DEFLATION_H +#define GRID_DEFLATION_H + +namespace Grid { + +struct ZeroGuesser { +public: + template + void operator()(const Field &src,Field &guess) { guess = Zero(); }; +}; +struct SourceGuesser { +public: + template + void operator()(const Field &src,Field &guess) { guess = src; }; +}; + +//////////////////////////////// +// Fine grid deflation +//////////////////////////////// +template +struct DeflatedGuesser { +private: + const std::vector &evec; + const std::vector &eval; + +public: + + DeflatedGuesser(const std::vector & _evec,const std::vector & _eval) : evec(_evec), eval(_eval) {}; + + void operator()(const Field &src,Field &guess) { + guess = zero; + assert(evec.size()==eval.size()); + auto N = evec.size(); + for (int i=0;i +class LocalCoherenceDeflatedGuesser { +private: + const std::vector &subspace; + const std::vector &evec_coarse; + const std::vector &eval_coarse; +public: + + LocalCoherenceDeflatedGuesser(const std::vector &_subspace, + const std::vector &_evec_coarse, + const std::vector &_eval_coarse) + : subspace(_subspace), + evec_coarse(_evec_coarse), + eval_coarse(_eval_coarse) + { + } + + void operator()(const FineField &src,FineField &guess) { + int N = (int)evec_coarse.size(); + CoarseField src_coarse(evec_coarse[0]._grid); + CoarseField guess_coarse(evec_coarse[0]._grid); guess_coarse = zero; + blockProject(src,src_coarse,subspace); + for (int i=0;i Date: Tue, 20 Feb 2018 15:12:31 +0000 Subject: [PATCH 168/174] Extra communicator free that I had missed. Hard to audit them all as this is complex --- lib/communicator/Communicator_mpi3.cc | 12 ++++++++++-- lib/communicator/SharedMemory.h | 1 + lib/communicator/SharedMemoryMPI.cc | 4 ++++ lib/communicator/SharedMemoryNone.cc | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/communicator/Communicator_mpi3.cc b/lib/communicator/Communicator_mpi3.cc index eb0144f0..424b7973 100644 --- a/lib/communicator/Communicator_mpi3.cc +++ b/lib/communicator/Communicator_mpi3.cc @@ -89,10 +89,16 @@ void CartesianCommunicator::ProcessorCoorFromRank(int rank, std::vector &c CartesianCommunicator::CartesianCommunicator(const std::vector &processors) { MPI_Comm optimal_comm; - GlobalSharedMemory::OptimalCommunicator (processors,optimal_comm); // Remap using the shared memory optimising routine + //////////////////////////////////////////////////// + // Remap using the shared memory optimising routine + // The remap creates a comm which must be freed + //////////////////////////////////////////////////// + GlobalSharedMemory::OptimalCommunicator (processors,optimal_comm); InitFromMPICommunicator(processors,optimal_comm); SetCommunicator(optimal_comm); + /////////////////////////////////////////////////// // Free the temp communicator + /////////////////////////////////////////////////// MPI_Comm_free(&optimal_comm); } @@ -202,8 +208,10 @@ CartesianCommunicator::CartesianCommunicator(const std::vector &processors, // Take the right SHM buffers ////////////////////////////////////////////////////////////////////////////////////////////////////// SetCommunicator(comm_split); - + + /////////////////////////////////////////////// // Free the temp communicator + /////////////////////////////////////////////// MPI_Comm_free(&comm_split); if(0){ diff --git a/lib/communicator/SharedMemory.h b/lib/communicator/SharedMemory.h index 0f647dc6..9f6b1a25 100644 --- a/lib/communicator/SharedMemory.h +++ b/lib/communicator/SharedMemory.h @@ -133,6 +133,7 @@ class SharedMemory public: SharedMemory() {}; + ~SharedMemory(); /////////////////////////////////////////////////////////////////////////////////////// // set the buffers & sizes /////////////////////////////////////////////////////////////////////////////////////// diff --git a/lib/communicator/SharedMemoryMPI.cc b/lib/communicator/SharedMemoryMPI.cc index 2a62b7ac..9e5d8f15 100644 --- a/lib/communicator/SharedMemoryMPI.cc +++ b/lib/communicator/SharedMemoryMPI.cc @@ -399,5 +399,9 @@ void *SharedMemory::ShmBufferTranslate(int rank,void * local_p) return (void *) remote; } } +SharedMemory::~SharedMemory() +{ + MPI_Comm_free(&ShmComm); +}; } diff --git a/lib/communicator/SharedMemoryNone.cc b/lib/communicator/SharedMemoryNone.cc index 7feed7e4..a23e3c1c 100644 --- a/lib/communicator/SharedMemoryNone.cc +++ b/lib/communicator/SharedMemoryNone.cc @@ -122,5 +122,7 @@ void *SharedMemory::ShmBufferTranslate(int rank,void * local_p) { return NULL; } +SharedMemory::~SharedMemory() +{}; } From 2e88408f5ce1bc1ba4052be07c4b1e94f0a99f5a Mon Sep 17 00:00:00 2001 From: Fionn O hOgain Date: Fri, 2 Mar 2018 22:27:41 +0000 Subject: [PATCH 169/174] Some changes needed for deflation interface --- lib/algorithms/iterative/Deflation.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/algorithms/iterative/Deflation.h b/lib/algorithms/iterative/Deflation.h index b6aa0d3d..b2239c55 100644 --- a/lib/algorithms/iterative/Deflation.h +++ b/lib/algorithms/iterative/Deflation.h @@ -59,7 +59,7 @@ public: assert(evec.size()==eval.size()); auto N = evec.size(); for (int i=0;i Date: Mon, 5 Mar 2018 12:22:18 +0000 Subject: [PATCH 170/174] Finalize protection --- lib/communicator/SharedMemoryMPI.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/communicator/SharedMemoryMPI.cc b/lib/communicator/SharedMemoryMPI.cc index 9e5d8f15..45edbb07 100644 --- a/lib/communicator/SharedMemoryMPI.cc +++ b/lib/communicator/SharedMemoryMPI.cc @@ -401,7 +401,10 @@ void *SharedMemory::ShmBufferTranslate(int rank,void * local_p) } SharedMemory::~SharedMemory() { - MPI_Comm_free(&ShmComm); + int MPI_is_finalised; MPI_Finalized(&MPI_is_finalised); + if ( !MPI_is_finalised ) { + MPI_Comm_free(&ShmComm); + } }; } From c399c2b44dea7e6cc4ca6ee34adcd1a86b07c338 Mon Sep 17 00:00:00 2001 From: paboyle Date: Mon, 5 Mar 2018 12:55:41 +0000 Subject: [PATCH 171/174] Guido broke the charge conjugate plaquette action with premature optimisation. This sector of the code does not matter for anything other than Guido's quenched HMC studies, and any plaq specific optimisations should be retained in a private branch instead of destroying the code simplicity. --- lib/qcd/action/gauge/WilsonGaugeAction.h | 12 ++++-------- lib/qcd/utils/WilsonLoops.h | 5 +++-- tests/forces/Test_gp_rect_force.cc | 4 ++-- tests/forces/Test_gpwilson_force.cc | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/qcd/action/gauge/WilsonGaugeAction.h b/lib/qcd/action/gauge/WilsonGaugeAction.h index 1ea780b7..77c2424c 100644 --- a/lib/qcd/action/gauge/WilsonGaugeAction.h +++ b/lib/qcd/action/gauge/WilsonGaugeAction.h @@ -71,18 +71,14 @@ class WilsonGaugeAction : public Action { RealD factor = 0.5 * beta / RealD(Nc); - //GaugeLinkField Umu(U._grid); + GaugeLinkField Umu(U._grid); GaugeLinkField dSdU_mu(U._grid); for (int mu = 0; mu < Nd; mu++) { - //Umu = PeekIndex(U, mu); + Umu = PeekIndex(U, mu); // Staple in direction mu - //WilsonLoops::Staple(dSdU_mu, U, mu); - //dSdU_mu = Ta(Umu * dSdU_mu) * factor; - - - WilsonLoops::StapleMult(dSdU_mu, U, mu); - dSdU_mu = Ta(dSdU_mu) * factor; + WilsonLoops::Staple(dSdU_mu, U, mu); + dSdU_mu = Ta(Umu * dSdU_mu) * factor; PokeIndex(dSdU, dSdU_mu, mu); } diff --git a/lib/qcd/utils/WilsonLoops.h b/lib/qcd/utils/WilsonLoops.h index cdd76ecc..6cf34e0c 100644 --- a/lib/qcd/utils/WilsonLoops.h +++ b/lib/qcd/utils/WilsonLoops.h @@ -212,6 +212,7 @@ public: // For the force term +/* static void StapleMult(GaugeMat &staple, const GaugeLorentz &Umu, int mu) { GridBase *grid = Umu._grid; std::vector U(Nd, grid); @@ -225,7 +226,7 @@ static void StapleMult(GaugeMat &staple, const GaugeLorentz &Umu, int mu) { for (int nu = 0; nu < Nd; nu++) { if (nu != mu) { - // this is ~10% faster than the Staple + // this is ~10% faster than the Staple -- PAB: so what it gives the WRONG answers for other BC's! tmp1 = Cshift(U[nu], mu, 1); tmp2 = Cshift(U[mu], nu, 1); staple += tmp1* adj(U[nu]*tmp2); @@ -235,7 +236,7 @@ static void StapleMult(GaugeMat &staple, const GaugeLorentz &Umu, int mu) { } staple = U[mu]*staple; } - +*/ ////////////////////////////////////////////////// // the sum over all staples on each site ////////////////////////////////////////////////// diff --git a/tests/forces/Test_gp_rect_force.cc b/tests/forces/Test_gp_rect_force.cc index bb35c77a..6b3349e0 100644 --- a/tests/forces/Test_gp_rect_force.cc +++ b/tests/forces/Test_gp_rect_force.cc @@ -59,8 +59,8 @@ int main (int argc, char ** argv) double beta = 1.0; double c1 = 0.331; - //GparityPlaqPlusRectangleActionR Action(beta,c1); - ConjugateWilsonGaugeActionR Action(beta); + ConjugatePlaqPlusRectangleActionR Action(beta,c1); + // ConjugateWilsonGaugeActionR Action(beta); //WilsonGaugeActionR Action(beta); ComplexD S = Action.S(U); diff --git a/tests/forces/Test_gpwilson_force.cc b/tests/forces/Test_gpwilson_force.cc index ebde61a5..e52ed7ee 100644 --- a/tests/forces/Test_gpwilson_force.cc +++ b/tests/forces/Test_gpwilson_force.cc @@ -91,7 +91,7 @@ int main (int argc, char ** argv) //////////////////////////////////// // Modify the gauge field a little //////////////////////////////////// - RealD dt = 0.0001; + RealD dt = 0.01; LatticeColourMatrix mommu(UGrid); LatticeColourMatrix forcemu(UGrid); From 485c5db0fe28b04c867caf33c879c58f9b924d96 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Tue, 6 Mar 2018 19:22:03 +0000 Subject: [PATCH 172/174] conversion of Grid tensors to nested std::vector in preparation for tensor serialisation --- lib/serialisation/BaseIO.h | 35 +++++++++++++++ tests/IO/Test_serialisation.cc | 78 +++++++--------------------------- 2 files changed, 51 insertions(+), 62 deletions(-) diff --git a/lib/serialisation/BaseIO.h b/lib/serialisation/BaseIO.h index 24e1cec7..1af5acc6 100644 --- a/lib/serialisation/BaseIO.h +++ b/lib/serialisation/BaseIO.h @@ -31,6 +31,7 @@ Author: Guido Cossu #define GRID_SERIALISATION_ABSTRACT_READER_H #include +#include namespace Grid { // Vector IO utilities /////////////////////////////////////////////////////// @@ -69,6 +70,40 @@ namespace Grid { return os; } + // convert Grid scalar tensors to std::vectors + template + void tensorToVec(V &v, const T& t) + { + v = t; + } + + template + void tensorToVec(V &v, const iScalar& t) + { + tensorToVec(v, t._internal); + } + + template + void tensorToVec(std::vector &v, const iVector& t) + { + v.resize(N); + for (unsigned int i = 0; i < N; i++) + { + tensorToVec(v[i], t._internal[i]); + } + } + + template + void tensorToVec(std::vector> &v, const iMatrix& t) + { + v.resize(N, std::vector(N)); + for (unsigned int i = 0; i < N; i++) + for (unsigned int j = 0; j < N; j++) + { + tensorToVec(v[i][j], t._internal[i][j]); + } + } + // Vector element trait ////////////////////////////////////////////////////// template struct element diff --git a/tests/IO/Test_serialisation.cc b/tests/IO/Test_serialisation.cc index 82638ad9..cdafd5c0 100644 --- a/tests/IO/Test_serialisation.cc +++ b/tests/IO/Test_serialisation.cc @@ -197,68 +197,22 @@ int main(int argc,char **argv) std::cout << flatdv.getVector() << std::endl; std::cout << std::endl; + std::cout << "==== Grid tensor to vector test" << std::endl; - std::cout << ".:::::: Testing JSON classes "<< std::endl; - - - { - JSONWriter JW("bother.json"); - - // test basic type writing - myenum a = myenum::red; - push(JW,"BasicTypes"); - write(JW,std::string("i16"),i16); - write(JW,"myenum",a); - write(JW,"u16",u16); - write(JW,"i32",i32); - write(JW,"u32",u32); - write(JW,"i64",i64); - write(JW,"u64",u64); - write(JW,"f",f); - write(JW,"d",d); - write(JW,"b",b); - pop(JW); - - - // test serializable class writing - myclass obj(1234); // non-trivial constructor - std::cout << obj << std::endl; - std::cout << "-- serialisable class writing to 'bother.json'..." << std::endl; - write(JW,"obj",obj); - JW.write("obj2", obj); - - - std::vector vec; - vec.push_back(myclass(1234)); - vec.push_back(myclass(5678)); - vec.push_back(myclass(3838)); - write(JW, "objvec", vec); - - } - - - { - JSONReader RD("bother.json"); - myclass jcopy1; - std::vector jveccopy1; - read(RD,"obj",jcopy1); - read(RD,"objvec", jveccopy1); - std::cout << "Loaded (JSON) -----------------" << std::endl; - std::cout << jcopy1 << std::endl << jveccopy1 << std::endl; - } - - -/* - // This is still work in progress - { - // Testing the next element function - JSONReader RD("test.json"); - RD.push("grid"); - RD.push("Observable"); - std::string name; - read(RD,"name", name); - } -*/ - + GridSerialRNG rng; + SpinColourMatrix scm; + SpinColourVector scv; + std::vector>>> scmv; + std::vector> scvv; + rng.SeedFixedIntegers(std::vector({42,10,81,9})); + random(rng, scm); + random(rng, scv); + std::cout << "Test spin-color matrix: " << scm << std::endl; + std::cout << "Test spin-color vector: " << scv << std::endl; + std::cout << "Converting to std::vector" << std::endl; + tensorToVec(scmv, scm); + tensorToVec(scvv, scv); + std::cout << "Spin-color matrix: " << scmv << std::endl; + std::cout << "Spin-color vector: " << scvv << std::endl; } From 8b14096990ff0fe1969ace0bad933ff3dbbac8fc Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 7 Mar 2018 15:12:18 +0000 Subject: [PATCH 173/174] Conversion of Grid tensors to std::vector made more elegant, also pair syntax changed to (x y) to avoid issues with JSON/XML --- lib/serialisation/BaseIO.h | 128 ++++++++++++++++++++++++------------- 1 file changed, 83 insertions(+), 45 deletions(-) diff --git a/lib/serialisation/BaseIO.h b/lib/serialisation/BaseIO.h index 1af5acc6..5b37e1fb 100644 --- a/lib/serialisation/BaseIO.h +++ b/lib/serialisation/BaseIO.h @@ -34,74 +34,76 @@ Author: Guido Cossu #include namespace Grid { - // Vector IO utilities /////////////////////////////////////////////////////// - // helper function to read space-separated values + // Grid scalar tensors to nested std::vectors ////////////////////////////////// template - std::vector strToVec(const std::string s) + struct TensorToVec { - std::istringstream sstr(s); - T buf; - std::vector v; - - while(!sstr.eof()) - { - sstr >> buf; - v.push_back(buf); - } - - return v; - } - - // output to streams for vectors - template < class T > - inline std::ostream & operator<<(std::ostream &os, const std::vector &v) + typedef T type; + }; + + template + struct TensorToVec> { - os << "["; - for (auto &x: v) - { - os << x << " "; - } - if (v.size() > 0) - { - os << "\b"; - } - os << "]"; - - return os; - } - - // convert Grid scalar tensors to std::vectors - template - void tensorToVec(V &v, const T& t) + typedef TensorToVec::type type; + }; + + template + struct TensorToVec> + { + typedef TensorToVec::type type; + }; + + template + struct TensorToVec> + { + typedef std::vector::type> type; + }; + + template + struct TensorToVec> + { + typedef std::vector::type>> type; + }; + + template + TensorToVec::type tensorToVec(const T &t) { v = t; } template - void tensorToVec(V &v, const iScalar& t) + TensorToVec>::type tensorToVec(V &v, const iScalar& t) { - tensorToVec(v, t._internal); + return tensorToVec(t._internal); } - template - void tensorToVec(std::vector &v, const iVector& t) + template + TensorToVec>::type tensorToVec(const iVector& t) { + TensorToVec>::type v; + v.resize(N); for (unsigned int i = 0; i < N; i++) { - tensorToVec(v[i], t._internal[i]); + v[i] = tensorToVec(t._internal[i]); } + + return v; } - template - void tensorToVec(std::vector> &v, const iMatrix& t) + template + TensorToVec>::type tensorToVec(const iMatrix& t) { + TensorToVec>::type v; + v.resize(N, std::vector(N)); for (unsigned int i = 0; i < N; i++) for (unsigned int j = 0; j < N; j++) { - tensorToVec(v[i][j], t._internal[i][j]); + v[i][j] = tensorToVec(t._internal[i][j]); } + + return v; } // Vector element trait ////////////////////////////////////////////////////// @@ -217,7 +219,43 @@ namespace Grid { template inline std::ostream & operator<<(std::ostream &os, const std::pair &p) { - os << "<" << p.first << " " << p.second << ">"; + os << "{" << p.first << " " << p.second << "}"; + return os; + } + + // Vector IO utilities /////////////////////////////////////////////////////// + // helper function to read space-separated values + template + std::vector strToVec(const std::string s) + { + std::istringstream sstr(s); + T buf; + std::vector v; + + while(!sstr.eof()) + { + sstr >> buf; + v.push_back(buf); + } + + return v; + } + + // output to streams for vectors + template < class T > + inline std::ostream & operator<<(std::ostream &os, const std::vector &v) + { + os << "["; + for (auto &x: v) + { + os << x << " "; + } + if (v.size() > 0) + { + os << "\b"; + } + os << "]"; + return os; } From 90dbe03e1764c28f3afac7f53576dd4249f07ea8 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 7 Mar 2018 15:12:18 +0000 Subject: [PATCH 174/174] Conversion of Grid tensors to std::vector made more elegant, also pair syntax changed to (x y) to avoid issues with JSON/XML --- lib/serialisation/BaseIO.h | 141 ++++++++++++++++++++------------- tests/IO/Test_serialisation.cc | 6 +- 2 files changed, 90 insertions(+), 57 deletions(-) diff --git a/lib/serialisation/BaseIO.h b/lib/serialisation/BaseIO.h index 1af5acc6..0a919aab 100644 --- a/lib/serialisation/BaseIO.h +++ b/lib/serialisation/BaseIO.h @@ -34,74 +34,73 @@ Author: Guido Cossu #include namespace Grid { - // Vector IO utilities /////////////////////////////////////////////////////// - // helper function to read space-separated values + // Grid scalar tensors to nested std::vectors ////////////////////////////////// template - std::vector strToVec(const std::string s) + struct TensorToVec { - std::istringstream sstr(s); - T buf; - std::vector v; - - while(!sstr.eof()) - { - sstr >> buf; - v.push_back(buf); - } - - return v; - } - - // output to streams for vectors - template < class T > - inline std::ostream & operator<<(std::ostream &os, const std::vector &v) + typedef T type; + }; + + template + struct TensorToVec> { - os << "["; - for (auto &x: v) - { - os << x << " "; - } - if (v.size() > 0) - { - os << "\b"; - } - os << "]"; - - return os; - } - - // convert Grid scalar tensors to std::vectors - template - void tensorToVec(V &v, const T& t) + typedef typename TensorToVec::type type; + }; + + template + struct TensorToVec> { - v = t; + typedef typename std::vector::type> type; + }; + + template + struct TensorToVec> + { + typedef typename std::vector::type>> type; + }; + + template + typename TensorToVec::type tensorToVec(const T &t) + { + return t; } - template - void tensorToVec(V &v, const iScalar& t) + template + typename TensorToVec>::type tensorToVec(const iScalar& t) { - tensorToVec(v, t._internal); + return tensorToVec(t._internal); } - template - void tensorToVec(std::vector &v, const iVector& t) + template + typename TensorToVec>::type tensorToVec(const iVector& t) { + typename TensorToVec>::type v; + v.resize(N); for (unsigned int i = 0; i < N; i++) { - tensorToVec(v[i], t._internal[i]); + v[i] = tensorToVec(t._internal[i]); } + + return v; } - template - void tensorToVec(std::vector> &v, const iMatrix& t) + template + typename TensorToVec>::type tensorToVec(const iMatrix& t) { - v.resize(N, std::vector(N)); + typename TensorToVec>::type v; + + v.resize(N); for (unsigned int i = 0; i < N; i++) - for (unsigned int j = 0; j < N; j++) { - tensorToVec(v[i][j], t._internal[i][j]); + v[i].resize(N); + for (unsigned int j = 0; j < N; j++) + { + v[i][j] = tensorToVec(t._internal[i][j]); + } } + + return v; } // Vector element trait ////////////////////////////////////////////////////// @@ -186,15 +185,15 @@ namespace Grid { do { is.get(c); - } while (c != '<' && !is.eof()); - if (c == '<') + } while (c != '(' && !is.eof()); + if (c == '(') { int start = is.tellg(); do { is.get(c); - } while (c != '>' && !is.eof()); - if (c == '>') + } while (c != ')' && !is.eof()); + if (c == ')') { int end = is.tellg(); int psize = end - start - 1; @@ -217,7 +216,43 @@ namespace Grid { template inline std::ostream & operator<<(std::ostream &os, const std::pair &p) { - os << "<" << p.first << " " << p.second << ">"; + os << "(" << p.first << " " << p.second << ")"; + return os; + } + + // Vector IO utilities /////////////////////////////////////////////////////// + // helper function to read space-separated values + template + std::vector strToVec(const std::string s) + { + std::istringstream sstr(s); + T buf; + std::vector v; + + while(!sstr.eof()) + { + sstr >> buf; + v.push_back(buf); + } + + return v; + } + + // output to streams for vectors + template < class T > + inline std::ostream & operator<<(std::ostream &os, const std::vector &v) + { + os << "["; + for (auto &x: v) + { + os << x << " "; + } + if (v.size() > 0) + { + os << "\b"; + } + os << "]"; + return os; } diff --git a/tests/IO/Test_serialisation.cc b/tests/IO/Test_serialisation.cc index cdafd5c0..d4b89652 100644 --- a/tests/IO/Test_serialisation.cc +++ b/tests/IO/Test_serialisation.cc @@ -202,8 +202,6 @@ int main(int argc,char **argv) GridSerialRNG rng; SpinColourMatrix scm; SpinColourVector scv; - std::vector>>> scmv; - std::vector> scvv; rng.SeedFixedIntegers(std::vector({42,10,81,9})); random(rng, scm); @@ -211,8 +209,8 @@ int main(int argc,char **argv) std::cout << "Test spin-color matrix: " << scm << std::endl; std::cout << "Test spin-color vector: " << scv << std::endl; std::cout << "Converting to std::vector" << std::endl; - tensorToVec(scmv, scm); - tensorToVec(scvv, scv); + auto scmv = tensorToVec(scm); + auto scvv = tensorToVec(scv); std::cout << "Spin-color matrix: " << scmv << std::endl; std::cout << "Spin-color vector: " << scvv << std::endl; }