1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-06 20:25:56 +01:00

Hadrons: starting scheduler implementation

This commit is contained in:
Antonin Portelli 2015-12-07 18:26:38 +00:00
parent 20ce7e0270
commit d4db009a58
4 changed files with 142 additions and 33 deletions

View File

@ -55,43 +55,56 @@ Application::~Application(void)
// execute /////////////////////////////////////////////////////////////////////
void Application::run(void)
{
Graph<string> 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<string> moduleGraph;
LOG(Message) << "Scheduling computation..." << endl;
for (auto &m: parameters_.modules)
{
for (auto &p: m.in)
{
moduleGraph.addEdge(p, m.name);
}
}
vector<Graph<string>> con = moduleGraph.getConnectedComponents();
LOG(Message) << "Program:" << endl;
LOG(Message) << " #segments: " << con.size() << endl;
for (unsigned int i = 0; i < con.size(); ++i)
{
vector<vector<string>> 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;
}
}

View File

@ -21,6 +21,7 @@
#define Hadrons_Application_hpp_
#include <Hadrons/Global.hpp>
#include <Hadrons/InputObjects.hpp>
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

View File

@ -101,6 +101,11 @@ private:
std::set<Edge> edgeSet_;
};
// build depedency matrix from topological sorts
template <typename T>
std::map<T, std::map<T, bool>>
makeDependencyMatrix(const std::vector<std::vector<T>> &topSort);
/******************************************************************************
* template implementation *
******************************************************************************/
@ -556,6 +561,33 @@ std::vector<std::vector<T>> Graph<T>::allTopoSort(void)
return res;
}
// build depedency matrix from topological sorts ///////////////////////////////
template <typename T>
std::map<T, std::map<T, bool>>
makeDependencyMatrix(const std::vector<std::vector<T>> &topSort)
{
std::map<T, std::map<T, bool>> m;
const std::vector<T> &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_

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef Hadrons_InputObjects_hpp_
#define Hadrons_InputObjects_hpp_
#include <Hadrons/Global.hpp>
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<std::string>, in
);
};
class Parameters: Serializable
{
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
#endif // Hadrons_InputObjects_hpp_