Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
useless cleanups
[simgrid.git] / src / msg / msg_gos.c
index 72eb74e..73c91df 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (c) 2004-2012. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2004-2014. 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. */
@@ -21,9 +22,17 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_gos, msg,
  * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
  * or #MSG_HOST_FAILURE otherwise
  */
-MSG_error_t MSG_task_execute(msg_task_t task)
+msg_error_t MSG_task_execute(msg_task_t task)
 {
-  return MSG_parallel_task_execute(task);
+  /* TODO: add this to other locations */
+  msg_host_t host = MSG_process_get_host(MSG_process_self());
+  MSG_host_add_task(host, task);
+
+  msg_error_t ret = MSG_parallel_task_execute(task);
+
+  MSG_host_del_task(host, task);
+
+  return ret;
 }
 
 /** \ingroup msg_task_usage
@@ -34,14 +43,14 @@ MSG_error_t MSG_task_execute(msg_task_t task)
  * \return #MSG_OK if the task was successfully completed, #MSG_TASK_CANCELED
  * or #MSG_HOST_FAILURE otherwise
  */
-MSG_error_t MSG_parallel_task_execute(msg_task_t task)
+msg_error_t MSG_parallel_task_execute(msg_task_t task)
 {
   xbt_ex_t e;
   simdata_task_t simdata = task->simdata;
   msg_process_t self = SIMIX_process_self();
   simdata_process_t p_simdata = SIMIX_process_self_get_data(self);
   e_smx_state_t comp_state;
-  MSG_error_t status = MSG_OK;
+  msg_error_t status = MSG_OK;
 
 #ifdef HAVE_TRACING
   TRACE_msg_task_execute_start(task);
@@ -49,7 +58,7 @@ MSG_error_t MSG_parallel_task_execute(msg_task_t task)
 
   xbt_assert((!simdata->compute) && (task->simdata->isused == 0),
              "This task is executed somewhere else. Go fix your code! %d",
-             task->simdata->isused);
+             task->simdata->isused!=NULL);
 
   XBT_DEBUG("Computing on %s", MSG_process_get_name(MSG_process_self()));
 
@@ -62,8 +71,10 @@ MSG_error_t MSG_parallel_task_execute(msg_task_t task)
 
 
   TRY {
-
-    simdata->isused=1;
+    if (msg_global->debug_multiple_use)
+      MSG_BT(simdata->isused, "Using Backtrace");
+    else
+      simdata->isused = (void*)1;
 
     if (simdata->host_nb > 0) {
       simdata->compute = simcall_host_parallel_execute(task->name,
@@ -74,10 +85,16 @@ MSG_error_t MSG_parallel_task_execute(msg_task_t task)
                                                        1.0, -1.0);
       XBT_DEBUG("Parallel execution action created: %p", simdata->compute);
     } else {
+      unsigned long affinity_mask = (unsigned long) xbt_dict_get_or_null_ext(simdata->affinity_mask_db, (char *) p_simdata->m_host, sizeof(msg_host_t));
+      XBT_DEBUG("execute %s@%s with affinity(0x%04lx)", MSG_task_get_name(task), MSG_host_get_name(p_simdata->m_host), affinity_mask);
+
       simdata->compute = simcall_host_execute(task->name,
-                                              p_simdata->m_host->smx_host,
+                                              p_simdata->m_host,
                                               simdata->computation_amount,
-                                              simdata->priority);
+                                              simdata->priority,
+                                              simdata->bound,
+                                              affinity_mask
+                                              );
 
     }
 #ifdef HAVE_TRACING
@@ -88,7 +105,9 @@ MSG_error_t MSG_parallel_task_execute(msg_task_t task)
 
     p_simdata->waiting_action = NULL;
 
-    simdata->isused=0;
+    if (msg_global->debug_multiple_use && simdata->isused!=0)
+      xbt_ex_free(*(xbt_ex_t*)simdata->isused);
+    simdata->isused = 0;
 
     XBT_DEBUG("Execution task '%s' finished in state %d",
               task->name, (int)comp_state);
