Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Tweak a bit the dependence function
[simgrid.git] / src / mc / mc_transition.c
index 5baeb9e..e4587a3 100644 (file)
@@ -1,5 +1,8 @@
 #include "private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans, mc,
+                               "Logging specific to MC transitions");
+
 /* Creates a new iSend transition */
 mc_transition_t MC_trans_isend_new(smx_rdv_t rdv)
 {
@@ -8,8 +11,7 @@ mc_transition_t MC_trans_isend_new(smx_rdv_t rdv)
   trans->type = mc_isend;
   trans->process = SIMIX_process_self();
   trans->isend.rdv = rdv;
-  trans->name = bprintf("[%s][%s] iSend (%p)", trans->process->smx_host->name,
-                        trans->process->name, trans); 
+  trans->name = bprintf("[%s]\t iSend (%p)", trans->process->smx_host->name, trans); 
   return trans;
 }
 
@@ -21,8 +23,7 @@ mc_transition_t MC_trans_irecv_new(smx_rdv_t rdv)
   trans->type = mc_irecv;
   trans->process = SIMIX_process_self();
   trans->irecv.rdv = rdv;
-  trans->name = bprintf("[%s][%s] iRecv (%p)", trans->process->smx_host->name, 
-                        trans->process->name, trans);
+  trans->name = bprintf("[%s]\t iRecv (%p)", trans->process->smx_host->name, trans);
   return trans;
 }
 
@@ -34,8 +35,7 @@ mc_transition_t MC_trans_wait_new(smx_comm_t comm)
   trans->type = mc_wait;
   trans->process = SIMIX_process_self();
   trans->wait.comm = comm;
-  trans->name = bprintf("[%s][%s] Wait (%p)", trans->process->smx_host->name,
-                        trans->process->name, trans);
+  trans->name = bprintf("[%s]\t Wait (%p)", trans->process->smx_host->name, trans);
   return trans;
 }
 
@@ -47,8 +47,7 @@ mc_transition_t MC_trans_test_new(smx_comm_t comm)
   trans->type = mc_test;
   trans->process = SIMIX_process_self();
   trans->test.comm = comm;
-  trans->name = bprintf("[%s][%s] Test (%p)", trans->process->smx_host->name,
-                        trans->process->name, trans);      
+  trans->name = bprintf("[%s]\t Test (%p)", trans->process->smx_host->name, trans);      
   return trans;
 }
 
@@ -60,26 +59,33 @@ mc_transition_t MC_trans_waitany_new(xbt_dynar_t comms)
   trans->type = mc_waitany;
   trans->process = SIMIX_process_self();
   trans->waitany.comms = comms;
-  trans->name = bprintf("[%s][%s] WaitAny (%p)", trans->process->smx_host->name,
-                        trans->process->name, trans);
+  trans->name = bprintf("[%s]\t WaitAny (%p)", trans->process->smx_host->name, trans);
   return trans;
 }
 
 /* Creates a new Random transition */
-mc_transition_t MC_trans_random_new(int min, int max)
+mc_transition_t MC_trans_random_new(int value)
 {
   mc_transition_t trans = xbt_new0(s_mc_transition_t, 1);
 
   trans->type = mc_random;
   trans->process = SIMIX_process_self();
-  trans->random.min = min;
-  trans->random.max = max;
-  trans->random.current_value = min;
-  trans->name = bprintf("[%s][%s] Random (%p)", trans->process->smx_host->name, 
-                        trans->process->name, trans);
+  trans->random.value = value;
+  trans->name = bprintf("[%s]\t Random %d (%p)", trans->process->smx_host->name, value, trans);
+
   return trans;
 }
 
+/**
+ * \brief Deletes a transition
+ * \param trans The transition to be deleted
+ */
+void MC_transition_delete(mc_transition_t trans)
+{
+  xbt_free(trans->name);
+  xbt_free(trans);
+}
+
 /************************** Interception Functions ****************************/
 /* These functions intercept all the actions relevant to the model-checking
  * process, the only difference between them is the type of transition they
@@ -177,15 +183,19 @@ void MC_trans_intercept_test(smx_comm_t comm)
  */
 void MC_trans_intercept_waitany(xbt_dynar_t comms)
 {
-  mc_transition_t trans=NULL;
+  unsigned int index = 0;
+  smx_comm_t comm = NULL;
+  mc_transition_t trans = NULL;
   mc_state_t current_state = NULL;
   if(!mc_replay_mode){
     MC_SET_RAW_MEM;
-    trans = MC_trans_waitany_new(comms);
     current_state = (mc_state_t) 
       xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack));
