mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +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 Hadrons;
|
||||
|
||||
#define BIG_SEP "==============="
|
||||
#define SEP "---------------"
|
||||
#define BIG_SEP "================"
|
||||
#define SEP "----------------"
|
||||
|
||||
/******************************************************************************
|
||||
* Application implementation *
|
||||
@ -54,11 +54,11 @@ Application::Application(void)
|
||||
loc[d] /= mpi[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) << "Global lattice : " << dim << std::endl;
|
||||
LOG(Message) << "MPI partition : " << mpi << std::endl;
|
||||
LOG(Message) << "Local lattice : " << loc << std::endl;
|
||||
LOG(Message) << "Global lattice: " << dim << std::endl;
|
||||
LOG(Message) << "MPI partition : " << mpi << std::endl;
|
||||
LOG(Message) << "Local lattice : " << loc << std::endl;
|
||||
LOG(Message) << std::endl;
|
||||
LOG(Message) << "** Default parameters (and associated C macro)" << std::endl;
|
||||
LOG(Message) << "ASCII output precision : " << MACOUT(DEFAULT_ASCII_PREC) << std::endl;
|
||||
@ -88,7 +88,6 @@ Application::Application(const std::string parameterFileName)
|
||||
void Application::setPar(const Application::GlobalPar &par)
|
||||
{
|
||||
par_ = par;
|
||||
env().setSeed(strToVec<int>(par_.seed));
|
||||
}
|
||||
|
||||
const Application::GlobalPar & Application::getPar(void)
|
||||
@ -99,10 +98,17 @@ const Application::GlobalPar & Application::getPar(void)
|
||||
// execute /////////////////////////////////////////////////////////////////////
|
||||
void Application::run(void)
|
||||
{
|
||||
LOG(Message) << "====== HADRONS APPLICATION START ======" << std::endl;
|
||||
if (!parameterFileName_.empty() and (vm().getNModule() == 0))
|
||||
{
|
||||
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();
|
||||
env().printContent();
|
||||
schedule();
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
|
||||
TrajRange, trajCounter,
|
||||
VirtualMachine::GeneticPar, genetic,
|
||||
std::string, seed);
|
||||
std::string, runId);
|
||||
};
|
||||
public:
|
||||
// constructors
|
||||
|
@ -195,11 +195,6 @@ double Environment::getVolume(void) const
|
||||
}
|
||||
|
||||
// random number generator /////////////////////////////////////////////////////
|
||||
void Environment::setSeed(const std::vector<int> &seed)
|
||||
{
|
||||
rng4d_->SeedFixedIntegers(seed);
|
||||
}
|
||||
|
||||
GridParallelRNG * Environment::get4dRng(void) const
|
||||
{
|
||||
return rng4d_.get();
|
||||
|
@ -97,7 +97,6 @@ public:
|
||||
unsigned int getNd(void) const;
|
||||
double getVolume(void) const;
|
||||
// random number generator
|
||||
void setSeed(const std::vector<int> &seed);
|
||||
GridParallelRNG * get4dRng(void) const;
|
||||
// general memory management
|
||||
void addObject(const std::string name,
|
||||
|
@ -128,3 +128,31 @@ std::map<std::string, GridTime> ModuleBase::getTimings(void)
|
||||
|
||||
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;
|
||||
// virtual machine shortcut
|
||||
DEFINE_VM_ALIAS;
|
||||
// RNG seeded from module string
|
||||
GridParallelRNG &rng4d(void);
|
||||
private:
|
||||
std::string name_, currentTimer_;
|
||||
std::string makeSeedString(void);
|
||||
private:
|
||||
std::string name_, currentTimer_, seed_;
|
||||
std::map<std::string, GridStopWatch> timer_;
|
||||
};
|
||||
|
||||
|
@ -67,5 +67,5 @@ void TRandom::execute(void)
|
||||
LOG(Message) << "Generating random gauge configuration" << std::endl;
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
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());
|
||||
|
||||
LOG(Message) << "Generating time-diluted, spin-color diagonal noise" << std::endl;
|
||||
noise.generateNoise(*env().get4dRng());
|
||||
noise.generateNoise(rng4d());
|
||||
}
|
||||
|
||||
END_MODULE_NAMESPACE
|
||||
|
@ -128,7 +128,7 @@ void TStochFreeField<SImpl>::execute(void)
|
||||
const unsigned int Nadj = Group::AdjointDimension;
|
||||
auto &phi = envGet(Field, getName());
|
||||
auto &w = envGet(ComplexField, "_" + getName() + "_weight");
|
||||
auto &rng = *env().get4dRng();
|
||||
auto &rng = rng4d();
|
||||
double trphi2;
|
||||
FFT fft(env().getGrid());
|
||||
Integer vol;
|
||||
|
@ -149,7 +149,7 @@ void TZ2<FImpl>::execute(void)
|
||||
hasT_ = true;
|
||||
}
|
||||
envGetTmp(LatticeComplex, eta);
|
||||
bernoulli(*env().get4dRng(), eta);
|
||||
bernoulli(rng4d(), eta);
|
||||
eta = (2.*eta - shift)*(1./::sqrt(2.));
|
||||
eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta);
|
||||
src = 1.;
|
||||
|
@ -83,7 +83,7 @@ void TRandomVectors<Field>::execute(void)
|
||||
|
||||
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_;
|
||||
}
|
||||
|
||||
// run tag /////////////////////////////////////////////////////////////////////
|
||||
void VirtualMachine::setRunId(const std::string id)
|
||||
{
|
||||
runId_ = id;
|
||||
}
|
||||
|
||||
std::string VirtualMachine::getRunId(void) const
|
||||
{
|
||||
return runId_;
|
||||
}
|
||||
|
||||
// module management ///////////////////////////////////////////////////////////
|
||||
void VirtualMachine::pushModule(VirtualMachine::ModPt &pt)
|
||||
{
|
||||
@ -622,9 +633,9 @@ VirtualMachine::Program VirtualMachine::schedule(const GeneticPar &par)
|
||||
}
|
||||
|
||||
// general execution ///////////////////////////////////////////////////////////
|
||||
#define BIG_SEP "==============="
|
||||
#define SEP "---------------"
|
||||
#define SMALL_SEP "..............."
|
||||
#define BIG_SEP "================"
|
||||
#define SEP "----------------"
|
||||
#define SMALL_SEP "................"
|
||||
#define MEM_MSG(size) sizeString(size)
|
||||
#define PRINT_TIME(name, t, total) \
|
||||
std::right << std::setw(30) << name << ": " << t.count() << " us (" \
|
||||
|
@ -91,6 +91,9 @@ public:
|
||||
// trajectory counter
|
||||
void setTrajectory(const unsigned int traj);
|
||||
unsigned int getTrajectory(void) const;
|
||||
// run tag
|
||||
void setRunId(const std::string id);
|
||||
std::string getRunId(void) const;
|
||||
// module management
|
||||
void pushModule(ModPt &pt);
|
||||
template <typename M>
|
||||
@ -151,6 +154,7 @@ private:
|
||||
void memoryProfile(const unsigned int address);
|
||||
private:
|
||||
// general
|
||||
std::string runId_;
|
||||
unsigned int traj_;
|
||||
// module and related maps
|
||||
std::vector<ModuleInfo> module_;
|
||||
|
@ -320,12 +320,14 @@ namespace Grid {
|
||||
|
||||
void SeedUniqueString(const std::string &s){
|
||||
std::vector<int> seeds;
|
||||
std::stringstream sha;
|
||||
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++){
|
||||
std::cout << GridLogMessage << "\t " <<seeds[i]<< std::endl;
|
||||
for(int i=0;i<seeds.size();i++) {
|
||||
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);
|
||||
}
|
||||
};
|
||||
@ -390,12 +392,14 @@ namespace Grid {
|
||||
|
||||
void SeedUniqueString(const std::string &s){
|
||||
std::vector<int> seeds;
|
||||
std::stringstream sha;
|
||||
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++){
|
||||
std::cout << GridLogMessage << "\t " <<seeds[i]<< std::endl;
|
||||
for(int i=0;i<seeds.size();i++) {
|
||||
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);
|
||||
}
|
||||
void SeedFixedIntegers(const std::vector<int> &seeds){
|
||||
|
Loading…
Reference in New Issue
Block a user