Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] DRY MC_do_the_modelcheck_for_real()
[simgrid.git] / src / mc / mc_comm_determinism.c
index d5aff26..37009cf 100644 (file)
@@ -11,6 +11,7 @@
 #include "mc_private.h"
 #include "mc_record.h"
 #include "mc_smx.h"
+#include "mc_client.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_determinism, mc,
                                 "Logging specific to MC communication determinism detection");
@@ -177,18 +178,28 @@ void MC_get_comm_pattern(xbt_dynar_t list, smx_simcall_t request, e_mc_call_type
     MC_process_read_simple(&mc_model_checker->process,
       &synchro, pattern->comm, sizeof(synchro));
 
-    // TODO, remote access to rdv->name and rdv_copy->name
-    pattern->rdv = (synchro.comm.rdv != NULL) ? strdup(synchro.comm.rdv->name) : strdup(synchro.comm.rdv_cpy->name);
+    char* remote_name;
+    MC_process_read_simple(&mc_model_checker->process, &remote_name,
+      synchro.comm.rdv ? &synchro.comm.rdv->name : &synchro.comm.rdv_cpy->name,
+      sizeof(remote_name));
+    pattern->rdv =
+      MC_process_read_string(&mc_model_checker->process, remote_name);
     pattern->src_proc = MC_smx_resolve_process(synchro.comm.src_proc)->pid;
     pattern->src_host = MC_smx_process_get_host_name(issuer);
-    pattern->tag = ((MPI_Request)simcall_comm_isend__get__data(request))->tag;
+
+    struct s_smpi_mpi_request mpi_request;
+    MC_process_read_simple(&mc_model_checker->process,
+      &mpi_request, (MPI_Request) simcall_comm_isend__get__data(request),
+      sizeof(mpi_request));
+    pattern->tag = mpi_request.tag;
+
     if(synchro.comm.src_buff != NULL){
       pattern->data_size = synchro.comm.src_buff_size;
       pattern->data = xbt_malloc0(pattern->data_size);
       MC_process_read_simple(&mc_model_checker->process,
         pattern->data, synchro.comm.src_buff, pattern->data_size);
     }
-    if(((MPI_Request)simcall_comm_isend__get__data(request))->detached){
+    if(mpi_request.detached){
       if (!initial_global_state->initial_communications_pattern_done) {
         /* Store comm pattern */
         xbt_dynar_push(((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, pattern->src_proc, mc_list_comm_pattern_t))->list, &pattern);
@@ -202,16 +213,24 @@ void MC_get_comm_pattern(xbt_dynar_t list, smx_simcall_t request, e_mc_call_type
   } else if (call_type == MC_CALL_TYPE_RECV) {                      
     pattern->type = SIMIX_COMM_RECEIVE;
     pattern->comm = simcall_comm_irecv__get__result(request);
-    // TODO, remote access
-    pattern->tag = ((MPI_Request)simcall_comm_irecv__get__data(request))->tag;
+
+    struct s_smpi_mpi_request mpi_request;
+    MC_process_read_simple(&mc_model_checker->process,
+      &mpi_request, (MPI_Request) simcall_comm_irecv__get__data(request),
+      sizeof(mpi_request));
+    pattern->tag = mpi_request.tag;
 
     s_smx_synchro_t synchro;
     MC_process_read_simple(&mc_model_checker->process,
       &synchro, pattern->comm, sizeof(synchro));
 
-    pattern->rdv = (synchro.comm.rdv != NULL) ? strdup(synchro.comm.rdv->name) : strdup(synchro.comm.rdv_cpy->name);
+    char* remote_name;
+    MC_process_read_simple(&mc_model_checker->process, &remote_name,
+      synchro.comm.rdv ? &synchro.comm.rdv->name : &synchro.comm.rdv_cpy->name,
+      sizeof(remote_name));
+    pattern->rdv =
+      MC_process_read_string(&mc_model_checker->process, remote_name);
     pattern->dst_proc = MC_smx_resolve_process(synchro.comm.dst_proc)->pid;
-    // FIXME, remote process access
     pattern->dst_host = MC_smx_process_get_host_name(issuer);
   } else {
     xbt_die("Unexpected call_type %i", (int) call_type);
@@ -254,7 +273,9 @@ void MC_complete_comm_pattern(xbt_dynar_t list, smx_synchro_t comm, unsigned int
 
 /************************ Main algorithm ************************/
 
-void MC_pre_modelcheck_comm_determinism(void)
+static void MC_modelcheck_comm_determinism_main(void);
+
+static void MC_pre_modelcheck_comm_determinism(void)
 {
   MC_SET_MC_HEAP;
 
@@ -301,7 +322,7 @@ void MC_pre_modelcheck_comm_determinism(void)
 
 }
 
-void MC_modelcheck_comm_determinism(void)
+static void MC_modelcheck_comm_determinism_main(void)
 {
 
   char *req_str = NULL;
@@ -328,8 +349,8 @@ void MC_modelcheck_comm_determinism(void)
         && (req = MC_state_get_request(state, &value))
         && (visited_state == NULL)) {
 
-      req_str = MC_request_to_string(req, value);  
-      XBT_DEBUG("Execute: %s", req_str);                 
+      req_str = MC_request_to_string(req, value, MC_REQUEST_SIMIX);
+      XBT_DEBUG("Execute: %s", req_str);
       xbt_free(req_str);
       
       if (dot_output != NULL) {
@@ -450,3 +471,35 @@ void MC_modelcheck_comm_determinism(void)
 
   return;
 }
+
+void MC_modelcheck_comm_determinism(void)
+{
+  if (mc_mode == MC_MODE_CLIENT) {
+    // This will move somehwere else:
+    MC_client_handle_messages();
+  }
+
+  xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
+
+  /* Create exploration stack */
+  mc_stack = xbt_fifo_new();
+
+  MC_SET_STD_HEAP;
+
+  MC_pre_modelcheck_comm_determinism();
+
+  MC_SET_MC_HEAP;
+  initial_global_state = xbt_new0(s_mc_global_t, 1);
+  initial_global_state->snapshot = MC_take_snapshot(0);
+  initial_global_state->initial_communications_pattern_done = 0;
+  initial_global_state->recv_deterministic = 1;
+  initial_global_state->send_deterministic = 1;
+  initial_global_state->recv_diff = NULL;
+  initial_global_state->send_diff = NULL;
+
+  MC_SET_STD_HEAP;
+
+  MC_modelcheck_comm_determinism_main();
+
+  mmalloc_set_current_heap(heap);
+}