Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 30 Jan 2020 23:34:18 +0000 (00:34 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 30 Jan 2020 23:34:18 +0000 (00:34 +0100)
16 files changed:
ChangeLog
MANIFEST.in
examples/s4u/CMakeLists.txt
examples/s4u/async-ready/s4u-async-ready.tesh
examples/s4u/comm-dependent/s4u-comm-dependent.cpp [new file with mode: 0644]
examples/s4u/comm-dependent/s4u-comm-dependent.tesh [new file with mode: 0644]
examples/s4u/exec-dependent/s4u-exec-dependent.cpp [new file with mode: 0644]
examples/s4u/exec-dependent/s4u-exec-dependent.tesh [new file with mode: 0644]
examples/s4u/io-dependent/s4u-io-dependent.cpp [new file with mode: 0644]
examples/s4u/io-dependent/s4u-io-dependent.tesh [new file with mode: 0644]
include/simgrid/s4u/Activity.hpp
src/kernel/activity/IoImpl.cpp
src/s4u/s4u_Comm.cpp
src/s4u/s4u_Exec.cpp
src/s4u/s4u_Io.cpp
src/s4u/s4u_Mailbox.cpp

index 57795a6..5ca0a64 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,9 +13,8 @@ Important user-visible changes:
 - SimDAG++: Automatic dependencies on S4U activities (experimental)
   - Some features are already implemented but not all of them
   - Cannot block an activity until it's scheduled on a resource
-  - Only Exec and Io so far. Comms are not handled yet.
-  - No heterogeneous wait_any() that would mix Exec and Io activities.
-  - See examples/s4u/{io-,exec-}dependent for what's already there.
+  - No heterogeneous wait_any() that would mix Exec/Comm/Io activities.
+  - See examples/s4u/{io,exec,comm}-dependent for what's already there.
 
 
 
index 1951c3d..189f842 100644 (file)
@@ -336,6 +336,8 @@ include examples/s4u/cloud-migration/s4u-cloud-migration.cpp
 include examples/s4u/cloud-migration/s4u-cloud-migration.tesh
 include examples/s4u/cloud-simple/s4u-cloud-simple.cpp
 include examples/s4u/cloud-simple/s4u-cloud-simple.tesh
+include examples/s4u/comm-dependent/s4u-comm-dependent.cpp
+include examples/s4u/comm-dependent/s4u-comm-dependent.tesh
 include examples/s4u/dht-chord/s4u-dht-chord-node.cpp
 include examples/s4u/dht-chord/s4u-dht-chord.cpp
 include examples/s4u/dht-chord/s4u-dht-chord.hpp
@@ -370,6 +372,8 @@ include examples/s4u/exec-async/s4u-exec-async.cpp
 include examples/s4u/exec-async/s4u-exec-async.tesh
 include examples/s4u/exec-basic/s4u-exec-basic.cpp
 include examples/s4u/exec-basic/s4u-exec-basic.tesh
+include examples/s4u/exec-dependent/s4u-exec-dependent.cpp
+include examples/s4u/exec-dependent/s4u-exec-dependent.tesh
 include examples/s4u/exec-dvfs/s4u-exec-dvfs.cpp
 include examples/s4u/exec-dvfs/s4u-exec-dvfs.tesh
 include examples/s4u/exec-ptask/s4u-exec-ptask.cpp
@@ -382,6 +386,8 @@ include examples/s4u/exec-waitfor/s4u-exec-waitfor.cpp
 include examples/s4u/exec-waitfor/s4u-exec-waitfor.tesh
 include examples/s4u/io-async/s4u-io-async.cpp
 include examples/s4u/io-async/s4u-io-async.tesh
+include examples/s4u/io-dependent/s4u-io-dependent.cpp
+include examples/s4u/io-dependent/s4u-io-dependent.tesh
 include examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp
 include examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh
 include examples/s4u/io-file-remote/s4u-io-file-remote.cpp
index e3d0199..822d01f 100644 (file)
@@ -6,11 +6,12 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill
                  actor-lifetime actor-migrate actor-suspend actor-yield
                  app-chainsend app-pingpong app-token-ring
                  async-ready async-wait async-waitany async-waitall async-waituntil
+                 comm-dependent
                  cloud-capping cloud-migration cloud-simple
                  energy-exec energy-boot energy-link energy-vm energy-exec-ptask
                  engine-filtering
-                 exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany exec-waitfor
-                 io-async io-file-system io-file-remote io-disk-raw
+                 exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany exec-waitfor exec-dependent
+                 io-async io-file-system io-file-remote io-disk-raw io-dependent
                  platform-failures platform-profile platform-properties
                  plugin-hostload
                  replay-comm replay-io
index d5d2591..9b6d9a8 100644 (file)
@@ -86,6 +86,6 @@ $ ${bindir:=.}/s4u-async-ready ${platfdir}/small_platform_fatpipe.xml s4u-async-
 > [  0.110000] (3:peer@Perl) I got a 'Message 5 from peer 1'.
 > [  0.110000] (3:peer@Perl) I got a 'finalize'.
 > [  0.110000] (3:peer@Perl) I'm done, just waiting for my peers to receive the messages before exiting
-> [  0.110000] (3:peer@Perl) Goodbye now!
 > [  0.110000] (1:peer@Tremblay) Goodbye now!
 > [  0.110000] (2:peer@Ruby) Goodbye now!
+> [  0.110000] (3:peer@Perl) Goodbye now!
diff --git a/examples/s4u/comm-dependent/s4u-comm-dependent.cpp b/examples/s4u/comm-dependent/s4u-comm-dependent.cpp
new file mode 100644 (file)
index 0000000..0e5f9ba
--- /dev/null
@@ -0,0 +1,54 @@
+/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <simgrid/s4u.hpp>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_comm_dependent, "Messages specific for this s4u example");
+
+static void sender(simgrid::s4u::Mailbox* mailbox)
+{
+  double* computation_amount = new double();
+  *computation_amount        = simgrid::s4u::this_actor::get_host()->get_speed();
+  simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * (*computation_amount));
+  simgrid::s4u::CommPtr comm = mailbox->put_init(computation_amount, 7e6);
+
+  exec->set_name("exec on sender")->add_successor(comm)->start();
+  comm->set_name("comm to receiver")->vetoable_start();
+  exec->wait();
+  comm->wait();
+}
+
+static void receiver(simgrid::s4u::Mailbox* mailbox)
+{
+  double* received           = nullptr;
+  double computation_amount  = simgrid::s4u::this_actor::get_host()->get_speed();
+  simgrid::s4u::ExecPtr exec = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
+  simgrid::s4u::CommPtr comm = mailbox->get_init()->set_dst_data((void**)&received, sizeof(double));
+
+  comm->set_name("comm from sender")->add_successor(exec)->start();
+  exec->set_name("exec on receiver")->vetoable_start();
+
+  comm->wait();
+  exec->wait();
+  XBT_INFO("Received: %.0f flops were computed on sender", *received);
+  delete received;
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  e.load_platform(argv[1]);
+
+  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("Mailbox");
+
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("Tremblay"), sender, mbox);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("Jupiter"), receiver, mbox);
+
+  e.run();
+
+  XBT_INFO("Simulation time: %.3f", e.get_clock());
+
+  return 0;
+}
diff --git a/examples/s4u/comm-dependent/s4u-comm-dependent.tesh b/examples/s4u/comm-dependent/s4u-comm-dependent.tesh
new file mode 100644 (file)
index 0000000..c5b4225
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env tesh
+
+p Testing with default compound
+
+$ ${bindir:=.}/s4u-comm-dependent ${platfdir}/small_platform.xml  --log=s4u_activity.t:debug "--log=root.fmt:[%6.2r]%e(%i:%P@%h)%e%m%n"
+> [  2.00] (1:sender@Tremblay) Remove a dependency from 'exec on sender' on 'comm to receiver'
+> [  2.00] (1:sender@Tremblay) All dependencies are solved, let's start 'comm to receiver'
+> [  3.07] (2:receiver@Jupiter) Remove a dependency from 'comm from sender' on 'exec on receiver'
+> [  3.07] (2:receiver@Jupiter) All dependencies are solved, let's start 'exec on receiver'
+> [  5.07] (2:receiver@Jupiter) Received: 98095000 flops were computed on sender
+> [  5.07] (0:maestro@) Simulation time: 5.070
diff --git a/examples/s4u/exec-dependent/s4u-exec-dependent.cpp b/examples/s4u/exec-dependent/s4u-exec-dependent.cpp
new file mode 100644 (file)
index 0000000..7eb7136
--- /dev/null
@@ -0,0 +1,62 @@
+/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "simgrid/s4u.hpp"
+#include <vector>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+static void worker()
+{
+  // Define an amount of work that should take 1 second to execute.
+  double computation_amount = simgrid::s4u::this_actor::get_host()->get_speed();
+
+  std::vector<simgrid::s4u::ExecPtr> pending_execs;
+  // Create a small DAG
+  // + Two parents and a child
+  // + First parent ends after 1 second and the Second parent after 2 seconds.
+  simgrid::s4u::ExecPtr first_parent  = simgrid::s4u::this_actor::exec_init(computation_amount);
+  pending_execs.push_back(first_parent);
+  simgrid::s4u::ExecPtr second_parent = simgrid::s4u::this_actor::exec_init(2 * computation_amount);
+  pending_execs.push_back(second_parent);
+  simgrid::s4u::ExecPtr child = simgrid::s4u::this_actor::exec_init(computation_amount);
+  pending_execs.push_back(child);
+
+  // Name the activities (for logging purposes only)
+  first_parent->set_name("parent 1");
+  second_parent->set_name("parent 2");
+  child->set_name("child");
+
+  // Create the dependencies by declaring 'child' as a successor of first_parent and second_parent
+  first_parent->add_successor(child);
+  second_parent->add_successor(child);
+
+  // Start the activities.
+  first_parent->start();
+  second_parent->start();
+  // child uses a vetoable start to force it to wait for the completion of its predecessors
+  child->vetoable_start();
+
+  // wait for the completion of all activities
+  while (not pending_execs.empty()) {
+    int changed_pos = simgrid::s4u::Exec::wait_any_for(&pending_execs, -1);
+    XBT_INFO("Exec '%s' is complete", pending_execs[changed_pos]->get_cname());
+    pending_execs.erase(pending_execs.begin() + changed_pos);
+  }
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  e.load_platform(argv[1]);
+
+  simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Fafard"), worker);
+
+  e.run();
+
+  XBT_INFO("Simulation time %g", e.get_clock());
+
+  return 0;
+}
diff --git a/examples/s4u/exec-dependent/s4u-exec-dependent.tesh b/examples/s4u/exec-dependent/s4u-exec-dependent.tesh
new file mode 100644 (file)
index 0000000..dab01ae
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env tesh
+
+! output sort
+$ ${bindir:=.}/s4u-exec-dependent ${platfdir}/small_platform.xml --log=s4u_activity.t:debug "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  2.000000] (1:worker@Fafard) Remove a dependency from 'parent 1' on 'child'
+> [  2.000000] (1:worker@Fafard) Exec 'parent 1' is complete
+> [  3.000000] (1:worker@Fafard) Remove a dependency from 'parent 2' on 'child'
+> [  3.000000] (1:worker@Fafard) All dependencies are solved, let's start 'child'
+> [  3.000000] (1:worker@Fafard) Exec 'parent 2' is complete
+> [  4.000000] (1:worker@Fafard) Exec 'child' is complete
+> [  4.000000] (0:maestro@) Simulation time 4
diff --git a/examples/s4u/io-dependent/s4u-io-dependent.cpp b/examples/s4u/io-dependent/s4u-io-dependent.cpp
new file mode 100644 (file)
index 0000000..908dd44
--- /dev/null
@@ -0,0 +1,61 @@
+/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "simgrid/s4u.hpp"
+#include <simgrid/plugins/file_system.h>
+#include <vector>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+static void test()
+{
+  simgrid::s4u::ExecPtr bob_compute = simgrid::s4u::this_actor::exec_init(1e9);
+  simgrid::s4u::IoPtr bob_write =
+      simgrid::s4u::Host::current()->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::WRITE);
+  simgrid::s4u::IoPtr carl_read =
+      simgrid::s4u::Host::by_name("carl")->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::READ);
+  simgrid::s4u::ExecPtr carl_compute = simgrid::s4u::Host::by_name("carl")->exec_async(1e9);
+
+  // Name the activities (for logging purposes only)
+  bob_compute->set_name("bob compute");
+  bob_write->set_name("bob write");
+  carl_read->set_name("carl read");
+  carl_compute->set_name("carl compute");
+
+  // Create the dependencies:
+  // 'bob_write' is a successor of 'bob_compute'
+  // 'carl_read' is a successor of 'bob_write'
+  // 'carl_compute' is a successor of 'carl_read'
+  bob_compute->add_successor(bob_write);
+  bob_write->add_successor(carl_read);
+  carl_read->add_successor(carl_compute);
+
+  // Start the activities.
+  bob_compute->start();
+  bob_write->vetoable_start();
+  carl_read->vetoable_start();
+  carl_compute->vetoable_start();
+
+  // Wait for their completion (should be replaced by a wait_any_for at some point)
+  bob_compute->wait();
+  bob_write->wait();
+  carl_read->wait();
+  carl_compute->wait();
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  sg_storage_file_system_init();
+  e.load_platform(argv[1]);
+
+  simgrid::s4u::Actor::create("bob", simgrid::s4u::Host::by_name("bob"), test);
+
+  e.run();
+
+  XBT_INFO("Simulation time %g", e.get_clock());
+
+  return 0;
+}
diff --git a/examples/s4u/io-dependent/s4u-io-dependent.tesh b/examples/s4u/io-dependent/s4u-io-dependent.tesh
new file mode 100644 (file)
index 0000000..26fb3b3
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env tesh
+
+! output sort
+$ ${bindir:=.}/s4u-io-dependent ${platfdir}/hosts_with_disks.xml --log=s4u_activity.t:debug "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  1.000000] (1:bob@bob) All dependencies are solved, let's start 'bob write'
+> [  1.000000] (1:bob@bob) Remove a dependency from 'bob compute' on 'bob write'
+> [  1.100000] (1:bob@bob) All dependencies are solved, let's start 'carl read'
+> [  1.100000] (1:bob@bob) Remove a dependency from 'bob write' on 'carl read'
+> [  1.166667] (1:bob@bob) All dependencies are solved, let's start 'carl compute'
+> [  1.166667] (1:bob@bob) Remove a dependency from 'carl read' on 'carl compute'
+> [  2.166667] (0:maestro@) Simulation time 2.16667
index fb07a24..33753de 100644 (file)
@@ -8,10 +8,14 @@
 
 #include "xbt/asserts.h"
 #include <atomic>