@@ -98,6 +117,9 @@ MSG_error_t MSG_parallel_task_execute(msg_task_t task)
     case cancel_error:
       status = MSG_TASK_CANCELED;
       break;
+    case host_error:
+      status = MSG_HOST_FAILURE;
+      break;
     default:
       RETHROW;
     }
@@ -123,9 +145,10 @@ MSG_error_t MSG_parallel_task_execute(msg_task_t task)
  *
  * \param nb_sec a number of second
  */
-MSG_error_t MSG_process_sleep(double nb_sec)
+msg_error_t MSG_process_sleep(double nb_sec)
 {
-  MSG_error_t status = MSG_OK;
+  xbt_ex_t e;
+  msg_error_t status = MSG_OK;
   /*msg_process_t proc = MSG_process_self();*/
 
 #ifdef HAVE_TRACING
@@ -137,10 +160,29 @@ MSG_error_t MSG_process_sleep(double nb_sec)
   /*proc->simdata->waiting_action = act_sleep;
 
   FIXME: check if not setting the waiting_action breaks something on msg
-  
+
   proc->simdata->waiting_action = NULL;*/
 
-  simcall_process_sleep(nb_sec);
+  TRY {
+    simcall_process_sleep(nb_sec);
+  }
+  CATCH(e) {
+    switch (e.category) {
+    case cancel_error:
+      XBT_DEBUG("According to the JAVA API, a sleep call should only deal with HostFailureException, WTF here ?"); 
+      // adsein: MSG_TASK_CANCELED is assigned when someone kills the process that made the sleep, this is not
+      // correct. For instance, when the node is turned off, the error should be MSG_HOST_FAILURE, which is by the way
+      // and according to the JAVA document, the only exception that can be triggered by MSG_Process_sleep call.
+      // To avoid possible impacts in the code, I just raised a host_failure exception for the moment in the JAVA code
+      // and did not change anythings at the C level.
+      // See comment in the jmsg_process.c file, function JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) 
+      status = MSG_TASK_CANCELED;
+      break;
+    default:
+      RETHROW;
+    }
+    xbt_ex_free(e);
+  }
 
   #ifdef HAVE_TRACING
     TRACE_msg_process_sleep_out(MSG_process_self());
@@ -179,13 +221,33 @@ MSG_error_t MSG_process_sleep(double nb_sec)
  * #MSG_OK if the task was successfully received,
  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
  */
-MSG_error_t
+msg_error_t
 MSG_task_receive_from_host(msg_task_t * task, const char *alias,
                            msg_host_t host)
 {
   return MSG_task_receive_ext(task, alias, -1, host);
 }
 
+/** msg_task_usage
+ *\brief Deprecated function that used to receive a task from a mailbox from a specific host
+ *\brief at a given rate
+ *
+ * \param task a memory location for storing a #msg_task_t.
+ * \param alias name of the mailbox to receive the task from
+ * \param host a #msg_host_t host from where the task was sent
+ * \param rate limit the reception to rate bandwidth
+ *
+ * \return Returns
+ * #MSG_OK if the task was successfully received,
+ * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
+ */
+msg_error_t
+MSG_task_receive_from_host_bounded(msg_task_t * task, const char *alias,
+                                   msg_host_t host, double rate)
+{
+  return MSG_task_receive_ext_bounded(task, alias, -1, host, rate);
+}
+
 /** \ingroup msg_task_usage
  * \brief Receives a task from a mailbox.
  *
@@ -200,11 +262,28 @@ MSG_task_receive_from_host(msg_task_t * task, const char *alias,
  * #MSG_OK if the task was successfully received,
  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
  */
-MSG_error_t MSG_task_receive(msg_task_t * task, const char *alias)
+msg_error_t MSG_task_receive(msg_task_t * task, const char *alias)
 {
   return MSG_task_receive_with_timeout(task, alias, -1);
 }
 
+/** \ingroup msg_task_usage
+ * \brief Receives a task from a mailbox at a given rate.
+ *
+ * \param task a memory location for storing a #msg_task_t.
+ * \param alias name of the mailbox to receive the task from
+ *  \param rate limit the reception to rate bandwidth
+ *
+ * \return Returns
+ * #MSG_OK if the task was successfully received,
+ * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
+ */
+msg_error_t MSG_task_receive_bounded(msg_task_t * task, const char *alias,
+                                     double rate)
+{
+  return MSG_task_receive_with_timeout_bounded(task, alias, -1, rate);
+}
+
 /** \ingroup msg_task_usage
  * \brief Receives a task from a mailbox with a given timeout.
  *
@@ -221,13 +300,32 @@ MSG_error_t MSG_task_receive(msg_task_t * task, const char *alias)
  * #MSG_OK if the task was successfully received,
  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
  */
-MSG_error_t
+msg_error_t
 MSG_task_receive_with_timeout(msg_task_t * task, const char *alias,
                               double timeout)
 {
   return MSG_task_receive_ext(task, alias, timeout, NULL);
 }
 
+/** \ingroup msg_task_usage
+ * \brief Receives a task from a mailbox with a given timeout and at a given rate.
+ *
+ * \param task a memory location for storing a #msg_task_t.
+ * \param alias name of the mailbox to receive the task from
+ * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_receive)
+ *  \param rate limit the reception to rate bandwidth
+ *
+ * \return Returns
+ * #MSG_OK if the task was successfully received,
+ * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
+ */
+msg_error_t
+MSG_task_receive_with_timeout_bounded(msg_task_t * task, const char *alias,
+                                      double timeout,double rate)
+{
+  return MSG_task_receive_ext_bounded(task, alias, timeout, NULL, rate);
+}
+
 /** \ingroup msg_task_usage
  * \brief Receives a task from a mailbox from a specific host with a given timeout.
  *
@@ -245,17 +343,128 @@ MSG_task_receive_with_timeout(msg_task_t * task, const char *alias,
  * #MSG_OK if the task was successfully received,
 * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
  */
-MSG_error_t
+msg_error_t
 MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout,
                      msg_host_t host)
 {
+  xbt_ex_t e;
+  msg_error_t ret = MSG_OK;
   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,
-                                  host, timeout);
+  TRY {
+    ret = MSG_mailbox_get_task_ext(MSG_mailbox_get_by_alias(alias), task,
+                                   host, timeout);
+  }
+  CATCH(e) {
+    switch (e.category) {
+    case cancel_error:          /* may be thrown by MSG_mailbox_get_by_alias */
+      ret = MSG_HOST_FAILURE;
+      break;
+    default:
+      RETHROW;
+    }
+    xbt_ex_free(e);
+  }
+  return ret;
 }
 
