Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Typos
[simgrid.git] / src / msg / gos.c
index 9ab4dc0..7d929e1 100644 (file)
@@ -37,24 +37,24 @@ MSG_error_t MSG_get_errno(void)
 MSG_error_t MSG_task_execute(m_task_t task)
 {
   simdata_task_t simdata = NULL;
-  m_process_t self = MSG_process_self();
+  simdata_process_t p_simdata;
   e_smx_state_t comp_state;
   CHECK_HOST();
 
   simdata = task->simdata;
 
-  xbt_assert0(simdata->host_nb == 0,
+  xbt_assert(simdata->host_nb == 0,
               "This is a parallel task. Go to hell.");
 
 #ifdef HAVE_TRACING
   TRACE_msg_task_execute_start(task);
 #endif
 
-  xbt_assert1((!simdata->compute) && (task->simdata->isused == 0),
+  xbt_assert((!simdata->compute) && (task->simdata->isused == 0),
               "This task is executed somewhere else. Go fix your code! %d",
               task->simdata->isused);
 
-  DEBUG1("Computing on %s", MSG_process_self()->simdata->m_host->name);
+  XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
 
   if (simdata->computation_amount == 0) {
 #ifdef HAVE_TRACING
@@ -71,13 +71,14 @@ MSG_error_t MSG_task_execute(m_task_t task)
   SIMIX_req_set_category(simdata->compute, task->category);
 #endif
 
-  self->simdata->waiting_action = simdata->compute;
+  p_simdata = SIMIX_process_self_get_data();
+  p_simdata->waiting_action = simdata->compute;
   comp_state = SIMIX_req_host_execution_wait(simdata->compute);
-  self->simdata->waiting_action = NULL;
+  p_simdata->waiting_action = NULL;
 
   simdata->isused=0;
 
-  DEBUG2("Execution task '%s' finished in state %d", task->name, comp_state);
+  XBT_DEBUG("Execution task '%s' finished in state %d", task->name, comp_state);
   if (comp_state == SIMIX_DONE) {
     /* action ended, set comm and compute = NULL, the actions is already destroyed in the main function */
     simdata->computation_amount = 0.0;
@@ -166,19 +167,20 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task)
 {
   simdata_task_t simdata = NULL;
   e_smx_state_t comp_state;
-  m_process_t self = MSG_process_self();
+  simdata_process_t p_simdata;
   CHECK_HOST();
 
   simdata = task->simdata;
+  p_simdata = SIMIX_process_self_get_data();
 
-  xbt_assert0((!simdata->compute)
+  xbt_assert((!simdata->compute)
               && (task->simdata->isused == 0),
               "This task is executed somewhere else. Go fix your code!");
 
-  xbt_assert0(simdata->host_nb,
+  xbt_assert(simdata->host_nb,
               "This is not a parallel task. Go to hell.");
 
-  DEBUG1("Parallel computing on %s", MSG_process_self()->simdata->m_host->name);
+  XBT_DEBUG("Parallel computing on %s", p_simdata->m_host->name);
 
   simdata->isused=1;
 
@@ -187,13 +189,13 @@ MSG_error_t MSG_parallel_task_execute(m_task_t task)
                                   simdata->host_list,
                                   simdata->comp_amount,
                                   simdata->comm_amount, 1.0, -1.0);
-  DEBUG1("Parallel execution action created: %p", simdata->compute);
+  XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
 
-  self->simdata->waiting_action = simdata->compute;
+  p_simdata->waiting_action = simdata->compute;
   comp_state = SIMIX_req_host_execution_wait(simdata->compute);
-  self->simdata->waiting_action = NULL;
+  p_simdata->waiting_action = NULL;
 
-  DEBUG2("Finished waiting for execution of action %p, state = %d", simdata->compute, comp_state);
+  XBT_DEBUG("Finished waiting for execution of action %p, state = %d", simdata->compute, comp_state);
 
   simdata->isused=0;
 
@@ -329,7 +331,7 @@ MSG_error_t
 MSG_task_get_ext(m_task_t * task, m_channel_t channel, double timeout,
                  m_host_t host)
 {
-  xbt_assert1((channel >= 0)
+  xbt_assert((channel >= 0)
               && (channel < msg_global->max_channel), "Invalid channel %d",
               channel);
 
@@ -362,7 +364,7 @@ MSG_error_t
 MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout,
                      m_host_t host)
 {
-  DEBUG1
+  XBT_DEBUG
       ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
        alias);
   return MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task,
@@ -380,6 +382,24 @@ MSG_task_receive_ext(m_task_t * task, const char *alias, double timeout,
  * \return the msg_comm_t communication created
  */
 msg_comm_t MSG_task_isend(m_task_t task, const char *alias)
+{
+  return MSG_task_isend_with_matching(task,alias,NULL,NULL);
+}
+/** \ingroup msg_gos_functions
+ * \brief Sends a task on a mailbox, with support for matching requests
+ *
+ * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
+ * to end the communication.
+ *
+ * \param task a #m_task_t to send on another location.
+ * \param alias name of the mailbox to sent the task to
+ * \param match_fun boolean function taking the #match_data provided by sender (here), and the one of the receiver (if any) and returning whether they match
+ * \param match_data user provided data passed to match_fun
+ * \return the msg_comm_t communication created
+ */
+XBT_INLINE msg_comm_t MSG_task_isend_with_matching(m_task_t task, const char *alias,
+    int (*match_fun)(void*,void*),
+    void *match_data)
 {
   simdata_task_t t_simdata = NULL;
   m_process_t process = MSG_process_self();
@@ -394,7 +414,7 @@ msg_comm_t MSG_task_isend(m_task_t task, const char *alias)
   t_simdata->sender = process;
   t_simdata->source = MSG_host_self();
 
-  xbt_assert0(t_simdata->isused == 0,
+  xbt_assert(t_simdata->isused == 0,
               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
 
   t_simdata->isused = 1;
@@ -407,7 +427,7 @@ msg_comm_t MSG_task_isend(m_task_t task, const char *alias)
   comm->status = MSG_OK;
   comm->s_comm =
     SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
-                         t_simdata->rate, task, sizeof(void *), NULL, NULL, 0);
+                         t_simdata->rate, task, sizeof(void *), match_fun, match_data, 0);
   t_simdata->comm = comm->s_comm; /* FIXME: is the field t_simdata->comm still useful? */
 
   return comm;
@@ -422,8 +442,11 @@ msg_comm_t MSG_task_isend(m_task_t task, const char *alias)
  *
  * \param task a #m_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 (if NULL, MSG_task_destroy() will
+ * be used by default)
  */
-void MSG_task_dsend(m_task_t task, const char *alias)
+void MSG_task_dsend(m_task_t task, const char *alias, void_f_pvoid_t cleanup)
 {
   simdata_task_t t_simdata = NULL;
   m_process_t process = MSG_process_self();
@@ -431,6 +454,10 @@ void MSG_task_dsend(m_task_t task, const char *alias)
 
   CHECK_HOST();
 
+  if (cleanup == NULL) {
+    cleanup = (void_f_pvoid_t) MSG_task_destroy;
+  }
+
   /* FIXME: these functions are not traceable */
 
   /* Prepare the task to send */
@@ -438,20 +465,15 @@ void MSG_task_dsend(m_task_t task, const char *alias)
   t_simdata->sender = process;
   t_simdata->source = MSG_host_self();
 
-  xbt_assert0(t_simdata->isused == 0,
+  xbt_assert(t_simdata->isused == 0,
               "This task is still being used somewhere else. You cannot send it now. Go fix your code!");
 
   t_simdata->isused = 1;
   msg_global->sent_msg++;
 
   /* Send it by calling SIMIX network layer */
-  msg_comm_t comm = xbt_new0(s_msg_comm_t, 1);
-  comm->task_sent = task;
-  comm->task_received = NULL;
-  comm->status = MSG_OK;
-    SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
-                         t_simdata->rate, task, sizeof(void *), NULL, NULL, 1);
-    /*t_simdata->comm = comm->s_comm;  FIXME: is the field t_simdata->comm still useful? */
+  SIMIX_req_comm_isend(mailbox, t_simdata->message_size,
+                       t_simdata->rate, task, sizeof(void *), NULL, cleanup, 1);
 }
 
 /** \ingroup msg_gos_functions
@@ -473,10 +495,10 @@ msg_comm_t MSG_task_irecv(m_task_t *task, const char *alias)
   /* FIXME: these functions are not tracable */
 
   /* Sanity check */
-  xbt_assert0(task, "Null pointer for the task storage");
+  xbt_assert(task, "Null pointer for the task storage");
 
   if (*task)
-    CRITICAL0
+    XBT_CRITICAL
         ("MSG_task_get() was asked to write in a non empty task struct.");
 
   /* Try to receive it by calling SIMIX network layer */
@@ -602,7 +624,7 @@ void MSG_comm_destroy(msg_comm_t comm)
   }
 
   /* FIXME auto-destroy comms from SIMIX to avoid this request */
-  SIMIX_req_comm_destroy(comm->s_comm);
+  /*SIMIX_req_comm_destroy(comm->s_comm);*/
   free(comm);
 }
 
@@ -709,7 +731,7 @@ int MSG_comm_waitany(xbt_dynar_t comms)
     xbt_ex_free(e);
   }
 
-  xbt_assert0(finished_index != -1, "WaitAny returned -1");
+  xbt_assert(finished_index != -1, "WaitAny returned -1");
   xbt_dynar_free(&s_comms);
 
   comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t);
@@ -733,7 +755,7 @@ MSG_error_t MSG_comm_get_status(msg_comm_t comm) {
 
 m_task_t MSG_comm_get_task(msg_comm_t comm)
 {
-  xbt_assert0(comm, "Invalid parameter");
+  xbt_assert(comm, "Invalid parameter");
 
   return comm->task_received ? *comm->task_received : comm->task_sent;
 }
@@ -816,11 +838,11 @@ MSG_error_t
 MSG_task_put_with_timeout(m_task_t task, m_host_t dest,
                           m_channel_t channel, double timeout)
 {
-  xbt_assert1((channel >= 0)
+  xbt_assert((channel >= 0)
               && (channel < msg_global->max_channel), "Invalid channel %d",
               channel);
 
-  DEBUG1("MSG_task_put_with_timout: Trying to send a task to '%s'", dest->name);
+  XBT_DEBUG("MSG_task_put_with_timout: Trying to send a task to '%s'", dest->name);
   return
       MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel
                                    (dest, channel), task, timeout);
@@ -828,7 +850,7 @@ MSG_task_put_with_timeout(m_task_t task, m_host_t dest,
 
 MSG_error_t MSG_task_send(m_task_t task, const char *alias)
 {
-  DEBUG1("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
+  XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
   return MSG_task_send_with_timeout(task, alias, -1);
 }
 
@@ -867,7 +889,7 @@ int MSG_task_listen(const char *alias)
  */
 int MSG_task_Iprobe(m_channel_t channel)
 {
-  xbt_assert1((channel >= 0)
+  xbt_assert((channel >= 0)
               && (channel < msg_global->max_channel), "Invalid channel %d",
               channel);
 
@@ -893,7 +915,7 @@ int MSG_task_Iprobe(m_channel_t channel)
  */
 int MSG_task_probe_from_host(int channel, m_host_t host)
 {
-  xbt_assert1((channel >= 0)
+  xbt_assert((channel >= 0)
               && (channel < msg_global->max_channel), "Invalid channel %d",
               channel);
 
@@ -930,7 +952,7 @@ int MSG_task_probe_from(m_channel_t channel)
 
   CHECK_HOST();
 
-  xbt_assert1((channel >= 0)
+  xbt_assert((channel >= 0)
               && (channel < msg_global->max_channel), "Invalid channel %d",
               channel);