diff --git a/programs/Hadrons/Application.cc b/programs/Hadrons/Application.cc index 8f132056..f0e6f6a4 100644 --- a/programs/Hadrons/Application.cc +++ b/programs/Hadrons/Application.cc @@ -55,43 +55,56 @@ Application::~Application(void) // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) { - Graph g; - - g.addEdge("A", "B"); - g.addEdge("B", "D"); - g.addEdge("B", "X1"); - g.addEdge("X1", "X2"); - g.addEdge("D", "E"); - g.addEdge("E", "C"); - g.addEdge("Z", "Y"); - g.addEdge("Z", "W"); - g.addEdge("Z", "R"); - g.addEdge("W", "R"); - g.addEdge("U", "I"); - - cout << g << endl; - auto vec = g.getConnectedComponents(); - for (auto &h: vec) - { - cout << h << endl; - } - for (auto &h: vec) - { - auto top = h.allTopoSort(); - for (auto &s: top) - { - for (auto &v: s) - { - cout << v << " "; - } - cout << endl; - } - cout << "--------" << endl; - } + parseParameterFile(); + schedule(); } // parse parameter file //////////////////////////////////////////////////////// void Application::parseParameterFile(void) { + XmlReader reader(parameterFileName_); + LOG(Message) << "Reading '" << parameterFileName_ << "'..." << endl; + read(reader, "parameters", parameters_); +} + +// schedule computation //////////////////////////////////////////////////////// +void Application::schedule(void) +{ + Graph moduleGraph; + + LOG(Message) << "Scheduling computation..." << endl; + for (auto &m: parameters_.modules) + { + for (auto &p: m.in) + { + moduleGraph.addEdge(p, m.name); + } + } + + vector> con = moduleGraph.getConnectedComponents(); + + LOG(Message) << "Program:" << endl; + LOG(Message) << " #segments: " << con.size() << endl; + for (unsigned int i = 0; i < con.size(); ++i) + { + vector> t = con[i].allTopoSort(); + auto m = makeDependencyMatrix(t); + + for (auto &v: t[0]) + { + cout << v << " "; + } + cout << endl; + for (auto &v1: t[0]) + { + for (auto &v2: t[0]) + { + cout << m[v1][v2] << " "; + } + cout << endl; + } + + LOG(Message) << " segment " << i << ":" << endl; + } } diff --git a/programs/Hadrons/Application.hpp b/programs/Hadrons/Application.hpp index deb1160f..670c644e 100644 --- a/programs/Hadrons/Application.hpp +++ b/programs/Hadrons/Application.hpp @@ -21,6 +21,7 @@ #define Hadrons_Application_hpp_ #include +#include BEGIN_HADRONS_NAMESPACE @@ -39,8 +40,11 @@ public: private: // parse parameter file void parseParameterFile(void); + // schedule computation + void schedule(void); private: std::string parameterFileName_; + Parameters parameters_; }; END_HADRONS_NAMESPACE diff --git a/programs/Hadrons/Graph.hpp b/programs/Hadrons/Graph.hpp index 14077ed0..a2747c1a 100644 --- a/programs/Hadrons/Graph.hpp +++ b/programs/Hadrons/Graph.hpp @@ -101,6 +101,11 @@ private: std::set edgeSet_; }; +// build depedency matrix from topological sorts +template +std::map> +makeDependencyMatrix(const std::vector> &topSort); + /****************************************************************************** * template implementation * ******************************************************************************/ @@ -556,6 +561,33 @@ std::vector> Graph::allTopoSort(void) return res; } +// build depedency matrix from topological sorts /////////////////////////////// +template +std::map> +makeDependencyMatrix(const std::vector> &topSort) +{ + std::map> m; + const std::vector &vList = topSort[0]; + + for (auto &v1: vList) + for (auto &v2: vList) + { + bool dep = true; + + for (auto &t: topSort) + { + auto i1 = std::find(t.begin(), t.end(), v1); + auto i2 = std::find(t.begin(), t.end(), v2); + + dep = dep and (i1 - i2 > 0); + if (!dep) break; + } + m[v1][v2] = dep; + } + + return m; +} + END_HADRONS_NAMESPACE #endif // Hadrons_Graph_hpp_ diff --git a/programs/Hadrons/InputObjects.hpp b/programs/Hadrons/InputObjects.hpp new file mode 100644 index 00000000..d18615fa --- /dev/null +++ b/programs/Hadrons/InputObjects.hpp @@ -0,0 +1,60 @@ +/* + * InputObjects.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 . + */ + +#ifndef Hadrons_InputObjects_hpp_ +#define Hadrons_InputObjects_hpp_ + +#include + +BEGIN_HADRONS_NAMESPACE + +/****************************************************************************** + * Serializable input classes * + ******************************************************************************/ +class Module: Serializable +{ +public: + // constructor + Module(void) = default; + // destructor + virtual ~Module(void) = default; + // serializable members + GRID_DECL_CLASS_MEMBERS(Module, + std::string , name, + std::vector, in + ); +}; + +class Parameters: Serializable +{ +public: + // constructor + Parameters(void) = default; + // destructor + virtual ~Parameters(void) = default; + // serializable members + GRID_DECL_CLASS_MEMBERS(Parameters, + std::vector, latticeSize, + std::vector , modules + ); +}; + +END_HADRONS_NAMESPACE + +#endif // Hadrons_InputObjects_hpp_