+/** \ingroup msg_task_usage
+ * \brief Receives a task from a mailbox from a specific host with a given timeout
+ *  and at a given rate.
+ *
+ * \param task a memory location for storing a #msg_task_t.
+ * \param alias name of the mailbox to receive the task from
+ * \param timeout is the maximum wait time for completion (provide -1 for no timeout)
+ * \param host a #msg_host_t host from where the task was sent
+ * \param rate limit the reception to rate bandwidth
+ *
+ * \return Returns
+ * #MSG_OK if the task was successfully received,
+* #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
+ */
+msg_error_t
+MSG_task_receive_ext_bounded(msg_task_t * task, const char *alias, double timeout,
+                             msg_host_t host, double rate)
+{
+  XBT_DEBUG
+      ("MSG_task_receive_ext: Trying to receive a message on mailbox '%s'",
+       alias);
+  return MSG_mailbox_get_task_ext_bounded(MSG_mailbox_get_by_alias(alias), task,
+                                          host, timeout, rate);
+}
+
+/* Internal function used to factorize code between
+ * MSG_task_isend_with_matching() and MSG_task_dsend().
+ */
+static XBT_INLINE
+msg_comm_t MSG_task_isend_internal(msg_task_t task, const char *alias,
+                                   int (*match_fun)(void*,void*, smx_action_t),
+                                   void *match_data, void_f_pvoid_t cleanup,
+                                   int detached)
+{
+  simdata_task_t t_simdata = NULL;
+  msg_process_t process = MSG_process_self();
+  msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
+
+#ifdef HAVE_TRACING
+  int call_end = TRACE_msg_task_put_start(task);
+#endif
+
+  /* Prepare the task to send */
+  t_simdata = task->simdata;
+  t_simdata->sender = process;
+  t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
+
+  if (t_simdata->isused != 0) {
+    if (msg_global->debug_multiple_use){
+      XBT_ERROR("This task is already used in there:");
+      xbt_backtrace_display(t_simdata->isused);
+      XBT_ERROR("And you try to reuse it from here:");
+      xbt_backtrace_display_current();
+    } else {
+      xbt_assert(t_simdata->isused == 0,
+                 "This task is still being used somewhere else. You cannot send it now. Go fix your code! (use --cfg=msg/debug_multiple_use:on to get the backtrace of the other process)");
+    }
+  }
+
+  if (msg_global->debug_multiple_use)
+    MSG_BT(t_simdata->isused, "Using Backtrace");
+  else
+    t_simdata->isused = (void*)1;
+  t_simdata->comm = NULL;
+  msg_global->sent_msg++;
+
+  /* Send it by calling SIMIX network layer */
+  smx_action_t act = simcall_comm_isend(SIMIX_process_self(), mailbox, t_simdata->message_size,
+                                        t_simdata->rate, task, sizeof(void *),
+                                        match_fun, cleanup, NULL, match_data,detached);
+  t_simdata->comm = act; /* FIXME: is the field t_simdata->comm still useful? */
+
+  msg_comm_t comm;
+  if (detached) {
+    comm = NULL;
+  } else {
+    comm = xbt_new0(s_msg_comm_t, 1);
+    comm->task_sent = task;
+    comm->task_received = NULL;
+    comm->status = MSG_OK;
+    comm->s_comm = act;
+  }
+
+#ifdef HAVE_TRACING
+  if (TRACE_is_enabled()) {
+    simcall_set_category(act, task->category);
+  }
+
+  if (call_end)
+    TRACE_msg_task_put_end();
+#endif
+
+  return comm;
+}
+
+
 /** \ingroup msg_task_usage
  * \brief Sends a task on a mailbox.
  *
@@ -268,9 +477,29 @@ MSG_task_receive_ext(msg_task_t * task, const char *alias, double timeout,
  */
 msg_comm_t MSG_task_isend(msg_task_t task, const char *alias)
 {
-  return MSG_task_isend_with_matching(task,alias,NULL,NULL);
+  return MSG_task_isend_internal(task, alias, NULL, NULL, NULL, 0);
 }
 