+#include <set>
 #include <simgrid/forward.h>
 #include <string>
+#include <vector>
 #include <xbt/signal.hpp>
 
+XBT_LOG_EXTERNAL_CATEGORY(s4u_activity);
+
 namespace simgrid {
 namespace s4u {
 
@@ -31,13 +35,41 @@ protected:
   Activity()  = default;
   virtual ~Activity() = default;
 
+  void release_dependencies()
+  {
+    while (not successors_.empty()) {
+      ActivityPtr b = successors_.back();
+      XBT_CDEBUG(s4u_activity, "Remove a dependency from '%s' on '%s'", get_cname(), b->get_cname());
+      b->dependencies_.erase(this);
+      if (b->dependencies_.empty()) {
+        b->vetoable_start();
+      }
+      successors_.pop_back();
+    }
+  }
+
+  void add_successor(ActivityPtr a)
+  {
+    successors_.push_back(a);
+    a->dependencies_.insert({this});
+  }
+
 public:
+  void vetoable_start()
+  {
+    state_ = State::STARTING;
+    if (dependencies_.empty()) {
+      XBT_CDEBUG(s4u_activity, "All dependencies are solved, let's start '%s'", get_cname());
+      start();
+    }
+  }
+
 #ifndef DOXYGEN
   Activity(Activity const&) = delete;
   Activity& operator=(Activity const&) = delete;
 #endif
 
-  enum class State { INITED = 0, STARTED, CANCELED, ERRORED, FINISHED };
+  enum class State { INITED = 0, STARTING, STARTED, CANCELED, ERRORED, FINISHED };
 
   /** Starts a previously created activity.
    *
@@ -57,12 +89,14 @@ public:
   virtual Activity* cancel() = 0;
   /** Retrieve the current state of the activity */
   Activity::State get_state() { return state_; }
+  void set_state(Activity::State state) { state_ = state; }
   /** Tests whether the given activity is terminated yet. This is a pure function. */
   virtual bool test() = 0;
+  virtual const char* get_cname()       = 0;
+  virtual const std::string& get_name() = 0;
 
   /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */
   virtual double get_remaining();
-
   /** Set the [remaining] amount of work that this Activity will entail
    *
    * It is forbidden to change the amount of work once the Activity is started */
@@ -85,16 +119,23 @@ private:
   kernel::activity::ActivityImplPtr pimpl_ = nullptr;
   Activity::State state_                   = Activity::State::INITED;
   double remains_                          = 0;
+  std::vector<ActivityPtr> successors_;
+  std::set<ActivityPtr> dependencies_;
   std::atomic_int_fast32_t refcount_{0};
 };
 
 template <class AnyActivity> class Activity_T : public Activity {
-private:
-  std::string name_             = "";
+  std::string name_             = "unnamed";
   std::string tracing_category_ = "";
   void* user_data_              = nullptr;
 
 public:
+  AnyActivity* add_successor(ActivityPtr a)
+  {
+    Activity::add_successor(a);
+    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 ce4254f..8125e0e 100644 (file)
@@ -34,6 +34,7 @@ void simcall_HANDLER_io_wait(smx_simcall_t simcall, simgrid::kernel::activity::I
       synchro->state_ = simgrid::kernel::activity::State::TIMEOUT;
     }
     synchro->finish();
+    return;
   }
 
   /* If the synchro is already finished then perform the error handling */
index b9a8811..8ccb862 100644 (file)
@@ -36,7 +36,10 @@ int Comm::wait_any_for(const std::vector<CommPtr>* comms, double timeout)
   std::unique_ptr<kernel::activity::CommImpl* []> rcomms(new kernel::activity::CommImpl*[comms->size()]);
   std::transform(begin(*comms), end(*comms), rcomms.get(),
                  [](const CommPtr& comm) { return static_cast<kernel::activity::CommImpl*>(comm->pimpl_.get()); });
-  return simcall_comm_waitany(rcomms.get(), comms->size(), timeout);
+  int changed_pos = simcall_comm_waitany(rcomms.get(), comms->size(), timeout);
+  if (changed_pos != -1)
+    comms->at(changed_pos)->release_dependencies();
+  return changed_pos;
 }
 
 void Comm::wait_all(const std::vector<CommPtr>* comms)
@@ -82,6 +85,7 @@ CommPtr Comm::set_src_data(void* buff, size_t size)
   src_buff_size_ = size;
   return this;
 }
