Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Improve the final stats reported by SafetyChecker, and revalidate tesh files
[simgrid.git] / src / mc / checker / CommunicationDeterminismChecker.cpp
index a5042f9..388e9e2 100644 (file)
@@ -113,8 +113,6 @@ static void update_comm_pattern(simgrid::mc::PatternCommunication* comm_pattern,
   auto dst_proc = api::get().get_dst_actor(comm_addr);
   comm_pattern->src_proc = src_proc->get_pid();
   comm_pattern->dst_proc = dst_proc->get_pid();
-  comm_pattern->src_host = &api::get().get_actor_host_name(src_proc);
-  comm_pattern->dst_host = &api::get().get_actor_host_name(dst_proc);
 
   if (comm_pattern->data.empty()) {
     comm_pattern->data = api::get().get_pattern_comm_data(comm_addr);
@@ -125,7 +123,7 @@ namespace simgrid {
 namespace mc {
 
 void CommunicationDeterminismChecker::deterministic_comm_pattern(aid_t process, const PatternCommunication* comm,
-                                                                 int backtracking)
+                                                                 bool backtracking)
 {
   if (not backtracking) {
     PatternCommunicationList& list = initial_communications_pattern[process];
@@ -175,7 +173,7 @@ void CommunicationDeterminismChecker::deterministic_comm_pattern(aid_t process,
 
 /********** Non Static functions ***********/
 
-void CommunicationDeterminismChecker::get_comm_pattern(smx_simcall_t request, CallType call_type, int backtracking)
+void CommunicationDeterminismChecker::get_comm_pattern(smx_simcall_t request, CallType call_type, bool backtracking)
 {
   const smx_actor_t issuer                                     = api::get().simcall_get_issuer(request);
   const mc::PatternCommunicationList& initial_pattern          = initial_communications_pattern[issuer->get_pid()];
@@ -190,7 +188,6 @@ void CommunicationDeterminismChecker::get_comm_pattern(smx_simcall_t request, Ca
     pattern->comm_addr = api::get().get_comm_isend_raw_addr(request);
     pattern->rdv       = api::get().get_pattern_comm_rdv(pattern->comm_addr);
     pattern->src_proc  = api::get().get_pattern_comm_src_proc(pattern->comm_addr);
-    pattern->src_host  = &api::get().get_actor_host_name(issuer);
 
 #if HAVE_SMPI
     pattern->tag = api::get().get_smpi_request_tag(request, simgrid::simix::Simcall::COMM_ISEND);
@@ -220,7 +217,6 @@ void CommunicationDeterminismChecker::get_comm_pattern(smx_simcall_t request, Ca
 #endif
     pattern->rdv = api::get().get_pattern_comm_rdv(pattern->comm_addr);
     pattern->dst_proc = api::get().get_pattern_comm_dst_proc(pattern->comm_addr);
-    pattern->dst_host = &api::get().get_actor_host_name(issuer);
   } else
     xbt_die("Unexpected call_type %i", (int)call_type);
 
@@ -228,8 +224,8 @@ void CommunicationDeterminismChecker::get_comm_pattern(smx_simcall_t request, Ca
   incomplete_communications_pattern[issuer->get_pid()].push_back(pattern.release());
 }
 
-void CommunicationDeterminismChecker::complete_comm_pattern(RemotePtr<kernel::activity::CommImpl> const& comm_addr, aid_t issuer,
-                                                            int backtracking)
+void CommunicationDeterminismChecker::complete_comm_pattern(RemotePtr<kernel::activity::CommImpl> const& comm_addr,
+                                                            aid_t issuer, bool backtracking)
 {
   /* Complete comm pattern */
   std::vector<PatternCommunication*>& incomplete_pattern = incomplete_communications_pattern[issuer];
@@ -269,10 +265,8 @@ RecordTrace CommunicationDeterminismChecker::get_record_trace() // override
 std::vector<std::string> CommunicationDeterminismChecker::get_textual_trace() // override
 {
   std::vector<std::string> trace;
-  for (auto const& state : stack_) {
-    smx_simcall_t req = &state->executed_req_;
-    trace.push_back(api::get().request_to_string(req, state->transition_.times_considered_));
-  }
+  for (auto const& state : stack_)
+    trace.push_back(state->get_transition()->to_string());
   return trace;
 }
 
@@ -292,9 +286,9 @@ void CommunicationDeterminismChecker::log_state() // override
       XBT_INFO("%s", this->send_diff);
     }
   }
-  XBT_INFO("Expanded states = %lu", expanded_states_count_);
+  XBT_INFO("Expanded states = %ld", State::get_expanded_states());
   XBT_INFO("Visited states = %lu", api::get().mc_get_visited_states());
-  XBT_INFO("Executed transitions = %lu", api::get().mc_get_executed_trans());
+  XBT_INFO("Executed transitions = %lu", Transition::get_executed_transitions());
   XBT_INFO("Send-deterministic : %s", this->send_deterministic ? "Yes" : "No");
   if (_sg_mc_comms_determinism)
     XBT_INFO("Recv-deterministic : %s", this->recv_deterministic ? "Yes" : "No");
@@ -307,8 +301,7 @@ void CommunicationDeterminismChecker::prepare()
   initial_communications_pattern.resize(maxpid);
   incomplete_communications_pattern.resize(maxpid);
 
-  ++expanded_states_count_;
-  auto initial_state = std::make_unique<State>(expanded_states_count_);
+  auto initial_state = std::make_unique<State>();
 
   XBT_DEBUG("********* Start communication determinism verification *********");
 
@@ -359,7 +352,7 @@ void CommunicationDeterminismChecker::restoreState()
     if (state == stack_.back())
       break;
 
-    int req_num                    = state->transition_.times_considered_;
+    int req_num                    = state->get_transition()->times_considered_;
     const s_smx_simcall* saved_req = &state->executed_req_;
     xbt_assert(saved_req);
 
@@ -371,17 +364,16 @@ void CommunicationDeterminismChecker::restoreState()
 
     /* TODO : handle test and testany simcalls */
     CallType call = MC_get_call_type(req);
-    api::get().handle_simcall(state->transition_);
+    state->get_transition()->replay();
     handle_comm_pattern(call, req, req_num, 1);
-    api::get().mc_wait_for_requests();
 
     /* Update statistics */
     api::get().mc_inc_visited_states();
-    api::get().mc_inc_executed_trans();
   }
 }
 
-void CommunicationDeterminismChecker::handle_comm_pattern(simgrid::mc::CallType call_type, smx_simcall_t req, int value, int backtracking)
+void CommunicationDeterminismChecker::handle_comm_pattern(simgrid::mc::CallType call_type, smx_simcall_t req, int value,
+                                                          bool backtracking)
 {
   using simgrid::mc::CallType;
   switch(call_type) {
@@ -409,52 +401,44 @@ void CommunicationDeterminismChecker::handle_comm_pattern(simgrid::mc::CallType
 void CommunicationDeterminismChecker::real_run()
 {
   std::unique_ptr<VisitedState> visited_state = nullptr;
-  smx_simcall_t req                           = nullptr;
 
   while (not stack_.empty()) {
     /* Get current state */
     State* cur_state = stack_.back().get();
 
     XBT_DEBUG("**************************************************");
-    XBT_DEBUG("Exploration depth = %zu (state = %d, interleaved processes = %zu)", stack_.size(), cur_state->num_,
+    XBT_DEBUG("Exploration depth = %zu (state = %ld, interleaved processes = %zu)", stack_.size(), cur_state->num_,
               cur_state->count_todo());
 
     /* Update statistics */
     api::get().mc_inc_visited_states();
 
+    int next_transition = -1;
     if (stack_.size() <= (std::size_t)_sg_mc_max_depth)
-      req = api::get().mc_state_choose_request(cur_state);
-    else
-      req = nullptr;
+      next_transition = cur_state->next_transition();
+
+    if (next_transition >= 0 && visited_state == nullptr) {
+      cur_state->execute_next(next_transition);
 
-    if (req != nullptr && visited_state == nullptr) {
-      int req_num = cur_state->transition_.times_considered_;
+      aid_t aid         = cur_state->get_transition()->aid_;
+      int req_num       = cur_state->get_transition()->times_considered_;
+      smx_simcall_t req = &cur_state->executed_req_;
 
-      XBT_DEBUG("Execute: %s", api::get().request_to_string(req, req_num).c_str());
+      XBT_DEBUG("Execute: %s", cur_state->get_transition()->to_cstring());
 
       std::string req_str;
       if (dot_output != nullptr)
-        req_str = api::get().request_get_dot_output(req, req_num);
-
-      api::get().mc_inc_executed_trans();
+        req_str = api::get().request_get_dot_output(aid, req_num);
 
       /* TODO : handle test and testany simcalls */
       CallType call = CallType::NONE;
       if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
         call = MC_get_call_type(req);
 
-      /* Answer the request */
-      api::get().handle_simcall(cur_state->transition_);
-      /* After this call req is no longer useful */
-
       handle_comm_pattern(call, req, req_num, 0);
 
-      /* Wait for requests (schedules processes) */
-      api::get().mc_wait_for_requests();
-
       /* Create the new expanded state */
-      ++expanded_states_count_;
-      auto next_state = std::make_unique<State>(expanded_states_count_);
+      auto next_state = std::make_unique<State>();
 
       /* If comm determinism verification, we cannot stop the exploration if some communications are not finished (at
        * least, data are transferred). These communications  are incomplete and they cannot be analyzed and compared
@@ -462,7 +446,7 @@ void CommunicationDeterminismChecker::real_run()
       bool compare_snapshots = this->initial_communications_pattern_done && all_communications_are_finished();
 
       if (_sg_mc_max_visited_states != 0)
-        visited_state = visited_states_.addVisitedState(expanded_states_count_, next_state.get(), compare_snapshots);
+        visited_state = visited_states_.addVisitedState(next_state->num_, next_state.get(), compare_snapshots);
       else
         visited_state = nullptr;
 
@@ -475,10 +459,10 @@ void CommunicationDeterminismChecker::real_run()
         }
 
         if (dot_output != nullptr)
-          fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", cur_state->num_, next_state->num_, req_str.c_str());
+          fprintf(dot_output, "\"%ld\" -> \"%ld\" [%s];\n", cur_state->num_, next_state->num_, req_str.c_str());
 
       } else if (dot_output != nullptr)
-        fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", cur_state->num_,
+        fprintf(dot_output, "\"%ld\" -> \"%ld\" [%s];\n", cur_state->num_,
                 visited_state->original_num == -1 ? visited_state->num : visited_state->original_num, req_str.c_str());
 
       stack_.push_back(std::move(next_state));
@@ -486,7 +470,7 @@ void CommunicationDeterminismChecker::real_run()
       if (stack_.size() > (std::size_t)_sg_mc_max_depth)
         XBT_WARN("/!\\ Max depth reached! /!\\ ");
       else if (visited_state != nullptr)
-        XBT_DEBUG("State already visited (equal to state %d), exploration stopped on this path.",
+        XBT_DEBUG("State already visited (equal to state %ld), exploration stopped on this path.",
                   visited_state->original_num == -1 ? visited_state->num : visited_state->original_num);
       else
         XBT_DEBUG("There are no more processes to interleave. (depth %zu)", stack_.size());
@@ -494,7 +478,7 @@ void CommunicationDeterminismChecker::real_run()
       this->initial_communications_pattern_done = true;
 
       /* Trash the current state, no longer needed */
-      XBT_DEBUG("Delete state %d at depth %zu", cur_state->num_, stack_.size());
+      XBT_DEBUG("Delete state %ld at depth %zu", cur_state->num_, stack_.size());
       stack_.pop_back();
 
       visited_state = nullptr;
@@ -506,16 +490,16 @@ void CommunicationDeterminismChecker::real_run()
         stack_.pop_back();
         if (state->count_todo() && stack_.size() < (std::size_t)_sg_mc_max_depth) {
           /* We found a back-tracking point, let's loop */
-          XBT_DEBUG("Back-tracking to state %d at depth %zu", state->num_, stack_.size() + 1);
+          XBT_DEBUG("Back-tracking to state %ld at depth %zu", state->num_, stack_.size() + 1);
           stack_.push_back(std::move(state));
 
           this->restoreState();
 
-          XBT_DEBUG("Back-tracking to state %d at depth %zu done", stack_.back()->num_, stack_.size());
+          XBT_DEBUG("Back-tracking to state %ld at depth %zu done", stack_.back()->num_, stack_.size());
 
           break;
         } else {
-          XBT_DEBUG("Delete state %d at depth %zu", state->num_, stack_.size() + 1);
+          XBT_DEBUG("Delete state %ld at depth %zu", state->num_, stack_.size() + 1);
         }
       }
     }