+/** \ingroup msg_task_usage
+ * \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 .
+ * \return the msg_comm_t communication created
+ */
+msg_comm_t MSG_task_isend_bounded(msg_task_t task, const char *alias,
+                                  double maxrate)
+{
+  task->simdata->rate = maxrate;
+  return MSG_task_isend_internal(task, alias, NULL, NULL, NULL, 0);
+}
+
+
 /** \ingroup msg_task_usage
  * \brief Sends a task on a mailbox, with support for matching requests
  *
@@ -286,39 +515,12 @@ msg_comm_t MSG_task_isend(msg_task_t task, const char *alias)
  * \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(msg_task_t task, const char *alias,
-    int (*match_fun)(void*,void*, smx_action_t),
-    void *match_data)
+msg_comm_t MSG_task_isend_with_matching(msg_task_t task, const char *alias,
+                                        int (*match_fun)(void*, void*,
+                                                         smx_action_t),
+                                        void *match_data)
 {
-  simdata_task_t t_simdata = NULL;
-  msg_process_t process = MSG_process_self();
-  msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
-
-  /* FIXME: these functions are not traceable */
-
-  /* Prepare the task to send */
-  t_simdata = task->simdata;
-  t_simdata->sender = process;
-  t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
-
-  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;
-  t_simdata->comm = NULL;
-  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;
-  comm->s_comm =
-    simcall_comm_isend(mailbox, t_simdata->message_size,
-                         t_simdata->rate, task, sizeof(void *), match_fun, NULL, match_data, 0);
-  t_simdata->comm = comm->s_comm; /* FIXME: is the field t_simdata->comm still useful? */
-
-  return comm;
+  return MSG_task_isend_internal(task, alias, match_fun, match_data, NULL, 0);
 }
 
 /** \ingroup msg_task_usage
@@ -340,28 +542,33 @@ XBT_INLINE msg_comm_t MSG_task_isend_with_matching(msg_task_t task, const char *
  */
 void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup)
 {
-  simdata_task_t t_simdata = NULL;
-  msg_process_t process = MSG_process_self();
-  msg_mailbox_t mailbox = MSG_mailbox_get_by_alias(alias);
-
-  /* FIXME: these functions are not traceable */
-
-  /* Prepare the task to send */
-  t_simdata = task->simdata;
-  t_simdata->sender = process;
-  t_simdata->source = ((simdata_process_t) SIMIX_process_self_get_data(process))->m_host;
-
-  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;
-  t_simdata->comm = NULL;
-  msg_global->sent_msg++;
+  MSG_task_isend_internal(task, alias, NULL, NULL, cleanup, 1);
+}
 
