Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sonar fixes
[simgrid.git] / src / mc / checker / CommunicationDeterminismChecker.cpp
1 /* Copyright (c) 2008-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/mc/checker/CommunicationDeterminismChecker.hpp"
7 #include "src/kernel/activity/MailboxImpl.hpp"
8 #include "src/mc/Session.hpp"
9 #include "src/mc/mc_config.hpp"
10 #include "src/mc/mc_exit.hpp"
11 #include "src/mc/mc_private.hpp"
12
13 #include <cstdint>
14
15 using api = simgrid::mc::Api;
16
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_determinism, mc, "Logging specific to MC communication determinism detection");
18
19 namespace simgrid {
20 namespace mc {
21
22 enum class CallType { NONE, SEND, RECV, WAIT, WAITANY };
23 enum class CommPatternDifference { NONE, TYPE, RDV, TAG, SRC_PROC, DST_PROC, DATA_SIZE, DATA };
24 enum class PatternCommunicationType {
25   none    = 0,
26   send    = 1,
27   receive = 2,
28 };
29
30 class PatternCommunication {
31 public:
32   int num = 0;
33   RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr{nullptr};
34   PatternCommunicationType type = PatternCommunicationType::send;
35   unsigned long src_proc        = 0;
36   unsigned long dst_proc        = 0;
37   std::string rdv;
38   std::vector<char> data;
39   int tag   = 0;
40   int index = 0;
41
42   PatternCommunication dup() const
43   {
44     simgrid::mc::PatternCommunication res;
45     // num?
46     res.comm_addr = this->comm_addr;
47     res.type      = this->type;
48     // src_proc?
49     // dst_proc?
50     res.dst_proc = this->dst_proc;
51     res.rdv      = this->rdv;
52     res.data     = this->data;
53     // tag?
54     res.index = this->index;
55     return res;
56   }
57 };
58
59 struct PatternCommunicationList {
60   unsigned int index_comm = 0;
61   std::vector<std::unique_ptr<simgrid::mc::PatternCommunication>> list;
62 };
63
64 static inline simgrid::mc::CallType MC_get_call_type(const s_smx_simcall* req)
65 {
66   using simgrid::mc::CallType;
67   using simgrid::simix::Simcall;
68   switch (req->call_) {
69     case Simcall::COMM_ISEND:
70       return CallType::SEND;
71     case Simcall::COMM_IRECV:
72       return CallType::RECV;
73     case Simcall::COMM_WAIT:
74       return CallType::WAIT;
75     case Simcall::COMM_WAITANY:
76       return CallType::WAITANY;
77     default:
78       return CallType::NONE;
79   }
80 }
81
82 /********** Checker extension **********/
83
84 struct CommDetExtension {
85   static simgrid::xbt::Extension<simgrid::mc::Checker, CommDetExtension> EXTENSION_ID;
86
87   CommDetExtension()
88   {
89     const unsigned long maxpid = api::get().get_maxpid();
90
91     initial_communications_pattern.resize(maxpid);
92     incomplete_communications_pattern.resize(maxpid);
93   }
94
95   std::vector<simgrid::mc::PatternCommunicationList> initial_communications_pattern;
96   std::vector<std::vector<simgrid::mc::PatternCommunication*>> incomplete_communications_pattern;
97
98   bool initial_communications_pattern_done = false;
99   bool recv_deterministic                  = true;
100   bool send_deterministic                  = true;
101   std::string send_diff;
102   std::string recv_diff;
103
104   void restore_communications_pattern(const simgrid::mc::State* state);
105   void deterministic_comm_pattern(aid_t process, const PatternCommunication* comm, bool backtracking);
106   void get_comm_pattern(smx_simcall_t request, CallType call_type, bool backtracking);
107   void complete_comm_pattern(RemotePtr<kernel::activity::CommImpl> const& comm_addr, aid_t issuer, bool backtracking);
108   void handle_comm_pattern(const Transition* transition, smx_simcall_t req, int value, bool backtracking);
109 };
110 simgrid::xbt::Extension<simgrid::mc::Checker, CommDetExtension> CommDetExtension::EXTENSION_ID;
111 /********** State Extension ***********/
112
113 class StateCommDet {
114   CommDetExtension* checker_;
115
116 public:
117   std::vector<std::vector<simgrid::mc::PatternCommunication>> incomplete_comm_pattern_;
118   std::vector<unsigned> communication_indices_;
119
120   static simgrid::xbt::Extension<simgrid::mc::State, StateCommDet> EXTENSION_ID;
121   explicit StateCommDet(CommDetExtension* checker) : checker_(checker)
122   {
123     copy_incomplete_comm_pattern();
124     copy_index_comm_pattern();
125   }
126
127   void copy_incomplete_comm_pattern()
128   {
129     incomplete_comm_pattern_.clear();
130     const unsigned long maxpid = api::get().get_maxpid();
131     for (unsigned long i = 0; i < maxpid; i++) {
132       std::vector<simgrid::mc::PatternCommunication> res;
133       for (auto const& comm : checker_->incomplete_communications_pattern[i])
134         res.push_back(comm->dup());
135       incomplete_comm_pattern_.push_back(std::move(res));
136     }
137   }
138
139   void copy_index_comm_pattern()
140   {
141     communication_indices_.clear();
142     for (auto const& list_process_comm : checker_->initial_communications_pattern)
143       this->communication_indices_.push_back(list_process_comm.index_comm);
144   }
145 };
146 simgrid::xbt::Extension<simgrid::mc::State, StateCommDet> StateCommDet::EXTENSION_ID;
147
148 static simgrid::mc::CommPatternDifference compare_comm_pattern(const simgrid::mc::PatternCommunication* comm1,
149                                                                const simgrid::mc::PatternCommunication* comm2)
150 {
151   using simgrid::mc::CommPatternDifference;
152   if (comm1->type != comm2->type)
153     return CommPatternDifference::TYPE;
154   if (comm1->rdv != comm2->rdv)
155     return CommPatternDifference::RDV;
156   if (comm1->src_proc != comm2->src_proc)
157     return CommPatternDifference::SRC_PROC;
158   if (comm1->dst_proc != comm2->dst_proc)
159     return CommPatternDifference::DST_PROC;
160   if (comm1->tag != comm2->tag)
161     return CommPatternDifference::TAG;
162   if (comm1->data.size() != comm2->data.size())
163     return CommPatternDifference::DATA_SIZE;
164   if (comm1->data != comm2->data)
165     return CommPatternDifference::DATA;
166   return CommPatternDifference::NONE;
167 }
168
169 void CommDetExtension::restore_communications_pattern(const simgrid::mc::State* state)
170 {
171   for (size_t i = 0; i < initial_communications_pattern.size(); i++)
172     initial_communications_pattern[i].index_comm =
173         state->extension<simgrid::mc::StateCommDet>()->communication_indices_[i];
174
175   const unsigned long maxpid = api::get().get_maxpid();
176   for (unsigned long i = 0; i < maxpid; i++) {
177     incomplete_communications_pattern[i].clear();
178     for (simgrid::mc::PatternCommunication const& comm :
179          state->extension<simgrid::mc::StateCommDet>()->incomplete_comm_pattern_[i])
180       incomplete_communications_pattern[i].push_back(new simgrid::mc::PatternCommunication(comm.dup()));
181   }
182 }
183
184 static std::string print_determinism_result(simgrid::mc::CommPatternDifference diff, aid_t process,
185                                             const simgrid::mc::PatternCommunication* comm, unsigned int cursor)
186 {
187   std::string type;
188   std::string res;
189
190   if (comm->type == simgrid::mc::PatternCommunicationType::send)
191     type = xbt::string_printf("The send communications pattern of the process %ld is different!", process - 1);
192   else
193     type = xbt::string_printf("The recv communications pattern of the process %ld is different!", process - 1);
194
195   using simgrid::mc::CommPatternDifference;
196   switch (diff) {
197     case CommPatternDifference::TYPE:
198       res = xbt::string_printf("%s Different type for communication #%u", type.c_str(), cursor);
199       break;
200     case CommPatternDifference::RDV:
201       res = xbt::string_printf("%s Different rdv for communication #%u", type.c_str(), cursor);
202       break;
203     case CommPatternDifference::TAG:
204       res = xbt::string_printf("%s Different tag for communication #%u", type.c_str(), cursor);
205       break;
206     case CommPatternDifference::SRC_PROC:
207       res = xbt::string_printf("%s Different source for communication #%u", type.c_str(), cursor);
208       break;
209     case CommPatternDifference::DST_PROC:
210       res = xbt::string_printf("%s Different destination for communication #%u", type.c_str(), cursor);
211       break;
212     case CommPatternDifference::DATA_SIZE:
213       res = xbt::string_printf("%s Different data size for communication #%u", type.c_str(), cursor);
214       break;
215     case CommPatternDifference::DATA:
216       res = xbt::string_printf("%s Different data for communication #%u", type.c_str(), cursor);
217       break;
218     default:
219       res = "";
220       break;
221   }
222
223   return res;
224 }
225
226 void CommDetExtension::deterministic_comm_pattern(aid_t actor, const PatternCommunication* comm, bool backtracking)
227 {
228   if (not backtracking) {
229     PatternCommunicationList& list = initial_communications_pattern[actor];
230     CommPatternDifference diff     = compare_comm_pattern(list.list[list.index_comm].get(), comm);
231
232     if (diff != CommPatternDifference::NONE) {
233       if (comm->type == PatternCommunicationType::send) {
234         send_deterministic = false;
235         send_diff          = print_determinism_result(diff, actor, comm, list.index_comm + 1);
236       } else {
237         recv_deterministic = false;
238         recv_diff          = print_determinism_result(diff, actor, comm, list.index_comm + 1);
239       }
240       if (_sg_mc_send_determinism && not send_deterministic) {
241         XBT_INFO("*********************************************************");
242         XBT_INFO("***** Non-send-deterministic communications pattern *****");
243         XBT_INFO("*********************************************************");
244         XBT_INFO("%s", send_diff.c_str());
245         api::get().log_state();
246         api::get().mc_exit(SIMGRID_MC_EXIT_NON_DETERMINISM);
247       } else if (_sg_mc_comms_determinism && (not send_deterministic && not recv_deterministic)) {
248         XBT_INFO("****************************************************");
249         XBT_INFO("***** Non-deterministic communications pattern *****");
250         XBT_INFO("****************************************************");
251         if (not send_diff.empty())
252           XBT_INFO("%s", send_diff.c_str());
253         if (not recv_diff.empty())
254           XBT_INFO("%s", recv_diff.c_str());
255         api::get().log_state();
256         api::get().mc_exit(SIMGRID_MC_EXIT_NON_DETERMINISM);
257       }
258     }
259   }
260 }
261
262 /********** Non Static functions ***********/
263
264 void CommDetExtension::get_comm_pattern(smx_simcall_t request, CallType call_type, bool backtracking)
265 {
266   const smx_actor_t issuer                                     = api::get().simcall_get_issuer(request);
267   const mc::PatternCommunicationList& initial_pattern          = initial_communications_pattern[issuer->get_pid()];
268   const std::vector<PatternCommunication*>& incomplete_pattern = incomplete_communications_pattern[issuer->get_pid()];
269
270   auto pattern   = std::make_unique<PatternCommunication>();
271   pattern->index = initial_pattern.index_comm + incomplete_pattern.size();
272
273   if (call_type == CallType::SEND) {
274     /* Create comm pattern */
275     pattern->type      = PatternCommunicationType::send;
276     pattern->comm_addr = api::get().get_comm_isend_raw_addr(request);
277     pattern->rdv       = api::get().get_pattern_comm_rdv(pattern->comm_addr);
278     pattern->src_proc  = api::get().get_pattern_comm_src_proc(pattern->comm_addr);
279
280 #if HAVE_SMPI
281     pattern->tag = api::get().get_smpi_request_tag(request, simgrid::simix::Simcall::COMM_ISEND);
282 #endif
283     pattern->data = api::get().get_pattern_comm_data(pattern->comm_addr);
284
285 #if HAVE_SMPI
286     auto send_detached = api::get().check_send_request_detached(request);
287     if (send_detached) {
288       if (initial_communications_pattern_done) {
289         /* Evaluate comm determinism */
290         deterministic_comm_pattern(pattern->src_proc, pattern.get(), backtracking);
291         initial_communications_pattern[pattern->src_proc].index_comm++;
292       } else {
293         /* Store comm pattern */
294         initial_communications_pattern[pattern->src_proc].list.push_back(std::move(pattern));
295       }
296       return;
297     }
298 #endif
299   } else if (call_type == CallType::RECV) {
300     pattern->type = PatternCommunicationType::receive;
301     pattern->comm_addr = api::get().get_comm_isend_raw_addr(request);
302
303 #if HAVE_SMPI
304     pattern->tag = api::get().get_smpi_request_tag(request, simgrid::simix::Simcall::COMM_IRECV);
305 #endif
306     pattern->rdv = api::get().get_pattern_comm_rdv(pattern->comm_addr);
307     pattern->dst_proc = api::get().get_pattern_comm_dst_proc(pattern->comm_addr);
308   } else
309     xbt_die("Unexpected call_type %i", (int)call_type);
310
311   XBT_DEBUG("Insert incomplete comm pattern %p for process %ld", pattern.get(), issuer->get_pid());
312   incomplete_communications_pattern[issuer->get_pid()].push_back(pattern.release());
313 }
314
315 void CommDetExtension::complete_comm_pattern(RemotePtr<kernel::activity::CommImpl> const& comm_addr, aid_t issuer,
316                                              bool backtracking)
317 {
318   /* Complete comm pattern */
319   std::vector<PatternCommunication*>& incomplete_pattern = incomplete_communications_pattern[issuer];
320   auto current_comm_pattern =
321       std::find_if(begin(incomplete_pattern), end(incomplete_pattern),
322                    [&comm_addr](const PatternCommunication* comm) { return (comm->comm_addr == comm_addr); });
323   xbt_assert(current_comm_pattern != std::end(incomplete_pattern), "Corresponding communication not found!");
324   std::unique_ptr<PatternCommunication> comm_pattern(*current_comm_pattern);
325
326   comm_pattern->src_proc = api::get().get_src_actor(comm_addr)->get_pid();
327   comm_pattern->dst_proc = api::get().get_dst_actor(comm_addr)->get_pid();
328   if (comm_pattern->data.empty())
329     comm_pattern->data = api::get().get_pattern_comm_data(comm_addr);
330
331   XBT_DEBUG("Remove incomplete comm pattern for process %ld at cursor %zd", issuer,
332             std::distance(begin(incomplete_pattern), current_comm_pattern));
333   incomplete_pattern.erase(current_comm_pattern);
334
335   if (initial_communications_pattern_done) {
336     /* Evaluate comm determinism */
337     deterministic_comm_pattern(issuer, comm_pattern.get(), backtracking);
338     initial_communications_pattern[issuer].index_comm++;
339   } else {
340     /* Store comm pattern */
341     initial_communications_pattern[issuer].list.push_back(std::move(comm_pattern));
342   }
343 }
344
345 CommunicationDeterminismChecker::CommunicationDeterminismChecker(Session* session) : Checker(session)
346 {
347   CommDetExtension::EXTENSION_ID = simgrid::mc::Checker::extension_create<CommDetExtension>();
348   StateCommDet::EXTENSION_ID = simgrid::mc::State::extension_create<StateCommDet>();
349 }
350
351 CommunicationDeterminismChecker::~CommunicationDeterminismChecker() = default;
352
353 RecordTrace CommunicationDeterminismChecker::get_record_trace() // override
354 {
355   RecordTrace res;
356   for (auto const& state : stack_)
357     res.push_back(state->get_transition());
358   return res;
359 }
360
361 std::vector<std::string> CommunicationDeterminismChecker::get_textual_trace() // override
362 {
363   std::vector<std::string> trace;
364   for (auto const& state : stack_)
365     trace.push_back(state->get_transition()->to_string());
366   return trace;
367 }
368
369 void CommunicationDeterminismChecker::log_state() // override
370 {
371   if (_sg_mc_comms_determinism) {
372     if (extension<CommDetExtension>()->send_deterministic && not extension<CommDetExtension>()->recv_deterministic) {
373       XBT_INFO("*******************************************************");
374       XBT_INFO("**** Only-send-deterministic communication pattern ****");
375       XBT_INFO("*******************************************************");
376       XBT_INFO("%s", extension<CommDetExtension>()->recv_diff.c_str());
377     }
378     if (not extension<CommDetExtension>()->send_deterministic && extension<CommDetExtension>()->recv_deterministic) {
379       XBT_INFO("*******************************************************");
380       XBT_INFO("**** Only-recv-deterministic communication pattern ****");
381       XBT_INFO("*******************************************************");
382       XBT_INFO("%s", extension<CommDetExtension>()->send_diff.c_str());
383     }
384   }
385   XBT_INFO("Expanded states = %ld", State::get_expanded_states());
386   XBT_INFO("Visited states = %lu", api::get().mc_get_visited_states());
387   XBT_INFO("Executed transitions = %lu", Transition::get_executed_transitions());
388   XBT_INFO("Send-deterministic : %s", extension<CommDetExtension>()->send_deterministic ? "Yes" : "No");
389   if (_sg_mc_comms_determinism)
390     XBT_INFO("Recv-deterministic : %s", extension<CommDetExtension>()->recv_deterministic ? "Yes" : "No");
391 }
392
393 void CommunicationDeterminismChecker::prepare()
394 {
395   auto initial_state = std::make_unique<State>();
396   extension_set(new CommDetExtension());
397   initial_state->extension_set(new StateCommDet(extension<CommDetExtension>()));
398
399   XBT_DEBUG("********* Start communication determinism verification *********");
400
401   /* Add all enabled actors to the interleave set of the initial state */
402   for (auto& act : api::get().get_actors()) {
403     auto actor = act.copy.get_buffer();
404     if (get_session().actor_is_enabled(actor->get_pid()))
405       initial_state->mark_todo(actor->get_pid());
406   }
407
408   stack_.push_back(std::move(initial_state));
409 }
410
411 void CommunicationDeterminismChecker::restoreState()
412 {
413   auto extension = this->extension<CommDetExtension>();
414
415   /* If asked to rollback on a state that has a snapshot, restore it */
416   State* last_state = stack_.back().get();
417   if (last_state->system_state_) {
418     api::get().restore_state(last_state->system_state_);
419     extension->restore_communications_pattern(last_state);
420     return;
421   }
422
423   /* if no snapshot, we need to restore the initial state and replay the transitions */
424   get_session().restore_initial_state();
425
426   const unsigned long maxpid = api::get().get_maxpid();
427   assert(maxpid == extension->incomplete_communications_pattern.size());
428   assert(maxpid == extension->initial_communications_pattern.size());
429   for (unsigned long j = 0; j < maxpid; j++) {
430     extension->incomplete_communications_pattern[j].clear();
431     extension->initial_communications_pattern[j].index_comm = 0;
432   }
433
434   /* Traverse the stack from the state at position start and re-execute the transitions */
435   for (std::unique_ptr<simgrid::mc::State> const& state : stack_) {
436     if (state == stack_.back())
437       break;
438
439     auto* transition = state->get_transition();
440
441     /* because we got a copy of the executed request, we have to fetch the real one,
442        pointed by the request field of the issuer process */
443     auto* saved_req          = &state->executed_req_;
444     const smx_actor_t issuer = api::get().simcall_get_issuer(saved_req);
445     smx_simcall_t req        = &issuer->simcall_;
446
447     /* TODO : handle test and testany simcalls */
448     transition->replay();
449     extension->handle_comm_pattern(transition, req, transition->times_considered_, true);
450
451     /* Update statistics */
452     api::get().mc_inc_visited_states();
453   }
454 }
455
456 void CommDetExtension::handle_comm_pattern(const Transition* transition, smx_simcall_t req, int value,
457                                            bool backtracking)
458 {
459   if (not _sg_mc_comms_determinism && not _sg_mc_send_determinism)
460     return;
461
462   using simgrid::mc::CallType;
463   switch (MC_get_call_type(req)) {
464     case CallType::NONE:
465       break;
466     case CallType::SEND:
467       get_comm_pattern(req, CallType::SEND, backtracking);
468       break;
469     case CallType::RECV:
470       get_comm_pattern(req, CallType::RECV, backtracking);
471       break;
472     case CallType::WAIT: {
473       auto comm_addr      = remote(simcall_comm_wait__getraw__comm(req));
474       auto simcall_issuer = api::get().simcall_get_issuer(req);
475       complete_comm_pattern(comm_addr, simcall_issuer->get_pid(), backtracking);
476       break;
477     }
478     case CallType::WAITANY: {
479       auto comm_addr = api::get().get_comm_waitany_raw_addr(req, value);
480       auto simcall_issuer = api::get().simcall_get_issuer(req);
481       complete_comm_pattern(comm_addr, simcall_issuer->get_pid(), backtracking);
482     } break;
483   default:
484     xbt_die("Unexpected call type %i", (int)MC_get_call_type(req));
485   }
486 }
487
488 void CommunicationDeterminismChecker::real_run()
489 {
490   auto extension = this->extension<CommDetExtension>();
491
492   std::unique_ptr<VisitedState> visited_state = nullptr;
493   const unsigned long maxpid                  = api::get().get_maxpid();
494
495   while (not stack_.empty()) {
496     /* Get current state */
497     State* cur_state = stack_.back().get();
498
499     XBT_DEBUG("**************************************************");
500     XBT_DEBUG("Exploration depth = %zu (state = %ld, interleaved processes = %zu)", stack_.size(), cur_state->num_,
501               cur_state->count_todo());
502
503     /* Update statistics */
504     api::get().mc_inc_visited_states();
505
506     int next_transition = -1;
507     if (stack_.size() <= (std::size_t)_sg_mc_max_depth)
508       next_transition = cur_state->next_transition();
509
510     if (next_transition >= 0 && visited_state == nullptr) {
511       cur_state->execute_next(next_transition);
512
513       auto* transition  = cur_state->get_transition();
514       smx_simcall_t req = &cur_state->executed_req_;
515
516       XBT_DEBUG("Execute: %s", transition->to_string().c_str());
517
518       std::string req_str;
519       if (dot_output != nullptr)
520         req_str = api::get().request_get_dot_output(transition);
521
522       extension->handle_comm_pattern(transition, req, transition->times_considered_, false);
523
524       /* Create the new expanded state */
525       auto next_state = std::make_unique<State>();
526       next_state->extension_set(new StateCommDet(extension));
527
528       bool all_communications_are_finished = true;
529       for (size_t current_actor = 1; all_communications_are_finished && current_actor < maxpid; current_actor++) {
530         if (not extension->incomplete_communications_pattern[current_actor].empty()) {
531           XBT_DEBUG("Some communications are not finished, cannot stop the exploration! State not visited.");
532           all_communications_are_finished = false;
533         }
534       }
535
536       /* If comm determinism verification, we cannot stop the exploration if some communications are not finished (at
537        * least, data are transferred). These communications  are incomplete and they cannot be analyzed and compared
538        * with the initial pattern. */
539       bool compare_snapshots = extension->initial_communications_pattern_done && all_communications_are_finished;
540
541       if (_sg_mc_max_visited_states != 0)
542         visited_state = visited_states_.addVisitedState(next_state->num_, next_state.get(), compare_snapshots);
543       else
544         visited_state = nullptr;
545
546       if (visited_state == nullptr) {
547         /* Add all enabled actors to the interleave set of the next state */
548         for (auto& act : api::get().get_actors()) {
549           auto actor = act.copy.get_buffer();
550           if (get_session().actor_is_enabled(actor->get_pid()))
551             next_state->mark_todo(actor->get_pid());
552         }
553
554         if (dot_output != nullptr)
555           fprintf(dot_output, "\"%ld\" -> \"%ld\" [%s];\n", cur_state->num_, next_state->num_, req_str.c_str());
556
557       } else if (dot_output != nullptr)
558         fprintf(dot_output, "\"%ld\" -> \"%ld\" [%s];\n", cur_state->num_,
559                 visited_state->original_num == -1 ? visited_state->num : visited_state->original_num, req_str.c_str());
560
561       stack_.push_back(std::move(next_state));
562     } else {
563       if (stack_.size() > (std::size_t)_sg_mc_max_depth)
564         XBT_WARN("/!\\ Max depth reached! /!\\ ");
565       else if (visited_state != nullptr)
566         XBT_DEBUG("State already visited (equal to state %ld), exploration stopped on this path.",
567                   visited_state->original_num == -1 ? visited_state->num : visited_state->original_num);
568       else
569         XBT_DEBUG("There are no more processes to interleave. (depth %zu)", stack_.size());
570
571       extension->initial_communications_pattern_done = true;
572
573       /* Trash the current state, no longer needed */
574       XBT_DEBUG("Delete state %ld at depth %zu", cur_state->num_, stack_.size());
575       stack_.pop_back();
576
577       visited_state = nullptr;
578
579       api::get().mc_check_deadlock();
580
581       while (not stack_.empty()) {
582         std::unique_ptr<State> state(std::move(stack_.back()));
583         stack_.pop_back();
584         if (state->count_todo() && stack_.size() < (std::size_t)_sg_mc_max_depth) {
585           /* We found a back-tracking point, let's loop */
586           XBT_DEBUG("Back-tracking to state %ld at depth %zu", state->num_, stack_.size() + 1);
587           stack_.push_back(std::move(state));
588
589           this->restoreState();
590
591           XBT_DEBUG("Back-tracking to state %ld at depth %zu done", stack_.back()->num_, stack_.size());
592
593           break;
594         } else {
595           XBT_DEBUG("Delete state %ld at depth %zu", state->num_, stack_.size() + 1);
596         }
597       }
598     }
599   }
600
601   api::get().log_state();
602 }
603
604 void CommunicationDeterminismChecker::run()
605 {
606   XBT_INFO("Check communication determinism");
607   get_session().take_initial_snapshot();
608
609   this->prepare();
610   this->real_run();
611 }
612
613 Checker* create_communication_determinism_checker(Session* session)
614 {
615   return new CommunicationDeterminismChecker(session);
616 }
617
618 } // namespace mc
619 } // namespace simgrid