mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-17 23:37:06 +01:00
Adding factories
This commit is contained in:
@ -151,7 +151,7 @@ class HMCWrapperTemplate {
|
||||
Implementation::TepidConfiguration(Resources.GetParallelRNG(), U);
|
||||
} else if (Payload.StartType == CheckpointStart) {
|
||||
// CheckpointRestart
|
||||
Resources.get_CheckPointer()->CheckpointRestore(Payload.Parameters.StartTrajectory, U,
|
||||
Resources.GetCheckPointer()->CheckpointRestore(Payload.Parameters.StartTrajectory, U,
|
||||
Resources.GetSerialRNG(),
|
||||
Resources.GetParallelRNG());
|
||||
}
|
||||
@ -164,7 +164,7 @@ class HMCWrapperTemplate {
|
||||
|
||||
for (int obs = 0; obs < ObservablesList.size(); obs++)
|
||||
HMC.AddObservable(ObservablesList[obs]);
|
||||
HMC.AddObservable(Resources.get_CheckPointer());
|
||||
HMC.AddObservable(Resources.GetCheckPointer());
|
||||
|
||||
|
||||
// Run it
|
||||
|
@ -50,6 +50,8 @@ struct HMCparameters {
|
||||
bool MetropolisTest;
|
||||
Integer NoMetropolisUntil;
|
||||
|
||||
// nest here the MDparameters and make all serializable
|
||||
|
||||
HMCparameters() {
|
||||
////////////////////////////// Default values
|
||||
MetropolisTest = true;
|
||||
|
@ -33,8 +33,42 @@ directory
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// Modules
|
||||
class GridModuleParameters: Serializable{
|
||||
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(GridModuleParameters,
|
||||
std::string, lattice,
|
||||
std::string, mpi);
|
||||
|
||||
public:
|
||||
// these namings are ugly
|
||||
// also ugly the distinction between the serializable members
|
||||
// and this
|
||||
std::vector<int> lattice_v;
|
||||
std::vector<int> mpi_v;
|
||||
|
||||
GridModuleParameters(const std::vector<int> l_ = std::vector<int>(),
|
||||
const std::vector<int> mpi_ = std::vector<int>()):lattice_v(l_), mpi_v(mpi_){}
|
||||
|
||||
template <class ReaderClass>
|
||||
GridModuleParameters(Reader<ReaderClass>& Reader) {
|
||||
read(Reader, "LatticeGrid", *this);
|
||||
lattice_v = strToVec<int>(lattice);
|
||||
mpi_v = strToVec<int>(mpi);
|
||||
if (mpi_v.size() != lattice_v.size()) {
|
||||
std::cout << "Error in GridModuleParameters: lattice and mpi dimensions "
|
||||
"do not match"
|
||||
<< std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class GridModule {
|
||||
public:
|
||||
GridCartesian* get_full() { return grid_.get(); }
|
||||
@ -46,11 +80,13 @@ class GridModule {
|
||||
protected:
|
||||
std::unique_ptr<GridCartesian> grid_;
|
||||
std::unique_ptr<GridRedBlackCartesian> rbgrid_;
|
||||
|
||||
};
|
||||
|
||||
// helpers
|
||||
class GridFourDimModule : public GridModule {
|
||||
public:
|
||||
// add a function to create the module from a Reader
|
||||
GridFourDimModule() {
|
||||
set_full(SpaceTimeGrid::makeFourDimGrid(
|
||||
GridDefaultLatt(), GridDefaultSimd(4, vComplex::Nsimd()),
|
||||
@ -58,50 +94,53 @@ class GridFourDimModule : public GridModule {
|
||||
set_rb(SpaceTimeGrid::makeFourDimRedBlackGrid(grid_.get()));
|
||||
}
|
||||
|
||||
template <class vector_type = vComplex>
|
||||
GridFourDimModule(GridModuleParameters Params) {
|
||||
if (Params.lattice_v.size() == 4) {
|
||||
set_full(SpaceTimeGrid::makeFourDimGrid(
|
||||
Params.lattice_v, GridDefaultSimd(4, vector_type::Nsimd()),
|
||||
Params.mpi_v));
|
||||
set_rb(SpaceTimeGrid::makeFourDimRedBlackGrid(grid_.get()));
|
||||
} else {
|
||||
std::cout
|
||||
<< "Error in GridFourDimModule: lattice dimension different from 4"
|
||||
<< std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
class RNGModuleParameters: Serializable {
|
||||
public:
|
||||
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(RNGModuleParameters,
|
||||
std::vector<int>, SerialSeed_,
|
||||
std::vector<int>, ParallelSeed_,);
|
||||
std::string, serial_seeds,
|
||||
std::string, parallel_seeds,);
|
||||
public:
|
||||
std::vector<int> SerialSeed;
|
||||
std::vector<int> ParallelSeed;
|
||||
|
||||
RNGModuleParameters(const std::vector<int> S = std::vector<int>(),
|
||||
const std::vector<int> P = std::vector<int>())
|
||||
: SerialSeed(S), ParallelSeed(P) {}
|
||||
|
||||
|
||||
// default constructor, needed for the non-Reader
|
||||
// construction of the module
|
||||
RNGModuleParameters(){
|
||||
SerialSeed_.resize(0);
|
||||
ParallelSeed_.resize(0);
|
||||
template <class ReaderClass >
|
||||
RNGModuleParameters(Reader<ReaderClass>& Reader){
|
||||
read(Reader, "RandomNumberGenerator", *this);
|
||||
SerialSeed = strToVec<int>(serial_seeds);
|
||||
ParallelSeed = strToVec<int>(parallel_seeds);
|
||||
}
|
||||
|
||||
RNGModuleParameters(const std::vector<int> S, const std::vector<int> P){
|
||||
set_RNGSeeds(S,P);
|
||||
}
|
||||
|
||||
template < class ReaderClass >
|
||||
RNGModuleParameters(ReaderClass &Reader){
|
||||
read(Reader, "RandomNumberGenerator", *this);
|
||||
}
|
||||
|
||||
void set_RNGSeeds(const std::vector<int>& S, const std::vector<int>& P){
|
||||
SerialSeed_ = S;
|
||||
ParallelSeed_ = P;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Random number generators module
|
||||
class RNGModule{
|
||||
// Random number generators
|
||||
GridSerialRNG sRNG_;
|
||||
std::unique_ptr<GridParallelRNG> pRNG_;
|
||||
RNGModuleParameters Params_;
|
||||
|
||||
public:
|
||||
template < class ReaderClass >
|
||||
RNGModule(ReaderClass &Reader):Params_(Reader){};
|
||||
|
||||
RNGModule(){};
|
||||
|
||||
@ -109,36 +148,23 @@ public:
|
||||
pRNG_.reset(pRNG);
|
||||
}
|
||||
|
||||
void set_RNGSeeds(const std::vector<int> S, const std::vector<int> P) {
|
||||
Params_.set_RNGSeeds(S,P);
|
||||
void set_RNGSeeds(RNGModuleParameters& Params) {
|
||||
Params_ = Params;
|
||||
}
|
||||
|
||||
GridSerialRNG& get_sRNG() { return sRNG_; }
|
||||
GridParallelRNG& get_pRNG() { return *pRNG_.get(); }
|
||||
|
||||
|
||||
GridSerialRNG& get_sRNG(){
|
||||
if (Params_.SerialSeed_.size()==0){
|
||||
std::cout << "Serial seeds not initialized" << std::endl;
|
||||
void seed() {
|
||||
if (Params_.SerialSeed.size() == 0 && Params_.ParallelSeed.size() == 0) {
|
||||
std::cout << "Seeds not initialized" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
return sRNG_;
|
||||
}
|
||||
GridParallelRNG& get_pRNG(){
|
||||
if (Params_.ParallelSeed_.size()==0){
|
||||
std::cout << "Parallel seeds not initialized" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
return *pRNG_.get();
|
||||
}
|
||||
|
||||
void seed(){
|
||||
sRNG_.SeedFixedIntegers(Params_.SerialSeed_);
|
||||
pRNG_->SeedFixedIntegers(Params_.ParallelSeed_);
|
||||
sRNG_.SeedFixedIntegers(Params_.SerialSeed);
|
||||
pRNG_->SeedFixedIntegers(Params_.ParallelSeed);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
/// Smearing module
|
||||
template <class ImplementationPolicy>
|
||||
|
@ -48,6 +48,7 @@ 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> \
|
||||
@ -64,18 +65,19 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
exit(1); \
|
||||
} \
|
||||
}
|
||||
*/
|
||||
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
|
||||
// HMC Resource manager
|
||||
template <class ImplementationPolicy>
|
||||
class HMCResourceManager{
|
||||
// Storage for grid pairs (std + red-black)
|
||||
template <class ImplementationPolicy>
|
||||
class HMCResourceManager {
|
||||
// Named storage for grid pairs (std + red-black)
|
||||
std::unordered_map<std::string, GridModule> Grids;
|
||||
RNGModule RNGs;
|
||||
|
||||
//SmearingModule<ImplementationPolicy> Smearing;
|
||||
// SmearingModule<ImplementationPolicy> Smearing;
|
||||
CheckPointModule<ImplementationPolicy> CP;
|
||||
|
||||
bool have_RNG;
|
||||
@ -83,6 +85,13 @@ class HMCResourceManager{
|
||||
|
||||
public:
|
||||
HMCResourceManager() : have_RNG(false), have_CheckPointer(false) {}
|
||||
|
||||
// Here need a constructor for using the Reader class
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Grids
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
void AddGrid(std::string s, GridModule& M) {
|
||||
// Check for name clashes
|
||||
auto search = Grids.find(s);
|
||||
@ -94,12 +103,14 @@ class HMCResourceManager{
|
||||
Grids[s] = std::move(M);
|
||||
}
|
||||
|
||||
// Add a named grid set
|
||||
// Add a named grid set, 4d shortcut
|
||||
void AddFourDimGrid(std::string s) {
|
||||
GridFourDimModule Mod;
|
||||
AddGrid(s, Mod);
|
||||
}
|
||||
|
||||
|
||||
|
||||
GridCartesian* GetCartesian(std::string s = "") {
|
||||
if (s.empty()) s = Grids.begin()->first;
|
||||
std::cout << GridLogDebug << "Getting cartesian grid from: " << s
|
||||
@ -114,6 +125,10 @@ class HMCResourceManager{
|
||||
return Grids[s].get_rb();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Random number generators
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
void AddRNGs(std::string s = "") {
|
||||
// Couple the RNGs to the GridModule tagged by s
|
||||
// the default is the first grid registered
|
||||
@ -124,43 +139,43 @@ class HMCResourceManager{
|
||||
have_RNG = true;
|
||||
}
|
||||
|
||||
void AddRNGSeeds(const std::vector<int> S, const std::vector<int> P) {
|
||||
RNGs.set_RNGSeeds(S, P);
|
||||
}
|
||||
void SetRNGSeeds(RNGModuleParameters& Params) { RNGs.set_RNGSeeds(Params); }
|
||||
|
||||
GridSerialRNG& GetSerialRNG() { return RNGs.get_sRNG(); }
|
||||
|
||||
GridParallelRNG& GetParallelRNG() {
|
||||
assert(have_RNG);
|
||||
return RNGs.get_pRNG();
|
||||
}
|
||||
|
||||
|
||||
void SeedFixedIntegers() {
|
||||
assert(have_RNG);
|
||||
RNGs.seed();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////
|
||||
// Checkpointers
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
BaseHmcCheckpointer<ImplementationPolicy>* get_CheckPointer(){
|
||||
BaseHmcCheckpointer<ImplementationPolicy>* GetCheckPointer() {
|
||||
if (have_CheckPointer)
|
||||
return CP.get_CheckPointer();
|
||||
else{
|
||||
std::cout << GridLogError << "Error: no checkpointer defined" << std::endl;
|
||||
return CP.get_CheckPointer();
|
||||
else {
|
||||
std::cout << GridLogError << "Error: no checkpointer defined"
|
||||
<< std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
RegisterLoadCheckPointerFunction (Binary);
|
||||
RegisterLoadCheckPointerFunction (Nersc);
|
||||
RegisterLoadCheckPointerFunction (ILDG);
|
||||
RegisterLoadCheckPointerFunction(Binary);
|
||||
RegisterLoadCheckPointerFunction(Nersc);
|
||||
RegisterLoadCheckPointerFunction(ILDG);
|
||||
|
||||
RegisterLoadCheckPointerReaderFunction (Binary);
|
||||
RegisterLoadCheckPointerReaderFunction (Nersc);
|
||||
RegisterLoadCheckPointerReaderFunction (ILDG);
|
||||
/*
|
||||
RegisterLoadCheckPointerReaderFunction(Binary);
|
||||
RegisterLoadCheckPointerReaderFunction(Nersc);
|
||||
RegisterLoadCheckPointerReaderFunction(ILDG);
|
||||
*/
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -30,27 +30,31 @@ directory
|
||||
#define BASE_CHECKPOINTER
|
||||
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
namespace QCD {
|
||||
|
||||
class CheckpointerParameters : Serializable {
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(CheckpointerParameters,
|
||||
std::string, config_prefix,
|
||||
std::string, rng_prefix,
|
||||
int, saveInterval,
|
||||
std::string, format, );
|
||||
class CheckpointerParameters : Serializable {
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(CheckpointerParameters,
|
||||
std::string, config_prefix,
|
||||
std::string, rng_prefix,
|
||||
int, saveInterval,
|
||||
std::string, format, );
|
||||
|
||||
CheckpointerParameters(std::string cf = "cfg", std::string rn = "rng",
|
||||
int savemodulo = 1, const std::string &f = "IEEE64BIG")
|
||||
: config_prefix(cf), rng_prefix(rn), saveInterval(savemodulo), format(f){};
|
||||
CheckpointerParameters(std::string cf = "cfg", std::string rn = "rng",
|
||||
int savemodulo = 1, const std::string &f = "IEEE64BIG")
|
||||
: config_prefix(cf),
|
||||
rng_prefix(rn),
|
||||
saveInterval(savemodulo),
|
||||
format(f){};
|
||||
|
||||
|
||||
template<class ReaderClass>
|
||||
CheckpointerParameters(ReaderClass &Reader){
|
||||
read(Reader, "Checkpointer", *this);
|
||||
}
|
||||
template <class ReaderClass, typename std::enable_if< isReader<ReaderClass>::value, int>::type = 0 >
|
||||
CheckpointerParameters(ReaderClass &Reader) {
|
||||
read(Reader, "Checkpointer", *this);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Base class for checkpointers
|
||||
|
@ -37,29 +37,30 @@ directory
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
|
||||
struct IntegratorParameters {
|
||||
unsigned int MDsteps; // number of outer steps
|
||||
RealD trajL; // trajectory length
|
||||
RealD stepsize; // trajectory stepsize
|
||||
class IntegratorParameters: Serializable {
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(IntegratorParameters,
|
||||
std::string, name, // name of the integrator
|
||||
unsigned int, MDsteps, // number of outer steps
|
||||
RealD, trajL, // trajectory length
|
||||
)
|
||||
|
||||
IntegratorParameters(int MDsteps_ = 10, RealD trajL_ = 1.0)
|
||||
: MDsteps(MDsteps_),
|
||||
trajL(trajL_),
|
||||
stepsize(trajL / MDsteps){
|
||||
// empty body constructor
|
||||
trajL(trajL_){
|
||||
// empty body constructor
|
||||
};
|
||||
|
||||
void set(int MDsteps_, RealD trajL_){
|
||||
MDsteps = MDsteps_;
|
||||
trajL = trajL_;
|
||||
stepsize = trajL/MDsteps;
|
||||
}
|
||||
|
||||
template <class ReaderClass, typename std::enable_if<isReader<ReaderClass>::value, int >::type = 0 >
|
||||
IntegratorParameters(ReaderClass & Reader){
|
||||
read(Reader, "Integrator", *this);
|
||||
}
|
||||
|
||||
void print_parameters() {
|
||||
std::cout << GridLogMessage << "[Integrator] Trajectory length : " << trajL << std::endl;
|
||||
std::cout << GridLogMessage << "[Integrator] Number of MD steps : " << MDsteps << std::endl;
|
||||
std::cout << GridLogMessage << "[Integrator] Step size : " << stepsize << std::endl;
|
||||
std::cout << GridLogMessage << "[Integrator] Step size : " << trajL/MDsteps << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -117,7 +117,7 @@ class LeapFrog : public Integrator<FieldImplementation, SmearingPolicy,
|
||||
// eps : current step size
|
||||
|
||||
// Get current level step size
|
||||
RealD eps = this->Params.stepsize;
|
||||
RealD eps = this->Params.trajL/this->Params.MDsteps;
|
||||
for (int l = 0; l <= level; ++l) eps /= this->as[l].multiplier;
|
||||
|
||||
int multiplier = this->as[level].multiplier;
|
||||
@ -166,7 +166,7 @@ class MinimumNorm2 : public Integrator<FieldImplementation, SmearingPolicy,
|
||||
|
||||
int fl = this->as.size() - 1;
|
||||
|
||||
RealD eps = this->Params.stepsize * 2.0;
|
||||
RealD eps = this->Params.trajL/this->Params.MDsteps * 2.0;
|
||||
for (int l = 0; l <= level; ++l) eps /= 2.0 * this->as[l].multiplier;
|
||||
|
||||
// Nesting: 2xupdate_U of size eps/2
|
||||
@ -247,7 +247,7 @@ class ForceGradient : public Integrator<FieldImplementation, SmearingPolicy,
|
||||
}
|
||||
|
||||
void step(Field& U, int level, int _first, int _last) {
|
||||
RealD eps = this->Params.stepsize * 2.0;
|
||||
RealD eps = this->Params.trajL/this->Params.MDsteps * 2.0;
|
||||
for (int l = 0; l <= level; ++l) eps /= 2.0 * this->as[l].multiplier;
|
||||
|
||||
RealD Chi = chi * eps * eps * eps;
|
||||
|
Reference in New Issue
Block a user