Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Chord: display the number of messages created
[simgrid.git] / src / simix / smx_network.c
index 5a1d603..d5dba6a 100644 (file)
@@ -13,18 +13,17 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_network, simix,
                                 "Logging specific to SIMIX (network)");
 
 static xbt_dict_t rdv_points = NULL;
+unsigned long int smx_total_comms = 0;
 
 static XBT_INLINE void SIMIX_comm_start(smx_action_t action);
 static void SIMIX_comm_finish(smx_action_t action);
 static void SIMIX_waitany_req_remove_from_actions(smx_req_t req);
 static void SIMIX_comm_copy_data(smx_action_t comm);
 static smx_action_t SIMIX_comm_new(e_smx_comm_type_t type);
-static XBT_INLINE void SIMIX_comm_wait_for_completion(smx_action_t comm,
-                                                      double timeout);
 static XBT_INLINE void SIMIX_rdv_push(smx_rdv_t rdv, smx_action_t comm);
 static XBT_INLINE void SIMIX_rdv_remove(smx_rdv_t rdv, smx_action_t comm);
 static smx_action_t SIMIX_rdv_get_request(smx_rdv_t rdv, e_smx_comm_type_t type,
-                                                                                 int (*match_fun)(void *, void *), void *);
+                                         int (*match_fun)(void *, void *), void *);
 static void SIMIX_rdv_free(void *data);
 
 void SIMIX_network_init(void)
@@ -166,10 +165,9 @@ smx_action_t SIMIX_comm_new(e_smx_comm_type_t type)
   smx_action_t act;
 
   /* alloc structures */
-  act = xbt_new0(s_smx_action_t, 1);
+  act = xbt_mallocator_get(simix_global->action_mallocator);
   act->type = SIMIX_ACTION_COMMUNICATE;
   act->state = SIMIX_WAITING;
-  act->request_list = xbt_fifo_new();
 
   /* set communication */
   act->comm.type = type;
@@ -185,6 +183,7 @@ smx_action_t SIMIX_comm_new(e_smx_comm_type_t type)
 #endif
 
   DEBUG1("Create communicate action %p", act);
+  ++smx_total_comms;
 
   return act;
 }
@@ -214,14 +213,16 @@ void SIMIX_comm_destroy(smx_action_t action)
   TRACE_smx_action_destroy(action);
 #endif
 
-  if (action->name)
-    xbt_free(action->name);
-
-  xbt_fifo_free(action->request_list);
-
+  xbt_free(action->name);
   SIMIX_comm_destroy_internal_actions(action);
 
-  xbt_free(action);
+  if (action->comm.detached && action->state != SIMIX_DONE) {
+    /* the communication has failed and was detached:
+     * we have to free the buffer */
+    ((void_f_pvoid_t) action->comm.src_data)(action->comm.src_buff);
+  }
+
+  xbt_mallocator_release(simix_global->action_mallocator, action);
 }
 
 void SIMIX_comm_destroy_internal_actions(smx_action_t action)
@@ -248,7 +249,8 @@ void SIMIX_comm_destroy_internal_actions(smx_action_t action)
 smx_action_t SIMIX_comm_isend(smx_process_t src_proc, smx_rdv_t rdv,
                               double task_size, double rate,
                               void *src_buff, size_t src_buff_size,
-                              int (*match_fun)(void *, void *), void *data)
+                              int (*match_fun)(void *, void *), void *data,
+                              int detached)
 {
   smx_action_t action;
 
@@ -264,6 +266,13 @@ smx_action_t SIMIX_comm_isend(smx_process_t src_proc, smx_rdv_t rdv,
     action->comm.type = SIMIX_COMM_READY;
   }
 
+  /* If the communication action is detached then decrease the refcount
+   * by one, so it will be eliminated by the receivers destroy call */
+  if (detached) {
+    action->comm.detached = 1;
+    action->comm.refcount--;
+  }
+
   /* Setup the communication request */
   action->comm.src_proc = src_proc;
   action->comm.task_size = task_size;
@@ -362,8 +371,20 @@ void SIMIX_pre_comm_wait(smx_req_t req, int idx)
 void SIMIX_pre_comm_test(smx_req_t req)
 {
   smx_action_t action = req->comm_test.comm;
-  req->comm_test.result = (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING);
 
+  if(MC_IS_ENABLED){
+    req->comm_test.result = action->comm.src_proc && action->comm.dst_proc;
+    if(req->comm_test.result){
+      action->state = SIMIX_DONE;
+      xbt_fifo_push(action->request_list, req);
+      SIMIX_comm_finish(action);
+    }else{
+      SIMIX_request_answer(req);
+    }
+    return;
+  }
+
+  req->comm_test.result = (action->state != SIMIX_WAITING && action->state != SIMIX_RUNNING);
   if (req->comm_test.result) {
     xbt_fifo_push(action->request_list, req);
     SIMIX_comm_finish(action);
@@ -384,6 +405,7 @@ void SIMIX_pre_comm_testany(smx_req_t req, int idx)
       SIMIX_request_answer(req);
     }else{
       action = xbt_dynar_get_as(actions, idx, smx_action_t);
+      req->comm_testany.result = idx;
       xbt_fifo_push(action->request_list, req);
       action->state = SIMIX_DONE;
       SIMIX_comm_finish(action);
@@ -483,6 +505,7 @@ static XBT_INLINE void SIMIX_comm_start(smx_action_t action)
 
 void SIMIX_comm_finish(smx_action_t action)
 {
+  unsigned int destroy_count = 0;
   smx_req_t req;
 
   while ((req = xbt_fifo_shift(action->request_list))) {
@@ -581,7 +604,11 @@ void SIMIX_comm_finish(smx_action_t action)
 
     req->issuer->waiting_action = NULL;
     SIMIX_request_answer(req);
+    destroy_count++;
   }
+
+  while(destroy_count-- > 0)
+    SIMIX_comm_destroy(action);
 }
 
 void SIMIX_post_comm(smx_action_t action)
@@ -696,33 +723,6 @@ void* SIMIX_comm_get_dst_data(smx_action_t action)
   return action->comm.dst_data;
 }
 
-void* SIMIX_comm_get_src_buff(smx_action_t action)
-{
-  return action->comm.src_buff;
-}
-
-void* SIMIX_comm_get_dst_buff(smx_action_t action)
-{
-  return action->comm.dst_buff;
-}
-
-size_t SIMIX_comm_get_src_buff_size(smx_action_t action)
-{
-  return action->comm.src_buff_size;
-}
-
-size_t SIMIX_comm_get_dst_buff_size(smx_action_t action)
-{
-  size_t buff_size;
-
-  if (action->comm.dst_buff_size)
-    buff_size = *(action->comm.dst_buff_size);
-  else
-    buff_size = 0;
-
-  return buff_size;
-}
-
 smx_process_t SIMIX_comm_get_src_proc(smx_action_t action)
 {
   return action->comm.src_proc;