+
 CommPtr Comm::set_dst_data(void** buff)
 {
   xbt_assert(state_ == State::INITED, "You cannot use %s() once your communication started (not implemented)",
@@ -116,8 +120,8 @@ CommPtr Comm::set_tracing_category(const std::string& category)
 
 Comm* Comm::start()
 {
-  xbt_assert(get_state() == State::INITED, "You cannot use %s() once your communication started (not implemented)",
-             __FUNCTION__);
+  xbt_assert(get_state() == State::INITED || get_state() == State::STARTING,
+             "You cannot use %s() once your communication started (not implemented)", __FUNCTION__);
 
   if (src_buff_ != nullptr) { // Sender side
     on_sender_start(*Actor::self());
@@ -154,7 +158,8 @@ Comm* Comm::wait_for(double timeout)
     case State::FINISHED:
       break;
 
-    case State::INITED: // It's not started yet. Do it in one simcall
+    case State::INITED:
+    case State::STARTING: // It's not started yet. Do it in one simcall
       if (src_buff_ != nullptr) {
         on_sender_start(*Actor::self());
         simcall_comm_send(sender_, mailbox_->get_impl(), remains_, rate_, src_buff_, src_buff_size_, match_fun_,
@@ -166,12 +171,14 @@ Comm* Comm::wait_for(double timeout)
                           get_user_data(), timeout, rate_);
       }
       state_ = State::FINISHED;
+      this->release_dependencies();
       break;
 
     case State::STARTED:
       simcall_comm_wait(pimpl_, timeout);
       on_completion(*Actor::self());
       state_ = State::FINISHED;
+      this->release_dependencies();
       break;
 
     case State::CANCELED:
@@ -182,12 +189,16 @@ Comm* Comm::wait_for(double timeout)
   }
   return this;
 }
+
 int Comm::test_any(const std::vector<CommPtr>* comms)
 {
   std::unique_ptr<kernel::activity::CommImpl* []> rcomms(new kernel::activity::CommImpl*[comms->size()]);
   std::transform(begin(*comms), end(*comms), rcomms.get(),
                  [](const CommPtr& comm) { return static_cast<kernel::activity::CommImpl*>(comm->pimpl_.get()); });
-  return simcall_comm_testany(rcomms.get(), comms->size());
+  int changed_pos = simcall_comm_testany(rcomms.get(), comms->size());
+  if (changed_pos != -1)
+    comms->at(changed_pos)->release_dependencies();
+  return changed_pos;
 }
 
 Comm* Comm::detach()
@@ -196,7 +207,8 @@ Comm* Comm::detach()
              __FUNCTION__);
   xbt_assert(src_buff_ != nullptr && src_buff_size_ != 0, "You can only detach sends, not recvs");
   detached_ = true;
-  return start();
+  vetoable_start();
+  return this;
 }
 
 Comm* Comm::cancel()