-    xbt_setset_set_insert(current_state->created_transitions, trans);
-    xbt_setset_set_insert(current_state->transitions, trans);
+    xbt_dynar_foreach(comms, index, comm){
+      trans = MC_trans_wait_new(comm);
+      xbt_setset_set_insert(current_state->created_transitions, trans);
+      xbt_setset_set_insert(current_state->transitions, trans);
+    }
     MC_UNSET_RAW_MEM;
   }
   SIMIX_process_yield();
@@ -198,42 +208,59 @@ void MC_trans_intercept_waitany(xbt_dynar_t comms)
  */
 void MC_trans_intercept_random(int min, int max)
 {
+  int i;
   mc_transition_t trans=NULL;
   mc_state_t current_state = NULL;
   if(!mc_replay_mode){
     MC_SET_RAW_MEM;
-    trans = MC_trans_random_new(min, max);
     current_state = (mc_state_t) 
       xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack));
-    xbt_setset_set_insert(current_state->created_transitions, trans);
-    xbt_setset_set_insert(current_state->transitions, trans);
+    for(i=min; i <= max; i++){
+      trans = MC_trans_random_new(i);
+      xbt_setset_set_insert(current_state->created_transitions, trans);
+      xbt_setset_set_insert(current_state->transitions, trans);
+    }
     MC_UNSET_RAW_MEM;
   }
   SIMIX_process_yield();
 }
 
-/**
- * \brief Deletes a transition
- * \param trans The transition to be deleted
- */
-void MC_transition_delete(mc_transition_t trans)
-{
-  xbt_free(trans->name);
-  xbt_free(trans);
-}
-
 /* Compute the subset of enabled transitions of the transition set */
 void MC_trans_compute_enabled(xbt_setset_set_t enabled, xbt_setset_set_t transitions)
 {
+  unsigned int index = 0;
+  smx_comm_t comm = NULL;
   mc_transition_t trans = NULL;
   xbt_setset_cursor_t cursor = NULL;
-  /* Add all the transitions to the enabled set and then remove the disabled ones */
-  xbt_setset_add(enabled, transitions); 
   xbt_setset_foreach(transitions, cursor, trans){
-    if(trans->type == mc_wait
-       && (trans->wait.comm->src_proc == NULL || trans->wait.comm->dst_proc == NULL)){
-      xbt_setset_set_remove(enabled, trans);
-    }
+    switch(trans->type){
+      /* Wait transitions are enabled only if the communication has both a
+         sender and receiver */
+      case mc_wait:
+        if(trans->wait.comm->src_proc && trans->wait.comm->dst_proc){
+          xbt_setset_set_insert(enabled, trans);
+          DEBUG1("Transition %p is enabled for next state", trans);
+        }
+        break;
+
+      /* WaitAny transitions are enabled if any of it's communications has both
+         a sender and a receiver */
+      case mc_waitany:
+        xbt_dynar_foreach(trans->waitany.comms, index, comm){            
+          if(comm->src_proc && comm->dst_proc){
+            xbt_setset_set_insert(enabled, trans);
+            DEBUG1("Transition %p is enabled for next state", trans);
+            break;
+          }
+        }
+        break;
+
+      /* The rest of the transitions cannot be disabled */
+      default:
+        xbt_setset_set_insert(enabled, trans);
+        DEBUG1("Transition %p is enabled for next state", trans);
+        break;
+    } 
   }
 }
 
@@ -251,6 +278,15 @@ int MC_transition_depend(mc_transition_t t1, mc_transition_t t2)
   if(t1->type != t2->type)
     return FALSE;
   
+/*  if(t1->type == mc_isend && t2->type == mc_irecv)
+    return FALSE;
+
+  if(t1->type == mc_irecv && t2->type == mc_isend)
+    return FALSE;*/
+  
+  if(t1->type == mc_random || t2->type == mc_random)
+    return FALSE;
+  
   if(t1->type == mc_isend && t2->type == mc_isend && t1->isend.rdv != t2->isend.rdv)
     return FALSE;
 
@@ -269,6 +305,7 @@ int MC_transition_depend(mc_transition_t t1, mc_transition_t t2)
      && t1->wait.comm->dst_buff != t2->wait.comm->dst_buff
      && t2->wait.comm->dst_buff != t1->wait.comm->src_buff)
     return FALSE;
   
   return TRUE;
 }
\ No newline at end of file