Logo AND Algorithmique Numérique Distribuée

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