Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Comment unused function parameters.
[simgrid.git] / src / mc / checker / CommunicationDeterminismChecker.cpp
1 /* Copyright (c) 2008-2018. 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 <cstdint>
7
8 #include <xbt/dynar.h>
9 #include <xbt/log.h>
10 #include <xbt/sysdep.h>
11
12 #include "src/mc/VisitedState.hpp"
13 #include "src/mc/checker/CommunicationDeterminismChecker.hpp"
14 #include "src/mc/mc_exit.hpp"
15 #include "src/mc/mc_private.hpp"
16 #include "src/mc/mc_record.hpp"
17 #include "src/mc/mc_request.hpp"
18 #include "src/mc/mc_smx.hpp"
19 #include "src/mc/mc_state.hpp"
20 #include "src/mc/remote/Client.hpp"
21
22 #include "smpi_request.hpp"
23
24 using simgrid::mc::remote;
25
26 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_determinism, mc, "Logging specific to MC communication determinism detection");
27
28 /********** Global variables **********/
29
30 xbt_dynar_t initial_communications_pattern;
31 xbt_dynar_t incomplete_communications_pattern;
32
33 /********** Static functions ***********/
34
35 static e_mc_comm_pattern_difference_t compare_comm_pattern(simgrid::mc::PatternCommunication* comm1,
36                                                            simgrid::mc::PatternCommunication* comm2)
37 {
38   if(comm1->type != comm2->type)
39     return TYPE_DIFF;
40   if (comm1->rdv != comm2->rdv)
41     return RDV_DIFF;
42   if (comm1->src_proc != comm2->src_proc)
43     return SRC_PROC_DIFF;
44   if (comm1->dst_proc != comm2->dst_proc)
45     return DST_PROC_DIFF;
46   if (comm1->tag != comm2->tag)
47     return TAG_DIFF;
48   if (comm1->data.size() != comm2->data.size())
49     return DATA_SIZE_DIFF;
50   if (comm1->data != comm2->data)
51     return DATA_DIFF;
52   return NONE_DIFF;
53 }
54
55 static char* print_determinism_result(e_mc_comm_pattern_difference_t diff, int process,
56                                       simgrid::mc::PatternCommunication* comm, unsigned int cursor)
57 {
58   char* type;
59   char* res;
60
61   if (comm->type == simgrid::mc::PatternCommunicationType::send)
62     type = bprintf("The send communications pattern of the process %d is different!", process - 1);
63   else
64     type = bprintf("The recv communications pattern of the process %d is different!", process - 1);
65
66   switch(diff) {
67   case TYPE_DIFF:
68     res = bprintf("%s Different type for communication #%u", type, cursor);
69     break;
70   case RDV_DIFF:
71     res = bprintf("%s Different rdv for communication #%u", type, cursor);
72     break;
73   case TAG_DIFF:
74     res = bprintf("%s Different tag for communication #%u", type, cursor);
75     break;
76   case SRC_PROC_DIFF:
77     res = bprintf("%s Different source for communication #%u", type, cursor);
78     break;
79   case DST_PROC_DIFF:
80     res = bprintf("%s Different destination for communication #%u", type, cursor);
81     break;
82   case DATA_SIZE_DIFF:
83     res = bprintf("%s\n Different data size for communication #%u", type, cursor);
84     break;
85   case DATA_DIFF:
86     res = bprintf("%s\n Different data for communication #%u", type, cursor);
87     break;
88   default:
89     res = nullptr;
90     break;
91   }
92
93   return res;
94 }
95
96 static void update_comm_pattern(simgrid::mc::PatternCommunication* comm_pattern,
97                                 simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr)
98 {
99   // HACK, type punning
100   simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
101   mc_model_checker->process().read(temp_comm, comm_addr);
102   simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
103
104   smx_actor_t src_proc   = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->src_proc));
105   smx_actor_t dst_proc   = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_proc));
106   comm_pattern->src_proc = src_proc->pid;
107   comm_pattern->dst_proc = dst_proc->pid;
108   comm_pattern->src_host = MC_smx_actor_get_host_name(src_proc);
109   comm_pattern->dst_host = MC_smx_actor_get_host_name(dst_proc);
110   if (comm_pattern->data.size() == 0 && comm->src_buff != nullptr) {
111     size_t buff_size;
112     mc_model_checker->process().read(&buff_size, remote(comm->dst_buff_size));
113     comm_pattern->data.resize(buff_size);
114     mc_model_checker->process().read_bytes(comm_pattern->data.data(), comm_pattern->data.size(),
115                                            remote(comm->src_buff));
116   }
117 }
118
119 namespace simgrid {
120 namespace mc {
121
122 void CommunicationDeterminismChecker::deterministic_comm_pattern(int process, simgrid::mc::PatternCommunication* comm,
123                                                                  int backtracking)
124 {
125   simgrid::mc::PatternCommunicationList* list =
126     xbt_dynar_get_as(initial_communications_pattern, process, simgrid::mc::PatternCommunicationList*);
127
128   if (not backtracking) {
129     e_mc_comm_pattern_difference_t diff = compare_comm_pattern(list->list[list->index_comm].get(), comm);
130
131     if (diff != NONE_DIFF) {
132       if (comm->type == simgrid::mc::PatternCommunicationType::send) {
133         this->send_deterministic = 0;
134         if (this->send_diff != nullptr)
135           xbt_free(this->send_diff);
136         this->send_diff = print_determinism_result(diff, process, comm, list->index_comm + 1);
137       } else {
138         this->recv_deterministic = 0;
139         if (this->recv_diff != nullptr)
140           xbt_free(this->recv_diff);
141         this->recv_diff = print_determinism_result(diff, process, comm, list->index_comm + 1);
142       }
143       if (_sg_mc_send_determinism && not this->send_deterministic) {
144         XBT_INFO("*********************************************************");
145         XBT_INFO("***** Non-send-deterministic communications pattern *****");
146         XBT_INFO("*********************************************************");
147         XBT_INFO("%s", this->send_diff);
148         xbt_free(this->send_diff);
149         this->send_diff = nullptr;
150         simgrid::mc::session->logState();
151         mc_model_checker->exit(SIMGRID_MC_EXIT_NON_DETERMINISM);
152       } else if (_sg_mc_comms_determinism && (not this->send_deterministic && not this->recv_deterministic)) {
153         XBT_INFO("****************************************************");
154         XBT_INFO("***** Non-deterministic communications pattern *****");
155         XBT_INFO("****************************************************");
156         XBT_INFO("%s", this->send_diff);
157         XBT_INFO("%s", this->recv_diff);
158         xbt_free(this->send_diff);
159         this->send_diff = nullptr;
160         xbt_free(this->recv_diff);
161         this->recv_diff = nullptr;
162         simgrid::mc::session->logState();
163         mc_model_checker->exit(SIMGRID_MC_EXIT_NON_DETERMINISM);
164       }
165     }
166   }
167 }
168
169 /********** Non Static functions ***********/
170
171 void CommunicationDeterminismChecker::get_comm_pattern(xbt_dynar_t list, smx_simcall_t request,
172                                                        e_mc_call_type_t call_type, int backtracking)
173 {
174   const smx_actor_t issuer = MC_smx_simcall_get_issuer(request);
175   simgrid::mc::PatternCommunicationList* initial_pattern =
176       xbt_dynar_get_as(initial_communications_pattern, issuer->pid, simgrid::mc::PatternCommunicationList*);
177   xbt_dynar_t incomplete_pattern = xbt_dynar_get_as(incomplete_communications_pattern, issuer->pid, xbt_dynar_t);
178
179   std::unique_ptr<simgrid::mc::PatternCommunication> pattern =
180       std::unique_ptr<simgrid::mc::PatternCommunication>(new simgrid::mc::PatternCommunication());
181   pattern->index = initial_pattern->index_comm + xbt_dynar_length(incomplete_pattern);
182
183   if (call_type == MC_CALL_TYPE_SEND) {
184     /* Create comm pattern */
185     pattern->type = simgrid::mc::PatternCommunicationType::send;
186     pattern->comm_addr = static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_isend__getraw__result(request));
187
188     simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_synchro;
189     mc_model_checker->process().read(temp_synchro,
190                                      remote(static_cast<simgrid::kernel::activity::CommImpl*>(pattern->comm_addr)));
191     simgrid::kernel::activity::CommImpl* synchro =
192         static_cast<simgrid::kernel::activity::CommImpl*>(temp_synchro.getBuffer());
193
194     char* remote_name = mc_model_checker->process().read<char*>(
195         RemotePtr<char*>((uint64_t)(synchro->mbox ? &synchro->mbox->name_ : &synchro->mbox_cpy->name_)));
196     pattern->rdv      = mc_model_checker->process().read_string(RemotePtr<char>(remote_name));
197     pattern->src_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(synchro->src_proc))->pid;
198     pattern->src_host = MC_smx_actor_get_host_name(issuer);
199
200     simgrid::smpi::Request mpi_request = mc_model_checker->process().read<simgrid::smpi::Request>(
201         RemotePtr<simgrid::smpi::Request>((std::uint64_t)simcall_comm_isend__get__data(request)));
202     pattern->tag = mpi_request.tag();
203
204     if (synchro->src_buff != nullptr) {
205       pattern->data.resize(synchro->src_buff_size);
206       mc_model_checker->process().read_bytes(pattern->data.data(), pattern->data.size(), remote(synchro->src_buff));
207     }
208     if(mpi_request.detached()){
209       if (not this->initial_communications_pattern_done) {
210         /* Store comm pattern */
211         simgrid::mc::PatternCommunicationList* list =
212             xbt_dynar_get_as(initial_communications_pattern, pattern->src_proc, simgrid::mc::PatternCommunicationList*);
213         list->list.push_back(std::move(pattern));
214       } else {
215         /* Evaluate comm determinism */
216         this->deterministic_comm_pattern(pattern->src_proc, pattern.get(), backtracking);
217         xbt_dynar_get_as(initial_communications_pattern, pattern->src_proc, simgrid::mc::PatternCommunicationList*)
218             ->index_comm++;
219       }
220       return;
221     }
222   } else if (call_type == MC_CALL_TYPE_RECV) {
223     pattern->type = simgrid::mc::PatternCommunicationType::receive;
224     pattern->comm_addr = static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_irecv__getraw__result(request));
225
226     simgrid::smpi::Request mpi_request;
227     mc_model_checker->process().read(&mpi_request,
228                                      remote((simgrid::smpi::Request*)simcall_comm_irecv__get__data(request)));
229     pattern->tag = mpi_request.tag();
230
231     simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
232     mc_model_checker->process().read(temp_comm,
233                                      remote(static_cast<simgrid::kernel::activity::CommImpl*>(pattern->comm_addr)));
234     simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
235
236     char* remote_name;
237     mc_model_checker->process().read(
238         &remote_name, remote(comm->mbox ? &simgrid::xbt::string::to_string_data(comm->mbox->name_).data
239                                         : &simgrid::xbt::string::to_string_data(comm->mbox_cpy->name_).data));
240     pattern->rdv      = mc_model_checker->process().read_string(RemotePtr<char>(remote_name));
241     pattern->dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_proc))->pid;
242     pattern->dst_host = MC_smx_actor_get_host_name(issuer);
243   } else
244     xbt_die("Unexpected call_type %i", (int) call_type);
245
246   XBT_DEBUG("Insert incomplete comm pattern %p for process %ld", pattern.get(), issuer->pid);
247   xbt_dynar_t dynar = xbt_dynar_get_as(incomplete_communications_pattern, issuer->pid, xbt_dynar_t);
248   simgrid::mc::PatternCommunication* pattern2 = pattern.release();
249   xbt_dynar_push(dynar, &pattern2);
250 }
251
252 void CommunicationDeterminismChecker::complete_comm_pattern(
253     xbt_dynar_t list, simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr, unsigned int issuer,
254     int backtracking)
255 {
256   simgrid::mc::PatternCommunication* current_comm_pattern;
257   unsigned int cursor = 0;
258   std::unique_ptr<simgrid::mc::PatternCommunication> comm_pattern;
259   int completed = 0;
260
261   /* Complete comm pattern */
262   xbt_dynar_foreach(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, current_comm_pattern)
263     if (remote(current_comm_pattern->comm_addr) == comm_addr) {
264       update_comm_pattern(current_comm_pattern, comm_addr);
265       completed = 1;
266       simgrid::mc::PatternCommunication* temp;
267       xbt_dynar_remove_at(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, &temp);
268       comm_pattern = std::unique_ptr<simgrid::mc::PatternCommunication>(temp);
269       XBT_DEBUG("Remove incomplete comm pattern for process %u at cursor %u", issuer, cursor);
270       break;
271     }
272
273   if (not completed)
274     xbt_die("Corresponding communication not found!");
275
276   simgrid::mc::PatternCommunicationList* pattern =
277       xbt_dynar_get_as(initial_communications_pattern, issuer, simgrid::mc::PatternCommunicationList*);
278
279   if (not this->initial_communications_pattern_done)
280     /* Store comm pattern */
281     pattern->list.push_back(std::move(comm_pattern));
282   else {
283     /* Evaluate comm determinism */
284     this->deterministic_comm_pattern(issuer, comm_pattern.get(), backtracking);
285     pattern->index_comm++;
286   }
287 }
288
289 CommunicationDeterminismChecker::CommunicationDeterminismChecker(Session& session) : Checker(session)
290 {
291 }
292
293 CommunicationDeterminismChecker::~CommunicationDeterminismChecker() = default;
294
295 RecordTrace CommunicationDeterminismChecker::getRecordTrace() // override
296 {
297   RecordTrace res;
298   for (auto const& state : stack_)
299     res.push_back(state->getTransition());
300   return res;
301 }
302
303 std::vector<std::string> CommunicationDeterminismChecker::getTextualTrace() // override
304 {
305   std::vector<std::string> trace;
306   for (auto const& state : stack_) {
307     smx_simcall_t req = &state->executed_req;
308     if (req)
309       trace.push_back(
310           simgrid::mc::request_to_string(req, state->transition.argument, simgrid::mc::RequestType::executed));
311   }
312   return trace;
313 }
314
315 void CommunicationDeterminismChecker::logState() // override
316 {
317   if (_sg_mc_comms_determinism && not this->recv_deterministic && this->send_deterministic) {
318     XBT_INFO("******************************************************");
319     XBT_INFO("**** Only-send-deterministic communication pattern ****");
320     XBT_INFO("******************************************************");
321     XBT_INFO("%s", this->recv_diff);
322   } else if (_sg_mc_comms_determinism && not this->send_deterministic && this->recv_deterministic) {
323     XBT_INFO("******************************************************");
324     XBT_INFO("**** Only-recv-deterministic communication pattern ****");
325     XBT_INFO("******************************************************");
326     XBT_INFO("%s", this->send_diff);
327   }
328   XBT_INFO("Expanded states = %lu", expandedStatesCount_);
329   XBT_INFO("Visited states = %lu", mc_model_checker->visited_states);
330   XBT_INFO("Executed transitions = %lu", mc_model_checker->executed_transitions);
331   XBT_INFO("Send-deterministic : %s", not this->send_deterministic ? "No" : "Yes");
332   if (_sg_mc_comms_determinism)
333     XBT_INFO("Recv-deterministic : %s", not this->recv_deterministic ? "No" : "Yes");
334 }
335
336 void CommunicationDeterminismChecker::prepare()
337 {
338   const int maxpid = MC_smx_get_maxpid();
339
340   // Create initial_communications_pattern elements:
341   initial_communications_pattern = simgrid::xbt::newDeleteDynar<simgrid::mc::PatternCommunicationList*>();
342   for (int i = 0; i < maxpid; i++) {
343     simgrid::mc::PatternCommunicationList* process_list_pattern = new simgrid::mc::PatternCommunicationList();
344     xbt_dynar_insert_at(initial_communications_pattern, i, &process_list_pattern);
345   }
346
347   // Create incomplete_communications_pattern elements:
348   incomplete_communications_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
349   for (int i = 0; i < maxpid; i++) {
350     xbt_dynar_t process_pattern = xbt_dynar_new(sizeof(simgrid::mc::PatternCommunication*), nullptr);
351     xbt_dynar_insert_at(incomplete_communications_pattern, i, &process_pattern);
352   }
353
354   std::unique_ptr<simgrid::mc::State> initial_state =
355       std::unique_ptr<simgrid::mc::State>(new simgrid::mc::State(++expandedStatesCount_));
356
357   XBT_DEBUG("********* Start communication determinism verification *********");
358
359   /* Get an enabled actor and insert it in the interleave set of the initial state */
360   for (auto& actor : mc_model_checker->process().actors())
361     if (simgrid::mc::actor_is_enabled(actor.copy.getBuffer()))
362       initial_state->addInterleavingSet(actor.copy.getBuffer());
363
364   stack_.push_back(std::move(initial_state));
365 }
366
367 static inline bool all_communications_are_finished()
368 {
369   for (size_t current_actor = 1; current_actor < MC_smx_get_maxpid(); current_actor++) {
370     xbt_dynar_t pattern = xbt_dynar_get_as(incomplete_communications_pattern, current_actor, xbt_dynar_t);
371     if (not xbt_dynar_is_empty(pattern)) {
372       XBT_DEBUG("Some communications are not finished, cannot stop the exploration! State not visited.");
373       return false;
374     }
375   }
376   return true;
377 }
378
379 void CommunicationDeterminismChecker::restoreState()
380 {
381   /* Intermediate backtracking */
382   simgrid::mc::State* state = stack_.back().get();
383   if (state->system_state) {
384     simgrid::mc::restore_snapshot(state->system_state);
385     MC_restore_communications_pattern(state);
386     return;
387   }
388
389   /* Restore the initial state */
390   simgrid::mc::session->restoreInitialState();
391
392   unsigned n = MC_smx_get_maxpid();
393   assert(n == xbt_dynar_length(incomplete_communications_pattern));
394   assert(n == xbt_dynar_length(initial_communications_pattern));
395   for (unsigned j=0; j < n ; j++) {
396     xbt_dynar_reset((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, j, xbt_dynar_t));
397     xbt_dynar_get_as(initial_communications_pattern, j, simgrid::mc::PatternCommunicationList*)->index_comm = 0;
398   }
399
400   /* Traverse the stack from the state at position start and re-execute the transitions */
401   for (std::unique_ptr<simgrid::mc::State> const& state : stack_) {
402     if (state == stack_.back())
403       break;
404
405     int req_num = state->transition.argument;
406     smx_simcall_t saved_req = &state->executed_req;
407     xbt_assert(saved_req);
408
409     /* because we got a copy of the executed request, we have to fetch the
410        real one, pointed by the request field of the issuer process */
411
412     const smx_actor_t issuer = MC_smx_simcall_get_issuer(saved_req);
413     smx_simcall_t req = &issuer->simcall;
414
415     /* TODO : handle test and testany simcalls */
416     e_mc_call_type_t call = MC_get_call_type(req);
417     mc_model_checker->handle_simcall(state->transition);
418     MC_handle_comm_pattern(call, req, req_num, nullptr, 1);
419     mc_model_checker->wait_for_requests();
420
421     /* Update statistics */
422     mc_model_checker->visited_states++;
423     mc_model_checker->executed_transitions++;
424   }
425 }
426
427 void CommunicationDeterminismChecker::main()
428 {
429   std::unique_ptr<simgrid::mc::VisitedState> visited_state = nullptr;
430   smx_simcall_t req = nullptr;
431
432   while (not stack_.empty()) {
433     /* Get current state */
434     simgrid::mc::State* state = stack_.back().get();
435
436     XBT_DEBUG("**************************************************");
437     XBT_DEBUG("Exploration depth = %zu (state = %d, interleaved processes = %zu)", stack_.size(), state->num,
438               state->interleaveSize());
439
440     /* Update statistics */
441     mc_model_checker->visited_states++;
442
443     if (stack_.size() <= (std::size_t)_sg_mc_max_depth)
444       req = MC_state_get_request(state);
445     else
446       req = nullptr;
447
448     if (req != nullptr && visited_state == nullptr) {
449
450       int req_num = state->transition.argument;
451
452       XBT_DEBUG("Execute: %s", simgrid::mc::request_to_string(req, req_num, simgrid::mc::RequestType::simix).c_str());
453
454       std::string req_str;
455       if (dot_output != nullptr)
456         req_str = simgrid::mc::request_get_dot_output(req, req_num);
457
458       mc_model_checker->executed_transitions++;
459
460       /* TODO : handle test and testany simcalls */
461       e_mc_call_type_t call = MC_CALL_TYPE_NONE;
462       if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
463         call = MC_get_call_type(req);
464
465       /* Answer the request */
466       mc_model_checker->handle_simcall(state->transition);
467       /* After this call req is no longer useful */
468
469       if (not this->initial_communications_pattern_done)
470         MC_handle_comm_pattern(call, req, req_num, initial_communications_pattern, 0);
471       else
472         MC_handle_comm_pattern(call, req, req_num, nullptr, 0);
473
474       /* Wait for requests (schedules processes) */
475       mc_model_checker->wait_for_requests();
476
477       /* Create the new expanded state */
478       std::unique_ptr<simgrid::mc::State> next_state =
479           std::unique_ptr<simgrid::mc::State>(new simgrid::mc::State(++expandedStatesCount_));
480
481       /* If comm determinism verification, we cannot stop the exploration if some communications are not finished (at
482        * least, data are transferred). These communications  are incomplete and they cannot be analyzed and compared
483        * with the initial pattern. */
484       bool compare_snapshots = all_communications_are_finished() && this->initial_communications_pattern_done;
485
486       if (_sg_mc_max_visited_states != 0)
487         visited_state = visitedStates_.addVisitedState(expandedStatesCount_, next_state.get(), compare_snapshots);
488       else
489         visited_state = nullptr;
490
491       if (visited_state == nullptr) {
492
493         /* Get enabled actors and insert them in the interleave set of the next state */
494         for (auto& actor : mc_model_checker->process().actors())
495           if (simgrid::mc::actor_is_enabled(actor.copy.getBuffer()))
496             next_state->addInterleavingSet(actor.copy.getBuffer());
497
498         if (dot_output != nullptr)
499           fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n",
500             state->num,  next_state->num, req_str.c_str());
501
502       } else if (dot_output != nullptr)
503         fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num,
504                 visited_state->original_num == -1 ? visited_state->num : visited_state->original_num, req_str.c_str());
505
506       stack_.push_back(std::move(next_state));
507
508     } else {
509
510       if (stack_.size() > (std::size_t) _sg_mc_max_depth)
511         XBT_WARN("/!\\ Max depth reached! /!\\ ");
512       else if (visited_state != nullptr)
513         XBT_DEBUG("State already visited (equal to state %d), exploration stopped on this path.",
514             visited_state->original_num == -1 ? visited_state->num : visited_state->original_num);
515       else
516         XBT_DEBUG("There are no more processes to interleave. (depth %zu)", stack_.size());
517
518       if (not this->initial_communications_pattern_done)
519         this->initial_communications_pattern_done = 1;
520
521       /* Trash the current state, no longer needed */
522       XBT_DEBUG("Delete state %d at depth %zu", state->num, stack_.size());
523       stack_.pop_back();
524
525       visited_state = nullptr;
526
527       /* Check for deadlocks */
528       if (mc_model_checker->checkDeadlock()) {
529         MC_show_deadlock();
530         throw simgrid::mc::DeadlockError();
531       }
532
533       while (not stack_.empty()) {
534         std::unique_ptr<simgrid::mc::State> state = std::move(stack_.back());
535         stack_.pop_back();
536         if (state->interleaveSize() && stack_.size() < (std::size_t)_sg_mc_max_depth) {
537           /* We found a back-tracking point, let's loop */
538           XBT_DEBUG("Back-tracking to state %d at depth %zu", state->num, stack_.size() + 1);
539           stack_.push_back(std::move(state));
540
541           this->restoreState();
542
543           XBT_DEBUG("Back-tracking to state %d at depth %zu done", stack_.back()->num, stack_.size());
544
545           break;
546         } else {
547           XBT_DEBUG("Delete state %d at depth %zu", state->num, stack_.size() + 1);
548         }
549       }
550     }
551   }
552
553   simgrid::mc::session->logState();
554 }
555
556 void CommunicationDeterminismChecker::run()
557 {
558   XBT_INFO("Check communication determinism");
559   simgrid::mc::session->initialize();
560
561   this->prepare();
562
563   this->main();
564 }
565
566 Checker* createCommunicationDeterminismChecker(Session& session)
567 {
568   return new CommunicationDeterminismChecker(session);
569 }
570
571 }
572 }