-  /* Send it by calling SIMIX network layer */
-  smx_action_t comm = simcall_comm_isend(mailbox, t_simdata->message_size,
-                       t_simdata->rate, task, sizeof(void *), NULL, cleanup, NULL, 1);
-  t_simdata->comm = comm;
+/** \ingroup msg_task_usage
+ * \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.
+ *
+ * \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 NULL, no function will be called)
+ * \param maxrate the maximum communication rate for sending this task
+ *
+ */
+void MSG_task_dsend_bounded(msg_task_t task, const char *alias,
+                            void_f_pvoid_t cleanup, double maxrate)
+{
+  task->simdata->rate = maxrate;
+  MSG_task_dsend(task, alias, cleanup);
 }
 
 /** \ingroup msg_task_usage
@@ -369,12 +576,27 @@ void MSG_task_dsend(msg_task_t task, const char *alias, void_f_pvoid_t cleanup)
  *
  * This is a non blocking function: use MSG_comm_wait() or MSG_comm_test()
  * to end the communication.
- * 
+ *
  * \param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
  * \param name of the mailbox to receive the task on
  * \return the msg_comm_t communication created
  */
 msg_comm_t MSG_task_irecv(msg_task_t *task, const char *name)
+{
+  return MSG_task_irecv_bounded(task, name, -1.0);
+}
+
+/** \ingroup msg_task_usage
+ * \brief Starts listening for receiving a task from an asynchronous communication
+ * at a given rate.
+ *
+ * \param task a memory location for storing a #msg_task_t. has to be valid until the end of the communication.
+ * \param name of the mailbox to receive the task on
+ * \param rate limit the bandwidth to the given rate
+ * \return the msg_comm_t communication created
+ */
+msg_comm_t MSG_task_irecv_bounded(msg_task_t *task, const char *name,
+                                  double rate)
 {
   smx_rdv_t rdv = MSG_mailbox_get_by_alias(name);
 
@@ -392,7 +614,7 @@ msg_comm_t MSG_task_irecv(msg_task_t *task, const char *name)
   comm->task_sent = NULL;
   comm->task_received = task;
   comm->status = MSG_OK;
-  comm->s_comm = simcall_comm_irecv(rdv, task, NULL, NULL, NULL);
+  comm->s_comm = simcall_comm_irecv(rdv, task, NULL, NULL, NULL, NULL, rate);
 
   return comm;
 }
@@ -409,11 +631,14 @@ int MSG_comm_test(msg_comm_t comm)
 {
   xbt_ex_t e;
   int finished = 0;
+
   TRY {
     finished = simcall_comm_test(comm->s_comm);
 
     if (finished && comm->task_received != NULL) {
       /* I am the receiver */
+      if (msg_global->debug_multiple_use && (*comm->task_received)->simdata->isused!=0)
+        xbt_ex_free(*(xbt_ex_t*)(*comm->task_received)->simdata->isused);
       (*comm->task_received)->simdata->isused = 0;
     }
   }
@@ -458,7 +683,7 @@ int MSG_comm_testany(xbt_dynar_t comms)
     xbt_dynar_push(s_comms, &comm->s_comm);
   }
 
