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
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
$ ${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
> [ 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
--- /dev/null
+/* 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;
+}
--- /dev/null
+#!/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
! 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
Activity() = default;
virtual ~Activity() = default;
+ virtual bool is_assigned() = 0;
+
void release_dependencies()
{
while (not successors_.empty()) {
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();
}
}
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
double get_finish_time() const;
double get_cost() const;
bool is_parallel() const { return parallel_; }
+ bool is_assigned() { return not hosts_.empty(); }
};
} // namespace s4u
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
* 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;
}
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)