Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 21 Nov 2023 13:53:32 +0000 (14:53 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 21 Nov 2023 13:53:32 +0000 (14:53 +0100)
docs/source/app_s4u.rst
include/simgrid/forward.h
include/simgrid/s4u/Task.hpp
src/kernel/activity/MessImpl.cpp
src/kernel/activity/MessImpl.hpp
src/kernel/activity/MessageQueueImpl.cpp
src/kernel/activity/MessageQueueImpl.hpp

index cf25747..ff648e0 100644 (file)
@@ -2735,12 +2735,12 @@ Querying info
 
       .. doxygenfunction:: simgrid::s4u::Task::get_cname() const
       .. doxygenfunction:: simgrid::s4u::Task::get_name() const
-      .. doxygenfunction:: simgrid::s4u::Task::get_count() const
-      .. doxygenfunction:: simgrid::s4u::Task::get_amount() const
-      .. doxygenfunction:: simgrid::s4u::Task::get_parallelism_degree() const
+      .. doxygenfunction:: simgrid::s4u::Task::get_count(std::string instance) const
+      .. doxygenfunction:: simgrid::s4u::Task::get_amount(std::string instance) const
+      .. doxygenfunction:: simgrid::s4u::Task::get_queued_firings(std::string instance) const
+      .. doxygenfunction:: simgrid::s4u::Task::get_running_count(std::string instance) const
+      .. doxygenfunction:: simgrid::s4u::Task::get_parallelism_degree(std::string instance) const
       .. doxygenfunction:: simgrid::s4u::Task::set_name(std::string name)
-      .. doxygenfunction:: simgrid::s4u::Task::set_amount(double amount)
-      .. doxygenfunction:: simgrid::s4u::Task::set_parallelism_degree(int n)
 
 Life cycle
 ----------
@@ -2749,9 +2749,12 @@ Life cycle
 
    .. group-tab:: C++
       .. doxygenfunction:: simgrid::s4u::Task::enqueue_firings(int n)
+      .. doxygenfunction:: simgrid::s4u::Task::set_amount(double amount, std::string instance)
+      .. doxygenfunction:: simgrid::s4u::Task::set_parallelism_degree(int n, std::string instance)
 
 Managing Dependencies
 ---------------------
+
 .. tabs::
 
    .. group-tab:: C++
@@ -2762,12 +2765,15 @@ Managing Dependencies
 
 Managing Tokens
 ---------------
+
 .. doxygenclass:: simgrid::s4u::Token
 
 .. tabs::
 
    .. group-tab:: C++
-      .. doxygenfunction:: simgrid::s4u::Task::get_next_token_from(TaskPtr t)
+      .. doxygenfunction:: simgrid::s4u::Task::get_token_from(TaskPtr t) const
+      .. doxygenfunction:: simgrid::s4u::Task::get_tokens_from(TaskPtr t) const
+      .. doxygenfunction:: simgrid::s4u::Task::deque_token_from(TaskPtr t)
       .. doxygenfunction:: simgrid::s4u::Task::set_token(std::shared_ptr<Token> token)
 
 Signals
@@ -2851,10 +2857,12 @@ Querying info
 
    .. group-tab:: C++
 
-      .. doxygenfunction:: simgrid::s4u::ExecTask::get_host() const
-      .. doxygenfunction:: simgrid::s4u::ExecTask::get_flops() const
-      .. doxygenfunction:: simgrid::s4u::ExecTask::set_host(Host* host);
-      .. doxygenfunction:: simgrid::s4u::ExecTask::set_flops(double flops);
+      .. doxygenfunction:: simgrid::s4u::ExecTask::get_host(std::string instance) const
+      .. doxygenfunction:: simgrid::s4u::ExecTask::get_flops(std::string instance) const
+      .. doxygenfunction:: simgrid::s4u::ExecTask::set_host(Host* host, std::string instance);
+      .. doxygenfunction:: simgrid::s4u::ExecTask::set_flops(double flops, std::string instance);
+      .. doxygenfunction:: simgrid::s4u::ExecTask::add_instances(int n);
+      .. doxygenfunction:: simgrid::s4u::ExecTask::remove_instances(int n);
 
 .. _API_s4u_IoTask:
 
index fc38085..e2a0606 100644 (file)
@@ -105,6 +105,19 @@ XBT_PUBLIC void intrusive_ptr_release(const Semaphore* m);
 XBT_PUBLIC void intrusive_ptr_add_ref(const Semaphore* m);
 
 class Disk;
+
+class Task;
+/** Smart pointer to a simgrid::s4u::Task */
+using TaskPtr = boost::intrusive_ptr<Task>;
+XBT_PUBLIC void intrusive_ptr_release(Task* o);
+XBT_PUBLIC void intrusive_ptr_add_ref(Task* o);
+class ExecTask;
+using ExecTaskPtr = boost::intrusive_ptr<ExecTask>;
+class CommTask;
+using CommTaskPtr = boost::intrusive_ptr<CommTask>;
+class IoTask;
+using IoTaskPtr = boost::intrusive_ptr<IoTask>;
+
 /**
  * @brief Callback to dynamically change the resource's capacity
  *
index f10729b..4c44875 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef SIMGRID_S4U_TASK_H_
 #define SIMGRID_S4U_TASK_H_
 
+#include <simgrid/forward.h>
 #include <simgrid/s4u/Activity.hpp>
 #include <simgrid/s4u/Io.hpp>
 #include <xbt/Extendable.hpp>
 
 namespace simgrid::s4u {
 
-class Task;
-using TaskPtr = boost::intrusive_ptr<Task>;
-XBT_PUBLIC void intrusive_ptr_release(Task* o);
-XBT_PUBLIC void intrusive_ptr_add_ref(Task* o);
-class ExecTask;
-using ExecTaskPtr = boost::intrusive_ptr<ExecTask>;
-class CommTask;
-using CommTaskPtr = boost::intrusive_ptr<CommTask>;
-class IoTask;
-using IoTaskPtr = boost::intrusive_ptr<IoTask>;
-
 class XBT_PUBLIC Token : public xbt::Extendable<Token> {};
 
-class Task {
+/** Task class */
+class XBT_PUBLIC Task {
 
   std::string name_;
 
@@ -70,32 +61,63 @@ protected:
   virtual void remove_instances(int n);
 
 public:
+  /** @param name The new name of this Task */
   void set_name(std::string name);
+  /** Retrieves the name of that Task as a C++ string */
   const std::string& get_name() const { return name_; }
+  /** Retrieves the name of that Task as a C string */
   const char* get_cname() const { return name_.c_str(); }
+  /** @param amount The new amount of work this instance of this Task has to do
+   *  @note In flops for ExecTasks instances and in bytes for CommTasks instances. In flops for dispatcher and collector
+   * instances */
   void set_amount(double amount, std::string instance = "instance_0");
+  /** @return Amout of work this instance of this Task has to process */
   double get_amount(std::string instance = "instance_0") const { return amount_.at(instance); }
-  int get_queued_firings(std::string instance = "instance_0") { return queued_firings_.at(instance); }
-  int get_running_count(std::string instance = "instance_0") { return running_instances_.at(instance); }
+  /** @return Amount of queued firings for this instance of this Task */
+  int get_queued_firings(std::string instance = "instance_0") const { return queued_firings_.at(instance); }
+  /** @return Amount currently running of this instance of this Task */
+  int get_running_count(std::string instance = "instance_0") const { return running_instances_.at(instance); }
+  /** @return Number of times this instance of this Task has been completed */
   int get_count(std::string instance = "collector") const { return count_.at(instance); }
+  /** @param n The parallelism degree to set
+   *  @brief The parallelism degree defines how many of this instance can run in parallel. */
   void set_parallelism_degree(int n, std::string instance = "all");
+  /** @return Parallelism degree of this instance of this Task */
   int get_parallelism_degree(std::string instance = "instance_0") const { return parallelism_degree_.at(instance); }
+  /** @param bytes The amount of bytes this instance has to send to the next instance of this Task
+   *  @note This amount is used when the host is different between the dispatcher and the instance doing the work of the
+   * Task, or between the instance and the collector. */
   void set_internal_bytes(int bytes, std::string instance = "instance_0");
+  /** @return Amount of bytes this instance of the Task has to send to the next instance */
   double get_internal_bytes(std::string instance = "instance_0") const { return internal_bytes_to_send_.at(instance); }
+  /** @param func The new balancing function
+   *  @note This function is used by the dispatcher to determine which instance will effectively do the work. This
+   * function must return the name of the instance as a string. The default balancing function always returns
+   * "instance_0" */
   void set_load_balancing_function(std::function<std::string()> func);
-
+  /** @param token The new token */
   void set_token(std::shared_ptr<Token> token);
+  /** @param t A Smart pointer to a Task
+   *  @return Oldest token received by this Task that was sent by Task t */
   std::shared_ptr<Token> get_token_from(TaskPtr t) const { return tokens_received_.at(t).front(); }
+  /** @param t A Smart pointer to a Task
+   *  @return All tokens received by this Task that were sent by Task t */
   std::deque<std::shared_ptr<Token>> get_tokens_from(TaskPtr t) const { return tokens_received_.at(t); }
+  /** @param t A Smart pointer to a Task
+   *   @brief Pop the oldest token received by this Task that was sent by Task t */
   void deque_token_from(TaskPtr t);
-
+  /** @param t A Smart pointer to a Task
+   *  @brief Add t as a successor of this Task */
   void add_successor(TaskPtr t);
+  /** @param t A Smart pointer to a Task
+   *  @brief Remove t from the successors of this Task */
   void remove_successor(TaskPtr t);
+  /** @brief Remove all successors from this Task */
   void remove_all_successors();
+  /** @return All successors of this Task */
   const std::set<Task*>& get_successors() const { return successors_; }
-
+  /** @param n The number of firings to enqueue */
   void enqueue_firings(int n);
-
   /** Add a callback fired before this task activity starts */
   void on_this_start_cb(const std::function<void(Task*)>& func) { on_this_start.connect(func); }
   /** Add a callback fired before a task activity starts.
@@ -119,6 +141,7 @@ public:
 #endif
 };
 
+/** CommTask class */
 class CommTask : public Task {
   Host* source_;
   Host* destination_;
@@ -130,14 +153,23 @@ public:
   static CommTaskPtr init(const std::string& name);
   static CommTaskPtr init(const std::string& name, double bytes, Host* source, Host* destination);
 
+  /** @param source The new source Host of this CommTask
+   *  @return A Smart pointer to this CommTask */
   CommTaskPtr set_source(Host* source);
+  /** @return A pointer to the source Host of this CommTask */
   Host* get_source() const { return source_; }
+  /** @param destination The new destination of this CommTask
+   *  @return A Smart pointer to the destination Host of this CommTask */
   CommTaskPtr set_destination(Host* destination);
+  /** @return A pointer to the destination Host of this CommTask */
   Host* get_destination() const { return destination_; }
+  /** @param bytes The amount of bytes this CommTask has to send */
   CommTaskPtr set_bytes(double bytes);
+  /** @return The amout of bytes this CommTask has to send */
   double get_bytes() const { return get_amount("instance_0"); }
 };
 
+/** ExecTask class */
 class ExecTask : public Task {
   std::map<std::string, Host*> host_ = {{"instance_0", nullptr}, {"dispatcher", nullptr}, {"collector", nullptr}};
 
@@ -148,15 +180,23 @@ public:
   static ExecTaskPtr init(const std::string& name);
   static ExecTaskPtr init(const std::string& name, double flops, Host* host);
 
+  /** @param host The new host of this instance of this ExecTask
+   *  @return a Smart pointer to this ExecTask */
   ExecTaskPtr set_host(Host* host, std::string instance = "all");
+  /** @return A pointer to the host of this instance of this ExecTask */
   Host* get_host(std::string instance = "instance_0") const { return host_.at(instance); }
+  /** @param flops The new amount of flops this instance of this Task has to execute
+   *  @return A Smart pointer to this ExecTask */
   ExecTaskPtr set_flops(double flops, std::string instance = "instance_0");
+  /** @return The amount of flops this instance of this ExecTask has to execute */
   double get_flops(std::string instance = "instance_0") const { return get_amount(instance); }
-
+  /** @param n The number of instances to add to this ExecTask */
   void add_instances(int n) override;
+  /** @param n The number of isntances to remove from this ExecTask */
   void remove_instances(int n) override;
 };
 
+/** IoTask class */
 class IoTask : public Task {
   Disk* disk_;
   Io::OpType type_;
@@ -167,11 +207,20 @@ public:
   static IoTaskPtr init(const std::string& name);
   static IoTaskPtr init(const std::string& name, double bytes, Disk* disk, Io::OpType type);
 
+  /** @param disk The new disk of this IoTask
+   * @return A Smart pointer to this IoTask */
   IoTaskPtr set_disk(Disk* disk);
+  /** @return A pointer to the disk of this IoTask */
   Disk* get_disk() const { return disk_; }
+  /** @param bytes The new amount of bytes this IoTask has to write or read
+   *  @return A Smart pointer to this IoTask */
   IoTaskPtr set_bytes(double bytes);
+  /** @return The amount of bytes this IoTask has to write or read */
   double get_bytes() const { return get_amount("instance_0"); }
+  /** @param type The type of operation this IoTask has to do
+   *  @return A Smart pointer to this IoTask */
   IoTaskPtr set_op_type(Io::OpType type);
+  /** @return The type of operation this IoTask has to to */
   Io::OpType get_op_type() const { return type_; }
 };
 } // namespace simgrid::s4u
index 28679c2..3a3e307 100644 (file)
@@ -130,9 +130,18 @@ void MessImpl::wait_for(actor::ActorImpl* issuer, double timeout)
   ActivityImpl::wait_for(issuer, timeout);
 }
 