-  MSG_error_t status = MSG_OK;
+  msg_error_t status = MSG_OK;
   TRY {
     finished_index = simcall_comm_testany(s_comms);
   }
@@ -488,6 +713,8 @@ int MSG_comm_testany(xbt_dynar_t comms)
 
     if (status == MSG_OK && comm->task_received != NULL) {
       /* I am the receiver */
+      if (msg_global->debug_multiple_use && (*comm->task_received)->simdata->isused!=0)
+        xbt_ex_free(*(xbt_ex_t*)(*comm->task_received)->simdata->isused);
       (*comm->task_received)->simdata->isused = 0;
     }
   }
@@ -509,11 +736,11 @@ void MSG_comm_destroy(msg_comm_t comm)
  *
  * It takes two parameters.
  * \param comm the communication to wait.
- * \param timeout Wait until the communication terminates or the timeout 
+ * \param timeout Wait until the communication terminates or the timeout
  * occurs. You can provide a -1 timeout to obtain an infinite timeout.
- * \return MSG_error_t
+ * \return msg_error_t
  */
-MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
+msg_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
 {
   xbt_ex_t e;
   TRY {
@@ -521,6 +748,8 @@ MSG_error_t MSG_comm_wait(msg_comm_t comm, double timeout)
 
     if (comm->task_received != NULL) {
       /* I am the receiver */
+      if (msg_global->debug_multiple_use && (*comm->task_received)->simdata->isused!=0)
+        xbt_ex_free(*(xbt_ex_t*)(*comm->task_received)->simdata->isused);
       (*comm->task_received)->simdata->isused = 0;
     }
 
@@ -577,7 +806,7 @@ int MSG_comm_waitany(xbt_dynar_t comms)
     xbt_dynar_push(s_comms, &comm->s_comm);
   }
 
-  MSG_error_t status = MSG_OK;
+  msg_error_t status = MSG_OK;
   TRY {
     finished_index = simcall_comm_waitany(s_comms);
   }
@@ -608,6 +837,8 @@ int MSG_comm_waitany(xbt_dynar_t comms)
 
   if (comm->task_received != NULL) {
     /* I am the receiver */
+    if (msg_global->debug_multiple_use && (*comm->task_received)->simdata->isused!=0)
+      xbt_ex_free(*(xbt_ex_t*)(*comm->task_received)->simdata->isused);
     (*comm->task_received)->simdata->isused = 0;
   }
 
@@ -621,7 +852,7 @@ int MSG_comm_waitany(xbt_dynar_t comms)
  * \return the status of the communication, or #MSG_OK if no error occured
  * during the communication
  */
-MSG_error_t MSG_comm_get_status(msg_comm_t comm) {
+msg_error_t MSG_comm_get_status(msg_comm_t comm) {
 
   return comm->status;
 }
@@ -640,7 +871,7 @@ msg_task_t MSG_comm_get_task(msg_comm_t comm)
 }
 
 /**
- * \brief This function is called by SIMIX to copy the data of a comm.
+ * \brief This function is called by SIMIX in kernel mode to copy the data of a comm.
  * \param comm the comm
  * \param buff the data copied
  * \param buff_size size of the buffer
@@ -671,7 +902,7 @@ void MSG_comm_copy_data_from_SIMIX(smx_action_t comm, void* buff, size_t buff_si
  * \return Returns #MSG_OK if the task was successfully sent,
  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
  */
-MSG_error_t MSG_task_send(msg_task_t task, const char *alias)
+msg_error_t MSG_task_send(msg_task_t task, const char *alias)
 {
   XBT_DEBUG("MSG_task_send: Trying to send a message on mailbox '%s'", alias);
   return MSG_task_send_with_timeout(task, alias, -1);
@@ -691,7 +922,7 @@ MSG_error_t MSG_task_send(msg_task_t task, const char *alias)
  * \return Returns #MSG_OK if the task was successfully sent,
  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE otherwise.
  */
-MSG_error_t
+msg_error_t
 MSG_task_send_bounded(msg_task_t task, const char *alias, double maxrate)
 {
   task->simdata->rate = maxrate;
@@ -711,7 +942,7 @@ MSG_task_send_bounded(msg_task_t task, const char *alias, double maxrate)
  * \return Returns #MSG_OK if the task was successfully sent,
  * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
  */
-MSG_error_t
+msg_error_t
 MSG_task_send_with_timeout(msg_task_t task, const char *alias,
                            double timeout)
 {
@@ -719,6 +950,29 @@ MSG_task_send_with_timeout(msg_task_t task, const char *alias,
                                       task, timeout);
 }
 
+/** \ingroup msg_task_usage
+ * \brief Sends a task to a mailbox with a timeout and with a maximum rate
+ *
+ * This is a blocking function, the execution flow will be blocked
+ * until the task is sent or the timeout is achieved.
+ *
+ * \param task the task to be sent
+ * \param alias the mailbox name to where the task is sent
+ * \param timeout is the maximum wait time for completion (if -1, this call is the same as #MSG_task_send)
+ * \param maxrate the maximum communication rate for sending this task
+ *
+ * \return Returns #MSG_OK if the task was successfully sent,
+ * #MSG_HOST_FAILURE, or #MSG_TRANSFER_FAILURE, or #MSG_TIMEOUT otherwise.
+ */
+msg_error_t
+MSG_task_send_with_timeout_bounded(msg_task_t task, const char *alias,
+                           double timeout, double maxrate)
+{
+  task->simdata->rate = maxrate;
+  return MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_alias(alias),
+                                      task, timeout);
+}
+
 /** \ingroup msg_task_usage
  * \brief Check if there is a communication going on in a mailbox.
  *
@@ -779,7 +1033,7 @@ int MSG_task_listen_from(const char *alias)
  * previously declared with the function #TRACE_category
  * (or with #TRACE_category_with_color).
  *
- * See \ref tracing_tracing for details on how to trace
+ * See \ref tracing for details on how to trace
  * the (categorized) resource utilization.
  *
  * \param task the task that is going to be categorized
@@ -813,13 +1067,49 @@ const char *MSG_task_get_category (msg_task_t task)
 #endif
 }
 
+/**
+ * \brief Returns the value of a given AS or router property
+ *
+ * \param asr the name of a router or AS
+ * \param name a property name
+ * \return value of a property (or NULL if property not set)
+ */
+const char *MSG_as_router_get_property_value(const char* asr, const char *name)
+{
+  return xbt_dict_get_or_null(MSG_as_router_get_properties(asr), name);
+}
+
+/**
+ * \brief Returns a xbt_dict_t consisting of the list of properties assigned to
+ * a the AS or router
+ *
+ * \param asr the name of a router or AS
+ * \return a dict containing the properties
+ */
+xbt_dict_t MSG_as_router_get_properties(const char* asr)
+{
+  return (simcall_asr_get_properties(asr));
+}
+
+/**
+ * \brief Change the value of a given AS or router
+ *
+ * \param asr the name of a router or AS
+ * \param name a property name
+ * \param value what to change the property to
+ * \param free_ctn the freeing function to use to kill the value on need
+ */
+void MSG_as_router_set_property_value(const char* asr, const char *name, char *value,void_f_pvoid_t free_ctn) {
+  xbt_dict_set(MSG_as_router_get_properties(asr), name, value,free_ctn);
+}
+
 #ifdef MSG_USE_DEPRECATED
 /** \ingroup msg_deprecated_functions
  *
  * \brief Return the last value returned by a MSG function (except
  * MSG_get_errno...).
  */
-MSG_error_t MSG_get_errno(void)
+msg_error_t MSG_get_errno(void)
 {
   return PROCESS_GET_ERRNO();
 }
@@ -849,7 +1139,7 @@ MSG_error_t MSG_get_errno(void)
  * #MSG_TRANSFER_FAILURE if the transfer could not be properly done
  * (network failure, dest failure) or #MSG_OK if it succeeded.
  */
-MSG_error_t MSG_task_put(msg_task_t task, msg_host_t dest, m_channel_t channel)
+msg_error_t MSG_task_put(msg_task_t task, msg_host_t dest, m_channel_t channel)
 {
   XBT_WARN("DEPRECATED! Now use MSG_task_send");
   return MSG_task_put_with_timeout(task, dest, channel, -1.0);
@@ -861,7 +1151,7 @@ MSG_error_t MSG_task_put(msg_task_t task, msg_host_t dest, m_channel_t channel)
  *
  * \sa MSG_task_put
  */
-MSG_error_t
+msg_error_t
 MSG_task_put_bounded(msg_task_t task, msg_host_t dest, m_channel_t channel,
                      double maxrate)
 {
@@ -900,7 +1190,7 @@ this function was called was shut down,
 #MSG_TRANSFER_FAILURE if the transfer could not be properly done
 (network failure, dest failure, timeout...) or #MSG_OK if the communication succeeded.
  */
-MSG_error_t
+msg_error_t
 MSG_task_put_with_timeout(msg_task_t task, msg_host_t dest,
                           m_channel_t channel, double timeout)
 {
@@ -909,7 +1199,7 @@ MSG_task_put_with_timeout(msg_task_t task, msg_host_t dest,
               && (channel < msg_global->max_channel), "Invalid channel %d",
               channel);
 
-  XBT_DEBUG("MSG_task_put_with_timout: Trying to send a task to '%s'", SIMIX_host_get_name(dest->smx_host));
+  XBT_DEBUG("MSG_task_put_with_timout: Trying to send a task to '%s'", MSG_host_get_name(dest));
   return
       MSG_mailbox_put_with_timeout(MSG_mailbox_get_by_channel
                                    (dest, channel), task, timeout);
@@ -1002,9 +1292,9 @@ int MSG_task_probe_from_host(int channel, msg_host_t host)
  listening. This value has to be >=0 and < than the maximal
  number of channels fixed with MSG_set_channel_number().
  * \param host the host that is to be watched.
- * \return a #MSG_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
+ * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
  */
-MSG_error_t
+msg_error_t
 MSG_task_get_from_host(msg_task_t * task, m_channel_t channel, msg_host_t host)
 {
   XBT_WARN("DEPRECATED! Now use MSG_task_receive_from_host");
@@ -1022,9 +1312,9 @@ MSG_task_get_from_host(msg_task_t * task, m_channel_t channel, msg_host_t host)
  * \param channel the channel on which the process should be
  listening. This value has to be >=0 and < than the maximal
  number of channels fixed with MSG_set_channel_number().
- * \return a #MSG_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
+ * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
  */
-MSG_error_t MSG_task_get(msg_task_t * task, m_channel_t channel)
+msg_error_t MSG_task_get(msg_task_t * task, m_channel_t channel)
 {
   XBT_WARN("DEPRECATED! Now use MSG_task_receive");
   return MSG_task_get_with_timeout(task, channel, -1);
@@ -1045,9 +1335,9 @@ MSG_error_t MSG_task_get(msg_task_t * task, m_channel_t channel)
  up. In such a case, #MSG_TRANSFER_FAILURE will be returned, \a task
  will not be modified and will still be
  equal to \c NULL when returning.
- * \return a #MSG_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
+ * \return a #msg_error_t indicating whether the operation was successful (#MSG_OK), or why it failed otherwise.
  */
-MSG_error_t
+msg_error_t
 MSG_task_get_with_timeout(msg_task_t * task, m_channel_t channel,
                           double max_duration)
 {
@@ -1055,7 +1345,7 @@ MSG_task_get_with_timeout(msg_task_t * task, m_channel_t channel,
   return MSG_task_get_ext(task, channel, max_duration, NULL);
 }
 
-MSG_error_t
+msg_error_t
 MSG_task_get_ext(msg_task_t * task, m_channel_t channel, double timeout,
                  msg_host_t host)
 {