mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-13 01:05:36 +00:00
Hadrons: first complete prototype for run loop
This commit is contained in:
parent
379580cd89
commit
76c78f04e2
@ -29,6 +29,8 @@ using namespace Hadrons;
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
// constructor /////////////////////////////////////////////////////////////////
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
Application::Application(int argc, char *argv[])
|
Application::Application(int argc, char *argv[])
|
||||||
|
: env_(Environment::getInstance())
|
||||||
|
, modFactory_(ModuleFactory::getInstance())
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
@ -43,6 +45,12 @@ Application::Application(int argc, char *argv[])
|
|||||||
HadronsLogMessage.Active(GridLogMessage.isActive());
|
HadronsLogMessage.Active(GridLogMessage.isActive());
|
||||||
HadronsLogDebug.Active(GridLogDebug.isActive());
|
HadronsLogDebug.Active(GridLogDebug.isActive());
|
||||||
LOG(Message) << "Grid initialized" << endl;
|
LOG(Message) << "Grid initialized" << endl;
|
||||||
|
LOG(Message) << "Modules available:" << endl;
|
||||||
|
auto list = modFactory_.getModuleList();
|
||||||
|
for (auto &m: list)
|
||||||
|
{
|
||||||
|
LOG(Message) << " " << m << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor //////////////////////////////////////////////////////////////////
|
// destructor //////////////////////////////////////////////////////////////////
|
||||||
@ -57,15 +65,40 @@ void Application::run(void)
|
|||||||
{
|
{
|
||||||
parseParameterFile();
|
parseParameterFile();
|
||||||
schedule();
|
schedule();
|
||||||
|
configLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse parameter file ////////////////////////////////////////////////////////
|
// parse parameter file ////////////////////////////////////////////////////////
|
||||||
|
class ModuleId: Serializable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GRID_SERIALIZABLE_CLASS_MEMBERS(ModuleId,
|
||||||
|
std::string, name,
|
||||||
|
std::string, type);
|
||||||
|
};
|
||||||
|
|
||||||
void Application::parseParameterFile(void)
|
void Application::parseParameterFile(void)
|
||||||
{
|
{
|
||||||
XmlReader reader(parameterFileName_);
|
XmlReader reader(parameterFileName_);
|
||||||
|
ModuleId id;
|
||||||
|
|
||||||
LOG(Message) << "Reading '" << parameterFileName_ << "'..." << endl;
|
LOG(Message) << "Reading '" << parameterFileName_ << "'..." << endl;
|
||||||
read(reader, "parameters", parameters_);
|
read(reader, "parameters", par_);
|
||||||
|
push(reader, "modules");
|
||||||
|
push(reader, "module");
|
||||||
|
do
|
||||||
|
{
|
||||||
|
read(reader, "id", id);
|
||||||
|
module_[id.name] = modFactory_.create(id.type, id.name);
|
||||||
|
module_[id.name]->parseParameters(reader, "options");
|
||||||
|
vector<string> output = module_[id.name]->getOutput();
|
||||||
|
for (auto &n: output)
|
||||||
|
{
|
||||||
|
associatedModule_[n] = id.name;
|
||||||
|
}
|
||||||
|
} while (reader.nextElement("module"));
|
||||||
|
pop(reader);
|
||||||
|
pop(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// schedule computation ////////////////////////////////////////////////////////
|
// schedule computation ////////////////////////////////////////////////////////
|
||||||
@ -74,37 +107,63 @@ void Application::schedule(void)
|
|||||||
Graph<string> moduleGraph;
|
Graph<string> moduleGraph;
|
||||||
|
|
||||||
LOG(Message) << "Scheduling computation..." << endl;
|
LOG(Message) << "Scheduling computation..." << endl;
|
||||||
for (auto &m: parameters_.modules)
|
|
||||||
|
// create dependency graph
|
||||||
|
for (auto &m: module_)
|
||||||
{
|
{
|
||||||
for (auto &p: m.in)
|
vector<string> input = m.second->getInput();
|
||||||
|
for (auto &n: input)
|
||||||
{
|
{
|
||||||
moduleGraph.addEdge(p, m.name);
|
try
|
||||||
|
{
|
||||||
|
moduleGraph.addEdge(associatedModule_.at(n), m.first);
|
||||||
|
}
|
||||||
|
catch (out_of_range &)
|
||||||
|
{
|
||||||
|
HADRON_ERROR("unknown object '" + n + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// topological sort
|
||||||
|
map<string, map<string, bool>> m;
|
||||||
|
unsigned int k = 0;
|
||||||
|
|
||||||
vector<Graph<string>> con = moduleGraph.getConnectedComponents();
|
vector<Graph<string>> con = moduleGraph.getConnectedComponents();
|
||||||
|
|
||||||
LOG(Message) << "Program:" << endl;
|
LOG(Message) << "Program:" << endl;
|
||||||
LOG(Message) << " #segments: " << con.size() << endl;
|
|
||||||
for (unsigned int i = 0; i < con.size(); ++i)
|
for (unsigned int i = 0; i < con.size(); ++i)
|
||||||
{
|
{
|
||||||
vector<vector<string>> t = con[i].allTopoSort();
|
vector<vector<string>> t = con[i].allTopoSort();
|
||||||
auto m = makeDependencyMatrix(t);
|
|
||||||
|
|
||||||
for (auto &v: t[0])
|
m = makeDependencyMatrix(t);
|
||||||
|
for (unsigned int j = 0; j < t[0].size(); ++j)
|
||||||
{
|
{
|
||||||
cout << v << " ";
|
program_.push_back(t[0][j]);
|
||||||
|
LOG(Message) << setw(4) << right << k << ": "
|
||||||
|
<< program_[k] << endl;
|
||||||
|
k++;
|
||||||
}
|
}
|
||||||
cout << endl;
|
}
|
||||||
for (auto &v1: t[0])
|
}
|
||||||
{
|
|
||||||
for (auto &v2: t[0])
|
// program execution ///////////////////////////////////////////////////////////
|
||||||
{
|
void Application::configLoop(void)
|
||||||
cout << m[v1][v2] << " ";
|
{
|
||||||
}
|
auto range = par_.configs.range;
|
||||||
cout << endl;
|
|
||||||
}
|
for (unsigned int t = range.start; t < range.end; t += range.step)
|
||||||
|
{
|
||||||
LOG(Message) << " segment " << i << ":" << endl;
|
LOG(Message) << "Starting measurement for trajectory " << t << endl;
|
||||||
|
execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::execute(void)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < program_.size(); ++i)
|
||||||
|
{
|
||||||
|
LOG(Message) << "Measurement step (" << i+1 << "/" << program_.size()
|
||||||
|
<< ")" << endl;
|
||||||
|
(*module_[program_[i]])(env_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,47 @@
|
|||||||
#define Hadrons_Application_hpp_
|
#define Hadrons_Application_hpp_
|
||||||
|
|
||||||
#include <Hadrons/Global.hpp>
|
#include <Hadrons/Global.hpp>
|
||||||
#include <Hadrons/InputObjects.hpp>
|
#include <Hadrons/Environment.hpp>
|
||||||
|
#include <Hadrons/ModuleFactory.hpp>
|
||||||
|
|
||||||
|
namespace Grid {
|
||||||
|
GRID_SERIALIZABLE_ENUM(ConfigType, undef, load, 1, unit, 2, gen, 3);
|
||||||
|
}
|
||||||
|
|
||||||
BEGIN_HADRONS_NAMESPACE
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
class TrajRange: Serializable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange,
|
||||||
|
unsigned int, start,
|
||||||
|
unsigned int, end,
|
||||||
|
unsigned int, step);
|
||||||
|
};
|
||||||
|
|
||||||
|
class ConfigPar: Serializable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GRID_SERIALIZABLE_CLASS_MEMBERS(ConfigPar,
|
||||||
|
std::string, ioStem,
|
||||||
|
TrajRange, range);
|
||||||
|
};
|
||||||
|
|
||||||
|
class GlobalPar: Serializable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
|
||||||
|
std::vector<double>, latticeSize,
|
||||||
|
ConfigPar, configs);
|
||||||
|
};
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Main program manager *
|
* Main program manager *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
class Application
|
class Application
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// constructor
|
// constructor
|
||||||
Application(int argc, char *argv[]);
|
Application(int argc, char *argv[]);
|
||||||
@ -42,9 +74,17 @@ private:
|
|||||||
void parseParameterFile(void);
|
void parseParameterFile(void);
|
||||||
// schedule computation
|
// schedule computation
|
||||||
void schedule(void);
|
void schedule(void);
|
||||||
|
// program execution
|
||||||
|
void configLoop(void);
|
||||||
|
void execute(void);
|
||||||
private:
|
private:
|
||||||
std::string parameterFileName_;
|
std::string parameterFileName_;
|
||||||
Parameters parameters_;
|
GlobalPar par_;
|
||||||
|
Environment &env_;
|
||||||
|
ModuleFactory &modFactory_;
|
||||||
|
std::map<std::string, std::unique_ptr<Module>> module_;
|
||||||
|
std::map<std::string, std::string> associatedModule_;
|
||||||
|
std::vector<std::string> program_;
|
||||||
};
|
};
|
||||||
|
|
||||||
END_HADRONS_NAMESPACE
|
END_HADRONS_NAMESPACE
|
||||||
|
65
programs/Hadrons/CMeson.cc
Normal file
65
programs/Hadrons/CMeson.cc
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* CMeson.cc, part of Grid
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Antonin Portelli
|
||||||
|
*
|
||||||
|
* Grid 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Grid 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 Grid. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Hadrons/CMeson.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
using namespace Hadrons;
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* CMeson implementation *
|
||||||
|
******************************************************************************/
|
||||||
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
|
CMeson::CMeson(const string &name)
|
||||||
|
: Module(name)
|
||||||
|
{}
|
||||||
|
|
||||||
|
// parse parameters ////////////////////////////////////////////////////////////
|
||||||
|
void CMeson::parseParameters(XmlReader &reader, const std::string &name)
|
||||||
|
{
|
||||||
|
read(reader, name, par_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// dependency relation /////////////////////////////////////////////////////////
|
||||||
|
vector<string> CMeson::getInput(void)
|
||||||
|
{
|
||||||
|
vector<string> input = {par_.q1, par_.q2};
|
||||||
|
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> CMeson::getOutput(void)
|
||||||
|
{
|
||||||
|
vector<string> output = {getName()};
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
// memory footprint ////////////////////////////////////////////////////////////
|
||||||
|
double CMeson::nCreatedProp(void)
|
||||||
|
{
|
||||||
|
return 0.;
|
||||||
|
}
|
||||||
|
|
||||||
|
// execution ///////////////////////////////////////////////////////////////////
|
||||||
|
void CMeson::operator()(Environment &env)
|
||||||
|
{
|
||||||
|
LOG(Message) << "computing meson contraction '" << getName() << "'" << endl;
|
||||||
|
}
|
65
programs/Hadrons/CMeson.hpp
Normal file
65
programs/Hadrons/CMeson.hpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* CMeson.hpp, part of Grid
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Antonin Portelli
|
||||||
|
*
|
||||||
|
* Grid 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Grid 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 Grid. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Hadrons_CMeson_hpp_
|
||||||
|
#define Hadrons_CMeson_hpp_
|
||||||
|
|
||||||
|
#include <Hadrons/Global.hpp>
|
||||||
|
#include <Hadrons/Module.hpp>
|
||||||
|
#include <Hadrons/ModuleFactory.hpp>
|
||||||
|
|
||||||
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* CMeson *
|
||||||
|
******************************************************************************/
|
||||||
|
class CMeson: public Module
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
class Par: Serializable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GRID_SERIALIZABLE_CLASS_MEMBERS(Par,
|
||||||
|
std::string, q1,
|
||||||
|
std::string, q2,
|
||||||
|
std::string, output);
|
||||||
|
};
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
CMeson(const std::string &name);
|
||||||
|
// destructor
|
||||||
|
virtual ~CMeson(void) = default;
|
||||||
|
// parse parameters
|
||||||
|
virtual void parseParameters(XmlReader &reader, const std::string &name);
|
||||||
|
// dependency relation
|
||||||
|
virtual std::vector<std::string> getInput(void);
|
||||||
|
virtual std::vector<std::string> getOutput(void);
|
||||||
|
// memory footprint
|
||||||
|
virtual double nCreatedProp(void);
|
||||||
|
// execution
|
||||||
|
virtual void operator()(Environment &env);
|
||||||
|
private:
|
||||||
|
Par par_;
|
||||||
|
};
|
||||||
|
|
||||||
|
MODULE_REGISTER(CMeson);
|
||||||
|
|
||||||
|
END_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
#endif // Hadrons_CMeson_hpp_
|
@ -29,3 +29,4 @@ using namespace Hadrons;
|
|||||||
// constructor /////////////////////////////////////////////////////////////////
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
Environment::Environment(void)
|
Environment::Environment(void)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -21,21 +21,15 @@
|
|||||||
#define Hadrons_Environment_hpp_
|
#define Hadrons_Environment_hpp_
|
||||||
|
|
||||||
#include <Hadrons/Global.hpp>
|
#include <Hadrons/Global.hpp>
|
||||||
#include <Hadrons/Graph.hpp>
|
|
||||||
|
|
||||||
BEGIN_HADRONS_NAMESPACE
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Global environment *
|
* Global environment *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
// TODO: make it a singleton
|
|
||||||
class Environment
|
class Environment
|
||||||
{
|
{
|
||||||
public:
|
SINGLETON(Environment);
|
||||||
// constructor
|
|
||||||
Environment(void);
|
|
||||||
// destructor
|
|
||||||
virtual ~Environment(void) = default;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
END_HADRONS_NAMESPACE
|
END_HADRONS_NAMESPACE
|
||||||
|
@ -49,6 +49,19 @@ extern HadronsLogger HadronsLogWarning;
|
|||||||
extern HadronsLogger HadronsLogMessage;
|
extern HadronsLogger HadronsLogMessage;
|
||||||
extern HadronsLogger HadronsLogDebug;
|
extern HadronsLogger HadronsLogDebug;
|
||||||
|
|
||||||
|
// singleton pattern
|
||||||
|
#define SINGLETON(name)\
|
||||||
|
public:\
|
||||||
|
name(const name &e) = delete;\
|
||||||
|
void operator=(const name &e) = delete;\
|
||||||
|
static name & getInstance(void)\
|
||||||
|
{\
|
||||||
|
static name e;\
|
||||||
|
return e;\
|
||||||
|
}\
|
||||||
|
private:\
|
||||||
|
name(void);
|
||||||
|
|
||||||
END_HADRONS_NAMESPACE
|
END_HADRONS_NAMESPACE
|
||||||
|
|
||||||
#endif // Hadrons_Global_hpp_
|
#endif // Hadrons_Global_hpp_
|
||||||
|
63
programs/Hadrons/MQuark.cc
Normal file
63
programs/Hadrons/MQuark.cc
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* MQuark.cc, part of Grid
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Antonin Portelli
|
||||||
|
*
|
||||||
|
* Grid 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Grid 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 Grid. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Hadrons/MQuark.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
using namespace Hadrons;
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* MQuark implementation *
|
||||||
|
******************************************************************************/
|
||||||
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
|
MQuark::MQuark(const std::string &name)
|
||||||
|
: Module(name)
|
||||||
|
{}
|
||||||
|
|
||||||
|
// parse parameters
|
||||||
|
void MQuark::parseParameters(XmlReader &reader, const std::string &name)
|
||||||
|
{
|
||||||
|
read(reader, name, par_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// dependency relation
|
||||||
|
vector<string> MQuark::getInput(void)
|
||||||
|
{
|
||||||
|
return vector<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> MQuark::getOutput(void)
|
||||||
|
{
|
||||||
|
vector<string> out = {getName(), getName() + "_5d"};
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// memory footprint
|
||||||
|
double MQuark::nCreatedProp(void)
|
||||||
|
{
|
||||||
|
return static_cast<double>((par_.Ls > 1) ? par_.Ls + 1 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// execution
|
||||||
|
void MQuark::operator()(Environment &env)
|
||||||
|
{
|
||||||
|
LOG(Message) << "computing quark propagator '" << getName() << "'" << endl;
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* InputObjects.hpp, part of Grid
|
* MQuark.hpp, part of Grid
|
||||||
*
|
*
|
||||||
* Copyright (C) 2015 Antonin Portelli
|
* Copyright (C) 2015 Antonin Portelli
|
||||||
*
|
*
|
||||||
@ -17,44 +17,46 @@
|
|||||||
* along with Grid. If not, see <http://www.gnu.org/licenses/>.
|
* along with Grid. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef Hadrons_InputObjects_hpp_
|
#ifndef Hadrons_MQuark_hpp_
|
||||||
#define Hadrons_InputObjects_hpp_
|
#define Hadrons_MQuark_hpp_
|
||||||
|
|
||||||
#include <Hadrons/Global.hpp>
|
#include <Hadrons/Global.hpp>
|
||||||
|
#include <Hadrons/Module.hpp>
|
||||||
|
#include <Hadrons/ModuleFactory.hpp>
|
||||||
|
|
||||||
BEGIN_HADRONS_NAMESPACE
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* Serializable input classes *
|
* MQuark *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
class Module: Serializable
|
class MQuark: public Module
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
class Par: Serializable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, Ls);
|
||||||
|
};
|
||||||
public:
|
public:
|
||||||
// constructor
|
// constructor
|
||||||
Module(void) = default;
|
MQuark(const std::string &name);
|
||||||
// destructor
|
// destructor
|
||||||
virtual ~Module(void) = default;
|
virtual ~MQuark(void) = default;
|
||||||
// serializable members
|
// parse parameters
|
||||||
GRID_DECL_CLASS_MEMBERS(Module,
|
virtual void parseParameters(XmlReader &reader, const std::string &name);
|
||||||
std::string , name,
|
// dependency relation
|
||||||
std::vector<std::string>, in
|
virtual std::vector<std::string> getInput(void);
|
||||||
);
|
virtual std::vector<std::string> getOutput(void);
|
||||||
|
// memory footprint
|
||||||
|
virtual double nCreatedProp(void);
|
||||||
|
// execution
|
||||||
|
virtual void operator()(Environment &env);
|
||||||
|
private:
|
||||||
|
Par par_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Parameters: Serializable
|
MODULE_REGISTER(MQuark);
|
||||||
{
|
|
||||||
public:
|
|
||||||
// constructor
|
|
||||||
Parameters(void) = default;
|
|
||||||
// destructor
|
|
||||||
virtual ~Parameters(void) = default;
|
|
||||||
// serializable members
|
|
||||||
GRID_DECL_CLASS_MEMBERS(Parameters,
|
|
||||||
std::vector<unsigned int>, latticeSize,
|
|
||||||
std::vector<Module> , modules
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
END_HADRONS_NAMESPACE
|
END_HADRONS_NAMESPACE
|
||||||
|
|
||||||
#endif // Hadrons_InputObjects_hpp_
|
#endif // Hadrons_MQuark_hpp_
|
@ -5,9 +5,16 @@ bin_PROGRAMS = Hadrons
|
|||||||
|
|
||||||
Hadrons_SOURCES = \
|
Hadrons_SOURCES = \
|
||||||
Application.cc \
|
Application.cc \
|
||||||
Application.hpp \
|
Environment.cc \
|
||||||
Global.hpp \
|
|
||||||
Global.cc \
|
Global.cc \
|
||||||
Hadrons.cc
|
Hadrons.cc \
|
||||||
|
Module.cc \
|
||||||
|
ModuleFactory.cc
|
||||||
|
|
||||||
|
Hadrons_SOURCES += \
|
||||||
|
MQuark.cc
|
||||||
|
|
||||||
|
Hadrons_SOURCES += \
|
||||||
|
CMeson.cc
|
||||||
|
|
||||||
Hadrons_LDADD = -lGrid
|
Hadrons_LDADD = -lGrid
|
||||||
|
38
programs/Hadrons/Module.cc
Normal file
38
programs/Hadrons/Module.cc
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Module.cc, part of Grid
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Antonin Portelli
|
||||||
|
*
|
||||||
|
* Grid 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Grid 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 Grid. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Hadrons/Module.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
using namespace Hadrons;
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Module implementation *
|
||||||
|
******************************************************************************/
|
||||||
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
|
Module::Module(const string &name)
|
||||||
|
: name_(name)
|
||||||
|
{}
|
||||||
|
|
||||||
|
// access //////////////////////////////////////////////////////////////////////
|
||||||
|
string Module::getName(void) const
|
||||||
|
{
|
||||||
|
return name_;
|
||||||
|
}
|
72
programs/Hadrons/Module.hpp
Normal file
72
programs/Hadrons/Module.hpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Module.hpp, part of Grid
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Antonin Portelli
|
||||||
|
*
|
||||||
|
* Grid 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Grid 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 Grid. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Hadrons_Module_hpp_
|
||||||
|
#define Hadrons_Module_hpp_
|
||||||
|
|
||||||
|
#include <Hadrons/Global.hpp>
|
||||||
|
|
||||||
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
// module registration macro
|
||||||
|
#define MODULE_REGISTER(mod)\
|
||||||
|
class mod##Registrar\
|
||||||
|
{\
|
||||||
|
public:\
|
||||||
|
mod##Registrar(void)\
|
||||||
|
{\
|
||||||
|
ModuleFactory &modFac = ModuleFactory::getInstance();\
|
||||||
|
modFac.registerModule(#mod, [&](const std::string &name)\
|
||||||
|
{\
|
||||||
|
return std::unique_ptr<mod>(new mod(name));\
|
||||||
|
});\
|
||||||
|
}\
|
||||||
|
};\
|
||||||
|
static mod##Registrar mod##RegistrarInstance;
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Module *
|
||||||
|
******************************************************************************/
|
||||||
|
class Environment;
|
||||||
|
|
||||||
|
class Module
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
Module(const std::string &name);
|
||||||
|
// destructor
|
||||||
|
virtual ~Module(void) = default;
|
||||||
|
// access
|
||||||
|
std::string getName(void) const;
|
||||||
|
// parse parameters
|
||||||
|
virtual void parseParameters(XmlReader &reader, const std::string &name) = 0;
|
||||||
|
// dependency relation
|
||||||
|
virtual std::vector<std::string> getInput(void) = 0;
|
||||||
|
virtual std::vector<std::string> getOutput(void) = 0;
|
||||||
|
// memory footprint
|
||||||
|
virtual double nCreatedProp(void) = 0;
|
||||||
|
// execution
|
||||||
|
virtual void operator()(Environment &env) = 0;
|
||||||
|
private:
|
||||||
|
std::string name_;
|
||||||
|
};
|
||||||
|
|
||||||
|
END_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
#endif // Hadrons_Module_hpp_
|
70
programs/Hadrons/ModuleFactory.cc
Normal file
70
programs/Hadrons/ModuleFactory.cc
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* ModuleFactory.cc, part of Grid
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Antonin Portelli
|
||||||
|
*
|
||||||
|
* Grid 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Grid 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 Grid. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Hadrons/ModuleFactory.hpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace Grid;
|
||||||
|
using namespace Hadrons;
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* ModuleFactory implementation *
|
||||||
|
******************************************************************************/
|
||||||
|
// constructor /////////////////////////////////////////////////////////////////
|
||||||
|
ModuleFactory::ModuleFactory(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// registration ////////////////////////////////////////////////////////////////
|
||||||
|
void ModuleFactory::registerModule(const std::string &type,
|
||||||
|
const FactoryFunc &f)
|
||||||
|
{
|
||||||
|
factory_[type] = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get module list /////////////////////////////////////////////////////////////
|
||||||
|
std::vector<std::string> ModuleFactory::getModuleList(void) const
|
||||||
|
{
|
||||||
|
std::vector<std::string> list;
|
||||||
|
|
||||||
|
for (auto &f: factory_)
|
||||||
|
{
|
||||||
|
list.push_back(f.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
// factory /////////////////////////////////////////////////////////////////////
|
||||||
|
unique_ptr<Module> ModuleFactory::create(const string &type,
|
||||||
|
const string &name) const
|
||||||
|
{
|
||||||
|
FactoryFunc func;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
func = factory_.at(type);
|
||||||
|
}
|
||||||
|
catch (out_of_range)
|
||||||
|
{
|
||||||
|
HADRON_ERROR("module type '" + type + "' unknown");
|
||||||
|
}
|
||||||
|
|
||||||
|
return func(name);
|
||||||
|
}
|
51
programs/Hadrons/ModuleFactory.hpp
Normal file
51
programs/Hadrons/ModuleFactory.hpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* ModuleFactory.hpp, part of Grid
|
||||||
|
*
|
||||||
|
* Copyright (C) 2015 Antonin Portelli
|
||||||
|
*
|
||||||
|
* Grid 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Grid 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 Grid. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Hadrons_ModuleFactory_hpp_
|
||||||
|
#define Hadrons_ModuleFactory_hpp_
|
||||||
|
|
||||||
|
#include <Hadrons/Global.hpp>
|
||||||
|
#include <Hadrons/Module.hpp>
|
||||||
|
|
||||||
|
BEGIN_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* ModuleFactory *
|
||||||
|
******************************************************************************/
|
||||||
|
class ModuleFactory
|
||||||
|
{
|
||||||
|
SINGLETON(ModuleFactory)
|
||||||
|
public:
|
||||||
|
typedef std::function<std::unique_ptr<Module>(const std::string &)>
|
||||||
|
FactoryFunc;
|
||||||
|
public:
|
||||||
|
// registration
|
||||||
|
void registerModule(const std::string &type, const FactoryFunc &f);
|
||||||
|
// get module list
|
||||||
|
std::vector<std::string> getModuleList(void) const;
|
||||||
|
// factory
|
||||||
|
std::unique_ptr<Module> create(const std::string &type,
|
||||||
|
const std::string &name) const;
|
||||||
|
private:
|
||||||
|
std::map<std::string, FactoryFunc> factory_;
|
||||||
|
};
|
||||||
|
|
||||||
|
END_HADRONS_NAMESPACE
|
||||||
|
|
||||||
|
#endif // Hadrons_ModuleFactory_hpp_
|
Loading…
Reference in New Issue
Block a user