mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-12 20:27:06 +01:00
Merge branch 'feature/hadrons' of https://github.com/paboyle/Grid into feature/hadrons
This commit is contained in:
@ -42,7 +42,6 @@ using namespace Hadrons;
|
||||
******************************************************************************/
|
||||
// constructors ////////////////////////////////////////////////////////////////
|
||||
Application::Application(void)
|
||||
: env_(Environment::getInstance())
|
||||
{
|
||||
LOG(Message) << "Modules available:" << std::endl;
|
||||
auto list = ModuleFactory::getInstance().getBuilderList();
|
||||
@ -74,11 +73,17 @@ Application::Application(const std::string parameterFileName)
|
||||
parameterFileName_ = parameterFileName;
|
||||
}
|
||||
|
||||
// environment shortcut ////////////////////////////////////////////////////////
|
||||
Environment & Application::env(void) const
|
||||
{
|
||||
return Environment::getInstance();
|
||||
}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
void Application::setPar(const Application::GlobalPar &par)
|
||||
{
|
||||
par_ = par;
|
||||
env_.setSeed(strToVec<int>(par_.seed));
|
||||
env().setSeed(strToVec<int>(par_.seed));
|
||||
}
|
||||
|
||||
const Application::GlobalPar & Application::getPar(void)
|
||||
@ -89,7 +94,7 @@ const Application::GlobalPar & Application::getPar(void)
|
||||
// execute /////////////////////////////////////////////////////////////////////
|
||||
void Application::run(void)
|
||||
{
|
||||
if (!parameterFileName_.empty() and (env_.getNModule() == 0))
|
||||
if (!parameterFileName_.empty() and (env().getNModule() == 0))
|
||||
{
|
||||
parseParameterFile(parameterFileName_);
|
||||
}
|
||||
@ -124,7 +129,7 @@ void Application::parseParameterFile(const std::string parameterFileName)
|
||||
do
|
||||
{
|
||||
read(reader, "id", id);
|
||||
env_.createModule(id.name, id.type, reader);
|
||||
env().createModule(id.name, id.type, reader);
|
||||
} while (reader.nextElement("module"));
|
||||
pop(reader);
|
||||
pop(reader);
|
||||
@ -134,7 +139,7 @@ void Application::saveParameterFile(const std::string parameterFileName)
|
||||
{
|
||||
XmlWriter writer(parameterFileName);
|
||||
ObjectId id;
|
||||
const unsigned int nMod = env_.getNModule();
|
||||
const unsigned int nMod = env().getNModule();
|
||||
|
||||
LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl;
|
||||
write(writer, "parameters", getPar());
|
||||
@ -142,10 +147,10 @@ void Application::saveParameterFile(const std::string parameterFileName)
|
||||
for (unsigned int i = 0; i < nMod; ++i)
|
||||
{
|
||||
push(writer, "module");
|
||||
id.name = env_.getModuleName(i);
|
||||
id.type = env_.getModule(i)->getRegisteredName();
|
||||
id.name = env().getModuleName(i);
|
||||
id.type = env().getModule(i)->getRegisteredName();
|
||||
write(writer, "id", id);
|
||||
env_.getModule(i)->saveParameters(writer, "options");
|
||||
env().getModule(i)->saveParameters(writer, "options");
|
||||
pop(writer);
|
||||
}
|
||||
pop(writer);
|
||||
@ -164,10 +169,10 @@ auto memPeak = [this](const std::vector<unsigned int> &program)\
|
||||
\
|
||||
msg = HadronsLogMessage.isActive();\
|
||||
HadronsLogMessage.Active(false);\
|
||||
env_.dryRun(true);\
|
||||
memPeak = env_.executeProgram(program);\
|
||||
env_.dryRun(false);\
|
||||
env_.freeAll();\
|
||||
env().dryRun(true);\
|
||||
memPeak = env().executeProgram(program);\
|
||||
env().dryRun(false);\
|
||||
env().freeAll();\
|
||||
HadronsLogMessage.Active(true);\
|
||||
\
|
||||
return memPeak;\
|
||||
@ -179,7 +184,7 @@ void Application::schedule(void)
|
||||
|
||||
// build module dependency graph
|
||||
LOG(Message) << "Building module graph..." << std::endl;
|
||||
auto graph = env_.makeModuleGraph();
|
||||
auto graph = env().makeModuleGraph();
|
||||
auto con = graph.getConnectedComponents();
|
||||
|
||||
// constrained topological sort using a genetic algorithm
|
||||
@ -256,7 +261,7 @@ void Application::saveSchedule(const std::string filename)
|
||||
<< std::endl;
|
||||
for (auto address: program_)
|
||||
{
|
||||
program.push_back(env_.getModuleName(address));
|
||||
program.push_back(env().getModuleName(address));
|
||||
}
|
||||
write(writer, "schedule", program);
|
||||
}
|
||||
@ -274,7 +279,7 @@ void Application::loadSchedule(const std::string filename)
|
||||
program_.clear();
|
||||
for (auto &name: program)
|
||||
{
|
||||
program_.push_back(env_.getModuleAddress(name));
|
||||
program_.push_back(env().getModuleAddress(name));
|
||||
}
|
||||
scheduled_ = true;
|
||||
memPeak_ = memPeak(program_);
|
||||
@ -291,7 +296,7 @@ void Application::printSchedule(void)
|
||||
for (unsigned int i = 0; i < program_.size(); ++i)
|
||||
{
|
||||
LOG(Message) << std::setw(4) << i + 1 << ": "
|
||||
<< env_.getModuleName(program_[i]) << std::endl;
|
||||
<< env().getModuleName(program_[i]) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,9 +309,9 @@ void Application::configLoop(void)
|
||||
{
|
||||
LOG(Message) << BIG_SEP << " Starting measurement for trajectory " << t
|
||||
<< " " << BIG_SEP << std::endl;
|
||||
env_.setTrajectory(t);
|
||||
env_.executeProgram(program_);
|
||||
env().setTrajectory(t);
|
||||
env().executeProgram(program_);
|
||||
}
|
||||
LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl;
|
||||
env_.freeAll();
|
||||
env().freeAll();
|
||||
}
|
||||
|
@ -98,11 +98,13 @@ public:
|
||||
void printSchedule(void);
|
||||
// loop on configurations
|
||||
void configLoop(void);
|
||||
private:
|
||||
// environment shortcut
|
||||
Environment & env(void) const;
|
||||
private:
|
||||
long unsigned int locVol_;
|
||||
std::string parameterFileName_{""};
|
||||
GlobalPar par_;
|
||||
Environment &env_;
|
||||
std::vector<unsigned int> program_;
|
||||
Environment::Size memPeak_;
|
||||
bool scheduled_{false};
|
||||
@ -115,14 +117,14 @@ private:
|
||||
template <typename M>
|
||||
void Application::createModule(const std::string name)
|
||||
{
|
||||
env_.createModule<M>(name);
|
||||
env().createModule<M>(name);
|
||||
}
|
||||
|
||||
template <typename M>
|
||||
void Application::createModule(const std::string name,
|
||||
const typename M::Par &par)
|
||||
{
|
||||
env_.createModule<M>(name, par);
|
||||
env().createModule<M>(name, par);
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
@ -41,8 +41,9 @@ using namespace Hadrons;
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
Environment::Environment(void)
|
||||
{
|
||||
nd_ = GridDefaultLatt().size();
|
||||
grid4d_.reset(SpaceTimeGrid::makeFourDimGrid(
|
||||
GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()),
|
||||
GridDefaultLatt(), GridDefaultSimd(nd_, vComplex::Nsimd()),
|
||||
GridDefaultMpi()));
|
||||
gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get()));
|
||||
auto loc = getGrid()->LocalDimensions();
|
||||
@ -126,6 +127,11 @@ GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int Environment::getNd(void) const
|
||||
{
|
||||
return nd_;
|
||||
}
|
||||
|
||||
// random number generator /////////////////////////////////////////////////////
|
||||
void Environment::setSeed(const std::vector<int> &seed)
|
||||
{
|
||||
|
@ -106,6 +106,7 @@ public:
|
||||
void createGrid(const unsigned int Ls);
|
||||
GridCartesian * getGrid(const unsigned int Ls = 1) const;
|
||||
GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const;
|
||||
unsigned int getNd(void) const;
|
||||
// random number generator
|
||||
void setSeed(const std::vector<int> &seed);
|
||||
GridParallelRNG * get4dRng(void) const;
|
||||
@ -200,6 +201,7 @@ private:
|
||||
std::map<unsigned int, GridPt> grid5d_;
|
||||
GridRbPt gridRb4d_;
|
||||
std::map<unsigned int, GridRbPt> gridRb5d_;
|
||||
unsigned int nd_;
|
||||
// random number generator
|
||||
RngPt rng4d_;
|
||||
// module and related maps
|
||||
|
@ -166,7 +166,7 @@ void GeneticScheduler<T>::initPopulation(void)
|
||||
{
|
||||
auto p = graph_.topoSort(gen_);
|
||||
|
||||
population_.emplace(func_(p), p);
|
||||
population_.insert(std::make_pair(func_(p), p));
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,8 +180,8 @@ void GeneticScheduler<T>::doCrossover(void)
|
||||
crossover(c1, c2, p1, p2);
|
||||
PARALLEL_CRITICAL
|
||||
{
|
||||
population_.emplace(func_(c1), c1);
|
||||
population_.emplace(func_(c2), c2);
|
||||
population_.insert(std::make_pair(func_(c1), c1));
|
||||
population_.insert(std::make_pair(func_(c2), c2));
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ void GeneticScheduler<T>::doMutation(void)
|
||||
mutation(m, it->second);
|
||||
PARALLEL_CRITICAL
|
||||
{
|
||||
population_.emplace(func_(m), m);
|
||||
population_.insert(std::make_pair(func_(m), m));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ void TSeqGamma<FImpl>::execute(void)
|
||||
g = makeGammaProd(par().gamma);
|
||||
p = strToVec<Real>(par().mom);
|
||||
ph = zero;
|
||||
for(unsigned int mu = 0; mu < Nd; mu++)
|
||||
for(unsigned int mu = 0; mu < env().getNd(); mu++)
|
||||
{
|
||||
LatticeCoordinate(coor, mu);
|
||||
ph = ph + p[mu]*coor;
|
||||
|
Reference in New Issue
Block a user