-foreach(example actor-create actor-yield exec-basic)
+foreach(example actor-create actor-migration actor-yield exec-basic)
set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.tesh)
set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.py)
def receiver(mailbox_name):
mailbox = Mailbox.by_name(mailbox_name)
- this_actor.info("Hello s4u, I'm ready to get any message you'd want on {:s}".format(mailbox.get_name()))
+ this_actor.info("Hello s4u, I'm ready to get any message you'd want on {:s}".format(mailbox.name))
msg1 = mailbox.get()
msg2 = mailbox.get()
--- /dev/null
+# Copyright (c) 2017-2018. 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.
+
+# This example demonstrate the actor migrations.
+#
+# The worker actor first move by itself, and then start an execution.
+# During that execution, the monitor migrates the worker, that wakes up on another host.
+# The execution was of the right amount of flops to take exactly 5 seconds on the first host
+# and 5 other seconds on the second one, so it stops after 10 seconds.
+#
+# Then another migration is done by the monitor while the worker is suspended.
+#
+# Note that worker() takes an uncommon set of parameters,
+# and that this is perfectly accepted by create().
+
+from simgrid import *
+import sys
+
+def worker(first_host, second_host):
+ flop_amount = first_host.speed * 5 + second_host.speed * 5
+
+ this_actor.info("Let's move to {:s} to execute {:.2f} Mflops (5sec on {:s} and 5sec on {:s})".format(first_host.name, flop_amount / 1e6, first_host.name, second_host.name))
+
+ this_actor.migrate(first_host)
+ this_actor.execute(flop_amount)
+
+ this_actor.info("I wake up on {:s}. Let's suspend a bit".format(this_actor.get_host().name))
+
+ this_actor.suspend()
+
+ this_actor.info("I wake up on {:s}".format(this_actor.get_host().name))
+ this_actor.info("Done")
+
+def monitor():
+ boivin = Host.by_name("Boivin")
+ jacquelin = Host.by_name("Jacquelin")
+ fafard = Host.by_name("Fafard")
+
+ actor = Actor.create("worker", fafard, worker, boivin, jacquelin)
+
+ this_actor.sleep_for(5)
+
+ this_actor.info("After 5 seconds, move the process to {:s}".format(jacquelin.name))
+ actor.migrate(jacquelin)
+
+ this_actor.sleep_until(15)
+ this_actor.info("At t=15, move the process to {:s} and resume it.".format(fafard.name))
+ actor.migrate(fafard)
+ actor.resume()
+
+if __name__ == '__main__':
+ e = Engine(sys.argv)
+ if len(sys.argv) < 2: raise AssertionError("Usage: actor-migration.py platform_file [other parameters]")
+ e.load_platform(sys.argv[1])
+
+ Actor.create("monitor", Host.by_name("Boivin"), monitor)
+ e.run()
+
--- /dev/null
+#!/usr/bin/env tesh
+
+p Testing the actor migration feature
+
+$ python3 ${bindir:=.}/actor-migration.py ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [ 0.000000] (worker@Fafard) Let's move to Boivin to execute 1177.14 Mflops (5sec on Boivin and 5sec on Jacquelin)
+> [ 5.000000] (monitor@Boivin) After 5 seconds, move the process to Jacquelin
+> [ 10.000000] (worker@Jacquelin) I wake up on Jacquelin. Let's suspend a bit
+> [ 15.000000] (monitor@Boivin) At t=15, move the process to Fafard and resume it.
+> [ 15.000000] (worker@Fafard) I wake up on Fafard
+> [ 15.000000] (worker@Fafard) Done
|br| `examples/s4u/actor-suspend/s4u-actor-suspend.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/actor-suspend/s4u-actor-suspend.cpp>`_
- **Migrating Actors:**
- Actors can move or be moved from a host to another with
- :cpp:func:`simgrid::s4u::this_actor::migrate()`.
- |br| `examples/s4u/actor-migration/s4u-actor-migration.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/actor-migration/s4u-actor-migration.cpp>`_
+ Actors can move or be moved from a host to another very easily.
+ |br| |cpp| `examples/s4u/actor-migration/s4u-actor-migration.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/actor-migration/s4u-actor-migration.cpp>`_
+ :cpp:func:`simgrid::s4u::this_actor::migrate()` |cpp|
+ |br| |py| `examples/python/actor-migration/actor-migration.py <https://framagit.org/simgrid/simgrid/tree/master/examples/python/actor-migration/actor-migration.py>`_
+ :py:func:`simgrid.this_actor.migrate()` |py|
- **Waiting for the termination of an actor:** (joining on it)
:cpp:func:`simgrid::s4u::Actor::join()` allows to block the current
actor, leaving a chance to the other actors that are ready to run
at this timestamp.
|br| |cpp| `examples/s4u/actor-yield/s4u-actor-yield.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/actor-yield/s4u-actor-yield.cpp>`_
- :cpp:func:`simgrid::s4u::this_actor::yield()`
+ :cpp:func:`simgrid::s4u::this_actor::yield()` |cpp|
|br| |py| `examples/python/actor-yield/actor-yield.py <https://framagit.org/simgrid/simgrid/tree/master/examples/python/actor-yield/actor-yield.py>`_
- :py:func:`simgrid.this_actor.yield_()`
+ :py:func:`simgrid.this_actor.yield_()` |py|
Traces Replay as a Workload
---------------------------
XBT_PUBLIC bool is_maestro();
-/** Block the actor sleeping for that amount of seconds (may throws hostFailure) */
+/** Block the actor sleeping for that amount of seconds (may throw hostFailure) */
XBT_PUBLIC void sleep_for(double duration);
+/** Block the actor sleeping until the specified timestamp (may throw hostFailure) */
XBT_PUBLIC void sleep_until(double timeout);
template <class Rep, class Period> inline void sleep_for(std::chrono::duration<Rep, Period> duration)
/** @brief Returns the name of the host on which the actor is running. */
XBT_PUBLIC Host* get_host();
-/** @brief Suspend the actor. */
+/** @brief Suspend the actor, that is blocked until resume()ed by another actor. */
XBT_PUBLIC void suspend();
/** @brief Yield the actor. */
XBT_PUBLIC void yield();
-/** @brief Resume the actor. */
+/** @brief Resume the actor, that was suspend()ed previously. */
XBT_PUBLIC void resume();
XBT_PUBLIC bool is_suspended();
/* 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 <functional>
#include <memory>
#include <string>
#include <vector>
-#include <pybind11/functional.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
-#include <simgrid/config.h>
-#include <xbt/log.h>
-#include <xbt/string.hpp>
-
#include <simgrid/s4u/Actor.hpp>
#include <simgrid/s4u/Engine.hpp>
#include <simgrid/s4u/Host.hpp>
#include <simgrid/s4u/Mailbox.hpp>
-#include <boost/intrusive_ptr.hpp>
-
namespace py = pybind11;
using simgrid::s4u::Actor;
using simgrid::s4u::ActorPtr;
m.attr("simgrid_version") = simgrid_version;
/* this_actor namespace */
+ void (*sleep_for_fun)(double) = &simgrid::s4u::this_actor::sleep_for; // pick the right overload
+ void (*sleep_until_fun)(double) = &simgrid::s4u::this_actor::sleep_until;
+
py::module m2 = m.def_submodule("this_actor", "Bindings of the s4u::this_actor namespace.");
m2.def("info", [](char* s) { XBT_INFO("%s", s); }, "Display a logging message of default priority.");
m2.def("execute", py::overload_cast<double, double>(&simgrid::s4u::this_actor::execute),
"Block the current actor, computing the given amount of flops at the given priority, see :cpp:func:`void "
"simgrid::s4u::this_actor::execute(double, double)`",
py::arg("flops"), py::arg("priority") = 1);
+ m2.def("get_host", &simgrid::s4u::this_actor::get_host, "Retrives host on which the current actor is located");
+ m2.def("migrate", &simgrid::s4u::this_actor::migrate, "Moves the current actor to another host, see :cpp:func:`void simgrid::s4u::this_actor::migrate()`",
+ py::arg("dest"));
+ m2.def("sleep_for", sleep_for_fun,
+ "Block the actor sleeping for that amount of seconds, see :cpp:func:`void simgrid::s4u::this_actor::sleep_for`", py::arg("duration"));
+ m2.def("sleep_until", sleep_until_fun,
+ "Block the actor sleeping until the specified timestamp, see :cpp:func:`void simgrid::s4u::this_actor::sleep_until`", py::arg("duration"));
+ m2.def("suspend", &simgrid::s4u::this_actor::suspend, "Suspend the current actor, that is blocked until resume()ed by another actor. see :cpp:func:`void simgrid::s4u::this_actor::suspend`");
m2.def("yield_", &simgrid::s4u::this_actor::yield,
"Yield the actor, see :cpp:func:`void simgrid::s4u::this_actor::yield()`");
;
/* Class Host */
- auto get_name = [](const Host* self) {
- return self->get_name();
- };
py::class_<simgrid::s4u::Host, std::unique_ptr<Host, py::nodelete>>(m, "Host", "Simulation Engine, see :ref:`class s4u::Host <API_s4u_Host>`")
.def("by_name", &Host::by_name, "Retrieve a host from its name, or die")
- .def("get_name", &Host::get_name, "Retrieve the name of this host")
- .def_property_readonly("name", get_name, "Retrieve the name of this host")
+ .def_property_readonly("name", [](Host* self) -> const std::string {
+ return static_cast<std::string>(self->get_name());
+ }, "Retrieve the name of this host")
.def_property_readonly("speed", &Host::get_speed,
"Get the peak computing speed in flops/s at the current pstate, taking the external load into account, see :cpp:func:`simgrid::s4u::Host::get_speed()`");
/* Class Mailbox */
py::class_<simgrid::s4u::Mailbox, std::unique_ptr<Mailbox, py::nodelete>>(m, "Mailbox", "Mailbox, see :ref:`class s4u::Mailbox <API_s4u_Mailbox>`")
.def("by_name", &Mailbox::by_name, "Retrieve a Mailbox from its name, see :cpp:func:`simgrid::s4u::Mailbox::by_name()`")
- .def("get_name", &Mailbox::get_name, "Retrieves the name of that host, see :cpp:func:`simgrid::s4u::Mailbox::get_name()`")
+ .def_property_readonly("name", &Mailbox::get_name, "Retrieves the name of that mailbox, see :cpp:func:`simgrid::s4u::Mailbox::get_name()`")
.def("put", [](Mailbox self, py::object data, int size) {
data.inc_ref();
self.put(data.ptr(), size);
throw pybind11::error_already_set();
});
},
- "Create an actor from a function or an object, see :cpp:func:`simgrid::s4u::Actor::create()`");
+ "Create an actor from a function or an object, see :cpp:func:`simgrid::s4u::Actor::create()`")
+ .def_property("host", &Actor::get_host, &Actor::migrate, "The host on which this actor is located")
+ .def("migrate", &Actor::migrate, "Moves that actor to another host, see :cpp:func:`void simgrid::s4u::Actor::migrate()`",
+ py::arg("dest"))
+ .def("suspend", &Actor::suspend, "Suspend that actor, that is blocked until resume()ed by another actor. See :cpp:func:`void simgrid::s4u::Actor::suspend()`")
+ .def("resume", &Actor::resume, "Resume that actor, that was previously suspend()ed. See :cpp:func:`void simgrid::s4u::Actor::suspend()`");
+
}