Просмотр исходного кода

mpi/cluster: add type to model graph

Eric Ramat 8 лет назад
Родитель
Сommit
b16b05ba82

+ 2 - 1
CMakeLists.txt

@@ -23,7 +23,8 @@ INCLUDE(CMakeCPack.cmake)
  # Debug mode
 #
 
-IF (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
+IF (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" OR
+    ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
   SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--no-as-needed -Wall -Wextra -std=c++11")
   IF (UNIX)

+ 1 - 1
src/tests/CMakeLists.txt

@@ -4,6 +4,6 @@ ADD_SUBDIRECTORY(common)
 ADD_SUBDIRECTORY(dtss)
 ADD_SUBDIRECTORY(mixed)
 ADD_SUBDIRECTORY(mpi)
-#ADD_SUBDIRECTORY(multithreading)
+ADD_SUBDIRECTORY(multithreading)
 ADD_SUBDIRECTORY(pdevs)
 #ADD_SUBDIRECTORY(plot)

+ 28 - 25
src/tests/mpi/cluster/graph_manager.hpp

@@ -41,10 +41,10 @@ namespace paradevs { namespace tests { namespace mpi { namespace cluster {
 
 struct SubGraphManagerParameters
 {
-  std::vector < int > indexes;
-  std::vector < std::pair < int, int > > internals;
-  std::vector < std::pair < int, int > > inputs;
-  std::vector < std::pair < int, int > > outputs;  
+    std::vector < std::pair < int, int > > indexes;
+    std::vector < std::pair < int, int > > internals;
+    std::vector < std::pair < int, int > > inputs;
+    std::vector < std::pair < int, int > > outputs;
 };
 
 class SubGraphManager :
@@ -58,14 +58,17 @@ public:
        common::DoubleTime,
        SubGraphManagerParameters >(coordinator, parameters)
   {
-    for (std::vector < int >::const_iterator it = parameters.indexes.begin();
-	 it != parameters.indexes.end(); ++it) {
+      for (std::vector < std::pair < int, int > >::const_iterator it =
+               parameters.indexes.begin(); it != parameters.indexes.end();
+           ++it) {
       std::stringstream ss;
-      
-      ss << "m_" << *it;
-      Simulator* m = new Simulator(ss.str(), paradevs::common::NoParameters());
-      
-      models[*it] = m;
+      AParameters p;
+
+      p.frequency = it->second;
+      ss << "m_" << it->first;
+      Simulator* m = new Simulator(ss.str(), p);
+
+      models[it->first] = m;
       add_child(m);
       m->add_in_port("in");
       m->add_out_port("out");
@@ -73,7 +76,7 @@ public:
     for (std::vector < std::pair < int, int > >::const_iterator it =
 	   parameters.inputs.begin(); it != parameters.inputs.end(); ++it) {
       std::stringstream ss;
-      
+
       ss << "in_" << it->first;
       if (not coordinator->exist_in_port(ss.str())) {
 	coordinator->add_in_port(ss.str());
@@ -85,7 +88,7 @@ public:
     for (std::vector < std::pair < int, int > >::const_iterator it =
 	   parameters.outputs.begin(); it != parameters.outputs.end(); ++it) {
       std::stringstream ss;
-      
+
       ss << "out_" << it->first;
       if (not coordinator->exist_out_port(ss.str())) {
 	coordinator->add_out_port(ss.str());
@@ -102,13 +105,13 @@ public:
       }
     }
   }
-  
+
   void init()
   { }
-  
+
   void start(common::DoubleTime::type /* t */)
   { }
-  
+
   void transition(const common::Models < common::DoubleTime >& /* receivers */,
 		  common::DoubleTime::type /* t */)
   { }
@@ -122,9 +125,9 @@ public:
 
 private:
   typedef paradevs::pdevs::Simulator < common::DoubleTime,
-				       A > Simulator;
+				       A, AParameters > Simulator;
   typedef std::map < int, Simulator* > Simulators;
-  
+
   Simulators models;
 };
 
@@ -137,7 +140,7 @@ struct LevelGraphManagerParameters
 	std::pair < int, int >,
 	std::pair < int, int > > > > parents;
 };
-	
+
 class LevelGraphManager :
         public paradevs::pdevs::GraphManager < common::DoubleTime,
                                                LevelGraphManagerParameters >
@@ -165,7 +168,7 @@ public:
 	     it2 != it->end(); ++it2) {
 	  std::stringstream out_ss;
 	  std::stringstream in_ss;
-	  
+
 	  if (it2->first.first == parameters.index) {
 	    out_ss << "out_" << it2->first.second;
 	    if (not model.exist_out_port(out_ss.str())) {
@@ -208,7 +211,7 @@ private:
 
   ModelProxy model;
 };
-	
+
 struct RootGraphManagerParameters
 {
   std::vector <
@@ -217,7 +220,7 @@ struct RootGraphManagerParameters
 	std::pair < int, int >,
 	std::pair < int, int > > > > parents;
 };
-	
+
 class RootGraphManager :
         public paradevs::pdevs::GraphManager < common::DoubleTime,
                                                RootGraphManagerParameters >
@@ -231,7 +234,7 @@ public:
                                             coordinator, parameters)
     {
       int index = 0;
-      
+
       for (std::vector < std::vector <
 	     std::pair < std::pair < int, int >,
 	     std::pair < int, int > > > >::const_iterator it =
@@ -303,8 +306,8 @@ public:
       }
     }
 
-    void transition(const common::Models < common::DoubleTime >& receivers,
-                    common::DoubleTime::type t)
+    void transition(const common::Models < common::DoubleTime >&
+                    /* receivers */, common::DoubleTime::type t)
     {
       for (Coordinators::iterator it = models.begin(); it != models.end();
 	   ++it) {

+ 133 - 122
src/tests/mpi/cluster/main.cpp

@@ -44,7 +44,7 @@ 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 > > > 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;
@@ -54,134 +54,145 @@ std::vector < std::vector < std::pair <
 
 void read_graphs(const std::string& path)
 {
-  for (int index = 0; index < clusters.size(); ++index) {
-    std::stringstream ss;
-    ss << path << "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])));
-      }
+    for (unsigned int index = 0; index < clusters.size(); ++index) {
+        std::stringstream ss;
+        ss << path << "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();
     }
-    graphFile.close();
-  }
 }
 
 void read_inputs(const std::string& path)
 {
-  for (int index = 0; index < clusters.size(); ++index) {
-    std::stringstream ss;
-    ss << path << "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])));
-      }
+    for (unsigned int index = 0; index < clusters.size(); ++index) {
+        std::stringstream ss;
+        ss << path << "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();
     }
-    inputsFile.close();
-  }
 }
 
 void read_outputs(const std::string& path)
 {
-  for (int index = 0; index < clusters.size(); ++index) {
-    std::stringstream ss;
-    ss << path << "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])));
-      }
+    for (unsigned int index = 0; index < clusters.size(); ++index) {
+        std::stringstream ss;
+        ss << path << "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();
     }
-    outputsFile.close();
-  }
 }
 
 void read_parents(const std::string& path)
 {
-  for (int index = 0; index < clusters.size(); ++index) {
-    std::stringstream ss;
-    ss << path << "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]))));
-      }
+    for (unsigned int index = 0; index < clusters.size(); ++index) {
+        std::stringstream ss;
+        ss << path << "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();
     }
-    parentsFile.close();
-  }
 }
 
 void read(const std::string& path)
 {
-  std::stringstream ss;
-  ss << path << "partition.txt";
-  std::ifstream clusterFile(ss.str());
-
-  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));
-	}
-      }
+    std::stringstream ss;
+    ss << path << "partition.txt";
+    std::ifstream clusterFile(ss.str());
+
+    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 < std::pair < int, int > >());
+            for (std::vector < std::string >::const_iterator it = strs.begin();
+                 it != strs.end();) {
+                if (it->size() > 0) {
+                    int index = boost::lexical_cast < int >(*it);
+
+                    ++it;
+                    clusters[clusters.size() - 1].
+                        push_back(std::make_pair(
+                                      index, boost::lexical_cast < int >(*it)));
+                }
+                ++it;
+            }
+        }
     }