+void MessImpl::cancel()
+{
+  /* if the synchro is a waiting state means that it is still in a mbox so remove from it and delete it */
+  if (get_state() == State::WAITING) {
+      queue_->remove(this);
+      set_state(State::CANCELED);
+  }
+}
+
 void MessImpl::finish()
 {
-  XBT_DEBUG("MessImpl::finish() comm %p, state %s, src_proc %p, dst_proc %p", this, get_state_str(),
+  XBT_DEBUG("MessImpl::finish() mess %p, state %s, src_proc %p, dst_proc %p", this, get_state_str(),
             src_actor_.get(), dst_actor_.get());
 
   if (get_iface()) {
index fad011c..2b2932f 100644 (file)
@@ -39,6 +39,9 @@ public:
   void wait_for(actor::ActorImpl* issuer, double timeout) override;
 
   MessImpl* start();
+  void suspend() override { /* no action to suspend for Mess */ }
+  void resume() override { /* no action to resume for Mess */ }
+  void cancel() override;
   void set_exception(actor::ActorImpl* issuer) override {};
   void finish() override;
 
index 714f86b..d649e6e 100644 (file)
@@ -13,6 +13,29 @@ namespace simgrid::kernel::activity {
 
 unsigned MessageQueueImpl::next_id_ = 0;
 
+MessageQueueImpl::~MessageQueueImpl()
+{
+  try {
+    clear();
+  } catch (const std::bad_alloc& ba) {
+    XBT_ERROR("MessageQueueImpl::clear() failure: %s", ba.what());
+  }
+}
+
+/** @brief Removes all message activities from a message queue */
+void MessageQueueImpl::clear()
+{
+  while (not queue_.empty()) {
+    auto mess = queue_.back();
+    if (mess->get_state() == State::WAITING) {
+      mess->cancel();
+      mess->set_state(State::FAILED);
+    } else
+      queue_.pop_back();
+  }
+  xbt_assert(queue_.empty());
+}
+
 void MessageQueueImpl::push(const MessImplPtr& mess)
 {
   mess->set_queue(this);
index 4bc010f..3016e04 100644 (file)
@@ -31,6 +31,8 @@ class MessageQueueImpl {
   MessageQueueImpl& operator=(const MailboxImpl&) = delete;
 
 public:
+  ~MessageQueueImpl();
+
   /** @brief Public interface */
   unsigned get_id() const { return id_; }
 
@@ -41,6 +43,7 @@ public:
   const char* get_cname() const { return name_.c_str(); }
   void push(const MessImplPtr& mess);
   void remove(const MessImplPtr& mess);
+  void clear();
   bool empty() const { return queue_.empty(); }
   size_t size() const { return queue_.size(); }
   const MessImplPtr& front() const { return queue_.front(); }