@@ -216,11 +228,12 @@ bool Comm::test()
   if (state_ == State::FINISHED)
     return true;
 
-  if (state_ == State::INITED)
-    this->start();
+  if (state_ == State::INITED || state_ == State::STARTING)
+    this->vetoable_start();
 
   if (simcall_comm_test(pimpl_)) {
     state_ = State::FINISHED;
+    this->release_dependencies();
     return true;
   }
   return false;
index 0aca559..a0d3cc5 100644 (file)
@@ -22,16 +22,18 @@ 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;
+    this->release_dependencies();
     return true;
   }
 
@@ -46,10 +48,11 @@ Exec* Exec::wait()
 Exec* Exec::wait_for(double timeout)
 {
   if (state_ == State::INITED)
-    start();
+    vetoable_start();
   simcall_execution_wait(pimpl_, timeout);
   state_ = State::FINISHED;
   on_completion(*Actor::self(), *this);
+  this->release_dependencies();
   return this;
 }
 
@@ -58,7 +61,11 @@ int Exec::wait_any_for(std::vector<ExecPtr>* execs, double timeout)
   std::unique_ptr<kernel::activity::ExecImpl* []> rexecs(new kernel::activity::ExecImpl*[execs->size()]);
   std::transform(begin(*execs), end(*execs), rexecs.get(),
                  [](const ExecPtr& exec) { return static_cast<kernel::activity::ExecImpl*>(exec->pimpl_.get()); });
