1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-12 20:27:06 +01:00

Added support for input file HMC modules (missing the actions yet)

This commit is contained in:
Guido Cossu
2017-01-16 16:07:12 +00:00
parent c6f59c2933
commit 87e8aad5a0
11 changed files with 418 additions and 107 deletions

View File

@ -34,7 +34,7 @@ namespace Grid {
namespace QCD {
// Some modules for the basic setup
///////////////////////////////////////////////////
@ -165,6 +165,9 @@ public:
}
};
/*
///////////////////////////////////////////////////////////////////
/// Smearing module
template <class ImplementationPolicy>
@ -177,24 +180,9 @@ class StoutSmearingModule: public SmearingModule<ImplementationPolicy>{
SmearedConfiguration<ImplementationPolicy> SmearingPolicy;
};
*/
////////////////////////////////////////////////////////////////////////
// Checkpoint module, owns the Checkpointer
template <class ImplementationPolicy>
class CheckPointModule {
std::unique_ptr<BaseHmcCheckpointer<ImplementationPolicy> > cp_;
public:
void set_Checkpointer(BaseHmcCheckpointer<ImplementationPolicy>* cp) {
cp_.reset(cp);
};
BaseHmcCheckpointer<ImplementationPolicy>* get_CheckPointer() {
return cp_.get();
}
void initialize(CheckpointerParameters& P) { cp_.initialize(P); }
};
} // namespace QCD
} // namespace Grid

View File

