From: Frederic Suter Date: Thu, 4 Feb 2021 16:18:21 +0000 (+0100) Subject: Implement a second veto on start. Activity must be assigned to a resource X-Git-Tag: v3.27~451 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5d6ee66c4a278f168be501318e781c0853085bdc Implement a second veto on start. Activity must be assigned to a resource --- diff --git a/MANIFEST.in b/MANIFEST.in index beb919eec7..ca11dc064a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 26f62ba668..801dba6b5b 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -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 diff --git a/examples/s4u/comm-dependent/s4u-comm-dependent.tesh b/examples/s4u/comm-dependent/s4u-comm-dependent.tesh index 3d39738522..613464dc69 100644 --- a/examples/s4u/comm-dependent/s4u-comm-dependent.tesh +++ b/examples/s4u/comm-dependent/s4u-comm-dependent.tesh @@ -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 diff --git a/examples/s4u/exec-dependent/s4u-exec-dependent.tesh b/examples/s4u/exec-dependent/s4u-exec-dependent.tesh index 75e916de76..c27d3ffc4e 100644 --- a/examples/s4u/exec-dependent/s4u-exec-dependent.tesh +++ b/examples/s4u/exec-dependent/s4u-exec-dependent.tesh @@ -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 index 0000000000..722609bdf5 --- /dev/null +++ b/examples/s4u/exec-unassigned/s4u-exec-unassigned.cpp @@ -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 + +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 index 0000000000..0e69351f51 --- /dev/null +++ b/examples/s4u/exec-unassigned/s4u-exec-unassigned.tesh @@ -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 diff --git a/examples/s4u/io-dependent/s4u-io-dependent.tesh b/examples/s4u/io-dependent/s4u-io-dependent.tesh index 3a3d2f995d..ba01e1dbef 100644 --- a/examples/s4u/io-dependent/s4u-io-dependent.tesh +++ b/examples/s4u/io-dependent/s4u-io-dependent.tesh @@ -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 diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index 83d4870e80..6e894f60f8 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -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(); } } diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index c952dcf459..b202540429 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -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 diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index 19fa207624..f9a4007f41 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -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 diff --git a/include/simgrid/s4u/Io.hpp b/include/simgrid/s4u/Io.hpp index afc1ad88e3..0191c7aa0f 100644 --- a/include/simgrid/s4u/Io.hpp +++ b/include/simgrid/s4u/Io.hpp @@ -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 diff --git a/src/s4u/s4u_Exec.cpp b/src/s4u/s4u_Exec.cpp index 31f69d287e..bc50765496 100644 --- a/src/s4u/s4u_Exec.cpp +++ b/src/s4u/s4u_Exec.cpp @@ -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(pimpl_)->migrate(host); + boost::static_pointer_cast(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& 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; } diff --git a/src/s4u/s4u_Io.cpp b/src/s4u/s4u_Io.cpp index c88ccc7fd4..dd45f7aaad 100644 --- a/src/s4u/s4u_Io.cpp +++ b/src/s4u/s4u_Io.cpp @@ -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)