瀏覽代碼

New pdevs/multithreading

Eric Ramat 3 年之前
父節點
當前提交
1f8eab3bc5
共有 2 個文件被更改,包括 46 次插入91 次删除
  1. 21 67
      src/tests/multithreading/simple/graph_manager.hpp
  2. 25 24
      src/tests/multithreading/simple/main.cpp

+ 21 - 67
src/tests/multithreading/simple/graph_manager.hpp

@@ -126,6 +126,12 @@ public:
     GENERATOR, LINK_1_2, LINK_3_4, LINK_5_6, LINK_7_8, COUNTER
   };
 
+  typedef artis::pdevs::multithreading::Coordinator<
+      artis::common::DoubleTime,
+      SimpleGraphManager,
+      GeneratorParameters,
+      artis::common::NoParameters> coordinator_type;
+
   SimpleGraphManager(
       artis::common::Coordinator<artis::common::DoubleTime> *coordinator,
       const GeneratorParameters &parameters,
@@ -198,83 +204,31 @@ public:
 
   void init()
   {
-    _link_1_2.set_sender(
-        (dynamic_cast< artis::pdevs::multithreading::Coordinator<
-            artis::common::DoubleTime,
-            SimpleGraphManager,
-            GeneratorParameters,
-            artis::common::NoParameters> *>(this->coordinator()))->get_sender());
-    _link_3_4.set_sender(
-        (dynamic_cast< artis::pdevs::multithreading::Coordinator<
-            artis::common::DoubleTime,
-            SimpleGraphManager,
-            GeneratorParameters,
-            artis::common::NoParameters> *>(this->coordinator()))->get_sender());
-    _link_5_6.set_sender(
-        (dynamic_cast< artis::pdevs::multithreading::Coordinator<
-            artis::common::DoubleTime,
-            SimpleGraphManager,
-            GeneratorParameters,
-            artis::common::NoParameters> *>(this->coordinator()))->get_sender());
-    _link_7_8.set_sender(
-        (dynamic_cast< artis::pdevs::multithreading::Coordinator<
-            artis::common::DoubleTime,
-            SimpleGraphManager,
-            GeneratorParameters,
-            artis::common::NoParameters> *>(this->coordinator()))->get_sender());
-  }
+    dynamic_cast< coordinator_type *>(this->coordinator())
+        ->attach_child(&_link_1_2, _link_1_2.get_queue());
+    dynamic_cast< coordinator_type *>(this->coordinator())
+        ->attach_child(&_link_3_4, _link_3_4.get_queue());
+    dynamic_cast< coordinator_type *>(this->coordinator())
+        ->attach_child(&_link_5_6, _link_5_6.get_queue());
+    dynamic_cast< coordinator_type *>(this->coordinator())
+        ->attach_child(&_link_7_8, _link_7_8.get_queue());
 
-  void start(common::DoubleTime::type t)
-  {
-    _link_1_2.get_sender().send(
-        artis::pdevs::multithreading::start_message<
-            artis::common::DoubleTime>(t));
-    _link_3_4.get_sender().send(
-        artis::pdevs::multithreading::start_message<
-            artis::common::DoubleTime>(t));
-    _link_5_6.get_sender().send(
-        artis::pdevs::multithreading::start_message<
-            artis::common::DoubleTime>(t));
-    _link_7_8.get_sender().send(
-        artis::pdevs::multithreading::start_message<
-            artis::common::DoubleTime>(t));
-  }
-
-  void transition(const common::Models<common::DoubleTime> &receivers,
-                  artis::common::DoubleTime::type t)
-  {
-    std::for_each(receivers.begin(), receivers.end(),
-                  [this, t](const common::Model<common::DoubleTime> *model) {
-                    if (not model->is_atomic()) {
-                      if (model == &_link_1_2) {
-                        _link_1_2.get_sender().send(
-                            artis::pdevs::multithreading::transition_message<
-                                artis::common::DoubleTime>(t));
-                      } else if (model == &_link_3_4) {
-                        _link_3_4.get_sender().send(
-                            artis::pdevs::multithreading::transition_message<
-                                artis::common::DoubleTime>(t));
-                      } else if (model == &_link_5_6) {
-                        _link_5_6.get_sender().send(
-                            artis::pdevs::multithreading::transition_message<
-                                artis::common::DoubleTime>(t));
-                      } else if (model == &_link_7_8) {
-                        _link_7_8.get_sender().send(
-                            artis::pdevs::multithreading::transition_message<
-                                artis::common::DoubleTime>(t));
-                      }
-                    }
-                  });
+    _link_1_2.attach_parent(dynamic_cast< coordinator_type *>(this->coordinator())->get_queue());
+    _link_3_4.attach_parent(dynamic_cast< coordinator_type *>(this->coordinator())->get_queue());
+    _link_5_6.attach_parent(dynamic_cast< coordinator_type *>(this->coordinator())->get_queue());
+    _link_7_8.attach_parent(dynamic_cast< coordinator_type *>(this->coordinator())->get_queue());
   }
 
 private:
   artis::pdevs::Simulator<artis::common::DoubleTime, Generator, GeneratorParameters> _generator;
-/*
+
+  /*
                     artis::pdevs::Coordinator<artis::common::DoubleTime, LinksGraphManager, GeneratorParameters, artis::common::NoParameters> _link_1_2;
                     artis::pdevs::Coordinator<artis::common::DoubleTime, LinksGraphManager, GeneratorParameters, artis::common::NoParameters> _link_3_4;
                     artis::pdevs::Coordinator<artis::common::DoubleTime, LinksGraphManager, GeneratorParameters, artis::common::NoParameters> _link_5_6;
                     artis::pdevs::Coordinator<artis::common::DoubleTime, LinksGraphManager, GeneratorParameters, artis::common::NoParameters> _link_7_8;
 */
+
   artis::pdevs::multithreading::Coordinator<artis::common::DoubleTime,
                                             LinksGraphManager,
                                             GeneratorParameters,

+ 25 - 24
src/tests/multithreading/simple/main.cpp

@@ -25,6 +25,7 @@
  */
 
 #include <artis-star/common/RootCoordinator.hpp>
+#include <artis-star/kernel/pdevs/multithreading/RootCoordinator.hpp>
 
 #include <tests/multithreading/simple/graph_manager.hpp>
 #include <tests/multithreading/simple/models.hpp>
@@ -36,33 +37,33 @@ using namespace artis::common;
 using namespace std::chrono;
 using namespace artis::tests::multithreading::simple;
 
-void simple_monothreading()
-{
-  GeneratorParameters parameters = {10, 2, 5, 763752};
-  artis::common::context::Context<artis::common::DoubleTime> context(0, 1000);
-  artis::common::RootCoordinator<
-      DoubleTime, artis::pdevs::Coordinator<
-          DoubleTime,
-          SimpleGraphManager,
-          GeneratorParameters,
-          NoParameters>
-  > rc(context, "root", parameters, NoParameters());
-
-  steady_clock::time_point t1 = steady_clock::now();
-
-  rc.run(context);
-
-  steady_clock::time_point t2 = steady_clock::now();
-
-  duration<double> time_span = duration_cast<duration<double> >(t2 - t1);
-
-  std::cout << "Time = " << time_span.count() << std::endl;
-}
+//void simple_monothreading()
+//{
+//  GeneratorParameters parameters = {10, 2, 5, 763752};
+//  artis::common::context::Context<artis::common::DoubleTime> context(0, 2000);
+//  artis::common::RootCoordinator<
+//      DoubleTime, artis::pdevs::Coordinator<
+//          DoubleTime,
+//          SimpleGraphManager,
+//          GeneratorParameters,
+//          NoParameters>
+//  > rc(context, "root", parameters, NoParameters());
+//
+//  steady_clock::time_point t1 = steady_clock::now();
+//
+//  rc.run(context);
+//
+//  steady_clock::time_point t2 = steady_clock::now();
+//
+//  duration<double> time_span = duration_cast<duration<double> >(t2 - t1);
+//
+//  std::cout << "Time = " << time_span.count() << std::endl;
+//}
 
 void simple_multithreading()
 {
   GeneratorParameters parameters = {10, 2, 5, 763752};
-  artis::common::context::Context<artis::common::DoubleTime> context(0, 1000);
+  artis::common::context::Context<artis::common::DoubleTime> context(0, 2000);
   artis::common::RootCoordinator<
       DoubleTime, artis::pdevs::multithreading::Coordinator<
           DoubleTime,
@@ -84,7 +85,7 @@ void simple_multithreading()
 
 int main()
 {
-//    simple_monothreading();
+//  simple_monothreading();
   simple_multithreading();
   return 0;
 }