Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement a second veto on start. Activity must be assigned to a resource
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 4 Feb 2021 16:18:21 +0000 (17:18 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 4 Feb 2021 16:18:21 +0000 (17:18 +0100)
13 files changed:
MANIFEST.in
examples/s4u/CMakeLists.txt
examples/s4u/comm-dependent/s4u-comm-dependent.tesh
examples/s4u/exec-dependent/s4u-exec-dependent.tesh
examples/s4u/exec-unassigned/s4u-exec-unassigned.cpp [new file with mode: 0644]
examples/s4u/exec-unassigned/s4u-exec-unassigned.tesh [new file with mode: 0644]
examples/s4u/io-dependent/s4u-io-dependent.tesh
include/simgrid/s4u/Activity.hpp
include/simgrid/s4u/Comm.hpp
include/simgrid/s4u/Exec.hpp
include/simgrid/s4u/Io.hpp
src/s4u/s4u_Exec.cpp
src/s4u/s4u_Io.cpp

index beb919e..ca11dc0 100644 (file)
@@ -424,6 +424,8 @@ include examples/s4u/exec-ptask/s4u-exec-ptask.cpp
 include examples/s4u/exec-ptask/s4u-exec-ptask.tesh
 include examples/s4u/exec-remote/s4u-exec-remote.cpp
 include examples/s4u/exec-remote/s4u-exec-remote.tesh
+include examples/s4u/exec-unassigned/s4u-exec-unassigned.cpp
+include examples/s4u/exec-unassigned/s4u-exec-unassigned.tesh
 include examples/s4u/exec-waitany/s4u-exec-waitany.cpp
 include examples/s4u/exec-waitany/s4u-exec-waitany.tesh
 include examples/s4u/exec-waitfor/s4u-exec-waitfor.cpp
index 26f62ba..801dba6 100644 (file)
@@ -68,7 +68,7 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill
                  dht-chord dht-kademlia
                  energy-exec energy-boot energy-link energy-vm energy-exec-ptask energy-wifi
                  engine-filtering
-                 exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany exec-waitfor exec-dependent
+                 exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany exec-waitfor exec-dependent exec-unassigned
                  maestro-set
                  mc-bugged1 mc-bugged2 mc-electric-fence mc-failing-assert
                 network-wifi
index 3d39738..613464d 100644 (file)
@@ -4,8 +4,8 @@ p Testing with default compound
 
 $ ${bindir:=.}/s4u-comm-dependent ${platfdir}/small_platform.xml  --log=s4u_activity.t:verbose "--log=root.fmt:[%6.2r]%e(%i:%a@%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'
+> [  2.00] (1:sender@Tremblay) 'comm to receiver' is assigned to a resource and all dependencies are solved. Let's start
 > [  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'
+> [  3.07] (2:receiver@Jupiter) 'exec on receiver' is assigned to a resource and all dependencies are solved. Let's start
 > [  5.07] (2:receiver@Jupiter) Received: 98095000 flops were computed on sender
 > [  5.07] (0:maestro@) Simulation time: 5.070
index 75e916d..c27d3ff 100644 (file)
@@ -5,7 +5,7 @@ $ ${bindir:=.}/s4u-exec-dependent ${platfdir}/small_platform.xml --log=s4u_activ
 > [  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) 'child' is assigned to a resource and all dependencies are solved. Let's start
 > [  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/exec-unassigned/s4u-exec-unassigned.cpp b/examples/s4u/exec-unassigned/s4u-exec-unassigned.cpp
new file mode 100644 (file)
index 0000000..722609b
--- /dev/null
@@ -0,0 +1,40 @@
+/* Copyright (c) 2007-2021. 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();
+
+  // Create an unassigned activity and start it
+  simgrid::s4u::ExecPtr exec =
+      simgrid::s4u::Exec::init()->set_flops_amount(computation_amount)->set_name("exec")->vetoable_start();
+
+  // Wait for a while
+  simgrid::s4u::this_actor::sleep_for(10);
+
+  // Assign the activity to the current host. This triggers its start, then waits for it completion.
+  exec->set_host(simgrid::s4u::Host::current())->wait();
+  XBT_INFO("Exec '%s' is complete", exec->get_cname());
+}
+
+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-unassigned/s4u-exec-unassigned.tesh b/examples/s4u/exec-unassigned/s4u-exec-unassigned.tesh
new file mode 100644 (file)
index 0000000..0e69351
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/env tesh
+
+! output sort
+$ ${bindir:=.}/s4u-exec-unassigned ${platfdir}/small_platform.xml --log=s4u_activity.t:verbose "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
+> [ 10.000000] (1:worker@Fafard) 'exec' is assigned to a resource and all dependencies are solved. Let's start
+> [ 11.000000] (1:worker@Fafard) Exec 'exec' is complete
+> [ 11.000000] (0:maestro@) Simulation time 11
\ No newline at end of file
index 3a3d2f9..ba01e1d 100644 (file)
@@ -2,10 +2,10 @@
 
 ! output sort
 $ ${bindir:=.}/s4u-io-dependent ${platfdir}/hosts_with_disks.xml --log=s4u_activity.t:verbose "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
-> [  1.000000] (1:bob@bob) All dependencies are solved, let's start 'bob write'
+> [  1.000000] (1:bob@bob) 'bob write' is assigned to a resource and all dependencies are solved. Let's start
 > [  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) 'carl read' is assigned to a resource and all dependencies are solved. Let's start
 > [  1.100000] (1:bob@bob) Remove a dependency from 'bob write' on 'carl read'
-> [  1.140000] (1:bob@bob) All dependencies are solved, let's start 'carl compute'
+> [  1.140000] (1:bob@bob) 'carl compute' is assigned to a resource and all dependencies are solved. Let's start
 > [  1.140000] (1:bob@bob) Remove a dependency from 'carl read' on 'carl compute'
 > [  2.140000] (0:maestro@) Simulation time 2.14
index 83d4870..6e894f6 100644 (file)
@@ -33,6 +33,8 @@ protected:
   Activity()  = default;
   virtual ~Activity() = default;
 
+  virtual bool is_assigned() = 0;
+
   void release_dependencies()
   {
     while (not successors_.empty()) {
@@ -56,8 +58,8 @@ public:
   void vetoable_start()
   {
     state_ = State::STARTING;
-    if (dependencies_.empty()) {
-      XBT_CVERB(s4u_activity, "All dependencies are solved, let's start '%s'", get_cname());
+    if (dependencies_.empty() && is_assigned()) {
+      XBT_CVERB(s4u_activity, "'%s' is assigned to a resource and all dependencies are solved. Let's start", get_cname());
       start();
     }
   }
index c952dcf..b202540 100644 (file)
@@ -132,6 +132,8 @@ public:
   size_t get_dst_data_size() const;
 
   Actor* get_sender() const;
+
+  bool is_assigned() { return (to_ != nullptr && from_ != nullptr) || (mailbox_ != nullptr); }
 };
 } // namespace s4u
 } // namespace simgrid
index 19fa207..f9a4007 100644 (file)
@@ -81,6 +81,7 @@ public:
   double get_finish_time() const;
   double get_cost() const;
   bool is_parallel() const { return parallel_; }
+  bool is_assigned() { return not hosts_.empty(); }
 };
 
 } // namespace s4u
index afc1ad8..0191c7a 100644 (file)
@@ -51,6 +51,8 @@ public:
   IoPtr set_disk(sg_disk_t disk);
   IoPtr set_size(sg_size_t size);
   IoPtr set_op_type(OpType type);
+
+  bool is_assigned() { return disk_ != nullptr; }
 };
 
 } // namespace s4u
index 31f69d2..bc50765 100644 (file)
@@ -147,19 +147,34 @@ ExecPtr Exec::set_priority(double priority)
  * The activity cannot be terminated already (but it may be started). */
 ExecPtr Exec::set_host(Host* host)
 {
-  xbt_assert(state_ == State::INITED || state_ == State::STARTED,
+  xbt_assert(state_ == State::INITED || state_ == State::STARTING || state_ == State::STARTED,
              "Cannot change the host of an exec once it's done (state: %d)", (int)state_);
+  hosts_.assign(1, host);
+
   if (state_ == State::STARTED)
     boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->migrate(host);
+
   boost::static_pointer_cast<kernel::activity::ExecImpl>(pimpl_)->set_host(host);
+
+  if (state_ == State::STARTING)
+  // Setting the host may allow to start the activity, let's try
+    vetoable_start();
+
   return this;
 }
 
 ExecPtr Exec::set_hosts(const std::vector<Host*>& hosts)
 {
-  xbt_assert(state_ == State::INITED, "Cannot change the hosts of an exec once it's done (state: %d)", (int)state_);
+  xbt_assert(state_ == State::INITED || state_ == State::STARTING,
+      "Cannot change the hosts of an exec once it's done (state: %d)", (int)state_);
+
   hosts_    = hosts;
   parallel_ = true;
+
+  // Setting the host may allow to start the activity, let's try
+  if (state_ == State::STARTING)
+     vetoable_start();
+
   return this;
 }
 
index c88ccc7..dd45f7a 100644 (file)
@@ -72,7 +72,12 @@ Io* Io::wait_for(double timeout)
 IoPtr Io::set_disk(sg_disk_t disk)
 {
   disk_ = disk;
-  return this;
+
+  // Setting the disk may allow to start the activity, let's try
+  if (state_ == State::STARTING)
+    vetoable_start();
+
+ return this;
 }
 
 IoPtr Io::set_size(sg_size_t size)