-  }
-  clusterFile.close();
-  read_graphs(path);
-  read_inputs(path);
-  read_outputs(path);
-  read_parents(path);
+    clusterFile.close();
+    read_graphs(path);
+    read_inputs(path);
+    read_outputs(path);
+    read_parents(path);
 }
 
 void example_simple(int argc, char *argv[])
@@ -223,14 +234,14 @@ void example_simple(int argc, char *argv[])
 	parameters.internals = graphs[world.rank() - 1];
         ss << "S" << world.rank();
 	paradevs::pdevs::mpi::Coordinator <
-	  DoubleTime,
-	  paradevs::tests::mpi::cluster::SubGraphManager,
-                paradevs::common::NoParameters,
-                paradevs::tests::mpi::cluster::SubGraphManagerParameters >
-	model(ss.str(), paradevs::common::NoParameters(), parameters);
+            DoubleTime,
+            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);
-	
+            DoubleTime > LP(&model, world.rank(), 0);
+
 	model.set_logical_processor(&LP);
 	LP.loop();
     }
@@ -238,11 +249,11 @@ void example_simple(int argc, char *argv[])
 
 int main(int argc, char *argv[])
 {
-  if (argc == 2) {
-    read(argv[1]);
-    example_simple(argc, argv);
-    return 0;
-  } else {
-    return -1;
-  }
+    if (argc == 2) {
+        read(argv[1]);
+        example_simple(argc, argv);
+        return 0;
+    } else {
+        return -1;
+    }
 }

