Logo AND Algorithmique Numérique Distribuée

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