From b45586e81c6584c264f3be4fb89fb6a8c0b812a2 Mon Sep 17 00:00:00 2001 From: Michael Marshall Date: Wed, 23 Jan 2019 21:17:56 +0000 Subject: [PATCH] Discovered bug root cause. setup() is called multiple times. Now ready to copy-paste the LapEvec code --- Hadrons/Modules/MDistil/Distil.hpp | 5 +- Hadrons/Modules/MDistil/LapEvec.hpp | 84 +++++++++++++++++----------- tests/hadrons/Test_hadrons_distil.cc | 6 +- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/Hadrons/Modules/MDistil/Distil.hpp b/Hadrons/Modules/MDistil/Distil.hpp index 38672dfb..74e35085 100644 --- a/Hadrons/Modules/MDistil/Distil.hpp +++ b/Hadrons/Modules/MDistil/Distil.hpp @@ -106,6 +106,7 @@ BEGIN_MODULE_NAMESPACE(MDistil) inline GridCartesian * MakeLowerDimGrid( GridCartesian * gridHD ) { + //LOG(Message) << "MakeLowerDimGrid() begin" << std::endl; int nd{static_cast(gridHD->_ndimension)}; std::vector latt_size = gridHD->_fdimensions; latt_size[nd-1] = 1; @@ -115,7 +116,9 @@ inline GridCartesian * MakeLowerDimGrid( GridCartesian * gridHD ) std::vector mpi_layout = gridHD->_processors; mpi_layout[nd-1] = 1; - return new GridCartesian(latt_size,simd_layout,mpi_layout,*gridHD); + GridCartesian * gridLD = new GridCartesian(latt_size,simd_layout,mpi_layout,*gridHD); + //LOG(Message) << "MakeLowerDimGrid() end" << std::endl; + return gridLD; } /****************************************************************************** diff --git a/Hadrons/Modules/MDistil/LapEvec.hpp b/Hadrons/Modules/MDistil/LapEvec.hpp index 62062f03..910c4315 100644 --- a/Hadrons/Modules/MDistil/LapEvec.hpp +++ b/Hadrons/Modules/MDistil/LapEvec.hpp @@ -33,6 +33,7 @@ #include #include #include +#include // These are members of Distillation #include @@ -105,6 +106,7 @@ class LapEvecPar: Serializable { public: GRID_SERIALIZABLE_CLASS_MEMBERS(LapEvecPar, + std::string, gauge, StoutParameters, Stout, ChebyshevParameters, Cheby, LanczosParameters, Lanczos, @@ -122,54 +124,57 @@ template class TLapEvec: public Module { public: - // constructor - TLapEvec(); - TLapEvec(const std::string name); - // destructor - virtual ~TLapEvec(void); - // dependency relation - virtual std::vector getInput(void); - virtual std::vector getOutput(void); - // setup - virtual void setup(void); - // execution - virtual void execute(void); + GAUGE_TYPE_ALIASES(FImpl,); + typedef std::vector > DistilEP; + public: - GridCartesian * gridLD = nullptr; + // constructor + TLapEvec(const std::string name); + // destructor + virtual ~TLapEvec(void); + // dependency relation + virtual std::vector getInput(void); + virtual std::vector getOutput(void); + // setup + virtual void setup(void); + // execution + virtual void execute(void); +protected: + // These variables are created in setup() and freed in Cleanup() + GridCartesian * gridLD; // Owned by me, so I must delete it + GridCartesian * gridHD; // Owned by environment (so I won't delete it) + int Nx, Ny, Nz, Nt; + +protected: + void Cleanup(void); }; MODULE_REGISTER_TMP(LapEvec, TLapEvec, MDistil); /****************************************************************************** - * TLapEvec implementation * + TLapEvec implementation ******************************************************************************/ + // constructor ///////////////////////////////////////////////////////////////// template -TLapEvec::TLapEvec(const std::string name) : Module(name) +TLapEvec::TLapEvec(const std::string name) : gridLD{nullptr}, Module(name) { - // NB: This constructor isn't used!!! LOG(Message) << "TLapEvec constructor : TLapEvec::TLapEvec(const std::string name)" << std::endl; - LOG(Message) << "TLapEvec constructor : Setting gridLD=nullptr" << std::endl; - gridLD = nullptr; + LOG(Message) << "this=" << this << ", gridLD=" << gridLD << std::endl; } // destructor ///////////////////////////////////////////////////////////////// template TLapEvec::~TLapEvec() { - if( gridLD != nullptr ) { - LOG(Message) << "Destroying lower dimensional grid" << std::endl; - delete gridLD; - } - else - LOG(Message) << "Lower dimensional grid was never created" << std::endl; + Cleanup(); } // dependencies/products /////////////////////////////////////////////////////// template std::vector TLapEvec::getInput(void) { - std::vector in; + std::vector in = {par().gauge}; return in; } @@ -186,15 +191,30 @@ std::vector TLapEvec::getOutput(void) template void TLapEvec::setup(void) { - LOG(Message) << "setup() : start" << std::endl; - LOG(Message) << "Stout.steps=" << par().Stout.steps << ", Stout.parm=" << par().Stout.parm << std::endl; - if( gridLD ) { - LOG(Message) << "Didn't expect to need to destroy gridLD here!" << std::endl; + Cleanup(); + Environment & e{env()}; + gridHD = e.getGrid(); + gridLD = MakeLowerDimGrid( gridHD ); + Nx = gridHD->_gdimensions[Xdir]; + Ny = gridHD->_gdimensions[Ydir]; + Nz = gridHD->_gdimensions[Zdir]; + Nt = gridHD->_gdimensions[Tdir]; + // Temporaries + envTmpLat(GaugeField, "Umu"); + envTmpLat(GaugeField, "Umu_stout"); + envTmpLat(GaugeField, "Umu_smear"); + // Output objects + envCreate(DistilEP, getName(), 1, Nt); +} + +// clean up any temporaries created by setup (that aren't stored in the environment) +template +void TLapEvec::Cleanup(void) +{ + if( gridLD != nullptr ) { delete gridLD; + gridLD = nullptr; } - LOG(Message) << "Creating lower dimensional grid" << std::endl; - gridLD = MakeLowerDimGrid( env().getGrid() ); - LOG(Message) << "setup() : end" << std::endl; } // execution /////////////////////////////////////////////////////////////////// diff --git a/tests/hadrons/Test_hadrons_distil.cc b/tests/hadrons/Test_hadrons_distil.cc index 7bd5e857..17d89331 100644 --- a/tests/hadrons/Test_hadrons_distil.cc +++ b/tests/hadrons/Test_hadrons_distil.cc @@ -224,8 +224,7 @@ void free_prop(Application &application) void test_LapEvec(Application &application) { - const unsigned int nt = GridDefaultLatt()[Tp]; - + const char szGaugeName[] = "gauge"; // global parameters Application::GlobalPar globalPar; globalPar.trajCounter.start = 1500; @@ -234,11 +233,12 @@ void test_LapEvec(Application &application) globalPar.runId = "test"; application.setPar(globalPar); // gauge field - application.createModule("gauge"); + application.createModule(szGaugeName); // Now make an instance of the LapEvec object MDistil::LapEvecPar par; par.Stout.steps = 173; par.Stout.parm = -9.87654321; + par.gauge = szGaugeName; application.createModule("LapEvec",par); }