-  return simcall_execution_waitany_for(rexecs.get(), execs->size(), timeout);
+
+  int changed_pos = simcall_execution_waitany_for(rexecs.get(), execs->size(), timeout);
+  if (changed_pos != -1)
+    execs->at(changed_pos)->release_dependencies();
+  return changed_pos;
 }
 
 Exec* Exec::cancel()
index 9b363ce..73149eb 100644 (file)
@@ -61,23 +61,28 @@ Io* Io::wait()
 
 Io* Io::wait_for(double timeout)
 {
+  if (state_ == State::INITED)
+    vetoable_start();
   simcall_io_wait(pimpl_, timeout);
   state_ = State::FINISHED;
+  this->release_dependencies();
   return this;
 }
 
 bool Io::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_io_test(pimpl_)) {
     state_ = State::FINISHED;
+    this->release_dependencies();
     return true;
   }
 
index 3fd04ac..810fd7f 100644 (file)
@@ -94,7 +94,7 @@ s4u::CommPtr Mailbox::put_async(void* payload, uint64_t simulated_size_in_bytes)
   xbt_assert(payload != nullptr, "You cannot send nullptr");
 
   s4u::CommPtr res = put_init(payload, simulated_size_in_bytes);
-  res->start();
+  res->vetoable_start();
   return res;
 }
 void Mailbox::put(void* payload, uint64_t simulated_size_in_bytes)
