Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv the internal isend function to the class
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 1 Mar 2019 19:45:23 +0000 (20:45 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 1 Mar 2019 19:45:23 +0000 (20:45 +0100)
src/msg/msg_gos.cpp
src/msg/msg_private.hpp
src/msg/msg_task.cpp

index 2b8836b..36d0b0f 100644 (file)
@@ -242,116 +242,6 @@ msg_error_t MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, d
   return ret;
 }
 
-/* Internal function used to factorize code between MSG_task_isend(), MSG_task_isend_bounded(), and MSG_task_dsend(). */
-static inline msg_comm_t MSG_task_isend_internal(msg_task_t task, const char* alias, void_f_pvoid_t cleanup,
-                                                 bool detached)
-{
-  TRACE_msg_task_put_start(task);
-
-  /* Prepare the task to send */
-  task->set_used();
-  task->comm = nullptr;
-  msg_global->sent_msg++;
-
-  simgrid::s4u::CommPtr comm =
-      simgrid::s4u::Mailbox::by_name(alias)->put_init(task, task->bytes_amount)->set_rate(task->get_rate());
-  task->comm                 = comm;
-  if (detached)
-    comm->detach(cleanup);
-  else
-    comm->start();
-
-  msg_comm_t msg_comm = nullptr;
-  if (not detached) {
-    msg_comm = new simgrid::msg::Comm(task, nullptr, comm);
-  }
-
-  if (TRACE_is_enabled() && task->has_tracing_category())
-    simgrid::simix::simcall([comm, task] { comm->get_impl()->set_category(std::move(task->get_tracing_category())); });
-
-  return msg_comm;
-}
-
-/**
- * @brief Sends a task on a mailbox.
- *
- * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
- *
- * @param task a #msg_task_t to send on another location.
- * @param alias name of the mailbox to sent the task to
- * @return the msg_comm_t communication created
- */
-msg_comm_t MSG_task_isend(msg_task_t task, const char *alias)
-{
-  return MSG_task_isend_internal(task, alias, nullptr, false);
-}
-
-/**
- * @brief Sends a task on a mailbox with a maximum rate
- *
- * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication. The maxrate
- * parameter allows the application to limit the bandwidth utilization of network links when sending the task.
- *
- * @param task a #msg_task_t to send on another location.
- * @param alias name of the mailbox to sent the task to
- * @param maxrate the maximum communication rate for sending this task (byte/sec).
- * @return the msg_comm_t communication created
- */
-msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char *alias, double maxrate)
-{
-  task->set_rate(maxrate);
-  return MSG_task_isend_internal(task, alias, nullptr, false);
-}
-
-/**
- * @brief Sends a task on a mailbox.
- *
- * This is a non blocking detached send function.
- * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
- * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
- * usual. More details on this can be obtained on
- * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
- * in the SimGrid-user mailing list archive.
- *
- * @param task a #msg_task_t to send on another location.
- * @param alias name of the mailbox to sent the task to
- * @param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy
- * (if nullptr, no function will be called)
- */
-void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup)
-{
-  msg_comm_t XBT_ATTRIB_UNUSED comm = MSG_task_isend_internal(task, alias, cleanup, true);
-  xbt_assert(comm == nullptr);
-}
-
-/**
- * @brief Sends a task on a mailbox with a maximal rate.
- *
- * This is a non blocking detached send function.
- * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
- * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
- * usual. More details on this can be obtained on
- * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
- * in the SimGrid-user mailing list archive.
- *
- * The rate parameter can be used to send a task with a limited
- * bandwidth (smaller than the physical available value). Use
- * MSG_task_dsend() if you don't limit the rate (or pass -1 as a rate
- * value do disable this feature).
- *
- * @param task a #msg_task_t to send on another location.
- * @param alias name of the mailbox to sent the task to
- * @param cleanup a function to destroy the task if the
- * communication fails, e.g. MSG_task_destroy
- * (if nullptr, no function will be called)
- * @param maxrate the maximum communication rate for sending this task (byte/sec)
- *
- */
-void MSG_task_dsend_bounded(msg_task_t task, const char *alias, void_f_pvoid_t cleanup, double maxrate)
-{
-  task->set_rate(maxrate);
-  MSG_task_dsend(task, alias, cleanup);
-}
 
 /**
  * @brief Starts listening for receiving a task from an asynchronous communication.
index ccacb30..31440dc 100644 (file)
@@ -39,6 +39,7 @@ public:
   static Task* create_parallel(std::string name, int host_nb, const msg_host_t* host_list, double* flops_amount,
                                double* bytes_amount, void* data);
   msg_error_t execute();
+  Comm* send_async(std::string alias, void_f_pvoid_t cleanup, bool detached);
   void cancel();
 
   Task(const Task&) = delete;
@@ -84,8 +85,8 @@ public:
 
 class Comm {
 public:
-  msg_task_t task_sent;        /* task sent (NULL for the receiver) */
-  msg_task_t* task_received;   /* where the task will be received (NULL for the sender) */
+  Task* task_sent;             /* task sent (NULL for the receiver) */
+  Task** task_received;        /* where the task will be received (NULL for the sender) */
   s4u::CommPtr s_comm;         /* SIMIX communication object encapsulated (the same for both processes) */
   msg_error_t status = MSG_OK; /* status of the communication once finished */
   Comm(msg_task_t sent, msg_task_t* received, s4u::CommPtr comm)
