From 01572747628ab6badfc94caa40af478ca88f4b6e Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Tue, 17 Jan 2017 10:46:49 +0000 Subject: [PATCH] HMC factories --- lib/qcd/hmc/GenericHMCrunner.h | 10 +++++++++- lib/qcd/hmc/HMC.h | 12 +++++++----- lib/qcd/hmc/checkpointers/CheckPointerModules.h | 6 ++++-- lib/qcd/modules/Modules.h | 15 +++++---------- tests/hmc/Test_hmc_Factories.cc | 2 +- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lib/qcd/hmc/GenericHMCrunner.h b/lib/qcd/hmc/GenericHMCrunner.h index 6fb76884..5bfe7a90 100644 --- a/lib/qcd/hmc/GenericHMCrunner.h +++ b/lib/qcd/hmc/GenericHMCrunner.h @@ -35,10 +35,17 @@ with this program; if not, write to the Free Software Foundation, Inc., namespace Grid { namespace QCD { +class HMCBase{ +public: + virtual void Run() = 0; + +}; + + template class Integrator, class RepresentationsPolicy = NoHirep> -class HMCWrapperTemplate { +class HMCWrapperTemplate: public HMCBase { public: INHERIT_FIELD_TYPES(Implementation); typedef Implementation ImplPolicy; // visible from outside @@ -134,6 +141,7 @@ class HMCWrapperTemplate { Resources.AddRNGs(); Field U(UGrid); + // Can move this outside? typedef IntegratorType TheIntegrator; TheIntegrator MDynamics(UGrid, MDparameters, TheAction, Smearing); diff --git a/lib/qcd/hmc/HMC.h b/lib/qcd/hmc/HMC.h index 7b32a195..c5e9e65b 100644 --- a/lib/qcd/hmc/HMC.h +++ b/lib/qcd/hmc/HMC.h @@ -44,11 +44,13 @@ directory namespace Grid { namespace QCD { -struct HMCparameters { - Integer StartTrajectory; - Integer Trajectories; /* @brief Number of sweeps in this run */ - bool MetropolisTest; - Integer NoMetropolisUntil; +struct HMCparameters: Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(HMCparameters, + Integer, StartTrajectory, + Integer, Trajectories, /* @brief Number of sweeps in this run */ + bool, MetropolisTest, + Integer, NoMetropolisUntil, + ) // nest here the MDparameters and make all serializable diff --git a/lib/qcd/hmc/checkpointers/CheckPointerModules.h b/lib/qcd/hmc/checkpointers/CheckPointerModules.h index 565ec0c5..973534a2 100644 --- a/lib/qcd/hmc/checkpointers/CheckPointerModules.h +++ b/lib/qcd/hmc/checkpointers/CheckPointerModules.h @@ -103,7 +103,7 @@ class BinaryCPModule: public CheckPointerModule< ImplementationPolicy> { // acquire resource virtual void initialize(){ - this->CheckPointPtr.reset(new BinaryHmcCheckpointer(this->Par_)); + this->CheckPointPtr.reset(new BinaryHmcCheckpointer(this->Par_)); } }; @@ -112,7 +112,7 @@ class BinaryCPModule: public CheckPointerModule< ImplementationPolicy> { template class NerscCPModule: public CheckPointerModule< ImplementationPolicy> { typedef CheckPointerModule< ImplementationPolicy> CPBase; - using CPBase::CPBase; // for constructors + using CPBase::CPBase; // for constructors inheritance // acquire resource virtual void initialize(){ @@ -140,6 +140,8 @@ class ILDGCPModule: public CheckPointerModule< ImplementationPolicy> { extern char cp_string[]; + +// use macros? static Registrar, HMC_CPModuleFactory > __CPBinarymodXMLInit("Binary"); static Registrar , HMC_CPModuleFactory > __CPNerscmodXMLInit("Nersc"); static Registrar , HMC_CPModuleFactory > __CPILDGmodXMLInit("ILDG"); diff --git a/lib/qcd/modules/Modules.h b/lib/qcd/modules/Modules.h index 8a45658d..42bd5b1e 100644 --- a/lib/qcd/modules/Modules.h +++ b/lib/qcd/modules/Modules.h @@ -173,7 +173,7 @@ typedef WilsonGModule WilsonGMod; // Factory is perfectly fine // Registar must be changed because I do not want to use the ModuleFactory -// ref to LatticeGaugeField must be changed +// explicit ref to LatticeGaugeField must be changed typedef HMCModuleBase< QCD::Action< QCD::LatticeGaugeField > > HMC_LGTActionModBase; template @@ -196,17 +196,10 @@ class HMC_LGTActionModuleFactory } }; -/* -then rewrite the registar - -when this is done we have all the modules that contain the pointer to the objects -(actions, integrators, checkpointers, solvers) - -factory will create only the modules and prepare the parameters -when needed a pointer is released -*/ + + @@ -226,6 +219,8 @@ class Registrar { extern char gauge_string[]; static Registrar > __WGmodXMLInit("Wilson"); +// add here the registration for other implementations and readers + } diff --git a/tests/hmc/Test_hmc_Factories.cc b/tests/hmc/Test_hmc_Factories.cc index 940367e2..f33beeb1 100644 --- a/tests/hmc/Test_hmc_Factories.cc +++ b/tests/hmc/Test_hmc_Factories.cc @@ -39,7 +39,7 @@ int main(int argc, char **argv) { // 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 + // Typedefs to simplify notation typedef GenericHMCRunner HMCWrapper; // Uses the default minimum norm typedef Grid::XmlReader InputFileReader;