+ 24 - 15
src/tests/mpi/cluster/models.hpp

@@ -129,7 +129,7 @@ public:
         dext(t, e, msgs);
     }
 
-    void dext(typename common::DoubleTime::type t,
+    void dext(typename common::DoubleTime::type /* t */,
               typename common::DoubleTime::type /* e */,
               const common::Bag < common::DoubleTime >& msgs)
     {
@@ -167,7 +167,7 @@ public:
     {
 
       //      std::cout << get_name() << " at " << t << ": dint" << std::endl;
-      
+
         mark_full(t);
         if (full_N()) {
             raz();
@@ -193,7 +193,7 @@ public:
     { return sigma; }
 
     common::Bag < common::DoubleTime > lambda(
-        typename common::DoubleTime::type t) const
+        typename common::DoubleTime::type /* t */) const
     {
         common::Bag < common::DoubleTime > msgs;
 
@@ -219,12 +219,18 @@ private:
     typename common::DoubleTime::type _last_time;
 };
 
-class A : public paradevs::pdevs::Dynamics < common::DoubleTime >
+struct AParameters
+{
+    unsigned int frequency;
+};
+
+class A : public paradevs::pdevs::Dynamics < common::DoubleTime, AParameters >
 {
 public:
     A(const std::string& name,
-      const common::NoParameters& parameters) :
-      paradevs::pdevs::Dynamics < common::DoubleTime >(name, parameters)
+      const AParameters& parameters) :
+        paradevs::pdevs::Dynamics < common::DoubleTime, AParameters >(
+            name, parameters), _frequency(parameters.frequency)
     { }
     virtual ~A()
     { }
@@ -238,21 +244,23 @@ public:
               typename common::DoubleTime::type /* e */,
               const common::Bag < common::DoubleTime >& /* msgs */)
     {
-      _sigma -= t - _last_time;
-      _last_time = t;
+        _sigma -= t - _last_time;
+        _last_time = t;
     }
 
-    void dint(typename common::DoubleTime::type t)
+    void dint(typename common::DoubleTime::type /* t */)
     {
-      _sigma = ((double)rand() / RAND_MAX); 
+        // _sigma = ((double)rand() / RAND_MAX);
+        _sigma = 1. / _frequency;
     }
 
     typename common::DoubleTime::type start(
         typename common::DoubleTime::type t)
     {
-      _sigma = ((double)rand() / RAND_MAX); 
-      _last_time = t;
-      return 0;
+//        _sigma = ((double)rand() / RAND_MAX);
+        _sigma = 1. / _frequency;
+        _last_time = t;
+        return 0;
     }
 
     typename common::DoubleTime::type ta(
@@ -260,7 +268,7 @@ public:
     { return _sigma; }
 
     common::Bag < common::DoubleTime > lambda(
-        typename common::DoubleTime::type t) const
+        typename common::DoubleTime::type /* t */) const
     {
         common::Bag < common::DoubleTime > msgs;
 
@@ -271,7 +279,8 @@ public:
 private:
     typename common::DoubleTime::type _sigma;
     typename common::DoubleTime::type _last_time;
-};	
+    unsigned int _frequency;
+};
 
 } } } } // namespace paradevs tests mpi cluster
 

