Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mist. (fix gcc MC builds)
[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(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(simgrid::mc::CallType call_type, 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 static void patterns_copy(std::vector<simgrid::mc::PatternCommunication*>& dest,
170                              std::vector<simgrid::mc::PatternCommunication> const& source)
171 {
172   dest.clear();
173   for (simgrid::mc::PatternCommunication const& comm : source) {
174     auto* copy_comm = new simgrid::mc::PatternCommunication(comm.dup());
175     dest.push_back(copy_comm);
176   }
177 }
178
179 void CommDetExtension::restore_communications_pattern(simgrid::mc::State* state)
180 {
181   for (size_t i = 0; i < initial_communications_pattern.size(); i++)
182     initial_communications_pattern[i].index_comm =
183         state->extension<simgrid::mc::StateCommDet>()->communication_indices_[i];
184
185   const unsigned long maxpid = api::get().get_maxpid();
186   for (unsigned long i = 0; i < maxpid; i++)
187     patterns_copy(incomplete_communications_pattern[i],
188                   state->extension<simgrid::mc::StateCommDet>()->incomplete_comm_pattern_[i]);
189 }
190
191 static std::string print_determinism_result(simgrid::mc::CommPatternDifference diff, aid_t process,
192                                             const simgrid::mc::PatternCommunication* comm, unsigned int cursor)
193 {
194   std::string type;
195   std::string res;
196
197   if (comm->type == simgrid::mc::PatternCommunicationType::send)
198     type = xbt::string_printf("The send communications pattern of the process %ld is different!", process - 1);
199   else
200     type = xbt::string_printf("The recv communications pattern of the process %ld is different!", process - 1);
201
202   using simgrid::mc::CommPatternDifference;
203   switch (diff) {
204     case CommPatternDifference::TYPE:
205       res = xbt::string_printf("%s Different type for communication #%u", type.c_str(), cursor);
206       break;
207     case CommPatternDifference::RDV:
208       res = xbt::string_printf("%s Different rdv for communication #%u", type.c_str(), cursor);
209       break;
210     case CommPatternDifference::TAG:
211       res = xbt::string_printf("%s Different tag for communication #%u", type.c_str(), cursor);
212       break;
213     case CommPatternDifference::SRC_PROC:
214       res = xbt::string_printf("%s Different source for communication #%u", type.c_str(), cursor);
215       break;
216     case CommPatternDifference::DST_PROC:
217       res = xbt::string_printf("%s Different destination for communication #%u", type.c_str(), cursor);
218       break;
219     case CommPatternDifference::DATA_SIZE:
220       res = xbt::string_printf("%s Different data size for communication #%u", type.c_str(), cursor);
221       break;
222     case CommPatternDifference::DATA:
223       res = xbt::string_printf("%s Different data for communication #%u", type.c_str(), cursor);
224       break;
225     default:
226       res = "";
227       break;
228   }
229
230   return res;
231 }
232
233 static void update_comm_pattern(simgrid::mc::PatternCommunication* comm_pattern,
234                                 simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> const& comm_addr)
235 {
236   auto src_proc = api::get().get_src_actor(comm_addr);
237   auto dst_proc = api::get().get_dst_actor(comm_addr);
238   comm_pattern->src_proc = src_proc->get_pid();
239   comm_pattern->dst_proc = dst_proc->get_pid();
240
241   if (comm_pattern->data.empty()) {
242     comm_pattern->data = api::get().get_pattern_comm_data(comm_addr);
243   }
244 }
245
246 void CommDetExtension::deterministic_comm_pattern(aid_t actor, const PatternCommunication* comm, bool backtracking)
247 {
248   if (not backtracking) {
249     PatternCommunicationList& list = initial_communications_pattern[actor];
250     CommPatternDifference diff     = compare_comm_pattern(list.list[list.index_comm].get(), comm);
251
252     if (diff != CommPatternDifference::NONE) {
253       if (comm->type == PatternCommunicationType::send) {
254         send_deterministic = false;
255         send_diff          = print_determinism_result(diff, actor, comm, list.index_comm + 1);
256       } else {
257         recv_deterministic = false;
258         recv_diff          = print_determinism_result(diff, actor, comm, list.index_comm + 1);
259       }
260       if (_sg_mc_send_determinism && not send_deterministic) {
261         XBT_INFO("*********************************************************");
262         XBT_INFO("***** Non-send-deterministic communications pattern *****");
263         XBT_INFO("*********************************************************");
264         XBT_INFO("%s", send_diff.c_str());
265         api::get().log_state();
266         api::get().mc_exit(SIMGRID_MC_EXIT_NON_DETERMINISM);
267       } else if (_sg_mc_comms_determinism && (not send_deterministic && not recv_deterministic)) {
268         XBT_INFO("****************************************************");
269         XBT_INFO("***** Non-deterministic communications pattern *****");
270         XBT_INFO("****************************************************");
271         if (not send_diff.empty())
272           XBT_INFO("%s", send_diff.c_str());
273         if (not recv_diff.empty())
274           XBT_INFO("%s", recv_diff.c_str());
275         api::get().log_state();
276         api::get().mc_exit(SIMGRID_MC_EXIT_NON_DETERMINISM);
277       }
278     }
279   }
280 }
281
282 /********** Non Static functions ***********/
283
284 void CommDetExtension::get_comm_pattern(smx_simcall_t request, CallType call_type, bool backtracking)
285 {
286   const smx_actor_t issuer                                     = api::get().simcall_get_issuer(request);
287   const mc::PatternCommunicationList& initial_pattern          = initial_communications_pattern[issuer->get_pid()];
288   const std::vector<PatternCommunication*>& incomplete_pattern = incomplete_communications_pattern[issuer->get_pid()];
289
290   auto pattern   = std::make_unique<PatternCommunication>();
291   pattern->index = initial_pattern.index_comm + incomplete_pattern.size();
292
293   if (call_type == CallType::SEND) {
294     /* Create comm pattern */
295     pattern->type      = PatternCommunicationType::send;
296     pattern->comm_addr = api::get().get_comm_isend_raw_addr(request);
297     pattern->rdv       = api::get().get_pattern_comm_rdv(pattern->comm_addr);
298     pattern->src_proc  = api::get().get_pattern_comm_src_proc(pattern->comm_addr);
299
300 #if HAVE_SMPI
301     pattern->tag = api::get().get_smpi_request_tag(request, simgrid::simix::Simcall::COMM_ISEND);
302 #endif
303     pattern->data = api::get().get_pattern_comm_data(pattern->comm_addr);
304
305 #if HAVE_SMPI
306     auto send_detached = api::get().check_send_request_detached(request);
307     if (send_detached) {
308       if (initial_communications_pattern_done) {
309         /* Evaluate comm determinism */
310         deterministic_comm_pattern(pattern->src_proc, pattern.get(), backtracking);
311         initial_communications_pattern[pattern->src_proc].index_comm++;
312       } else {
313         /* Store comm pattern */
314         initial_communications_pattern[pattern->src_proc].list.push_back(std::move(pattern));
315       }
316       return;
317     }
318 #endif
319   } else if (call_type == CallType::RECV) {
320     pattern->type = PatternCommunicationType::receive;
321     pattern->comm_addr = api::get().get_comm_isend_raw_addr(request);
322
323 #if HAVE_SMPI
324     pattern->tag = api::get().get_smpi_request_tag(request, simgrid::simix::Simcall::COMM_IRECV);
325 #endif
326     pattern->rdv = api::get().get_pattern_comm_rdv(pattern->comm_addr);
327     pattern->dst_proc = api::get().get_pattern_comm_dst_proc(pattern->comm_addr);
328   } else
329     xbt_die("Unexpected call_type %i", (int)call_type);
330
331   XBT_DEBUG("Insert incomplete comm pattern %p for process %ld", pattern.get(), issuer->get_pid());
332   incomplete_communications_pattern[issuer->get_pid()].push_back(pattern.release());
333 }
334
335 void CommDetExtension::complete_comm_pattern(RemotePtr<kernel::activity::CommImpl> const& comm_addr, aid_t issuer,
336                                              bool backtracking)
337 {
338   /* Complete comm pattern */
339   std::vector<PatternCommunication*>& incomplete_pattern = incomplete_communications_pattern[issuer];
340   auto current_comm_pattern =
341       std::find_if(begin(incomplete_pattern), end(incomplete_pattern),
342                    [&comm_addr](const PatternCommunication* comm) { return (comm->comm_addr == comm_addr); });
343   xbt_assert(current_comm_pattern != std::end(incomplete_pattern), "Corresponding communication not found!");
344
345   update_comm_pattern(*current_comm_pattern, comm_addr);
346   std::unique_ptr<PatternCommunication> comm_pattern(*current_comm_pattern);
347   XBT_DEBUG("Remove incomplete comm pattern for process %ld at cursor %zd", issuer,
348             std::distance(begin(incomplete_pattern), current_comm_pattern));
349   incomplete_pattern.erase(current_comm_pattern);
350
351   if (initial_communications_pattern_done) {
352     /* Evaluate comm determinism */
353     deterministic_comm_pattern(issuer, comm_pattern.get(), backtracking);
354     initial_communications_pattern[issuer].index_comm++;
355   } else {
356     /* Store comm pattern */
357     initial_communications_pattern[issuer].list.push_back(std::move(comm_pattern));
358   }
359 }
360
361 CommunicationDeterminismChecker::CommunicationDeterminismChecker(Session* session) : Checker(session)
362 {
363   CommDetExtension::EXTENSION_ID = simgrid::mc::Checker::extension_create<CommDetExtension>();
364   StateCommDet::EXTENSION_ID = simgrid::mc::State::extension_create<StateCommDet>();
365 }
366
367 CommunicationDeterminismChecker::~CommunicationDeterminismChecker() = default;
368
369 RecordTrace CommunicationDeterminismChecker::get_record_trace() // override
370 {
371   RecordTrace res;
372   for (auto const& state : stack_)
373     res.push_back(state->get_transition());
374   return res;
375 }
376
377 std::vector<std::string> CommunicationDeterminismChecker::get_textual_trace() // override
378 {
379   std::vector<std::string> trace;
380   for (auto const& state : stack_)
381     trace.push_back(state->get_transition()->to_string());
382   return trace;
383 }
384
385 void CommunicationDeterminismChecker::log_state() // override
386 {
387   if (_sg_mc_comms_determinism) {
388     if (extension<CommDetExtension>()->send_deterministic && not extension<CommDetExtension>()->recv_deterministic) {
389       XBT_INFO("*******************************************************");
390       XBT_INFO("**** Only-send-deterministic communication pattern ****");
391       XBT_INFO("*******************************************************");
392       XBT_INFO("%s", extension<CommDetExtension>()->recv_diff.c_str());
393     }
394     if (not extension<CommDetExtension>()->send_deterministic && extension<CommDetExtension>()->recv_deterministic) {
395       XBT_INFO("*******************************************************");
396       XBT_INFO("**** Only-recv-deterministic communication pattern ****");
397       XBT_INFO("*******************************************************");
398       XBT_INFO("%s", extension<CommDetExtension>()->send_diff.c_str());
399     }
400   }
401   XBT_INFO("Expanded states = %ld", State::get_expanded_states());
402   XBT_INFO("Visited states = %lu", api::get().mc_get_visited_states());
403   XBT_INFO("Executed transitions = %lu", Transition::get_executed_transitions());
404   XBT_INFO("Send-deterministic : %s", extension<CommDetExtension>()->send_deterministic ? "Yes" : "No");
405   if (_sg_mc_comms_determinism)
406     XBT_INFO("Recv-deterministic : %s", extension<CommDetExtension>()->recv_deterministic ? "Yes" : "No");
407 }
408
409 void CommunicationDeterminismChecker::prepare()
410 {
411   auto initial_state = std::make_unique<State>();
412   extension_set(new CommDetExtension());
413   initial_state->extension_set(new StateCommDet(extension<CommDetExtension>()));
414
415   XBT_DEBUG("********* Start communication determinism verification *********");
416
417   /* Add all enabled actors to the interleave set of the initial state */
418   for (auto& act : api::get().get_actors()) {
419     auto actor = act.copy.get_buffer();
420     if (get_session().actor_is_enabled(actor->get_pid()))
421       initial_state->mark_todo(actor->get_pid());
422   }
423
424   stack_.push_back(std::move(initial_state));
425 }
426
427 void CommunicationDeterminismChecker::restoreState()
428 {
429   auto extension = this->extension<CommDetExtension>();
430
431   /* Intermediate backtracking */
432   State* last_state = stack_.back().get();
433   if (last_state->system_state_) {
434     api::get().restore_state(last_state->system_state_);
435     extension->restore_communications_pattern(last_state);
436     return;
437   }
438
439   get_session().restore_initial_state();
440
441   const unsigned long maxpid = api::get().get_maxpid();
442   assert(maxpid == extension->incomplete_communications_pattern.size());
443   assert(maxpid == extension->initial_communications_pattern.size());
444   for (unsigned long j = 0; j < maxpid; j++) {
445     extension->incomplete_communications_pattern[j].clear();
446     extension->initial_communications_pattern[j].index_comm = 0;
447   }
448
449   /* Traverse the stack from the state at position start and re-execute the transitions */
450   for (std::unique_ptr<simgrid::mc::State> const& state : stack_) {
451     if (state == stack_.back())
452       break;
453
454     int req_num                    = state->get_transition()->times_considered_;
455     const s_smx_simcall* saved_req = &state->executed_req_;
456     xbt_assert(saved_req);
457
458     /* because we got a copy of the executed request, we have to fetch the
459        real one, pointed by the request field of the issuer process */
460
461     const smx_actor_t issuer = api::get().simcall_get_issuer(saved_req);
462     smx_simcall_t req        = &issuer->simcall_;
463
464     /* TODO : handle test and testany simcalls */
465     CallType call = MC_get_call_type(req);
466     state->get_transition()->replay();
467     extension->handle_comm_pattern(call, req, req_num, true);
468
469     /* Update statistics */
470     api::get().mc_inc_visited_states();
471   }
472 }
473
474 void CommDetExtension::handle_comm_pattern(simgrid::mc::CallType call_type, smx_simcall_t req, int value,
475                                            bool backtracking)
476 {
477   using simgrid::mc::CallType;
478   switch(call_type) {
479     case CallType::NONE:
480       break;
481     case CallType::SEND:
482     case CallType::RECV:
483       get_comm_pattern(req, call_type, backtracking);
484       break;
485     case CallType::WAIT:
486     case CallType::WAITANY: {
487       RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr;
488       if (call_type == CallType::WAIT)
489         comm_addr = remote(simcall_comm_wait__getraw__comm(req));
490       else
491         comm_addr = api::get().get_comm_waitany_raw_addr(req, value);
492       auto simcall_issuer = api::get().simcall_get_issuer(req);
493       complete_comm_pattern(comm_addr, simcall_issuer->get_pid(), backtracking);
494     } break;
495   default:
496     xbt_die("Unexpected call type %i", (int)call_type);
497   }
498 }
499
500 void CommunicationDeterminismChecker::real_run()
501 {
502   auto extension = this->extension<CommDetExtension>();
503
504   std::unique_ptr<VisitedState> visited_state = nullptr;
505   const unsigned long maxpid                  = api::get().get_maxpid();
506
507   while (not stack_.empty()) {
508     /* Get current state */
509     State* cur_state = stack_.back().get();
510
511     XBT_DEBUG("**************************************************");
512     XBT_DEBUG("Exploration depth = %zu (state = %ld, interleaved processes = %zu)", stack_.size(), cur_state->num_,
513               cur_state->count_todo());
514
515     /* Update statistics */
516     api::get().mc_inc_visited_states();
517
518     int next_transition = -1;
519     if (stack_.size() <= (std::size_t)_sg_mc_max_depth)
520       next_transition = cur_state->next_transition();
521
522     if (next_transition >= 0 && visited_state == nullptr) {
523       cur_state->execute_next(next_transition);
524
525       int req_num       = cur_state->get_transition()->times_considered_;
526       smx_simcall_t req = &cur_state->executed_req_;
527
528       XBT_DEBUG("Execute: %s", cur_state->get_transition()->to_string().c_str());
529
530       std::string req_str;
531       if (dot_output != nullptr)
532         req_str = api::get().request_get_dot_output(cur_state->get_transition());
533
534       /* TODO : handle test and testany simcalls */
535       CallType call = CallType::NONE;
536       if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
537         call = MC_get_call_type(req);
538
539       extension->handle_comm_pattern(call, req, req_num, false);
540
541       /* Create the new expanded state */
542       auto next_state = std::make_unique<State>();
543       next_state->extension_set(new StateCommDet(extension));
544
545       bool all_communications_are_finished = true;
546       for (size_t current_actor = 1; all_communications_are_finished && current_actor < maxpid; current_actor++) {
547         if (not extension->incomplete_communications_pattern[current_actor].empty()) {
548           XBT_DEBUG("Some communications are not finished, cannot stop the exploration! State not visited.");
549           all_communications_are_finished = false;
550         }
551       }
552
553       /* If comm determinism verification, we cannot stop the exploration if some communications are not finished (at
554        * least, data are transferred). These communications  are incomplete and they cannot be analyzed and compared
555        * with the initial pattern. */
556       bool compare_snapshots = extension->initial_communications_pattern_done && all_communications_are_finished;
557
558       if (_sg_mc_max_visited_states != 0)
559         visited_state = visited_states_.addVisitedState(next_state->num_, next_state.get(), compare_snapshots);
560       else
561         visited_state = nullptr;
562
563       if (visited_state == nullptr) {
564         /* Add all enabled actors to the interleave set of the next state */
565         for (auto& act : api::get().get_actors()) {
566           auto actor = act.copy.get_buffer();
567           if (get_session().actor_is_enabled(actor->get_pid()))
568             next_state->mark_todo(actor->get_pid());
569         }
570
571         if (dot_output != nullptr)
572           fprintf(dot_output, "\"%ld\" -> \"%ld\" [%s];\n", cur_state->num_, next_state->num_, req_str.c_str());
573
574       } else if (dot_output != nullptr)
575         fprintf(dot_output, "\"%ld\" -> \"%ld\" [%s];\n", cur_state->num_,
576                 visited_state->original_num == -1 ? visited_state->num : visited_state->original_num, req_str.c_str());
577
578       stack_.push_back(std::move(next_state));
579     } else {
580       if (stack_.size() > (std::size_t)_sg_mc_max_depth)
581         XBT_WARN("/!\\ Max depth reached! /!\\ ");
582       else if (visited_state != nullptr)
583         XBT_DEBUG("State already visited (equal to state %ld), exploration stopped on this path.",
584                   visited_state->original_num == -1 ? visited_state->num : visited_state->original_num);
585       else
586         XBT_DEBUG("There are no more processes to interleave. (depth %zu)", stack_.size());
587
588       extension->initial_communications_pattern_done = true;
589
590       /* Trash the current state, no longer needed */
591       XBT_DEBUG("Delete state %ld at depth %zu", cur_state->num_, stack_.size());
592       stack_.pop_back();
593
594       visited_state = nullptr;
595
596       api::get().mc_check_deadlock();
597
598       while (not stack_.empty()) {
599         std::unique_ptr<State> state(std::move(stack_.back()));
600         stack_.pop_back();
601         if (state->count_todo() && stack_.size() < (std::size_t)_sg_mc_max_depth) {
602           /* We found a back-tracking point, let's loop */
603           XBT_DEBUG("Back-tracking to state %ld at depth %zu", state->num_, stack_.size() + 1);
604           stack_.push_back(std::move(state));
605
606           this->restoreState();
607
608           XBT_DEBUG("Back-tracking to state %ld at depth %zu done", stack_.back()->num_, stack_.size());
609
610           break;
611         } else {
612           XBT_DEBUG("Delete state %ld at depth %zu", state->num_, stack_.size() + 1);
613         }
614       }
615     }
616   }
617
618   api::get().log_state();
619 }
620
621 void CommunicationDeterminismChecker::run()
622 {
623   XBT_INFO("Check communication determinism");
624   get_session().take_initial_snapshot();
625
626   this->prepare();
627   this->real_run();
628 }
629
630 Checker* create_communication_determinism_checker(Session* session)
631 {
632   return new CommunicationDeterminismChecker(session);
633 }
634
635 } // namespace mc
636 } // namespace simgrid