Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
working version
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 11 Dec 2019 14:08:11 +0000 (15:08 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 24 Jan 2020 12:04:49 +0000 (13:04 +0100)
examples/s4u/exec-dependent/s4u-exec-dependent.cpp
examples/s4u/exec-dependent/s4u-exec-dependent.tesh
include/simgrid/s4u/Activity.hpp
src/s4u/s4u_Exec.cpp

index 1615b33..9f373a1 100644 (file)
@@ -7,25 +7,35 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
 
-simgrid::s4u::ExecPtr second;
+simgrid::s4u::ExecPtr child;
 
 static void worker()
 {
   double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
 
-  simgrid::s4u::ExecPtr first = simgrid::s4u::this_actor::exec_init(computation_amount);
-  second                      = simgrid::s4u::this_actor::exec_init(computation_amount);
+  simgrid::s4u::ExecPtr first_parent  = simgrid::s4u::this_actor::exec_init(computation_amount);
+  simgrid::s4u::ExecPtr second_parent = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
 
-  first->add_successor(second.get());
-  first->start();
-  first->wait();
+  child = simgrid::s4u::this_actor::exec_init(computation_amount);
+
+  first_parent->add_successor(child.get());
+  second_parent->add_successor(child.get());
+  second_parent->start();
+  first_parent->wait();
+  second_parent->wait();
 }
 
 static void vetoed_worker()
 {
-  second->vetoable_start();
-  XBT_INFO("%d %d", (int)second->get_state(), second->has_dependencies());
-  second->wait();
+  child->vetoable_start();
+  while (not child->test()) {
+    if (child->get_state() == simgrid::s4u::Exec::State::STARTING)
+      XBT_INFO("child cannot start yet");
+    else
+      XBT_INFO("child is now in state %d", (int)child->get_state());
+    simgrid::s4u::this_actor::sleep_for(0.25);
+  }
+  XBT_INFO("Should be okay now, child is in state %d", (int)child->get_state());
 }
 
 int main(int argc, char* argv[])
index d92f921..2c274ff 100644 (file)
@@ -1,3 +1,21 @@
 #!/usr/bin/env tesh
 
 $ ${bindir:=.}/s4u-exec-dependent ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  0.250000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  0.500000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  0.750000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  1.000000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  1.250000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  1.500000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  1.750000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  2.000000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  2.250000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  2.500000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  2.750000] (2:vetoed_worker@Fafard) child cannot start yet
+> [  3.000000] (2:vetoed_worker@Fafard) child is now in state 2
+> [  3.250000] (2:vetoed_worker@Fafard) child is now in state 2
+> [  3.500000] (2:vetoed_worker@Fafard) child is now in state 2
+> [  3.750000] (2:vetoed_worker@Fafard) child is now in state 2
+> [  4.000000] (2:vetoed_worker@Fafard) Should be okay now, child is in state 5
+> [  4.000000] (0:maestro@) Simulation time 4
index 582c61a..6858bb6 100644 (file)
@@ -55,7 +55,7 @@ public:
    */
   virtual Activity* start() = 0;
   /** Blocks until the activity is terminated */
-  //  virtual Activity* wait() = 0;
+  virtual Activity* wait() = 0;
   /** Blocks until the activity is terminated, or until the timeout is elapsed
    *  Raises: timeout exception.*/
   virtual Activity* wait_for(double timeout) = 0;
@@ -128,7 +128,6 @@ public:
 
   void add_successor(AnyActivity* a)
   {
-    //    XBT_INFO("Adding %s as a successor of %s", get_name(), a->get_name());
     successors_.push_back(a);
     a->add_dependency_on(static_cast<AnyActivity*>(this));
   }
@@ -139,7 +138,7 @@ public:
   void add_dependency_on(AnyActivity* a) { dependencies_.insert({a}); }
   void remove_dependency_on(AnyActivity* a) { dependencies_.erase(a); }
   bool has_dependencies() { return not dependencies_.empty(); }
-  void on_activity_done()
+  void release_dependencies()
   {
     while (has_successors()) {
       AnyActivity* b = get_successor();
@@ -163,13 +162,6 @@ public:
     return static_cast<AnyActivity*>(this);
   }
 
-  virtual AnyActivity* wait()
-  {
-    static_cast<AnyActivity*>(this)->wait();
-    on_activity_done();
-    return static_cast<AnyActivity*>(this);
-  }
-
   AnyActivity* set_name(const std::string& name)
   {
     xbt_assert(get_state() == State::INITED, "Cannot change the name of an activity after its start");
index 0aca559..4ce71e5 100644 (file)
@@ -22,13 +22,14 @@ Exec::Exec()
 
 bool Exec::test()
 {
-  xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
+  xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING ||
+             state_ == State::FINISHED);
 
   if (state_ == State::FINISHED)
     return true;
 
-  if (state_ == State::INITED)
-    this->start();
+  if (state_ == State::INITED || state_ == State::STARTING)
+    this->vetoable_start();
 
   if (simcall_execution_test(pimpl_)) {
     state_ = State::FINISHED;
@@ -50,6 +51,7 @@ Exec* Exec::wait_for(double timeout)
   simcall_execution_wait(pimpl_, timeout);
   state_ = State::FINISHED;
   on_completion(*Actor::self(), *this);
+  this->release_dependencies();
   return this;
 }