1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-09 21:50:45 +01:00

Merge branch 'feature/hadrons' into develop

This commit is contained in:
Antonin Portelli 2017-01-19 14:10:01 -08:00
commit d6401e6d2c
5 changed files with 61 additions and 16 deletions

View File

@ -306,7 +306,7 @@ void Application::configLoop(void)
<< " " << BIG_SEP << std::endl; << " " << BIG_SEP << std::endl;
env_.setTrajectory(t); env_.setTrajectory(t);
env_.executeProgram(program_); env_.executeProgram(program_);
env_.freeAll();
} }
LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl; LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl;
env_.freeAll();
} }

View File

@ -41,8 +41,9 @@ using namespace Hadrons;
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
Environment::Environment(void) Environment::Environment(void)
{ {
nd_ = GridDefaultLatt().size();
grid4d_.reset(SpaceTimeGrid::makeFourDimGrid( grid4d_.reset(SpaceTimeGrid::makeFourDimGrid(
GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()), GridDefaultLatt(), GridDefaultSimd(nd_, vComplex::Nsimd()),
GridDefaultMpi())); GridDefaultMpi()));
gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get())); gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get()));
auto loc = getGrid()->LocalDimensions(); 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 ///////////////////////////////////////////////////// // random number generator /////////////////////////////////////////////////////
void Environment::setSeed(const std::vector<int> &seed) void Environment::setSeed(const std::vector<int> &seed)
{ {
@ -410,12 +416,19 @@ Environment::Size Environment::executeProgram(const std::vector<std::string> &p)
// general memory management /////////////////////////////////////////////////// // general memory management ///////////////////////////////////////////////////
void Environment::addObject(const std::string name, const int moduleAddress) void Environment::addObject(const std::string name, const int moduleAddress)
{ {
ObjInfo info; if (!hasObject(name))
{
info.name = name; ObjInfo info;
info.module = moduleAddress;
object_.push_back(std::move(info)); info.name = name;
objectAddress_[name] = static_cast<unsigned int>(object_.size() - 1); info.module = moduleAddress;
object_.push_back(std::move(info));
objectAddress_[name] = static_cast<unsigned int>(object_.size() - 1);
}
else
{
HADRON_ERROR("object '" + name + "' already exists");
}
} }
void Environment::registerObject(const unsigned int address, void Environment::registerObject(const unsigned int address,
@ -444,6 +457,10 @@ void Environment::registerObject(const unsigned int address,
void Environment::registerObject(const std::string name, void Environment::registerObject(const std::string name,
const unsigned int size, const unsigned int Ls) const unsigned int size, const unsigned int Ls)
{ {
if (!hasObject(name))
{
addObject(name);
}
registerObject(getObjectAddress(name), size, Ls); registerObject(getObjectAddress(name), size, Ls);
} }
@ -573,6 +590,30 @@ bool Environment::hasRegisteredObject(const std::string name) const
} }
} }
bool Environment::hasCreatedObject(const unsigned int address) const
{
if (hasObject(address))
{
return (object_[address].data != nullptr);
}
else
{
return false;
}
}
bool Environment::hasCreatedObject(const std::string name) const
{
if (hasObject(name))
{
return hasCreatedObject(getObjectAddress(name));
}
else
{
return false;
}
}
bool Environment::isObject5d(const unsigned int address) const bool Environment::isObject5d(const unsigned int address) const
{ {
return (getObjectLs(address) > 1); return (getObjectLs(address) > 1);

View File

@ -106,6 +106,7 @@ public:
void createGrid(const unsigned int Ls); void createGrid(const unsigned int Ls);
GridCartesian * getGrid(const unsigned int Ls = 1) const; GridCartesian * getGrid(const unsigned int Ls = 1) const;
GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const; GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const;
unsigned int getNd(void) const;
// random number generator // random number generator
void setSeed(const std::vector<int> &seed); void setSeed(const std::vector<int> &seed);
GridParallelRNG * get4dRng(void) const; GridParallelRNG * get4dRng(void) const;
@ -137,7 +138,7 @@ public:
Size executeProgram(const std::vector<std::string> &p); Size executeProgram(const std::vector<std::string> &p);
// general memory management // general memory management
void addObject(const std::string name, void addObject(const std::string name,
const int moduleAddress); const int moduleAddress = -1);
void registerObject(const unsigned int address, void registerObject(const unsigned int address,
const unsigned int size, const unsigned int size,
const unsigned int Ls = 1); const unsigned int Ls = 1);
@ -176,6 +177,8 @@ public:
bool hasObject(const std::string name) const; bool hasObject(const std::string name) const;
bool hasRegisteredObject(const unsigned int address) const; bool hasRegisteredObject(const unsigned int address) const;
bool hasRegisteredObject(const std::string name) const; bool hasRegisteredObject(const std::string name) const;
bool hasCreatedObject(const unsigned int address) const;
bool hasCreatedObject(const std::string name) const;
bool isObject5d(const unsigned int address) const; bool isObject5d(const unsigned int address) const;
bool isObject5d(const std::string name) const; bool isObject5d(const std::string name) const;
Environment::Size getTotalSize(void) const; Environment::Size getTotalSize(void) const;
@ -198,6 +201,7 @@ private:
std::map<unsigned int, GridPt> grid5d_; std::map<unsigned int, GridPt> grid5d_;
GridRbPt gridRb4d_; GridRbPt gridRb4d_;
std::map<unsigned int, GridRbPt> gridRb5d_; std::map<unsigned int, GridRbPt> gridRb5d_;
unsigned int nd_;
// random number generator // random number generator
RngPt rng4d_; RngPt rng4d_;
// module and related maps // module and related maps

View File

@ -134,7 +134,7 @@ void GeneticScheduler<T>::nextGeneration(void)
LOG(Debug) << "Starting population:\n" << *this << std::endl; LOG(Debug) << "Starting population:\n" << *this << std::endl;
// random mutations // random mutations
PARALLEL_FOR_LOOP //PARALLEL_FOR_LOOP
for (unsigned int i = 0; i < par_.popSize; ++i) for (unsigned int i = 0; i < par_.popSize; ++i)
{ {
doMutation(); doMutation();
@ -142,7 +142,7 @@ void GeneticScheduler<T>::nextGeneration(void)
LOG(Debug) << "After mutations:\n" << *this << std::endl; LOG(Debug) << "After mutations:\n" << *this << std::endl;
// mating // mating
PARALLEL_FOR_LOOP //PARALLEL_FOR_LOOP
for (unsigned int i = 0; i < par_.popSize/2; ++i) for (unsigned int i = 0; i < par_.popSize/2; ++i)
{ {
doCrossover(); doCrossover();
@ -166,7 +166,7 @@ void GeneticScheduler<T>::initPopulation(void)
{ {
auto p = graph_.topoSort(gen_); 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); crossover(c1, c2, p1, p2);
PARALLEL_CRITICAL PARALLEL_CRITICAL
{ {
population_.emplace(func_(c1), c1); population_.insert(std::make_pair(func_(c1), c1));
population_.emplace(func_(c2), c2); population_.insert(std::make_pair(func_(c2), c2));
} }
} }
@ -200,7 +200,7 @@ void GeneticScheduler<T>::doMutation(void)
mutation(m, it->second); mutation(m, it->second);
PARALLEL_CRITICAL PARALLEL_CRITICAL
{ {
population_.emplace(func_(m), m); population_.insert(std::make_pair(func_(m), m));
} }
} }
} }

View File

@ -147,7 +147,7 @@ void TSeqGamma<FImpl>::execute(void)
g = makeGammaProd(par().gamma); g = makeGammaProd(par().gamma);
p = strToVec<Real>(par().mom); p = strToVec<Real>(par().mom);
ph = zero; ph = zero;
for(unsigned int mu = 0; mu < Nd; mu++) for(unsigned int mu = 0; mu < env().getNd(); mu++)
{ {
LatticeCoordinate(coor, mu); LatticeCoordinate(coor, mu);
ph = ph + p[mu]*coor; ph = ph + p[mu]*coor;