1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-05 19:55:56 +01:00

Hadrons: environment with fully generic object store

This commit is contained in:
Antonin Portelli 2016-06-06 17:45:37 +01:00
parent 1826ed06a3
commit 8e2078be71
15 changed files with 321 additions and 385 deletions

View File

@ -127,7 +127,7 @@ void Application::schedule(void)
// constrained topological sort using a genetic algorithm
LOG(Message) << "Scheduling computation..." << std::endl;
constexpr unsigned int maxGen = 200, maxCstGen = 50;
constexpr unsigned int maxGen = 2000000, maxCstGen = 2000000;
unsigned int k = 0, gen, prevPeak, nCstPeak = 0;
auto graph = env_.makeModuleGraph();
auto con = graph.getConnectedComponents();

View File

@ -139,39 +139,28 @@ GridParallelRNG * Environment::get4dRng(void) const
void Environment::createModule(const std::string name, const std::string type,
XmlReader &reader)
{
auto addObject = [this](const std::string name, const int moduleAddress)
{
ObjInfo info;
object_.push_back(info);
objectName_.push_back(name);
objectAddress_[name] = object_.size() - 1;
objectModule_.push_back(moduleAddress);
owners_.push_back(std::set<unsigned int>());
properties_.push_back(std::set<unsigned int>());
};
if (!hasModule(name))
{
auto &factory = ModuleFactory::getInstance();
std::vector<unsigned int> inputAddress;
ModuleInfo m;
module_.push_back(factory.create(type, name));
moduleType_.push_back(type);
moduleName_.push_back(name);
moduleAddress_[name] = module_.size() - 1;
module_.back()->parseParameters(reader, "options");
auto input = module_.back()->getInput();
m.data = factory.create(type, name);
m.type = typeIdPt(*m.data.get());
m.name = name;
m.data->parseParameters(reader, "options");
auto input = m.data->getInput();
for (auto &in: input)
{
if (!hasObject(in))
{
addObject(in , -1);
}
inputAddress.push_back(objectAddress_[in]);
m.input.push_back(objectAddress_[in]);
}
moduleInput_.push_back(inputAddress);
auto output = module_.back()->getOutput();
auto output = m.data->getOutput();
module_.push_back(std::move(m));
moduleAddress_[name] = module_.size() - 1;
for (auto &out: output)
{
if (!hasObject(out))
@ -180,16 +169,16 @@ void Environment::createModule(const std::string name, const std::string type,
}
else
{
if (objectModule_[objectAddress_[out]] < 0)
if (object_[objectAddress_[out]].module < 0)
{
objectModule_[objectAddress_[out]] = module_.size() - 1;
object_[objectAddress_[out]].module = module_.size() - 1;
}
else
{
HADRON_ERROR("object '" + out
+ "' is already produced by module '"
+ moduleName_[objectModule_[getObjectAddress(out)]]
+ "' (while creating module '" + name + "')");
+ "' is already produced by module '"
+ module_[object_[getObjectAddress(out)].module].name
+ "' (while creating module '" + name + "')");
}
}
}
@ -204,7 +193,7 @@ ModuleBase * Environment::getModule(const unsigned int address) const
{
if (hasModule(address))
{
return module_[address].get();
return module_[address].data.get();
}
else
{
@ -233,7 +222,7 @@ std::string Environment::getModuleName(const unsigned int address) const
{
if (hasModule(address))
{
return moduleName_[address];
return module_[address].name;
}
else
{
@ -245,7 +234,7 @@ std::string Environment::getModuleType(const unsigned int address) const
{
if (hasModule(address))
{
return moduleType_[address];
return module_[address].type->name();
}
else
{
@ -275,9 +264,9 @@ Graph<unsigned int> Environment::makeModuleGraph(void) const
for (unsigned int i = 0; i < module_.size(); ++i)
{
moduleGraph.addVertex(i);
for (auto &j: moduleInput_[i])
for (auto &j: module_[i].input)
{
moduleGraph.addEdge(objectModule_[j], i);
moduleGraph.addEdge(object_[j].module, i);
}
}
@ -301,10 +290,10 @@ unsigned int Environment::executeProgram(const std::vector<unsigned int> &p)
{
auto pred = [i, this](const unsigned int j)
{
auto &in = moduleInput_[j];
auto &in = module_[j].input;
auto it = std::find(in.begin(), in.end(), i);
return (it != in.end()) or (j == objectModule_[i]);
return (it != in.end()) or (j == object_[i].module);
};
auto it = std::find_if(p.rbegin(), p.rend(), pred);
if (it != p.rend())
@ -320,10 +309,10 @@ unsigned int Environment::executeProgram(const std::vector<unsigned int> &p)
if (!isDryRun())
{
LOG(Message) << SEP << " Measurement step " << i+1 << "/"
<< p.size() << " (module '" << moduleName_[p[i]]
<< p.size() << " (module '" << module_[p[i]].name
<< "') " << SEP << std::endl;
}
(*module_[p[i]])();
(*module_[p[i]].data)();
sizeBefore = getTotalSize();
// print used memory after execution
if (!isDryRun())
@ -369,9 +358,9 @@ unsigned int Environment::executeProgram(const std::vector<unsigned int> &p)
}
}
// print used memory after garbage collection if necessary
sizeAfter = getTotalSize();
if (!isDryRun())
{
sizeAfter = getTotalSize();
if (sizeBefore != sizeAfter)
{
LOG(Message) << "Allocated objects: " << MEM_MSG(sizeAfter)
@ -399,204 +388,17 @@ unsigned int Environment::executeProgram(const std::vector<std::string> &p)
return executeProgram(pAddress);
}
// lattice store ///////////////////////////////////////////////////////////////
void Environment::freeLattice(const unsigned int address)
{
if (hasLattice(address))
{
if (!isDryRun())
{
LOG(Message) << "Freeing lattice '" << objectName_[address]
<< "'" << std::endl;
}
lattice_.erase(address);
object_[address] = ObjInfo();
}
else
{
HADRON_ERROR("trying to free unknown lattice (address "
+ std::to_string(address) + ")");
}
}
bool Environment::hasLattice(const unsigned int address) const
{
return (hasRegisteredObject(address)
and (lattice_.find(address) != lattice_.end()));
}
bool Environment::hasLattice(const std::string name) const
{
if (hasObject(name))
{
return hasLattice(getObjectAddress(name));
}
else
{
return false;
}
}
// fermion actions /////////////////////////////////////////////////////////////
void Environment::addFermionMatrix(const std::string name, FMat *fMat)
{
if (hasRegisteredObject(name))
{
fMat_[getObjectAddress(name)].reset(fMat);
}
else
{
HADRON_ERROR("no object named '" << name << "'");
}
}
Environment::FMat * Environment::getFermionMatrix(const std::string name) const
{
unsigned int i;
if (hasFermionMatrix(name))
{
i = getObjectAddress(name);
return fMat_.at(i).get();
}
else
{
if (hasSolver(name))
{
i = getObjectAddress(solverAction_.at(name));
return fMat_.at(i).get();
}
else
{
HADRON_ERROR("no action/solver with name '" << name << "'");
}
}
}
bool Environment::hasFermionMatrix(const unsigned int address) const
{
return (hasRegisteredObject(address)
and (fMat_.find(address) != fMat_.end()));
}
bool Environment::hasFermionMatrix(const std::string name) const
{
if (hasObject(name))
{
return hasFermionMatrix(getObjectAddress(name));
}
else
{
return false;
}
}
void Environment::freeFermionMatrix(const unsigned int address)
{
if (hasFermionMatrix(address))
{
if (!isDryRun())
{
LOG(Message) << "Freeing fermion matrix '" << objectName_[address]
<< "'" << std::endl;
}
fMat_.erase(address);
object_[address] = ObjInfo();
}
else
{
HADRON_ERROR("trying to free unknown fermion matrix (address "
+ std::to_string(address) + ")");
}
}
void Environment::freeFermionMatrix(const std::string name)
{
freeFermionMatrix(getObjectAddress(name));
}
// solvers /////////////////////////////////////////////////////////////////////
void Environment::addSolver(const std::string name, Solver s)
{
auto address = getObjectAddress(name);
if (hasRegisteredObject(address))
{
solver_[address] = s;
}
else
{
HADRON_ERROR("object with name '" + name
+ "' exsists but is not registered");
}
}
bool Environment::hasSolver(const unsigned int address) const
{
return (hasRegisteredObject(address)
and (solver_.find(address) != solver_.end()));
}
bool Environment::hasSolver(const std::string name) const
{
if (hasObject(name))
{
return hasSolver(getObjectAddress(name));
}
else
{
return false;
}
}
void Environment::setSolverAction(const std::string name,
const std::string actionName)
{
if (hasObject(name))
{
solverAction_[name] = actionName;
}
else
{
HADRON_ERROR("no object named '" << name << "'");
}
}
std::string Environment::getSolverAction(const std::string name) const
{
if (hasObject(name))
{
try
{
return solverAction_.at(name);
}
catch (std::out_of_range &)
{
HADRON_ERROR("no action registered for solver '" << name << "'")
}
}
else
{
HADRON_ERROR("no object with name '" << name << "'");
}
}
void Environment::callSolver(const std::string name, LatticeFermion &sol,
const LatticeFermion &source) const
{
if (hasSolver(name))
{
solver_.at(getObjectAddress(name))(sol, source);
}
else
{
HADRON_ERROR("no solver with name '" << name << "'");
}
}
// general memory management ///////////////////////////////////////////////////
void Environment::addObject(const std::string name, const int moduleAddress)
{
ObjInfo info;
info.name = name;
info.module = moduleAddress;
object_.push_back(std::move(info));
objectAddress_[name] = object_.size() - 1;
}
void Environment::registerObject(const unsigned int address,
const unsigned int size, const unsigned int Ls)
{
@ -604,12 +406,9 @@ void Environment::registerObject(const unsigned int address,
{
if (hasObject(address))
{
ObjInfo info;
info.size = size;
info.Ls = Ls;
info.isRegistered = true;
object_[address] = info;
object_[address].size = size;
object_[address].Ls = Ls;
object_[address].isRegistered = true;
}
else
{
@ -645,7 +444,7 @@ std::string Environment::getObjectName(const unsigned int address) const
{
if (hasObject(address))
{
return objectName_[address];
return object_[address].name;
}
else
{
@ -653,6 +452,28 @@ std::string Environment::getObjectName(const unsigned int address) const
}
}
std::string Environment::getObjectType(const unsigned int address) const
{
if (hasRegisteredObject(address))
{
return object_[address].type->name();
}
else if (hasObject(address))
{
HADRON_ERROR("object with address " + std::to_string(address)
+ " exists but is not registered");
}
else
{
HADRON_ERROR("no object with address " + std::to_string(address));
}
}
std::string Environment::getObjectType(const std::string name) const
{
return getObjectType(getObjectAddress(name));
}
unsigned int Environment::getObjectSize(const unsigned int address) const
{
if (hasRegisteredObject(address))
@ -662,7 +483,7 @@ unsigned int Environment::getObjectSize(const unsigned int address) const
else if (hasObject(address))
{
HADRON_ERROR("object with address " + std::to_string(address)
+ " exsists but is not registered");
+ " exists but is not registered");
}
else
{
@ -684,7 +505,7 @@ unsigned int Environment::getObjectLs(const unsigned int address) const
else if (hasObject(address))
{
HADRON_ERROR("object with address " + std::to_string(address)
+ " exsists but is not registered");
+ " exists but is not registered");
}
else
{
@ -761,8 +582,22 @@ long unsigned int Environment::getTotalSize(void) const
void Environment::addOwnership(const unsigned int owner,
const unsigned int property)
{
owners_[property].insert(owner);
properties_[owner].insert(property);
if (hasObject(property))
{
object_[property].owners.insert(owner);
}
else
{
HADRON_ERROR("no object with address " + std::to_string(property));
}
if (hasObject(owner))
{
object_[owner].properties.insert(property);
}
else
{
HADRON_ERROR("no object with address " + std::to_string(owner));
}
}
void Environment::addOwnership(const std::string owner,
@ -776,7 +611,7 @@ bool Environment::hasOwners(const unsigned int address) const
if (hasObject(address))
{
return (!owners_[address].empty());
return (!object_[address].owners.empty());
}
else
{
@ -793,23 +628,22 @@ bool Environment::freeObject(const unsigned int address)
{
if (!hasOwners(address))
{
for (auto &p: properties_[address])
if (!isDryRun())
{
owners_[p].erase(address);
LOG(Message) << "Destroying object '" << object_[address].name
<< "'" << std::endl;
}
properties_[address].clear();
if (hasLattice(address))
for (auto &p: object_[address].properties)
{
freeLattice(address);
}
else if (hasFermionMatrix(address))
{
freeFermionMatrix(address);
}
else if (hasObject(address))
{
object_[address] = ObjInfo();
object_[p].owners.erase(address);
}
object_[address].size = 0;
object_[address].Ls = 0;
object_[address].isRegistered = false;
object_[address].type = nullptr;
object_[address].owners.clear();
object_[address].properties.clear();
object_[address].data.reset(nullptr);
return true;
}
@ -826,12 +660,10 @@ bool Environment::freeObject(const std::string name)
void Environment::freeAll(void)
{
lattice_.clear();
fMat_.clear();
solver_.clear();
solverAction_.clear();
owners_.clear();
properties_.clear();
for (unsigned int i = 0; i < object_.size(); ++i)
{
freeObject(i);
}
}
void Environment::printContent(void)
@ -840,13 +672,13 @@ void Environment::printContent(void)
for (unsigned int i = 0; i < module_.size(); ++i)
{
LOG(Message) << std::setw(4) << std::right << i << ": "
<< moduleName_[i] << " ("
<< moduleType_[i] << ")" << std::endl;
<< getModuleName(i) << " ("
<< getModuleType(i) << ")" << std::endl;
}
LOG(Message) << "Objects: " << std::endl;
for (unsigned int i = 0; i < object_.size(); ++i)
{
LOG(Message) << std::setw(4) << std::right << i << ": "
<< objectName_[i] << std::endl;
<< getObjectName(i) << std::endl;
}
}

View File

@ -39,6 +39,27 @@ BEGIN_HADRONS_NAMESPACE
// forward declaration of Module
class ModuleBase;
class Object
{
public:
Object(void) = default;
virtual ~Object(void) = default;
};
template <typename T>
class Holder: public Object
{
public:
Holder(void) = default;
Holder(T *pt);
virtual ~Holder(void) = default;
T & get(void) const;
T * getPt(void) const;
void reset(T *pt);
private:
std::unique_ptr<T> objPt_{nullptr};
};
class Environment
{
SINGLETON(Environment);
@ -53,10 +74,22 @@ public:
typedef std::unique_ptr<GridParallelRNG> RngPt;
typedef std::unique_ptr<LatticeBase> LatticePt;
private:
struct ModuleInfo
{
const std::type_info *type{nullptr};
std::string name;
std::unique_ptr<ModuleBase> data{nullptr};
std::vector<unsigned int> input;
};
struct ObjInfo
{
unsigned int size{0}, Ls{0};
bool isRegistered{false};
unsigned int size{0}, Ls{0};
bool isRegistered{false};
const std::type_info *type{nullptr};
std::string name;
int module{-1};
std::set<unsigned int> owners, properties;
std::unique_ptr<Object> data{nullptr};
};
public:
// dry run
@ -91,35 +124,9 @@ public:
Graph<unsigned int> makeModuleGraph(void) const;
unsigned int executeProgram(const std::vector<unsigned int> &p);
unsigned int executeProgram(const std::vector<std::string> &p);
// lattice store
template <typename T>
T * create(const std::string name);
template <typename T>
T * get(const std::string name) const;
bool hasLattice(const unsigned int address) const;
bool hasLattice(const std::string name) const;
void freeLattice(const unsigned int address);
void freeLattice(const std::string name);
template <typename T>
unsigned int lattice4dSize(void) const;
// fermion actions
void addFermionMatrix(const std::string name, FMat *mat);
FMat * getFermionMatrix(const std::string name) const;
bool hasFermionMatrix(const unsigned int address) const;
bool hasFermionMatrix(const std::string name) const;
void freeFermionMatrix(const unsigned int address);
void freeFermionMatrix(const std::string name);
// solvers
void addSolver(const std::string name, Solver s);
bool hasSolver(const unsigned int address) const;
bool hasSolver(const std::string name) const;
void setSolverAction(const std::string name,
const std::string actionName);
std::string getSolverAction(const std::string name) const;
void callSolver(const std::string name,
LatticeFermion &sol,
const LatticeFermion &src) const;
// general memory management
void addObject(const std::string name,
const int moduleAddress);
void registerObject(const unsigned int address,
const unsigned int size,
const unsigned int Ls = 1);
@ -127,13 +134,29 @@ public:
const unsigned int size,
const unsigned int Ls = 1);
template <typename T>
unsigned int lattice4dSize(void) const;
template <typename T>
void registerLattice(const unsigned int address,
const unsigned int Ls = 1);
template <typename T>
void registerLattice(const std::string name,
const unsigned int Ls = 1);
template <typename T>
void setObject(const unsigned int address, T *object);
template <typename T>
void setObject(const std::string name, T *object);
template <typename T>
T * getObject(const unsigned int address) const;
template <typename T>
T * getObject(const std::string name) const;
template <typename T>
T * createLattice(const unsigned int address);
template <typename T>
T * createLattice(const std::string name);
unsigned int getObjectAddress(const std::string name) const;
std::string getObjectName(const unsigned int address) const;
std::string getObjectType(const unsigned int address) const;
std::string getObjectType(const std::string name) const;
unsigned int getObjectSize(const unsigned int address) const;
unsigned int getObjectSize(const std::string name) const;
unsigned int getObjectLs(const unsigned int address) const;
@ -167,11 +190,8 @@ private:
// random number generator
RngPt rng4d_;
// module and related maps
std::vector<ModPt> module_;
std::vector<std::string> moduleType_;
std::vector<std::string> moduleName_;
std::vector<ModuleInfo> module_;
std::map<std::string, unsigned int> moduleAddress_;
std::vector<std::vector<unsigned int>> moduleInput_;
// lattice store
std::map<unsigned int, LatticePt> lattice_;
// fermion matrix store
@ -179,18 +199,37 @@ private:
// solver store & solver/action map
std::map<unsigned int, Solver> solver_;
std::map<std::string, std::string> solverAction_;
// object register
// object store
std::vector<ObjInfo> object_;
std::vector<std::string> objectName_;
std::map<std::string, unsigned int> objectAddress_;
std::vector<int> objectModule_;
std::vector<std::set<unsigned int>> owners_;
std::vector<std::set<unsigned int>> properties_;
};
/******************************************************************************
* template implementation *
******************************************************************************/
template <typename T>
Holder<T>::Holder(T *pt)
: objPt_(pt)
{}
template <typename T>
T & Holder<T>::get(void) const
{
return &objPt_.get();
}
template <typename T>
T * Holder<T>::getPt(void) const
{
return objPt_.get();
}
template <typename T>
void Holder<T>::reset(T *pt)
{
objPt_.reset(pt);
}
template <typename M>
M * Environment::getModule(const unsigned int address) const
{
@ -200,9 +239,9 @@ M * Environment::getModule(const unsigned int address) const
}
else
{
HADRON_ERROR("module '" + moduleName_[address] + "' does not have type "
+ typeName<M>() + "(object type: "
+ typeName(*module_.at(address).get()) + ")");
HADRON_ERROR("module '" + module_[address].name
+ "' does not have type " + typeid(M).name()
+ "(object type: " + getModuleType(address) + ")");
}
}
@ -218,56 +257,93 @@ unsigned int Environment::lattice4dSize(void) const
return sizeof(typename T::vector_object)/getGrid()->Nsimd();
}
template <typename T>
T * Environment::create(const std::string name)
{
auto i = getObjectAddress(name);
GridCartesian *g = getGrid(getObjectLs(i));
lattice_[i].reset(new T(g));
return dynamic_cast<T *>(lattice_[i].get());
}
template <typename T>
T * Environment::get(const std::string name) const
{
if (hasLattice(name))
{
auto i = getObjectAddress(name);
if (auto pt = dynamic_cast<T *>(lattice_.at(i).get()))
{
return pt;
}
else
{
HADRON_ERROR("object '" + name + "' does not have type "
+ typeName<T>() + "(object type: "
+ typeName(*lattice_.at(i).get()) + ")");
}
}
else
{
HADRON_ERROR("no lattice with name '" + name + "'");
return nullptr;
}
}
template <typename T>
void Environment::registerLattice(const unsigned int address,
const unsigned int Ls)
{
createGrid(Ls);
registerObject(address, Ls*lattice4dSize<T>());
registerObject(address, Ls*lattice4dSize<T>(), Ls);
}
template <typename T>
void Environment::registerLattice(const std::string name, const unsigned int Ls)
{
createGrid(Ls);
registerObject(name, Ls*lattice4dSize<T>());
registerObject(name, Ls*lattice4dSize<T>(), Ls);
}
template <typename T>
void Environment::setObject(const unsigned int address, T *object)
{
if (hasRegisteredObject(address))
{
object_[address].data.reset(new Holder<T>(object));
object_[address].type = &typeid(T);
}
else if (hasObject(address))
{
HADRON_ERROR("object with address " + std::to_string(address) +
" exists but is not registered");
}
else
{
HADRON_ERROR("no object with address " + std::to_string(address));
}
}
template <typename T>
void Environment::setObject(const std::string name, T *object)
{
setObject(getObjectAddress(name), object);
}
template <typename T>
T * Environment::getObject(const unsigned int address) const
{
if (hasRegisteredObject(address))
{
if (auto h = dynamic_cast<Holder<T> *>(object_[address].data.get()))
{
return h->getPt();
}
else
{
HADRON_ERROR("object with address " + std::to_string(address) +
" does not have type '" + typeid(T).name() +
"' (has type '" + getObjectType(address) + "')");
}
}
else if (hasObject(address))
{
HADRON_ERROR("object with address " + std::to_string(address) +
" exists but is not registered");
}
else
{
HADRON_ERROR("no object with address " + std::to_string(address));
}
}
template <typename T>
T * Environment::getObject(const std::string name) const
{
return getObject<T>(getObjectAddress(name));
}
template <typename T>
T * Environment::createLattice(const unsigned int address)
{
GridCartesian *g = getGrid(getObjectLs(address));
setObject(address, new T(g));
return getObject<T>(address);
}
template <typename T>
T * Environment::createLattice(const std::string name)
{
return createLattice<T>(getObjectAddress(name));
}
END_HADRONS_NAMESPACE

View File

@ -111,6 +111,18 @@ std::string typeName(void)
return name;
}
template <typename T>
const std::type_info * typeIdPt(const T &x)
{
return &typeid(x);
}
template <typename T>
const std::type_info * typeName(void)
{
return &typeid(T);
}
END_HADRONS_NAMESPACE
#endif // Hadrons_Global_hpp_

View File

@ -55,6 +55,10 @@ static mod##ModuleRegistrar mod##ModuleRegistrarInstance;
// base class
class ModuleBase
{
public:
// convenient type shortcuts
typedef Environment::FMat FMat;
typedef Environment::Solver Solver;
public:
// constructor
ModuleBase(const std::string name);
@ -99,7 +103,19 @@ private:
};
// no parameter type
typedef Serializable NoPar;
class NoPar {};
template <>
class Module<NoPar>: public ModuleBase
{
public:
// constructor
Module(const std::string name): ModuleBase(name) {};
// destructor
virtual ~Module(void) = default;
// parse parameters (do nothing)
virtual void parseParameters(XmlReader &reader, const std::string name) {};
};
/******************************************************************************
* Template implementation *

View File

@ -65,19 +65,17 @@ void ADWF::setup(void)
// execution ///////////////////////////////////////////////////////////////////
void ADWF::execute(void)
{
env().createGrid(par().Ls);
auto &U = *env().get<LatticeGaugeField>(par().gauge);
auto &g4 = *env().getGrid();
auto &grb4 = *env().getRbGrid();
auto &g5 = *env().getGrid(par().Ls);
auto &grb5 = *env().getRbGrid(par().Ls);
auto fMatPt = new DomainWallFermionR(U, g5, grb5, g4, grb4,
par().mass, par().M5);
LOG(Message) << "Setting up domain wall fermion matrix with m= "
<< par().mass << ", M5= " << par().M5 << " and Ls= "
<< par().Ls << " using gauge field '" << par().gauge << "'"
<< std::endl;
env().addFermionMatrix(getName(), fMatPt);
env().createGrid(par().Ls);
auto &U = *env().getObject<LatticeGaugeField>(par().gauge);
auto &g4 = *env().getGrid();
auto &grb4 = *env().getRbGrid();
auto &g5 = *env().getGrid(par().Ls);
auto &grb5 = *env().getRbGrid(par().Ls);
FMat *fMatPt = new DomainWallFermionR(U, g5, grb5, g4, grb4, par().mass,
par().M5);
env().setObject(getName(), fMatPt);
}

View File

@ -65,13 +65,11 @@ void AWilson::setup(void)
// execution ///////////////////////////////////////////////////////////////////
void AWilson::execute()
{
auto &U = *env().get<LatticeGaugeField>(par().gauge);
auto &grid = *env().getGrid();
auto &gridRb = *env().getRbGrid();
auto fMatPt = new WilsonFermionR(U, grid, gridRb, par().mass);
unsigned int size;
LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass
<< " using gauge field '" << par().gauge << "'" << std::endl;
env().addFermionMatrix(getName(), fMatPt);
auto &U = *env().getObject<LatticeGaugeField>(par().gauge);
auto &grid = *env().getGrid();
auto &gridRb = *env().getRbGrid();
FMat *fMatPt = new WilsonFermionR(U, grid, gridRb, par().mass);
env().setObject(getName(), fMatPt);
}

View File

@ -62,8 +62,8 @@ void CMeson::execute(void)
<< std::endl;
XmlWriter writer(par().output);
LatticePropagator &q1 = *env().get<LatticePropagator>(par().q1);
LatticePropagator &q2 = *env().get<LatticePropagator>(par().q2);
LatticePropagator &q1 = *env().getObject<LatticePropagator>(par().q1);
LatticePropagator &q2 = *env().getObject<LatticePropagator>(par().q2);
LatticeComplex c(env().getGrid());
SpinMatrix g[Ns*Ns], g5;
std::vector<TComplex> buf;

View File

@ -68,7 +68,7 @@ void GLoad::execute(void)
LOG(Message) << "Loading NERSC configuration from file '" << fileName
<< "'" << std::endl;
LatticeGaugeField &U = *env().create<LatticeGaugeField>(getName());
LatticeGaugeField &U = *env().createLattice<LatticeGaugeField>(getName());
NerscIO::readConfiguration(U, header, fileName);
LOG(Message) << "NERSC header:" << std::endl;
dump_nersc_header(header, LOG(Message));

View File

@ -61,6 +61,6 @@ void GRandom::setup(void)
void GRandom::execute(void)
{
LOG(Message) << "Generating random gauge configuration" << std::endl;
LatticeGaugeField &U = *env().create<LatticeGaugeField>(getName());
LatticeGaugeField &U = *env().createLattice<LatticeGaugeField>(getName());
SU3::HotConfiguration(*env().get4dRng(), U);
}

View File

@ -61,6 +61,6 @@ void GUnit::setup(void)
void GUnit::execute(void)
{
LOG(Message) << "Creating unit gauge configuration" << std::endl;
LatticeGaugeField &U = *env().create<LatticeGaugeField>(getName());
LatticeGaugeField &U = *env().createLattice<LatticeGaugeField>(getName());
SU3::ColdConfiguration(*env().get4dRng(), U);
}

View File

@ -57,7 +57,7 @@ std::vector<std::string> MQuark::getOutput(void)
// setup ///////////////////////////////////////////////////////////////////////
void MQuark::setup(void)
{
Ls_ = env().getObjectLs(env().getSolverAction(par().solver));
Ls_ = env().getObjectLs(par().solver);
env().registerLattice<LatticePropagator>(getName());
if (Ls_ > 1)
{
@ -74,11 +74,12 @@ void MQuark::execute(void)
LOG(Message) << "Computing quark propagator '" << getName() << "'"
<< std::endl;
LatticePropagator &prop = *env().create<LatticePropagator>(propName);
LatticePropagator &fullSrc = *env().get<LatticePropagator>(par().source);
LatticePropagator &prop = *env().createLattice<LatticePropagator>(propName);
LatticePropagator &fullSrc = *env().getObject<LatticePropagator>(par().source);
Environment::Solver &solver = *env().getObject<Environment::Solver>(par().solver);
if (Ls_ > 1)
{
env().create<LatticePropagator>(getName());
env().createLattice<LatticePropagator>(getName());
}
LOG(Message) << "Inverting using solver '" << par().solver
@ -86,6 +87,8 @@ void MQuark::execute(void)
for (unsigned int s = 0; s < Ns; ++s)
for (unsigned int c = 0; c < Nc; ++c)
{
LOG(Message) << "Inversion for spin= " << s << ", color= " << c
<< std::endl;
// source conversion for 4D sources
if (!env().isObject5d(par().source))
{
@ -116,12 +119,12 @@ void MQuark::execute(void)
}
}
sol = zero;
env().callSolver(par().solver, sol, source);
solver(sol, source);
FermToProp(prop, sol, s, c);
// create 4D propagators from 5D one if necessary
if (Ls_ > 1)
{
LatticePropagator &p4d = *env().get<LatticePropagator>(getName());
LatticePropagator &p4d = *env().getObject<LatticePropagator>(getName());
axpby_ssp_pminus(sol, 0., sol, 1., sol, 0, 0);
axpby_ssp_pplus(sol, 0., sol, 1., sol, 0, Ls_-1);

View File

@ -57,15 +57,16 @@ std::vector<std::string> SolRBPrecCG::getOutput(void)
// setup ///////////////////////////////////////////////////////////////////////
void SolRBPrecCG::setup(void)
{
env().registerObject(getName(), 0);
auto Ls = env().getObjectLs(par().action);
env().registerObject(getName(), 0, Ls);
env().addOwnership(getName(), par().action);
env().setSolverAction(getName(), par().action);
}
// execution ///////////////////////////////////////////////////////////////////
void SolRBPrecCG::execute(void)
{
auto &mat = *(env().getFermionMatrix(par().action));
auto &mat = *(env().getObject<Environment::FMat>(par().action));
auto solver = [&mat, this](LatticeFermion &sol,
const LatticeFermion &source)
{
@ -78,5 +79,5 @@ void SolRBPrecCG::execute(void)
LOG(Message) << "setting up Schur red-black preconditioned CG for"
<< " action '" << par().action << "' with residual "
<< par().residual << std::endl;
env().addSolver(getName(), solver);
env().setObject(getName(), new Environment::Solver(solver));
}

View File

@ -67,7 +67,7 @@ void SrcPoint::execute(void)
LOG(Message) << "Creating point source at position [" << par().position
<< "]" << std::endl;
LatticePropagator &src = *env().create<LatticePropagator>(getName());
LatticePropagator &src = *env().createLattice<LatticePropagator>(getName());
id = 1.;
src = zero;
pokeSite(id, src, position);

View File

@ -77,7 +77,7 @@ void SrcZ2::execute(void)
LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= "
<< par().tB << std::endl;
}
LatticePropagator &src = *env().create<LatticePropagator>(getName());
LatticePropagator &src = *env().createLattice<LatticePropagator>(getName());
LatticeCoordinate(t, Tp);
bernoulli(*env().get4dRng(), eta);
eta = (2.*eta - shift)*(1./::sqrt(2.));