@ -38,8 +38,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
if (!have_CheckPointer) { \
std::cout << GridLogDebug << "Loading Checkpointer " << #NAME \
<< std::endl; \
CP.set_Checkpointer( \
new NAME##HmcCheckpointer<ImplementationPolicy>(Params_)); \
CP = std::unique_ptr<CheckpointerBaseModule>( \
new NAME##CPModule<ImplementationPolicy>(Params_)); \
have_CheckPointer = true; \
} else { \
std::cout << GridLogError << "Checkpointer already loaded " \
@ -48,24 +48,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
} \
}
/*
// One function per Checkpointer using the reader, use a macro to simplify
#define RegisterLoadCheckPointerReaderFunction(NAME) \
template <class Reader> \
void Load##NAME##Checkpointer(Reader& Reader_) { \
if (!have_CheckPointer) { \
std::cout << GridLogDebug << "Loading Checkpointer " << #NAME \
<< std::endl; \
CP.set_Checkpointer(new NAME##HmcCheckpointer<ImplementationPolicy>( \
CheckpointerParameters(Reader_))); \
have_CheckPointer = true; \
} else { \
std::cout << GridLogError << "Checkpointer already loaded " \
<< std::endl; \
exit(1); \
} \
}
*/
namespace Grid {
namespace QCD {
@ -73,20 +55,49 @@ namespace QCD {
// HMC Resource manager
template <class ImplementationPolicy>
class HMCResourceManager {
typedef HMCModuleBase< QCD::BaseHmcCheckpointer<ImplementationPolicy> > CheckpointerBaseModule;
// Named storage for grid pairs (std + red-black)
std::unordered_map<std::string, GridModule> Grids;
RNGModule RNGs;
// SmearingModule<ImplementationPolicy> Smearing;
CheckPointModule<ImplementationPolicy> CP;
std::unique_ptr<CheckpointerBaseModule > CP;
bool have_RNG;
bool have_CheckPointer;
public:
HMCResourceManager() : have_RNG(false), have_CheckPointer(false) {}
// Here need a constructor for using the Reader class
template <class ReaderClass >
void initialize(ReaderClass &Read){
// assumes we are starting from the main node
// Geometry
GridModuleParameters GridPar(Read);
GridFourDimModule GridMod( GridPar) ;
AddGrid("gauge", GridMod);
// Checkpointer
auto &CPfactory = HMC_CPModuleFactory<cp_string, QCD::PeriodicGimplR, ReaderClass >::getInstance();
Read.push("Checkpointer");
std::string cp_type;
Read.readDefault("name", cp_type);
std::cout << "Registered types " << std::endl;
std::cout << CPfactory.getBuilderList() << std::endl;
CP = CPfactory.create(cp_type, Read);
CP->print_parameters();
Read.pop();
have_CheckPointer = true;
RNGModuleParameters RNGpar(Read);
SetRNGSeeds(RNGpar);
// HMC here
}
//////////////////////////////////////////////////////////////
// Grids
@ -159,7 +170,7 @@ class HMCResourceManager {
BaseHmcCheckpointer<ImplementationPolicy>* GetCheckPointer() {
if (have_CheckPointer)
return CP.get_CheckPointer();
return CP->getPtr();
else {
std::cout << GridLogError << "Error: no checkpointer defined"
<< std::endl;
@ -170,13 +181,6 @@ class HMCResourceManager {
RegisterLoadCheckPointerFunction(Binary);
RegisterLoadCheckPointerFunction(Nersc);
RegisterLoadCheckPointerFunction(ILDG);
/*
RegisterLoadCheckPointerReaderFunction(Binary);
RegisterLoadCheckPointerReaderFunction(Nersc);
RegisterLoadCheckPointerReaderFunction(ILDG);
*/
};
}
}

View File

@ -48,8 +48,8 @@ class CheckpointerParameters : Serializable {
format(f){};
template <class ReaderClass, typename std::enable_if< isReader<ReaderClass>::value, int>::type = 0 >
CheckpointerParameters(ReaderClass &Reader) {
template <class ReaderClass >
CheckpointerParameters(Reader<ReaderClass> &Reader) {
read(Reader, "Checkpointer", *this);
}

View File

@ -0,0 +1,150 @@
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: ./lib/qcd/action/gauge/WilsonGaugeAction.h
Copyright (C) 2016
Author: Guido Cossu <guido.cossu@ed.ac.uk>
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 CP_MODULES_H
#define CP_MODULES_H
// FIXME Reorganize QCD namespace
namespace Grid {
////////////////////////////////////////////////////////////////////////
// Checkpoint module, owns the Checkpointer
////////////////////////////////////////////////////////////////////////
template <class ImplementationPolicy>
class CheckPointerModule: public Parametrized<QCD::CheckpointerParameters>, public HMCModuleBase< QCD::BaseHmcCheckpointer<ImplementationPolicy> > {
public:
std::unique_ptr<QCD::BaseHmcCheckpointer<ImplementationPolicy> > CheckPointPtr;
typedef QCD::CheckpointerParameters APar;
typedef HMCModuleBase< QCD::BaseHmcCheckpointer<ImplementationPolicy> > Base;
typedef typename Base::Product Product;
CheckPointerModule(APar Par): Parametrized<APar>(Par) {}
template <class ReaderClass>
CheckPointerModule(Reader<ReaderClass>& Reader) : Parametrized<APar>(Reader){};
virtual void print_parameters(){
std::cout << this->Par_ << std::endl;
}
Product* getPtr() {
if (!CheckPointPtr) initialize();
return CheckPointPtr.get();
}
private:
virtual void initialize() = 0;
};
template <char const *str, class ImplementationPolicy, class ReaderClass >
class HMC_CPModuleFactory
: public Factory < HMCModuleBase< QCD::BaseHmcCheckpointer<ImplementationPolicy> > , Reader<ReaderClass> > {
public:
typedef Reader<ReaderClass> TheReader;
// use SINGLETON FUNCTOR MACRO HERE
HMC_CPModuleFactory(const HMC_CPModuleFactory& e) = delete;
void operator=(const HMC_CPModuleFactory& e) = delete;
static HMC_CPModuleFactory& getInstance(void) {
static HMC_CPModuleFactory e;
return e;
}
private:
HMC_CPModuleFactory(void) = default;
std::string obj_type() const {
return std::string(str);
}
};
/////////////////////////////////////////////////////////////////////
// Concrete classes
/////////////////////////////////////////////////////////////////////
namespace QCD{
template<class ImplementationPolicy>
class BinaryCPModule: public CheckPointerModule< ImplementationPolicy> {
typedef CheckPointerModule< ImplementationPolicy> CPBase;
using CPBase::CPBase; // for constructors
// acquire resource
virtual void initialize(){
this->CheckPointPtr.reset(new BinaryHmcCheckpointer<ImplementationPolicy>(this->Par_));
}
};
template<class ImplementationPolicy>
class NerscCPModule: public CheckPointerModule< ImplementationPolicy> {
typedef CheckPointerModule< ImplementationPolicy> CPBase;
using CPBase::CPBase; // for constructors
// acquire resource
virtual void initialize(){
this->CheckPointPtr.reset(new NerscHmcCheckpointer<ImplementationPolicy>(this->Par_));
}
};
template<class ImplementationPolicy>
class ILDGCPModule: public CheckPointerModule< ImplementationPolicy> {
typedef CheckPointerModule< ImplementationPolicy> CPBase;
using CPBase::CPBase; // for constructors
// acquire resource
virtual void initialize(){
this->CheckPointPtr.reset(new ILDGHmcCheckpointer<ImplementationPolicy>(this->Par_));
}
};
}// QCD temporarily here
extern char cp_string[];
static Registrar<QCD::BinaryCPModule<QCD::PeriodicGimplR>, HMC_CPModuleFactory<cp_string, QCD::PeriodicGimplR, XmlReader> > __CPBinarymodXMLInit("Binary");
static Registrar<QCD::NerscCPModule<QCD::PeriodicGimplR> , HMC_CPModuleFactory<cp_string, QCD::PeriodicGimplR, XmlReader> > __CPNerscmodXMLInit("Nersc");
static Registrar<QCD::ILDGCPModule<QCD::PeriodicGimplR> , HMC_CPModuleFactory<cp_string, QCD::PeriodicGimplR, XmlReader> > __CPILDGmodXMLInit("ILDG");
}// Grid
#endif //CP_MODULES_H

View File

@ -0,0 +1,40 @@
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: ./lib/qcd/action/gauge/WilsonGaugeAction.h
Copyright (C) 2016
Author: Guido Cossu <guido.cossu@ed.ac.uk>
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 CHECKPOINTERS_H
#define CHECKPOINTERS_H
#include <Grid/qcd/hmc/checkpointers/BaseCheckpointer.h>
#include <Grid/qcd/hmc/checkpointers/NerscCheckpointer.h>
#include <Grid/qcd/hmc/checkpointers/BinaryCheckpointer.h>
#include <Grid/qcd/hmc/checkpointers/ILDGCheckpointer.h>
#include <Grid/qcd/hmc/checkpointers/CheckPointerModules.h>
#endif // CHECKPOINTERS_H