|
@@ -28,18 +28,174 @@
|
|
|
|
|
|
#include <boost/mpi/environment.hpp>
|
|
|
#include <boost/mpi/communicator.hpp>
|
|
|
+#include <boost/algorithm/string.hpp>
|
|
|
+#include <boost/lexical_cast.hpp>
|
|
|
|
|
|
#include <paradevs/common/time/DoubleTime.hpp>
|
|
|
#include <paradevs/kernel/pdevs/mpi/LogicalProcessor.hpp>
|
|
|
#include <tests/mpi/cluster/graph_manager.hpp>
|
|
|
|
|
|
#include <chrono>
|
|
|
+#include <fstream>
|
|
|
|
|
|
using namespace paradevs::tests::mpi::cluster;
|
|
|
using namespace paradevs::common;
|
|
|
using namespace boost::mpi;
|
|
|
using namespace std::chrono;
|
|
|
|
|
|
+std::vector < std::vector < int > > clusters;
|
|
|
+std::vector < std::vector < std::pair < int, int > > > graphs;
|
|
|
+std::vector < std::vector < std::pair < int, int > > > inputs;
|
|
|
+std::vector < std::vector < std::pair < int, int > > > outputs;
|
|
|
+std::vector < std::vector < std::pair <
|
|
|
+ std::pair < int, int >,
|
|
|
+ std::pair < int, int > > > > parents;
|
|
|
+
|
|
|
+void read_graphs()
|
|
|
+{
|
|
|
+
|
|
|
+ std::cout << "READ GRAPHS" << std::endl;
|
|
|
+
|
|
|
+ for (int index = 0; index < clusters.size(); ++index) {
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "../data/cluster/graphe/graphe_" << index << ".txt";
|
|
|
+ std::ifstream graphFile(ss.str());
|
|
|
+
|
|
|
+ graphs.push_back(std::vector < std::pair < int, int > >());
|
|
|
+ while (not graphFile.eof()) {
|
|
|
+ std::string str;
|
|
|
+ std::vector < std::string > strs;
|
|
|
+
|
|
|
+ std::getline(graphFile, str);
|
|
|
+ if (str.size() > 0) {
|
|
|
+ boost::split(strs, str, boost::is_any_of(" "));
|
|
|
+ graphs[graphs.size() - 1].
|
|
|
+ push_back(std::make_pair(boost::lexical_cast < int >(strs[0]),
|
|
|
+ boost::lexical_cast < int >(strs[1])));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ graphFile.close();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void read_inputs()
|
|
|
+{
|
|
|
+
|
|
|
+ std::cout << "READ INPUTS" << std::endl;
|
|
|
+
|
|
|
+ for (int index = 0; index < clusters.size(); ++index) {
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "../data/cluster/input_edges/input_edges_" << index << ".txt";
|
|
|
+ std::ifstream inputsFile(ss.str());
|
|
|
+
|
|
|
+ inputs.push_back(std::vector < std::pair < int, int > >());
|
|
|
+ while (not inputsFile.eof()) {
|
|
|
+ std::string str;
|
|
|
+ std::vector < std::string > strs;
|
|
|
+
|
|
|
+ std::getline(inputsFile, str);
|
|
|
+ if (str.size() > 0) {
|
|
|
+ boost::split(strs, str, boost::is_any_of(" "));
|
|
|
+ inputs[inputs.size() - 1].
|
|
|
+ push_back(std::make_pair(boost::lexical_cast < int >(strs[0]),
|
|
|
+ boost::lexical_cast < int >(strs[1])));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ inputsFile.close();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void read_outputs()
|
|
|
+{
|
|
|
+
|
|
|
+ std::cout << "READ OUTPUTS" << std::endl;
|
|
|
+
|
|
|
+ for (int index = 0; index < clusters.size(); ++index) {
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "../data/cluster/output_edges/output_edges_" << index << ".txt";
|
|
|
+ std::ifstream outputsFile(ss.str());
|
|
|
+
|
|
|
+ outputs.push_back(std::vector < std::pair < int, int > >());
|
|
|
+ while (not outputsFile.eof()) {
|
|
|
+ std::string str;
|
|
|
+ std::vector < std::string > strs;
|
|
|
+
|
|
|
+ std::getline(outputsFile, str);
|
|
|
+ if (str.size() > 0) {
|
|
|
+ boost::split(strs, str, boost::is_any_of(" "));
|
|
|
+ outputs[outputs.size() - 1].
|
|
|
+ push_back(std::make_pair(boost::lexical_cast < int >(strs[0]),
|
|
|
+ boost::lexical_cast < int >(strs[1])));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ outputsFile.close();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void read_parents()
|
|
|
+{
|
|
|
+
|
|
|
+ std::cout << "READ PARENTS" << std::endl;
|
|
|
+
|
|
|
+ for (int index = 0; index < clusters.size(); ++index) {
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << "../data/cluster/parent_connection/parent_connection_" << index
|
|
|
+ << ".txt";
|
|
|
+ std::ifstream parentsFile(ss.str());
|
|
|
+
|
|
|
+ parents.push_back(std::vector < std::pair < std::pair < int, int >,
|
|
|
+ std::pair < int, int > > >());
|
|
|
+ while (not parentsFile.eof()) {
|
|
|
+ std::string str;
|
|
|
+ std::vector < std::string > strs;
|
|
|
+
|
|
|
+ std::getline(parentsFile, str);
|
|
|
+ if (str.size() > 0) {
|
|
|
+ boost::split(strs, str, boost::is_any_of(" "));
|
|
|
+ parents[parents.size() - 1].
|
|
|
+ push_back(std::make_pair(
|
|
|
+ std::make_pair(boost::lexical_cast < int >(strs[0]),
|
|
|
+ boost::lexical_cast < int >(strs[1])),
|
|
|
+ std::make_pair(boost::lexical_cast < int >(strs[2]),
|
|
|
+ boost::lexical_cast < int >(strs[3]))));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ parentsFile.close();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void read()
|
|
|
+{
|
|
|
+
|
|
|
+ std::cout << "READ CLUSTERS" << std::endl;
|
|
|
+
|
|
|
+ std::ifstream clusterFile("../data/cluster/partition.txt");
|
|
|
+
|
|
|
+ while (not clusterFile.eof()) {
|
|
|
+ std::string str;
|
|
|
+ std::vector < std::string > strs;
|
|
|
+
|
|
|
+ std::getline(clusterFile, str);
|
|
|
+ boost::split(strs, str, boost::is_any_of(" "));
|
|
|
+
|
|
|
+ if (str.size() > 0) {
|
|
|
+ clusters.push_back(std::vector < int >());
|
|
|
+ for (std::vector < std::string >::const_iterator it = strs.begin();
|
|
|
+ it != strs.end(); ++it) {
|
|
|
+ if (it->size() > 0) {
|
|
|
+ clusters[clusters.size() - 1].
|
|
|
+ push_back(boost::lexical_cast < int >(*it));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ clusterFile.close();
|
|
|
+ read_graphs();
|
|
|
+ read_inputs();
|
|
|
+ read_outputs();
|
|
|
+ read_parents();
|
|
|
+}
|
|
|
+
|
|
|
void example_simple(int argc, char *argv[])
|
|
|
{
|
|
|
environment env(argc, argv);
|
|
@@ -50,15 +206,7 @@ void example_simple(int argc, char *argv[])
|
|
|
if (world.rank() == 0) {
|
|
|
paradevs::tests::mpi::cluster::RootGraphManagerParameters parameters;
|
|
|
|
|
|
- parameters.ranks.push_back(1);
|
|
|
- parameters.ranks.push_back(2);
|
|
|
- parameters.ranks.push_back(3);
|
|
|
- parameters.ranks.push_back(4);
|
|
|
- parameters.ranks.push_back(5);
|
|
|
- parameters.ranks.push_back(6);
|
|
|
- parameters.ranks.push_back(7);
|
|
|
- parameters.ranks.push_back(8);
|
|
|
-
|
|
|
+ parameters.parents = parents;
|
|
|
paradevs::common::RootCoordinator <
|
|
|
DoubleTime,
|
|
|
paradevs::pdevs::Coordinator <
|
|
@@ -80,14 +228,20 @@ void example_simple(int argc, char *argv[])
|
|
|
std::cout << "time = " << time_span.count() << std::endl;
|
|
|
|
|
|
} else {
|
|
|
+ paradevs::tests::mpi::cluster::SubGraphManagerParameters parameters;
|
|
|
std::stringstream ss;
|
|
|
|
|
|
+ parameters.indexes = clusters[world.rank() - 1];
|
|
|
+ parameters.inputs = inputs[world.rank() - 1];
|
|
|
+ parameters.outputs = outputs[world.rank() - 1];
|
|
|
+ parameters.internals = graphs[world.rank() - 1];
|
|
|
ss << "S" << world.rank();
|
|
|
paradevs::pdevs::mpi::Coordinator <
|
|
|
DoubleTime,
|
|
|
- paradevs::tests::mpi::cluster::SubGraphManager >
|
|
|
- model(ss.str(), paradevs::common::NoParameters(),
|
|
|
- paradevs::common::NoParameters());
|
|
|
+ paradevs::tests::mpi::cluster::SubGraphManager,
|
|
|
+ paradevs::common::NoParameters,
|
|
|
+ paradevs::tests::mpi::cluster::SubGraphManagerParameters >
|
|
|
+ model(ss.str(), paradevs::common::NoParameters(), parameters);
|
|
|
paradevs::pdevs::mpi::LogicalProcessor <
|
|
|
DoubleTime > LP(&model, world.rank(), 0);
|
|
|
|
|
@@ -99,5 +253,6 @@ void example_simple(int argc, char *argv[])
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
example_simple(argc, argv);
|
|
|
+ read();
|
|
|
return 0;
|
|
|
}
|