- Activity::on_resumed_cb() is renamed to Activity::on_resume_cb(), and fired right before the resume.
- Resource::on_state_change_cb() is renamed to Resource::on_onoff_cb() to distinguish from the
Activity::on_state_change_cb() that is related to the activity state machine, not on/off.
+ - Activity signals (veto, suspend, resume, completion) are now specialized by activity class.
+ That is, callbacks registered in Exec::on_suspend_cb will not be fired for Comms nor Ios.
New S4U plugins:
- Operation: They are designed to represent workflows, i.e, graphs of repeatable Activities.
- :cpp:func:`Comm::on_send <simgrid::s4u::Comm::on_send_cb>`
:cpp:func:`Comm::on_recv <simgrid::s4u::Comm::on_recv_cb>`
:cpp:func:`Comm::on_completion <simgrid::s4u::Comm::on_completion_cb>`
+ :cpp:func:`Comm::on_suspend <simgrid::s4u::Comm::on_suspend_cb>`
+ :cpp:func:`Comm::on_resume <simgrid::s4u::Comm::on_resume_cb>`
+ :cpp:func:`Comm::on_veto <simgrid::s4u::Comm::on_veto_cb>`
- :cpp:func:`CommImpl::on_start <simgrid::s4u::CommImpl::on_start_cb>`
:cpp:func:`CommImpl::on_completion <simgrid::s4u::CommImpl::on_completion_cb>`
- :cpp:func:`Exec::on_start <simgrid::s4u::Exec::on_start_cb>`
:cpp:func:`Exec::on_completion <simgrid::s4u::Exec::on_completion_cb>`
+ :cpp:func:`Exec::on_completion <simgrid::s4u::Exec::on_completion_cb>`
+ :cpp:func:`Exec::on_suspend <simgrid::s4u::Exec::on_suspend_cb>`
+ :cpp:func:`Exec::on_resume <simgrid::s4u::Exec::on_resume_cb>`
+ :cpp:func:`Exec::on_veto <simgrid::s4u::Exec::on_veto_cb>`
- :cpp:func:`Io::on_start <simgrid::s4u::Io::on_start_cb>`
:cpp:func:`Io::on_completion <simgrid::s4u::Io::on_completion_cb>`
+ :cpp:func:`Io::on_completion <simgrid::s4u::Io::on_completion_cb>`
+ :cpp:func:`Io::on_suspend <simgrid::s4u::Io::on_suspend_cb>`
+ :cpp:func:`Io::on_resume <simgrid::s4u::Io::on_resume_cb>`
+ :cpp:func:`Io::on_veto <simgrid::s4u::Io::on_veto_cb>`
Existing Plugins
****************
.. doxygenfunction:: simgrid::s4u::Activity::resume
.. doxygenfunction:: simgrid::s4u::Activity::is_suspended
-Signals
--------
-
-.. tabs::
-
- .. group-tab:: C++
-
- .. doxygenfunction:: simgrid::s4u::Activity::on_completion_cb
- .. doxygenfunction:: simgrid::s4u::Activity::on_suspended_cb
- .. doxygenfunction:: simgrid::s4u::Activity::on_resumed_cb
-
.. _API_s4u_Comm:
=============
.. doxygenfunction:: simgrid::s4u::Comm::on_recv_cb
.. doxygenfunction:: simgrid::s4u::Comm::on_send_cb
+ .. doxygenfunction:: simgrid::s4u::Comm::on_completion_cb
+ .. doxygenfunction:: simgrid::s4u::Comm::on_suspended_cb
+ .. doxygenfunction:: simgrid::s4u::Comm::on_resumed_cb
+ .. doxygenfunction:: simgrid::s4u::Comm::on_veto_cb
+
.. _API_s4u_Exec:
=============
.. doxygenfunction:: simgrid::s4u::Exec::on_start_cb
.. doxygenfunction:: simgrid::s4u::Exec::on_completion_cb
+ .. doxygenfunction:: simgrid::s4u::Exec::on_completion_cb
+ .. doxygenfunction:: simgrid::s4u::Exec::on_suspended_cb
+ .. doxygenfunction:: simgrid::s4u::Exec::on_resumed_cb
+ .. doxygenfunction:: simgrid::s4u::Exec::on_veto_cb
+
.. _API_s4u_Io:
===========
.. doxygenfunction:: simgrid::s4u::Io::on_start_cb
.. doxygenfunction:: simgrid::s4u::Io::on_completion_cb
+ .. doxygenfunction:: simgrid::s4u::Io::on_completion_cb
+ .. doxygenfunction:: simgrid::s4u::Io::on_suspended_cb
+ .. doxygenfunction:: simgrid::s4u::Io::on_resumed_cb
+ .. doxygenfunction:: simgrid::s4u::Io::on_veto_cb
+
.. _API_s4u_Synchronizations:
=======================
auto jupiter = e.host_by_name("Jupiter");
// Display the details on vetoed activities
- sg4::Activity::on_veto_cb([](const sg4::Activity& a) {
- XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", a.get_cname(),
- (a.dependencies_solved() ? "solved" : "NOT solved"), (a.is_assigned() ? "assigned" : "NOT assigned"));
+ sg4::Exec::on_veto_cb([](sg4::Exec const& exec) {
+ XBT_INFO("Execution '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(),
+ (exec.dependencies_solved() ? "solved" : "NOT solved"), (exec.is_assigned() ? "assigned" : "NOT assigned"));
+ });
+ sg4::Comm::on_veto_cb([](sg4::Comm const& comm) {
+ XBT_INFO("Communication '%s' vetoed. Dependencies: %s; Ressources: %s", comm.get_cname(),
+ (comm.dependencies_solved() ? "solved" : "NOT solved"), (comm.is_assigned() ? "assigned" : "NOT assigned"));
});
sg4::Exec::on_completion_cb([](sg4::Exec const& exec) {
#!/usr/bin/env tesh
$ ${bindir:=.}/s4u-dag-comm ${platfdir}/two_hosts.xml --log=s4u_activity.t:verbose "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
-> [ 0.000000] (0:maestro@) Activity 'parent' vetoed. Dependencies: solved; Ressources: NOT assigned
-> [ 0.000000] (0:maestro@) Activity 'transfer' vetoed. Dependencies: NOT solved; Ressources: NOT assigned
-> [ 0.000000] (0:maestro@) Activity 'child' vetoed. Dependencies: NOT solved; Ressources: NOT assigned
+> [ 0.000000] (0:maestro@) Execution 'parent' vetoed. Dependencies: solved; Ressources: NOT assigned
+> [ 0.000000] (0:maestro@) Communication 'transfer' vetoed. Dependencies: NOT solved; Ressources: NOT assigned
+> [ 0.000000] (0:maestro@) Execution 'child' vetoed. Dependencies: NOT solved; Ressources: NOT assigned
> [ 0.000000] (0:maestro@) 'parent' is assigned to a resource and all dependencies are solved. Let's start
-> [ 0.000000] (0:maestro@) Activity 'transfer' vetoed. Dependencies: NOT solved; Ressources: NOT assigned
-> [ 0.000000] (0:maestro@) Activity 'child' vetoed. Dependencies: NOT solved; Ressources: assigned
-> [ 0.000000] (0:maestro@) Activity 'transfer' vetoed. Dependencies: NOT solved; Ressources: assigned
+> [ 0.000000] (0:maestro@) Communication 'transfer' vetoed. Dependencies: NOT solved; Ressources: NOT assigned
+> [ 0.000000] (0:maestro@) Execution 'child' vetoed. Dependencies: NOT solved; Ressources: assigned
+> [ 0.000000] (0:maestro@) Communication 'transfer' vetoed. Dependencies: NOT solved; Ressources: assigned
> [ 1.000000] (0:maestro@) Exec 'parent' is complete (start time: 0.000000, finish time: 1.000000)
> [ 1.000000] (0:maestro@) Remove a dependency from 'parent' on 'transfer'
> [ 1.000000] (0:maestro@) 'transfer' is assigned to a resource and all dependencies are solved. Let's start
auto carl = e.host_by_name("carl");
// Display the details on vetoed activities
- sg4::Activity::on_veto_cb([](const sg4::Activity& a) {
- XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", a.get_cname(),
- (a.dependencies_solved() ? "solved" : "NOT solved"), (a.is_assigned() ? "assigned" : "NOT assigned"));
+ sg4::Exec::on_veto_cb([](sg4::Exec const& exec) {
+ XBT_INFO("Exec '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(),
+ (exec.dependencies_solved() ? "solved" : "NOT solved"), (exec.is_assigned() ? "assigned" : "NOT assigned"));
+ });
+ sg4::Io::on_veto_cb([](sg4::Io const& io) {
+ XBT_INFO("Io '%s' vetoed. Dependencies: %s; Ressources: %s", io.get_cname(),
+ (io.dependencies_solved() ? "solved" : "NOT solved"), (io.is_assigned() ? "assigned" : "NOT assigned"));
});
sg4::Exec::on_completion_cb([](sg4::Exec const& exec) {
$ ${bindir:=.}/s4u-dag-io ${platfdir}/hosts_with_disks.xml --log=s4u_activity.t:verbose "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
> [ 0.000000] (0:maestro@) 'parent' is assigned to a resource and all dependencies are solved. Let's start
-> [ 0.000000] (0:maestro@) Activity 'write' vetoed. Dependencies: NOT solved; Ressources: assigned
-> [ 0.000000] (0:maestro@) Activity 'read' vetoed. Dependencies: NOT solved; Ressources: assigned
-> [ 0.000000] (0:maestro@) Activity 'child' vetoed. Dependencies: NOT solved; Ressources: assigned
+> [ 0.000000] (0:maestro@) Io 'write' vetoed. Dependencies: NOT solved; Ressources: assigned
+> [ 0.000000] (0:maestro@) Io 'read' vetoed. Dependencies: NOT solved; Ressources: assigned
+> [ 0.000000] (0:maestro@) Exec 'child' vetoed. Dependencies: NOT solved; Ressources: assigned
> [ 1.000000] (0:maestro@) Exec 'parent' is complete (start time: 0.000000, finish time: 1.000000)
> [ 1.000000] (0:maestro@) Remove a dependency from 'parent' on 'write'
> [ 1.000000] (0:maestro@) 'write' is assigned to a resource and all dependencies are solved. Let's start
auto fafard = e.host_by_name("Fafard");
// Display the details on vetoed activities
- sg4::Activity::on_veto_cb([](const sg4::Activity& a) {
+ sg4::Exec::on_veto_cb([](sg4::Exec const& a) {
const auto& exec = static_cast<const sg4::Exec&>(a); // all activities are execs in this example
- XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(),
+ XBT_INFO("Execution '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(),
(exec.dependencies_solved() ? "solved" : "NOT solved"),
(exec.is_assigned() ? "assigned" : "NOT assigned"));
});
sg4::Exec::on_completion_cb([](sg4::Exec const& exec) {
- XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec.get_cname(), exec.get_start_time(),
+ XBT_INFO("Execution '%s' is complete (start time: %f, finish time: %f)", exec.get_cname(), exec.get_start_time(),
exec.get_finish_time());
});
$ ${bindir:=.}/s4u-dag-simple ${platfdir}/small_platform.xml --log=s4u_activity.t:verbose "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
> [ 0.000000] (0:maestro@) 'parent 1' is assigned to a resource and all dependencies are solved. Let's start
> [ 0.000000] (0:maestro@) 'parent 2' is assigned to a resource and all dependencies are solved. Let's start
-> [ 0.000000] (0:maestro@) Activity 'child' vetoed. Dependencies: NOT solved; Ressources: NOT assigned
-> [ 2.000000] (0:maestro@) Activity 'parent 1' is complete (start time: 0.000000, finish time: 2.000000)
+> [ 0.000000] (0:maestro@) Execution 'child' vetoed. Dependencies: NOT solved; Ressources: NOT assigned
+> [ 2.000000] (0:maestro@) Execution 'parent 1' is complete (start time: 0.000000, finish time: 2.000000)
> [ 2.000000] (0:maestro@) Remove a dependency from 'parent 1' on 'child'
> [ 2.000000] (0:maestro@) Activity child not ready.
-> [ 3.000000] (0:maestro@) Activity 'parent 2' is complete (start time: 0.000000, finish time: 3.000000)
+> [ 3.000000] (0:maestro@) Execution 'parent 2' is complete (start time: 0.000000, finish time: 3.000000)
> [ 3.000000] (0:maestro@) Remove a dependency from 'parent 2' on 'child'
-> [ 3.000000] (0:maestro@) Activity 'child' vetoed. Dependencies: solved; Ressources: NOT assigned
+> [ 3.000000] (0:maestro@) Execution 'child' vetoed. Dependencies: solved; Ressources: NOT assigned
> [ 3.000000] (0:maestro@) Activity child's dependencies are resolved. Let's assign it to Fafard.
> [ 3.000000] (0:maestro@) 'child' is assigned to a resource and all dependencies are solved. Let's start
-> [ 4.000000] (0:maestro@) Activity 'child' is complete (start time: 3.000000, finish time: 4.000000)
+> [ 4.000000] (0:maestro@) Execution 'child' is complete (start time: 3.000000, finish time: 4.000000)
> [ 4.000000] (0:maestro@) Simulation time 4
sg4::Actor::create("worker", e.host_by_name("Fafard"), worker);
- sg4::Activity::on_veto_cb([&e](sg4::Activity& a) {
- auto& exec = static_cast<sg4::Exec&>(a);
+ sg4::Exec::on_veto_cb([&e](sg4::Exec& exec) {
// First display the situation
XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(),
* It is forbidden to change the amount of work once the Activity is started */
Activity* set_remaining(double remains);
- virtual void fire_this_completion() const = 0;
-
-private:
- static xbt::signal<void(Activity&)> on_veto;
- static xbt::signal<void(Activity const&)> on_suspend;
- static xbt::signal<void(Activity const&)> on_resume;
+ virtual void fire_on_completion() const = 0;
+ virtual void fire_on_veto() const = 0;
+ virtual void fire_on_suspend() const = 0;
+ virtual void fire_on_resume() const = 0;
public:
- /*! Add a callback fired each time that the activity fails to start because of a veto (e.g., unsolved dependency or no
- * resource assigned) */
- static void on_veto_cb(const std::function<void(Activity&)>& cb) { on_veto.connect(cb); }
- /*! Add a callback fired when the activity is suspended */
- static void on_suspend_cb(const std::function<void(Activity const&)>& cb)
- {
- on_suspend.connect(cb);
- }
- /*! Add a callback fired when the activity is resumed after being suspended */
- static void on_resume_cb(const std::function<void(Activity const&)>& cb)
- {
- on_resume.connect(cb);
- }
-
- XBT_ATTRIB_DEPRECATED_v337("Please use on_suspend_cb() instead") static void on_suspended_cb(
- const std::function<void(Activity const&)>& cb)
- {
- on_suspend.connect(cb);
- }
- XBT_ATTRIB_DEPRECATED_v337("Please use on_resume_cb() instead") static void on_resumed_cb(
- const std::function<void(Activity const&)>& cb)
- {
- on_resume.connect(cb);
- }
-
XBT_ATTRIB_DEPRECATED_v334("All start() are vetoable now. Please use start() ") void vetoable_start()
{
start();
} else {
if (vetoed_activities_ != nullptr)
vetoed_activities_->insert(this);
- on_veto(*this);
+ fire_on_veto();
}
}
// released by the on_completion() callbacks.
ActivityPtr keepalive(this);
state_ = state;
- fire_this_completion();
+ fire_on_completion();
if (state == State::FINISHED)
release_dependencies();
}
protected:
inline static xbt::signal<void(AnyActivity const&)> on_completion;
+ inline static xbt::signal<void(AnyActivity&)> on_veto;
+ inline static xbt::signal<void(AnyActivity const&)> on_suspend;
+ inline static xbt::signal<void(AnyActivity const&)> on_resume;
public:
/*! Add a callback fired when the activity completes (either normally, cancelled or failed) */
static void on_completion_cb(const std::function<void(AnyActivity const&)>& cb) { on_completion.connect(cb); }
+ /*! Add a callback fired each time that the activity fails to start because of a veto (e.g., unsolved dependency or no
+ * resource assigned) */
+ static void on_veto_cb(const std::function<void(AnyActivity&)>& cb) { on_veto.connect(cb); }
+ /*! Add a callback fired when the activity is suspended */
+ static void on_suspend_cb(const std::function<void(AnyActivity const&)>& cb) { on_suspend.connect(cb); }
+ /*! Add a callback fired when the activity is resumed after being suspended */
+ static void on_resume_cb(const std::function<void(AnyActivity const&)>& cb) { on_resume.connect(cb); }
+
+ XBT_ATTRIB_DEPRECATED_v337("Please use on_suspend_cb() instead") static void on_suspended_cb(
+ const std::function<void(Activity const&)>& cb) { on_suspend.connect(cb); }
+ XBT_ATTRIB_DEPRECATED_v337("Please use on_resume_cb() instead") static void on_resumed_cb(
+ const std::function<void(Activity const&)>& cb) { on_resume.connect(cb); }
+
AnyActivity* add_successor(ActivityPtr a)
{
static xbt::signal<void(Comm const&)> on_start;
protected:
- void fire_this_completion() const override { on_completion(*this); }
+ void fire_on_completion() const override { on_completion(*this); }
+ void fire_on_veto() const override { on_veto(const_cast<Comm&>(*this)); }
+ void fire_on_suspend() const override { on_suspend(*this); }
+ void fire_on_resume() const override { on_resume(*this); }
public:
static void on_send_cb(const std::function<void(Comm const&)>& cb) { on_send.connect(cb); }
void reset() const;
static xbt::signal<void(Exec const&)> on_start;
- void fire_this_completion() const override { on_completion(*this); }
+ void fire_on_completion() const override { on_completion(*this); }
+ void fire_on_veto() const override { on_veto(const_cast<Exec&>(*this)); }
+ void fire_on_suspend() const override { on_suspend(*this); }
+ void fire_on_resume() const override { on_resume(*this); }
public:
#ifndef DOXYGEN
protected:
explicit Io(kernel::activity::IoImplPtr pimpl);
Io* do_start() override;
- void fire_this_completion() const override { on_completion(*this); }
+ void fire_on_completion() const override { on_completion(*this); }
+ void fire_on_veto() const override { on_veto(const_cast<Io&>(*this)); }
+ void fire_on_suspend() const override { on_suspend(*this); }
+ void fire_on_resume() const override { on_resume(*this); }
public:
enum class OpType { READ, WRITE };
s4u::Host::on_exec_state_change_cb(on_action_state_change);
s4u::Link::on_communication_state_change_cb(on_action_state_change);
- s4u::Activity::on_suspend_cb(on_activity_suspend_resume);
- s4u::Activity::on_resume_cb(on_activity_suspend_resume);
+ s4u::Exec::on_suspend_cb(on_activity_suspend_resume);
+ s4u::Exec::on_resume_cb(on_activity_suspend_resume);
if (TRACE_actor_is_enabled()) {
s4u::Actor::on_creation_cb(on_actor_creation);
return;
}
XBT_VERB("This activity is suspended (remain: %f)", model_action_->get_remains());
- s4u::Activity::on_suspend(*get_iface());
+ get_iface()->fire_on_suspend();
model_action_->suspend();
}
if (model_action_ == nullptr)
return;
XBT_VERB("This activity is resumed (remain: %f)", model_action_->get_remains());
- s4u::Activity::on_resume(*get_iface());
+ get_iface()->fire_on_resume();
model_action_->resume();
}
s4u::Host::on_onoff_cb(host_onoff);
s4u::Exec::on_start_cb(add_active_exec);
s4u::Exec::on_completion_cb(remove_active_exec);
- s4u::Activity::on_resume_cb(add_active_activity);
- s4u::Activity::on_suspend_cb(remove_active_activity);
+ s4u::Exec::on_resume_cb(add_active_activity);
+ s4u::Exec::on_suspend_cb(remove_active_activity);
}
double VMModel::next_occurring_event(double now)
namespace s4u {
-xbt::signal<void(Activity&)> Activity::on_veto;
-xbt::signal<void(Activity const&)> Activity::on_suspend;
-xbt::signal<void(Activity const&)> Activity::on_resume;
-
std::set<Activity*>* Activity::vetoed_activities_ = nullptr;
void Activity::destroy()