mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-14 01:35:36 +00:00
Hadrons: module RNG uniquely seeded with <run id> + <module name> + <trajectory>
This commit is contained in:
parent
133d5c2e34
commit
ac69f042b1
@ -34,8 +34,8 @@ using namespace Grid;
|
|||||||
using namespace QCD;
|
using namespace QCD;
|
||||||
using namespace Hadrons;
|
using namespace Hadrons;
|
||||||
|
|
||||||
#define BIG_SEP "==============="
|
#define BIG_SEP "================"
|
||||||
#define SEP "---------------"
|
#define SEP "----------------"
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Application implementation *
|
* Application implementation *
|
||||||
@ -54,7 +54,7 @@ Application::Application(void)
|
|||||||
loc[d] /= mpi[d];
|
loc[d] /= mpi[d];
|
||||||
locVol_ *= loc[d];
|
locVol_ *= loc[d];
|
||||||
}
|
}
|
||||||
LOG(Message) << "====== HADRONS APPLICATION STARTING ======" << std::endl;
|
LOG(Message) << "====== HADRONS APPLICATION INITIALISATION ======" << std::endl;
|
||||||
LOG(Message) << "** Dimensions" << std::endl;
|
LOG(Message) << "** Dimensions" << std::endl;
|
||||||
LOG(Message) << "Global lattice: " << dim << std::endl;
|
LOG(Message) << "Global lattice: " << dim << std::endl;
|
||||||
LOG(Message) << "MPI partition : " << mpi << std::endl;
|
LOG(Message) << "MPI partition : " << mpi << std::endl;
|
||||||
@ -88,7 +88,6 @@ Application::Application(const std::string parameterFileName)
|
|||||||
void Application::setPar(const Application::GlobalPar &par)
|
void Application::setPar(const Application::GlobalPar &par)
|
||||||
{
|
{
|
||||||
par_ = par;
|
par_ = par;
|
||||||
env().setSeed(strToVec<int>(par_.seed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Application::GlobalPar & Application::getPar(void)
|
const Application::GlobalPar & Application::getPar(void)
|
||||||
@ -99,10 +98,17 @@ const Application::GlobalPar & Application::getPar(void)
|
|||||||
// execute /////////////////////////////////////////////////////////////////////
|
// execute /////////////////////////////////////////////////////////////////////
|
||||||
void Application::run(void)
|
void Application::run(void)
|
||||||
{
|
{
|
||||||
|
LOG(Message) << "====== HADRONS APPLICATION START ======" << std::endl;
|
||||||
if (!parameterFileName_.empty() and (vm().getNModule() == 0))
|
if (!parameterFileName_.empty() and (vm().getNModule() == 0))
|
||||||
{
|
{
|
||||||
parseParameterFile(parameterFileName_);
|
parseParameterFile(parameterFileName_);
|
||||||
}
|
}
|
||||||
|
if (getPar().runId.empty())
|
||||||
|
{
|
||||||
|
HADRONS_ERROR(Definition, "run id is empty");
|
||||||
|
}
|
||||||
|
LOG(Message) << "RUN ID '" << getPar().runId << "'" << std::endl;
|
||||||
|
vm().setRunId(getPar().runId);
|
||||||
vm().printContent();
|
vm().printContent();
|
||||||
env().printContent();
|
env().printContent();
|
||||||
schedule();
|
schedule();
|
||||||
|
@ -55,7 +55,7 @@ public:
|
|||||||
GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
|
GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
|
||||||
TrajRange, trajCounter,
|
TrajRange, trajCounter,
|
||||||
VirtualMachine::GeneticPar, genetic,
|
VirtualMachine::GeneticPar, genetic,
|
||||||
std::string, seed);
|
std::string, runId);
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
|
@ -195,11 +195,6 @@ double Environment::getVolume(void) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// random number generator /////////////////////////////////////////////////////
|
// random number generator /////////////////////////////////////////////////////
|
||||||
void Environment::setSeed(const std::vector<int> &seed)
|
|
||||||
{
|
|
||||||
rng4d_->SeedFixedIntegers(seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
GridParallelRNG * Environment::get4dRng(void) const
|
GridParallelRNG * Environment::get4dRng(void) const
|
||||||
{
|
{
|
||||||
return rng4d_.get();
|
return rng4d_.get();
|
||||||
|
@ -97,7 +97,6 @@ public:
|
|||||||
unsigned int getNd(void) const;
|
unsigned int getNd(void) const;
|
||||||
double getVolume(void) const;
|
double getVolume(void) const;
|
||||||
// random number generator
|
// random number generator
|
||||||
void setSeed(const std::vector<int> &seed);
|
|
||||||
GridParallelRNG * get4dRng(void) const;
|
GridParallelRNG * get4dRng(void) const;
|
||||||
// general memory management
|
// general memory management
|
||||||
void addObject(const std::string name,
|
void addObject(const std::string name,
|
||||||
|
@ -128,3 +128,31 @@ std::map<std::string, GridTime> ModuleBase::getTimings(void)
|
|||||||
|
|
||||||
return timing;
|
return timing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ModuleBase::makeSeedString(void)
|
||||||
|
{
|
||||||
|
std::string seed;
|
||||||
|
|
||||||
|
if (!vm().getRunId().empty())
|
||||||
|
{
|
||||||
|
seed += vm().getRunId() + "-";
|
||||||
|
}
|
||||||
|
seed += getName() + "-" + std::to_string(vm().getTrajectory());
|
||||||
|
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
GridParallelRNG & ModuleBase::rng4d(void)
|
||||||
|
{
|
||||||
|
auto &r = *env().get4dRng();
|
||||||
|
|
||||||
|
if (makeSeedString() != seed_)
|
||||||
|
{
|
||||||
|
seed_ = makeSeedString();
|
||||||
|
LOG(Message) << "Seeding 4D RNG " << &r << " with string '"
|
||||||
|
<< seed_ << "'" << std::endl;
|
||||||
|
r.SeedUniqueString(seed_);
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
@ -176,8 +176,12 @@ protected:
|
|||||||
DEFINE_ENV_ALIAS;
|
DEFINE_ENV_ALIAS;
|
||||||
// virtual machine shortcut
|
// virtual machine shortcut
|
||||||
DEFINE_VM_ALIAS;
|
DEFINE_VM_ALIAS;
|
||||||
|
// RNG seeded from module string
|
||||||
|
GridParallelRNG &rng4d(void);
|
||||||
private:
|
private:
|
||||||
std::string name_, currentTimer_;
|
std::string makeSeedString(void);
|
||||||
|
private:
|
||||||
|
std::string name_, currentTimer_, seed_;
|
||||||
std::map<std::string, GridStopWatch> timer_;
|
std::map<std::string, GridStopWatch> timer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,5 +67,5 @@ void TRandom::execute(void)
|
|||||||
LOG(Message) << "Generating random gauge configuration" << std::endl;
|
LOG(Message) << "Generating random gauge configuration" << std::endl;
|
||||||
|
|
||||||
auto &U = envGet(LatticeGaugeField, getName());
|
auto &U = envGet(LatticeGaugeField, getName());
|
||||||
SU3::HotConfiguration(*env().get4dRng(), U);
|
SU3::HotConfiguration(rng4d(), U);
|
||||||
}
|
}
|
||||||
|
@ -81,5 +81,5 @@ void TStochEm::execute(void)
|
|||||||
<< par().zmScheme << ")..." << std::endl;
|
<< par().zmScheme << ")..." << std::endl;
|
||||||
photon.StochasticWeight(w);
|
photon.StochasticWeight(w);
|
||||||
}
|
}
|
||||||
photon.StochasticField(a, *env().get4dRng(), w);
|
photon.StochasticField(a, rng4d(), w);
|
||||||
}
|
}
|
||||||
|
@ -65,5 +65,5 @@ void TUnit::execute(void)
|
|||||||
LOG(Message) << "Creating unit gauge configuration" << std::endl;
|
LOG(Message) << "Creating unit gauge configuration" << std::endl;
|
||||||
|
|
||||||
auto &U = envGet(LatticeGaugeField, getName());
|
auto &U = envGet(LatticeGaugeField, getName());
|
||||||
SU3::ColdConfiguration(*env().get4dRng(), U);
|
SU3::ColdConfiguration(rng4d(), U);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,7 @@ void TTimeDilutedSpinColorDiagonal<FImpl>::execute(void)
|
|||||||
auto &noise = envGet(DilutedNoise<FImpl>, getName());
|
auto &noise = envGet(DilutedNoise<FImpl>, getName());
|
||||||
|
|
||||||
LOG(Message) << "Generating time-diluted, spin-color diagonal noise" << std::endl;
|
LOG(Message) << "Generating time-diluted, spin-color diagonal noise" << std::endl;
|
||||||
noise.generateNoise(*env().get4dRng());
|
noise.generateNoise(rng4d());
|
||||||
}
|
}
|
||||||
|
|
||||||
END_MODULE_NAMESPACE
|
END_MODULE_NAMESPACE
|
||||||
|
@ -128,7 +128,7 @@ void TStochFreeField<SImpl>::execute(void)
|
|||||||
const unsigned int Nadj = Group::AdjointDimension;
|
const unsigned int Nadj = Group::AdjointDimension;
|
||||||
auto &phi = envGet(Field, getName());
|
auto &phi = envGet(Field, getName());
|
||||||
auto &w = envGet(ComplexField, "_" + getName() + "_weight");
|
auto &w = envGet(ComplexField, "_" + getName() + "_weight");
|
||||||
auto &rng = *env().get4dRng();
|
auto &rng = rng4d();
|
||||||
double trphi2;
|
double trphi2;
|
||||||
FFT fft(env().getGrid());
|
FFT fft(env().getGrid());
|
||||||
Integer vol;
|
Integer vol;
|
||||||
|
@ -149,7 +149,7 @@ void TZ2<FImpl>::execute(void)
|
|||||||
hasT_ = true;
|
hasT_ = true;
|
||||||
}
|
}
|
||||||
envGetTmp(LatticeComplex, eta);
|
envGetTmp(LatticeComplex, eta);
|
||||||
bernoulli(*env().get4dRng(), eta);
|
bernoulli(rng4d(), eta);
|
||||||
eta = (2.*eta - shift)*(1./::sqrt(2.));
|
eta = (2.*eta - shift)*(1./::sqrt(2.));
|
||||||
eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta);
|
eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta);
|
||||||
src = 1.;
|
src = 1.;
|
||||||
|
@ -83,7 +83,7 @@ void TRandomVectors<Field>::execute(void)
|
|||||||
|
|
||||||
for (unsigned int i = 0; i < vec.size(); ++i)
|
for (unsigned int i = 0; i < vec.size(); ++i)
|
||||||
{
|
{
|
||||||
random(*env().get4dRng(), vec[i]);
|
random(rng4d(), vec[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,17 @@ unsigned int VirtualMachine::getTrajectory(void) const
|
|||||||
return traj_;
|
return traj_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// run tag /////////////////////////////////////////////////////////////////////
|
||||||
|
void VirtualMachine::setRunId(const std::string id)
|
||||||
|
{
|
||||||
|
runId_ = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string VirtualMachine::getRunId(void) const
|
||||||
|
{
|
||||||
|
return runId_;
|
||||||
|
}
|
||||||
|
|
||||||
// module management ///////////////////////////////////////////////////////////
|
// module management ///////////////////////////////////////////////////////////
|
||||||
void VirtualMachine::pushModule(VirtualMachine::ModPt &pt)
|
void VirtualMachine::pushModule(VirtualMachine::ModPt &pt)
|
||||||
{
|
{
|
||||||
@ -622,9 +633,9 @@ VirtualMachine::Program VirtualMachine::schedule(const GeneticPar &par)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// general execution ///////////////////////////////////////////////////////////
|
// general execution ///////////////////////////////////////////////////////////
|
||||||
#define BIG_SEP "==============="
|
#define BIG_SEP "================"
|
||||||
#define SEP "---------------"
|
#define SEP "----------------"
|
||||||
#define SMALL_SEP "..............."
|
#define SMALL_SEP "................"
|
||||||
#define MEM_MSG(size) sizeString(size)
|
#define MEM_MSG(size) sizeString(size)
|
||||||
#define PRINT_TIME(name, t, total) \
|
#define PRINT_TIME(name, t, total) \
|
||||||
std::right << std::setw(30) << name << ": " << t.count() << " us (" \
|
std::right << std::setw(30) << name << ": " << t.count() << " us (" \
|
||||||
|
@ -91,6 +91,9 @@ public:
|
|||||||
// trajectory counter
|
// trajectory counter
|
||||||
void setTrajectory(const unsigned int traj);
|
void setTrajectory(const unsigned int traj);
|
||||||
unsigned int getTrajectory(void) const;
|
unsigned int getTrajectory(void) const;
|
||||||
|
// run tag
|
||||||
|
void setRunId(const std::string id);
|
||||||
|
std::string getRunId(void) const;
|
||||||
// module management
|
// module management
|
||||||
void pushModule(ModPt &pt);
|
void pushModule(ModPt &pt);
|
||||||
template <typename M>
|
template <typename M>
|
||||||
@ -151,6 +154,7 @@ private:
|
|||||||
void memoryProfile(const unsigned int address);
|
void memoryProfile(const unsigned int address);
|
||||||
private:
|
private:
|
||||||
// general
|
// general
|
||||||
|
std::string runId_;
|
||||||
unsigned int traj_;
|
unsigned int traj_;
|
||||||
// module and related maps
|
// module and related maps
|
||||||
std::vector<ModuleInfo> module_;
|
std::vector<ModuleInfo> module_;
|
||||||
|
@ -320,12 +320,14 @@ namespace Grid {
|
|||||||
|
|
||||||
void SeedUniqueString(const std::string &s){
|
void SeedUniqueString(const std::string &s){
|
||||||
std::vector<int> seeds;
|
std::vector<int> seeds;
|
||||||
|
std::stringstream sha;
|
||||||
seeds = GridChecksum::sha256_seeds(s);
|
seeds = GridChecksum::sha256_seeds(s);
|
||||||
std::cout << GridLogMessage << "Intialising Serial RNG with unique string " <<s<< std::endl;
|
|
||||||
std::cout << GridLogMessage << "SHA seeds are: " <<s<< std::endl;
|
|
||||||
for(int i=0;i<seeds.size();i++) {
|
for(int i=0;i<seeds.size();i++) {
|
||||||
std::cout << GridLogMessage << "\t " <<seeds[i]<< std::endl;
|
sha << std::hex << seeds[i];
|
||||||
}
|
}
|
||||||
|
std::cout << GridLogMessage << "Intialising serial RNG with unique string '"
|
||||||
|
<< s << "'" << std::endl;
|
||||||
|
std::cout << GridLogMessage << "Seed SHA256: " << sha.str() << std::endl;
|
||||||
SeedFixedIntegers(seeds);
|
SeedFixedIntegers(seeds);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -390,12 +392,14 @@ namespace Grid {
|
|||||||
|
|
||||||
void SeedUniqueString(const std::string &s){
|
void SeedUniqueString(const std::string &s){
|
||||||
std::vector<int> seeds;
|
std::vector<int> seeds;
|
||||||
|
std::stringstream sha;
|
||||||
seeds = GridChecksum::sha256_seeds(s);
|
seeds = GridChecksum::sha256_seeds(s);
|
||||||
std::cout << GridLogMessage << "Intialising Parallel RNG with unique string " <<s<< std::endl;
|
|
||||||
std::cout << GridLogMessage << "SHA seeds are: " <<s<< std::endl;
|
|
||||||
for(int i=0;i<seeds.size();i++) {
|
for(int i=0;i<seeds.size();i++) {
|
||||||
std::cout << GridLogMessage << "\t " <<seeds[i]<< std::endl;
|
sha << std::hex << seeds[i];
|
||||||
}
|
}
|
||||||
|
std::cout << GridLogMessage << "Intialising parallel RNG with unique string '"
|
||||||
|
<< s << "'" << std::endl;
|
||||||
|
std::cout << GridLogMessage << "Seed SHA256: " << sha.str() << std::endl;
|
||||||
SeedFixedIntegers(seeds);
|
SeedFixedIntegers(seeds);
|
||||||
}
|
}
|
||||||
void SeedFixedIntegers(const std::vector<int> &seeds){
|
void SeedFixedIntegers(const std::vector<int> &seeds){
|
||||||
|
Loading…
Reference in New Issue
Block a user