Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
woops, I broke the build while fixing the doc
[simgrid.git] / include / simgrid / s4u / Actor.hpp
index 026b326..409e257 100644 (file)
@@ -121,18 +121,15 @@ namespace s4u {
 
 /** @brief Simulation Agent */
 class XBT_PUBLIC Actor : public simgrid::xbt::Extendable<Actor> {
-#ifndef DOXYGEN
-  friend Exec;
-  friend Mailbox;
+  friend simgrid::s4u::Exec;
+  friend simgrid::s4u::Mailbox;
   friend simgrid::kernel::actor::ActorImpl;
   friend simgrid::kernel::activity::MailboxImpl;
-#endif
+
   kernel::actor::ActorImpl* pimpl_ = nullptr;
 
   explicit Actor(smx_actor_t pimpl) : pimpl_(pimpl) {}
 
-  typedef std::function<void()> callback_type;
-
 public:
 
   // ***** No copy *****
@@ -161,14 +158,17 @@ public:
   static simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_migration_start;
   /** Signal to others that an actor is has been migrated to another host **/
   static simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_migration_end;
-  /** Signal indicating that the given actor is about to disappear */
+  /** Signal indicating that an actor is about to disappear.
+   *  This signal is fired for any dying actor, which is mostly useful when
+   *  designing plugins and extensions. If you want to register to the
+   *  termination of a given actor, use this_actor::on_exit() instead.*/
   static simgrid::xbt::signal<void(simgrid::s4u::ActorPtr)> on_destruction;
 
   /** Create an actor from a std::function<void()>
    *
    *  If the actor is restarted, the actor has a fresh copy of the function.
    */
-  static ActorPtr create(std::string name, s4u::Host* host, callback_type code);
+  static ActorPtr create(std::string name, s4u::Host* host, std::function<void()> code);
 
   /** Create an actor from a std::function
    *
@@ -176,7 +176,7 @@ public:
    */
   template <class F> static ActorPtr create(std::string name, s4u::Host* host, F code)
   {
-    return create(name, host, callback_type(std::move(code)));
+    return create(name, host, std::function<void()>(std::move(code)));
   }
 
   /** Create an actor using a callable thing and its arguments.
@@ -260,6 +260,7 @@ public:
    */
   void kill();
 
+  /** Kill an actor from its ID */
   static void kill(aid_t pid);
 
   /** Retrieves the actor that have the given PID (or nullptr if not existing) */
@@ -409,8 +410,65 @@ XBT_PUBLIC void execute(double flop);
  *  An execution of priority 2 computes twice as fast as an execution at priority 1. */
 XBT_PUBLIC void execute(double flop, double priority);
 
-XBT_PUBLIC void parallel_execute(int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount);
-XBT_PUBLIC void parallel_execute(int host_nb, sg_host_t* host_list, double* flops_amount, double* bytes_amount,
+/**
+ * @example examples/s4u/exec-ptask/s4u-exec-ptask.cpp
+ */
+
+/** Block the actor until the built parallel execution terminates
+ *
+ * \rst
+ * .. _API_s4u_parallel_execute:
+ *
+ * **Example of use:** `examples/s4u/exec-ptask/s4u-exec-ptask.cpp
+ * <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/exec-ptask/s4u-exec-ptask.cpp>`_
+ *
+ * Parallel executions convenient abstractions of parallel computational kernels that span over several machines,
+ * such as a PDGEM and the other ScaLAPACK routines. If you are interested in the effects of such parallel kernel
+ * on the platform (e.g. to schedule them wisely), there is no need to model them in all details of their internal
+ * execution and communications. It is much more convenient to model them as a single execution activity that spans
+ * over several hosts. This is exactly what s4u's Parallel Executions are.
+ *
+ * To build such an object, you need to provide a list of hosts that are involved in the parallel kernel (the
+ * actor's own host may or may not be in this list) and specify the amount of computations that should be done by
+ * each host, using a vector of flops amount. Then, you should specify the amount of data exchanged between each
+ * hosts during the parallel kernel. For that, a matrix of values is expected.
+ *
+ * For example, if your list of hosts is ``[host0, host1]``, passing a vector ``[1000, 2000]`` as a `flops_amount`
+ * vector means that `host0` should compute 1000 flops while `host1` will compute 2000 flops. A matrix of
+ * communications' sizes of ``[0, 1, 2, 3]`` specifies the following data exchanges:
+ *
+ *   +-----------+-------+------+
+ *   |from \\ to | host0 | host1|
+ *   +===========+=======+======+
+ *   |host0      |   0   |  1   |
+ *   +-----------+-------+------+
+ *   |host1      |   2   |  3   |
+ *   +-----------+-------+------+
+ *
+ * - From host0 to host0: 0 bytes are exchanged
+ * - From host0 to host1: 1 byte is exchanged
+ * - From host1 to host0: 2 bytes are exchanged
+ * - From host1 to host1: 3 bytes are exchanged
+ *
+ * In a parallel execution, all parts (all executions on each hosts, all communications) progress exactly at the
+ * same pace, so they all terminate at the exact same pace. If one part is slow because of a slow resource or
+ * because of contention, this slows down the parallel execution as a whole.
+ *
+ * These objects are somewhat surprising from a modeling point of view. For example, the unit of their speed is
+ * somewhere between flop/sec and byte/sec. It is **strongly advised** to only use the LV08 host model when using
+ * parallel executions. Note that you can mix regular executions and communications with parallel executions,
+ * provided that the platform model is LV08.
+ *
+ *
+ * \endrst
+ */
+
+XBT_PUBLIC void parallel_execute(int host_nb, s4u::Host** host_list, double* flops_amount, double* bytes_amount);
+/** \rst
+ * Block the actor until the built :ref:`parallel execution <API_s4u_parallel_execute>` completes, or until the timeout.
+ * \endrst
+ */
+XBT_PUBLIC void parallel_execute(int host_nb, s4u::Host** host_list, double* flops_amount, double* bytes_amount,
                                  double timeout);
 
 XBT_PUBLIC ExecPtr exec_init(double flops_amounts);
@@ -444,16 +502,18 @@ XBT_PUBLIC bool is_suspended();
 /** @brief kill the actor. */
 XBT_PUBLIC void exit();
 
-#ifndef DOXYGEN
-/** @deprecated Please use std::function<void(int, void*)> for first parameter */
-XBT_ATTRIB_DEPRECATED_v323("Please use std::function<void(int, void*)> for first parameter.") XBT_PUBLIC
-    void on_exit(int_f_pvoid_pvoid_t fun, void* data);
 /** @brief Add a function to the list of "on_exit" functions. */
 XBT_PUBLIC void on_exit(std::function<void(int, void*)> fun, void* data);
 
 /** @brief Migrate the actor to a new host. */
 XBT_PUBLIC void migrate(Host* new_host);
 
+/** @} */
+
+#ifndef DOXYGEN
+/** @deprecated Please use std::function<void(int, void*)> for first parameter */
+XBT_ATTRIB_DEPRECATED_v323("Please use std::function<void(int, void*)> for first parameter.") XBT_PUBLIC
+    void on_exit(int_f_pvoid_pvoid_t fun, void* data);
 /** @deprecated See this_actor::get_name() */
 XBT_ATTRIB_DEPRECATED_v323("Please use this_actor::get_name()") XBT_PUBLIC std::string getName();
 /** @deprecated See this_actor::get_cname() */
@@ -475,7 +535,6 @@ XBT_ATTRIB_DEPRECATED_v324("Please use this_actor::exit()") XBT_PUBLIC void kill
 #endif
 }
 
-/** @} */
 
 }} // namespace simgrid::s4u