index 07a5423..ff50989 100644 (file)
@@ -4,10 +4,11 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "msg_private.hpp"
-#include "src/simix/smx_private.hpp"
+#include "src/instr/instr_private.hpp"
 #include <simgrid/s4u/Comm.hpp>
 #include <simgrid/s4u/Exec.hpp>
 #include <simgrid/s4u/Host.hpp>
+#include <simgrid/s4u/Mailbox.hpp>
 
 #include <algorithm>
 #include <vector>
@@ -96,6 +97,32 @@ msg_error_t Task::execute()
   return status;
 }
 
+Comm* Task::send_async(std::string alias, void_f_pvoid_t cleanup, bool detached)
+{
+  TRACE_msg_task_put_start(this);
+
+  /* Prepare the task to send */
+  set_used();
+  this->comm = nullptr;
+  msg_global->sent_msg++;
+
+  s4u::CommPtr comm = s4u::Mailbox::by_name(alias)->put_init(this, bytes_amount)->set_rate(get_rate());
+  this->comm        = comm;
+
+  if (detached)
+    comm->detach(cleanup);
+  else
+    comm->start();
+
+  if (TRACE_is_enabled() && has_tracing_category())
+    simgrid::simix::simcall([comm, this] { comm->get_impl()->set_category(std::move(tracing_category_)); });
+
+  if (not detached)
+    return new Comm(this, nullptr, comm);
+  else
+    return nullptr;
+}
+
 void Task::cancel()
 {
   if (compute) {
@@ -252,6 +279,83 @@ msg_error_t MSG_task_execute(msg_task_t task)
 {
   return task->execute();
 }
+/**
+ * @brief Sends a task on a mailbox.
+ *
+ * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication.
+ *
+ * @param task a #msg_task_t to send on another location.
+ * @param alias name of the mailbox to sent the task to
+ * @return the msg_comm_t communication created
+ */
+msg_comm_t MSG_task_isend(msg_task_t task, const char* alias)
+{
+  return task->send_async(alias, nullptr, false);
+}
+
+/**
+ * @brief Sends a task on a mailbox with a maximum rate
+ *
+ * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test() to end the communication. The maxrate
+ * parameter allows the application to limit the bandwidth utilization of network links when sending the task.
+ *
+ * @param task a #msg_task_t to send on another location.
+ * @param alias name of the mailbox to sent the task to
+ * @param maxrate the maximum communication rate for sending this task (byte/sec).
+ * @return the msg_comm_t communication created
+ */
+msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char* alias, double maxrate)
+{
+  task->set_rate(maxrate);
+  return task->send_async(alias, nullptr, false);
+}
+
+/**
+ * @brief Sends a task on a mailbox.
+ *
+ * This is a non blocking detached send function.
+ * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
+ * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
+ * usual. More details on this can be obtained on
+ * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
+ * in the SimGrid-user mailing list archive.
+ *
+ * @param task a #msg_task_t to send on another location.
+ * @param alias name of the mailbox to sent the task to
+ * @param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy
+ * (if nullptr, no function will be called)
+ */
+void MSG_task_dsend(msg_task_t task, const char* alias, void_f_pvoid_t cleanup)
+{
+  msg_comm_t XBT_ATTRIB_UNUSED comm = task->send_async(alias, cleanup, true);
+  xbt_assert(comm == nullptr);
+}
+
+/**
+ * @brief Sends a task on a mailbox with a maximal rate.
+ *
+ * This is a non blocking detached send function.
+ * Think of it as a best effort send. Keep in mind that the third parameter is only called if the communication fails.
+ * If the communication does work, it is responsibility of the receiver code to free anything related to the task, as
+ * usual. More details on this can be obtained on
+ * <a href="http://lists.gforge.inria.fr/pipermail/simgrid-user/2011-November/002649.html">this thread</a>
+ * in the SimGrid-user mailing list archive.
+ *
+ * The rate parameter can be used to send a task with a limited bandwidth (smaller than the physical available value).
+ * Use MSG_task_dsend() if you don't limit the rate (or pass -1 as a rate value do disable this feature).
+ *
+ * @param task a #msg_task_t to send on another location.
+ * @param alias name of the mailbox to sent the task to
+ * @param cleanup a function to destroy the task if the communication fails, e.g. MSG_task_destroy (if nullptr, no
+ *        function will be called)
+ * @param maxrate the maximum communication rate for sending this task (byte/sec)
+ *
+ */
+void MSG_task_dsend_bounded(msg_task_t task, const char* alias, void_f_pvoid_t cleanup, double maxrate)
+{
+  task->set_rate(maxrate);
+  MSG_task_dsend(task, alias, cleanup);
+}
 
 /** @brief Destroys the given task.
  *