+ 1 - 30
src/tests/multithreading/CMakeLists.txt

@@ -1,31 +1,2 @@
-INCLUDE_DIRECTORIES(
-  ${CMAKE_SOURCE_DIR}/src
-  ${PARADEVS_INCLUDE_DIRS}
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
-
-LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR})
-
-ADD_EXECUTABLE(pdevs-multithreading-tests graph_manager.hpp tests.cpp)
-
-TARGET_LINK_LIBRARIES(pdevs-multithreading-tests
-  ${CMAKE_THREAD_LIBS_INIT}
-  ${Boost_SYSTEM_LIBRARY}
-  ${Boost_TIMER_LIBRARY})
-
-ADD_EXECUTABLE(pdevs-multithreading-main graph_manager.hpp main.cpp
-  ../boost_graph/graph_builder.hpp ../boost_graph/graph_generator.hpp
-  ../boost_graph/graph_defs.hpp ../boost_graph/graph_manager.hpp
-  ../boost_graph/graph_partitioning.hpp ../boost_graph/models.hpp
-  ../boost_graph/partitioning/utils.hpp ../boost_graph/partitioning/gggp.hpp
-  ../boost_graph/partitioning/graph_build.hpp)
-
-TARGET_LINK_LIBRARIES(pdevs-multithreading-main
-  ${CMAKE_THREAD_LIBS_INIT}
-  ${Boost_SYSTEM_LIBRARY}
-  ${Boost_TIMER_LIBRARY})
-
 ADD_SUBDIRECTORY(lifegame)
+#ADD_SUBDIRECTORY(tree)

+ 2 - 5
src/tests/multithreading/lifegame/CMakeLists.txt

@@ -10,12 +10,9 @@ LINK_DIRECTORIES(
   ${LIBXML_LIBRARY_DIR})
 
 ADD_EXECUTABLE(pdevs-multithreading-lifegame-main graph_manager.hpp main.cpp
-  models.hpp
-  ../../boost_graph/partitioning/utils.hpp
-  ../../boost_graph/partitioning/gggp.hpp
-  ../../boost_graph/partitioning/graph_build.hpp)
+  models.hpp)
 
 TARGET_LINK_LIBRARIES(pdevs-multithreading-lifegame-main
   ${CMAKE_THREAD_LIBS_INIT}
   ${Boost_SYSTEM_LIBRARY}
-  ${Boost_TIMER_LIBRARY})
+  ${Boost_TIMER_LIBRARY})

+ 0 - 1
src/tests/multithreading/lifegame/main.cpp

@@ -87,7 +87,6 @@ void lifegame(int n)
         std::cout << lifegame_monothreading() << std::endl;
     } else {
         std::cout << lifegame_multithreading(n) << std::endl;
-        // lifegame_multithreading(n);
     }
 }
 

src/tests/multithreading/graph_manager.hpp → src/tests/multithreading/tree/graph_manager.hpp


src/tests/multithreading/main.cpp → src/tests/multithreading/tree/main.cpp


src/tests/multithreading/tests.cpp → src/tests/multithreading/tree/tests.cpp