2016-02-25 12:07:21 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: programs/Hadrons/Environment.cc
|
|
|
|
|
|
|
|
Copyright (C) 2015
|
|
|
|
|
|
|
|
Author: Antonin Portelli <antonin.portelli@me.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution
|
|
|
|
directory.
|
|
|
|
*******************************************************************************/
|
2015-11-05 14:28:14 +00:00
|
|
|
|
|
|
|
#include <Hadrons/Environment.hpp>
|
|
|
|
|
|
|
|
using namespace Grid;
|
2016-01-14 04:23:51 +00:00
|
|
|
using namespace QCD;
|
2015-11-05 14:28:14 +00:00
|
|
|
using namespace Hadrons;
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Environment implementation *
|
|
|
|
******************************************************************************/
|
|
|
|
// constructor /////////////////////////////////////////////////////////////////
|
|
|
|
Environment::Environment(void)
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
|
|
|
grid4d_.reset(SpaceTimeGrid::makeFourDimGrid(
|
|
|
|
GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()),
|
|
|
|
GridDefaultMpi()));
|
2016-02-25 11:56:16 +00:00
|
|
|
gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get()));
|
|
|
|
rng4d_.reset(new GridParallelRNG(grid4d_.get()));
|
2016-01-14 04:23:51 +00:00
|
|
|
}
|
2015-12-23 14:21:35 +00:00
|
|
|
|
2016-01-14 04:23:51 +00:00
|
|
|
// dry run /////////////////////////////////////////////////////////////////////
|
|
|
|
void Environment::dryRun(const bool isDry)
|
|
|
|
{
|
|
|
|
dryRun_ = isDry;
|
|
|
|
}
|
|
|
|
|
2016-04-30 08:17:04 +01:00
|
|
|
bool Environment::isDryRun(void) const
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
|
|
|
return dryRun_;
|
|
|
|
}
|
|
|
|
|
2016-05-04 01:07:00 +01:00
|
|
|
// trajectory number ///////////////////////////////////////////////////////////
|
|
|
|
void Environment::setTrajectory(const unsigned int traj)
|
|
|
|
{
|
|
|
|
traj_ = traj;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Environment::getTrajectory(void) const
|
|
|
|
{
|
|
|
|
return traj_;
|
|
|
|
}
|
|
|
|
|
2016-02-25 11:56:16 +00:00
|
|
|
// grids ///////////////////////////////////////////////////////////////////////
|
2016-05-07 21:19:38 +01:00
|
|
|
void Environment::createGrid(const unsigned int Ls)
|
|
|
|
{
|
2016-05-09 14:49:06 +01:00
|
|
|
if (grid5d_.find(Ls) == grid5d_.end())
|
|
|
|
{
|
|
|
|
auto g = getGrid();
|
|
|
|
|
|
|
|
grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g));
|
|
|
|
gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g));
|
|
|
|
}
|
2016-05-07 21:19:38 +01:00
|
|
|
}
|
|
|
|
|
2016-04-30 08:17:04 +01:00
|
|
|
GridCartesian * Environment::getGrid(const unsigned int Ls) const
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (Ls == 1)
|
|
|
|
{
|
|
|
|
return grid4d_.get();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return grid5d_.at(Ls).get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(std::out_of_range &)
|
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
HADRON_ERROR("no grid with Ls= " << Ls);
|
2016-04-30 08:17:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-04-30 08:17:04 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (Ls == 1)
|
|
|
|
{
|
|
|
|
return gridRb4d_.get();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return gridRb5d_.at(Ls).get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(std::out_of_range &)
|
|
|
|
{
|
|
|
|
HADRON_ERROR("no red-black 5D grid with Ls= " << Ls);
|
|
|
|
}
|
2016-02-25 11:56:16 +00:00
|
|
|
}
|
|
|
|
|
2016-04-30 08:17:04 +01:00
|
|
|
// fermion actions /////////////////////////////////////////////////////////////
|
2016-05-07 21:19:38 +01:00
|
|
|
void Environment::addFermionMatrix(const std::string name, FMat *fMat)
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
if (hasObject(name))
|
|
|
|
{
|
|
|
|
fMat_[name].reset(fMat);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HADRON_ERROR("no object named '" << name << "'");
|
|
|
|
}
|
2016-02-25 11:56:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 00:30:29 +01:00
|
|
|
Environment::FMat * Environment::getFermionMatrix(const std::string name) const
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-05-05 03:11:03 +01:00
|
|
|
if (hasFermionMatrix(name))
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-05-04 00:30:29 +01:00
|
|
|
return fMat_.at(name).get();
|
2016-02-25 11:56:16 +00:00
|
|
|
}
|
2016-05-05 03:11:03 +01:00
|
|
|
else
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-05-06 00:13:14 +01:00
|
|
|
if (hasSolver(name))
|
2016-04-30 08:17:04 +01:00
|
|
|
{
|
2016-05-04 00:30:29 +01:00
|
|
|
return fMat_.at(solverAction_.at(name)).get();
|
2016-04-30 08:17:04 +01:00
|
|
|
}
|
2016-05-06 00:13:14 +01:00
|
|
|
else
|
2016-04-30 08:17:04 +01:00
|
|
|
{
|
2016-05-06 00:13:14 +01:00
|
|
|
HADRON_ERROR("no action/solver with name '" << name << "'");
|
2016-04-30 08:17:04 +01:00
|
|
|
}
|
2016-02-25 11:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-05 03:11:03 +01:00
|
|
|
void Environment::freeFermionMatrix(const std::string name)
|
|
|
|
{
|
|
|
|
if (hasFermionMatrix(name))
|
|
|
|
{
|
2016-05-07 21:26:56 +01:00
|
|
|
LOG(Message) << "Freeing fermion matrix '" << name << "'" << std::endl;
|
2016-05-05 03:11:03 +01:00
|
|
|
fMat_.erase(name);
|
2016-05-07 21:19:38 +01:00
|
|
|
object_.erase(name);
|
2016-05-05 03:11:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
HADRON_ERROR("trying to free unknown fermion matrix '" + name + "'");
|
2016-05-05 03:11:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Environment::hasFermionMatrix(const std::string name) const
|
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
return (hasObject(name) and (fMat_.find(name) != fMat_.end()));
|
2016-05-05 03:11:03 +01:00
|
|
|
}
|
|
|
|
|
2016-04-30 08:17:04 +01:00
|
|
|
// solvers /////////////////////////////////////////////////////////////////////
|
2016-05-07 21:19:38 +01:00
|
|
|
void Environment::addSolver(const std::string name, Solver s)
|
2016-04-30 08:17:04 +01:00
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
if (hasObject(name))
|
|
|
|
{
|
|
|
|
solver_[name] = s;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HADRON_ERROR("no object named '" << name << "'");
|
|
|
|
}
|
2016-04-30 08:17:04 +01:00
|
|
|
}
|
|
|
|
|
2016-05-05 03:11:03 +01:00
|
|
|
bool Environment::hasSolver(const std::string name) const
|
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
return (hasObject(name) and (solver_.find(name) != solver_.end()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Environment::setSolverAction(const std::string name,
|
|
|
|
const std::string actionName)
|
|
|
|
{
|
|
|
|
if (hasObject(name))
|
|
|
|
{
|
|
|
|
solverAction_[name] = actionName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HADRON_ERROR("no object named '" << name << "'");
|
|
|
|
}
|
2016-05-05 03:11:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Environment::getSolverAction(const std::string name) const
|
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
if (hasObject(name))
|
2016-05-05 03:11:03 +01:00
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return solverAction_.at(name);
|
|
|
|
}
|
|
|
|
catch (std::out_of_range &)
|
|
|
|
{
|
|
|
|
HADRON_ERROR("no action registered for solver '" << name << "'")
|
|
|
|
}
|
2016-05-05 03:11:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
HADRON_ERROR("no object with name '" << name << "'");
|
2016-05-05 03:11:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 08:17:04 +01:00
|
|
|
void Environment::callSolver(const std::string name, LatticeFermion &sol,
|
|
|
|
const LatticeFermion &source) const
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-05-05 03:11:03 +01:00
|
|
|
if (hasSolver(name))
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-04-30 08:17:04 +01:00
|
|
|
solver_.at(name)(sol, source);
|
2016-02-25 11:56:16 +00:00
|
|
|
}
|
2016-05-05 03:11:03 +01:00
|
|
|
else
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-04-30 08:17:04 +01:00
|
|
|
HADRON_ERROR("no solver with name '" << name << "'");
|
2016-02-25 11:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 20:17:27 +01:00
|
|
|
// random number generator /////////////////////////////////////////////////////
|
|
|
|
void Environment::setSeed(const std::vector<int> &seed)
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
2016-05-04 20:17:27 +01:00
|
|
|
rng4d_->SeedFixedIntegers(seed);
|
|
|
|
}
|
2016-02-25 11:56:16 +00:00
|
|
|
|
2016-05-04 20:17:27 +01:00
|
|
|
GridParallelRNG * Environment::get4dRng(void) const
|
|
|
|
{
|
|
|
|
return rng4d_.get();
|
2016-01-14 04:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 03:11:03 +01:00
|
|
|
// lattice store ///////////////////////////////////////////////////////////////
|
2016-05-04 20:17:27 +01:00
|
|
|
void Environment::freeLattice(const std::string name)
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
2016-05-04 20:17:27 +01:00
|
|
|
if (hasLattice(name))
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
2016-05-07 21:26:56 +01:00
|
|
|
LOG(Message) << "Freeing lattice '" << name << "'" << std::endl;
|
2016-05-04 20:17:27 +01:00
|
|
|
lattice_.erase(name);
|
2016-05-07 21:19:38 +01:00
|
|
|
object_.erase(name);
|
2016-01-14 04:23:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
HADRON_ERROR("trying to free unknown lattice '" + name + "'");
|
2016-01-14 04:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 20:17:27 +01:00
|
|
|
bool Environment::hasLattice(const std::string name) const
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
return (hasObject(name) and (lattice_.find(name) != lattice_.end()));
|
2016-01-14 04:23:51 +00:00
|
|
|
}
|
|
|
|
|
2016-05-07 21:19:38 +01:00
|
|
|
// general memory management ///////////////////////////////////////////////////
|
|
|
|
bool Environment::hasObject(const std::string name) const
|
|
|
|
{
|
|
|
|
return (object_.find(name) != object_.end());
|
|
|
|
}
|
2016-05-04 20:17:27 +01:00
|
|
|
|
2016-05-07 21:19:38 +01:00
|
|
|
void Environment::registerObject(const std::string name,
|
|
|
|
const unsigned int size, const unsigned int Ls)
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
if (!hasObject(name))
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
ObjInfo info{size, Ls};
|
|
|
|
|
|
|
|
object_[name] = info;
|
2016-01-14 04:23:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
HADRON_ERROR("object '" + name + "' already exists");
|
2016-01-14 04:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-07 21:19:38 +01:00
|
|
|
unsigned int Environment::getObjectSize(const std::string name) const
|
2016-04-30 08:17:04 +01:00
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
if (hasObject(name))
|
2016-04-30 08:17:04 +01:00
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
return object_.at(name).size;
|
2016-04-30 08:17:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
HADRON_ERROR("no object named '" + name + "'");
|
2016-04-30 08:17:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-07 21:19:38 +01:00
|
|
|
long unsigned int Environment::getTotalSize(void) const
|
|
|
|
{
|
|
|
|
long unsigned int size = 0;
|
|
|
|
|
|
|
|
for (auto &s: object_)
|
|
|
|
{
|
|
|
|
size += s.second.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Environment::getObjectLs(const std::string name) const
|
|
|
|
{
|
|
|
|
if (hasObject(name))
|
|
|
|
{
|
|
|
|
return object_.at(name).Ls;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HADRON_ERROR("no object named '" + name + "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Environment::isObject5d(const std::string name) const
|
|
|
|
{
|
|
|
|
return (getObjectLs(name) > 1);
|
|
|
|
}
|
|
|
|
|
2016-05-05 03:11:03 +01:00
|
|
|
void Environment::addOwnership(const std::string owner,
|
|
|
|
const std::string property)
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
2016-05-05 03:11:03 +01:00
|
|
|
owners_[property].insert(owner);
|
|
|
|
properties_[owner].insert(property);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Environment::hasOwners(const std::string name) const
|
|
|
|
{
|
2016-05-09 14:49:06 +01:00
|
|
|
|
|
|
|
auto it = owners_.find(name);
|
|
|
|
|
|
|
|
if (it != owners_.end())
|
2016-05-05 03:11:03 +01:00
|
|
|
{
|
2016-05-09 14:49:06 +01:00
|
|
|
return (!it->second.empty());
|
2016-05-05 03:11:03 +01:00
|
|
|
}
|
2016-05-09 14:49:06 +01:00
|
|
|
else
|
2016-01-14 04:23:51 +00:00
|
|
|
{
|
2016-05-05 03:11:03 +01:00
|
|
|
return false;
|
2016-01-14 04:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-07 21:19:38 +01:00
|
|
|
bool Environment::freeObject(const std::string name)
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-05-05 03:11:03 +01:00
|
|
|
if (!hasOwners(name))
|
|
|
|
{
|
|
|
|
for (auto &p: properties_[name])
|
|
|
|
{
|
|
|
|
owners_[p].erase(name);
|
|
|
|
}
|
|
|
|
properties_[name].clear();
|
|
|
|
if (hasLattice(name))
|
|
|
|
{
|
|
|
|
freeLattice(name);
|
|
|
|
}
|
|
|
|
else if (hasFermionMatrix(name))
|
|
|
|
{
|
|
|
|
freeFermionMatrix(name);
|
|
|
|
}
|
2016-05-07 21:19:38 +01:00
|
|
|
else if (hasObject(name))
|
|
|
|
{
|
|
|
|
object_.erase(name);
|
|
|
|
}
|
2016-05-05 03:11:03 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-25 11:56:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 03:11:03 +01:00
|
|
|
void Environment::freeAll(void)
|
2016-02-25 11:56:16 +00:00
|
|
|
{
|
2016-05-07 21:19:38 +01:00
|
|
|
object_.clear();
|
2016-05-05 03:11:03 +01:00
|
|
|
lattice_.clear();
|
|
|
|
fMat_.clear();
|
|
|
|
solver_.clear();
|
2016-05-07 21:19:38 +01:00
|
|
|
solverAction_.clear();
|
2016-05-06 00:13:14 +01:00
|
|
|
owners_.clear();
|
|
|
|
properties_.clear();
|
2016-02-25 11:56:16 +00:00
|
|
|
}
|