@@ -104,6 +104,7 @@ void Mailbox::put(void* payload, uint64_t simulated_size_in_bytes)
   CommPtr c = put_init();
   c->set_remaining(simulated_size_in_bytes);
   c->set_src_data(payload);
+  c->vetoable_start();
   c->wait();
 }
 /** Blocking send with timeout */
@@ -114,7 +115,7 @@ void Mailbox::put(void* payload, uint64_t simulated_size_in_bytes, double timeou
   CommPtr c = put_init();
   c->set_remaining(simulated_size_in_bytes);
   c->set_src_data(payload);
-  // c->start() is optional.
+  c->vetoable_start();
   c->wait_for(timeout);
 }
 
@@ -129,7 +130,7 @@ s4u::CommPtr Mailbox::get_async(void** data)
 {
   s4u::CommPtr res = get_init();
   res->set_dst_data(data, sizeof(*data));
-  res->start();
+  res->vetoable_start();
   return res;
 }
 
@@ -138,6 +139,7 @@ void* Mailbox::get()
   void* res = nullptr;
   CommPtr c = get_init();
   c->set_dst_data(&res, sizeof(res));
+  c->vetoable_start();
   c->wait();
   return res;
 }
@@ -146,6 +148,7 @@ void* Mailbox::get(double timeout)
   void* res = nullptr;
   CommPtr c = get_init();
   c->set_dst_data(&res, sizeof(res));
+  c->vetoable_start();
   c->wait_for(timeout);
   return res;
 }