Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e40236d8557dc3a5235ad8b6e76f95df9b3b1454
[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->pid_;
106   comm_pattern->dst_proc = dst_proc->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->pid_, simgrid::mc::PatternCommunicationList*);
176   xbt_dynar_t incomplete_pattern = xbt_dynar_get_as(incomplete_communications_pattern, issuer->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 = mc_model_checker->process().resolveActor(simgrid::mc::remote(synchro->src_actor_.get()))->pid_;
197     pattern->src_host = MC_smx_actor_get_host_name(issuer);
198
199 #if HAVE_SMPI
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 #endif
204
205     if (synchro->src_buff_ != nullptr) {
206       pattern->data.resize(synchro->src_buff_size_);
207       mc_model_checker->process().read_bytes(pattern->data.data(), pattern->data.size(), remote(synchro->src_buff_));
208     }
209 #if HAVE_SMPI
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 #endif
225   } else if (call_type == MC_CALL_TYPE_RECV) {
226     pattern->type = simgrid::mc::PatternCommunicationType::receive;
227     pattern->comm_addr = static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_irecv__getraw__result(request));
228
229 #if HAVE_SMPI
230     simgrid::smpi::Request mpi_request;
231     mc_model_checker->process().read(&mpi_request,
232                                      remote((simgrid::smpi::Request*)simcall_comm_irecv__get__data(request)));
233     pattern->tag = mpi_request.tag();
234 #endif
235
236     simgrid::mc::Remote<simgrid::kernel::activity::CommImpl> temp_comm;
237     mc_model_checker->process().read(temp_comm,
238                                      remote(static_cast<simgrid::kernel::activity::CommImpl*>(pattern->comm_addr)));
239     simgrid::kernel::activity::CommImpl* comm = temp_comm.getBuffer();
240
241     char* remote_name;
242     mc_model_checker->process().read(
243         &remote_name, remote(comm->mbox ? &simgrid::xbt::string::to_string_data(comm->mbox->name_).data
244                                         : &simgrid::xbt::string::to_string_data(comm->mbox_cpy->name_).data));
245     pattern->rdv      = mc_model_checker->process().read_string(RemotePtr<char>(remote_name));
246     pattern->dst_proc = mc_model_checker->process().resolveActor(simgrid::mc::remote(comm->dst_actor_.get()))->pid_;
247     pattern->dst_host = MC_smx_actor_get_host_name(issuer);
248   } else
249     xbt_die("Unexpected call_type %i", (int) call_type);
250
251   XBT_DEBUG("Insert incomplete comm pattern %p for process %ld", pattern.get(), issuer->pid_);
252   xbt_dynar_t dynar = xbt_dynar_get_as(incomplete_communications_pattern, issuer->pid_, xbt_dynar_t);
253   simgrid::mc::PatternCommunication* pattern2 = pattern.release();
254   xbt_dynar_push(dynar, &pattern2);
255 }
256
257 void CommunicationDeterminismChecker::complete_comm_pattern(
258     xbt_dynar_t list, simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr, unsigned int issuer,
259     int backtracking)
260 {
261   simgrid::mc::PatternCommunication* current_comm_pattern;
262   unsigned int cursor = 0;
263   std::unique_ptr<simgrid::mc::PatternCommunication> comm_pattern;
264   int completed = 0;
265
266   /* Complete comm pattern */
267   xbt_dynar_foreach(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, current_comm_pattern)
268     if (remote(current_comm_pattern->comm_addr) == comm_addr) {
269       update_comm_pattern(current_comm_pattern, comm_addr);
270       completed = 1;
271       simgrid::mc::PatternCommunication* temp;
272       xbt_dynar_remove_at(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, &temp);
273       comm_pattern = std::unique_ptr<simgrid::mc::PatternCommunication>(temp);
274       XBT_DEBUG("Remove incomplete comm pattern for process %u at cursor %u", issuer, cursor);
275       break;
276     }
277
278   if (not completed)
279     xbt_die("Corresponding communication not found!");
280
281   simgrid::mc::PatternCommunicationList* pattern =
282       xbt_dynar_get_as(initial_communications_pattern, issuer, simgrid::mc::PatternCommunicationList*);
283
284   if (not this->initial_communications_pattern_done)
285     /* Store comm pattern */
286     pattern->list.push_back(std::move(comm_pattern));
287   else {
288     /* Evaluate comm determinism */
289     this->deterministic_comm_pattern(issuer, comm_pattern.get(), backtracking);
290     pattern->index_comm++;
291   }
292 }
293
294 CommunicationDeterminismChecker::CommunicationDeterminismChecker(Session& session) : Checker(session)
295 {
296 }
297
298 CommunicationDeterminismChecker::~CommunicationDeterminismChecker() = default;
299
300 RecordTrace CommunicationDeterminismChecker::getRecordTrace() // override
301 {
302   RecordTrace res;
303   for (auto const& state : stack_)
304     res.push_back(state->getTransition());
305   return res;
306 }
307
308 std::vector<std::string> CommunicationDeterminismChecker::getTextualTrace() // override
309 {
310   std::vector<std::string> trace;
311   for (auto const& state : stack_) {
312     smx_simcall_t req = &state->executed_req;
313     if (req)
314       trace.push_back(
315           simgrid::mc::request_to_string(req, state->transition.argument, simgrid::mc::RequestType::executed));
316   }
317   return trace;
318 }
319
320 void CommunicationDeterminismChecker::logState() // override
321 {
322   if (_sg_mc_comms_determinism && not this->recv_deterministic && this->send_deterministic) {
323     XBT_INFO("******************************************************");
324     XBT_INFO("**** Only-send-deterministic communication pattern ****");
325     XBT_INFO("******************************************************");
326     XBT_INFO("%s", this->recv_diff);
327   } else if (_sg_mc_comms_determinism && not this->send_deterministic && this->recv_deterministic) {
328     XBT_INFO("******************************************************");
329     XBT_INFO("**** Only-recv-deterministic communication pattern ****");
330     XBT_INFO("******************************************************");
331     XBT_INFO("%s", this->send_diff);
332   }
333   XBT_INFO("Expanded states = %lu", expandedStatesCount_);
334   XBT_INFO("Visited states = %lu", mc_model_checker->visited_states);
335   XBT_INFO("Executed transitions = %lu", mc_model_checker->executed_transitions);
336   XBT_INFO("Send-deterministic : %s", not this->send_deterministic ? "No" : "Yes");
337   if (_sg_mc_comms_determinism)
338     XBT_INFO("Recv-deterministic : %s", not this->recv_deterministic ? "No" : "Yes");
339 }
340
341 void CommunicationDeterminismChecker::prepare()
342 {
343   const int maxpid = MC_smx_get_maxpid();
344
345   // Create initial_communications_pattern elements:
346   initial_communications_pattern = simgrid::xbt::newDeleteDynar<simgrid::mc::PatternCommunicationList*>();
347   for (int i = 0; i < maxpid; i++) {
348     simgrid::mc::PatternCommunicationList* process_list_pattern = new simgrid::mc::PatternCommunicationList();
349     xbt_dynar_insert_at(initial_communications_pattern, i, &process_list_pattern);
350   }
351
352   // Create incomplete_communications_pattern elements:
353   incomplete_communications_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
354   for (int i = 0; i < maxpid; i++) {
355     xbt_dynar_t process_pattern = xbt_dynar_new(sizeof(simgrid::mc::PatternCommunication*), nullptr);
356     xbt_dynar_insert_at(incomplete_communications_pattern, i, &process_pattern);
357   }
358
359   std::unique_ptr<simgrid::mc::State> initial_state =
360       std::unique_ptr<simgrid::mc::State>(new simgrid::mc::State(++expandedStatesCount_));
361
362   XBT_DEBUG("********* Start communication determinism verification *********");
363
364   /* Get an enabled actor and insert it in the interleave set of the initial state */
365   for (auto& actor : mc_model_checker->process().actors())
366     if (simgrid::mc::actor_is_enabled(actor.copy.getBuffer()))
367       initial_state->addInterleavingSet(actor.copy.getBuffer());
368
369   stack_.push_back(std::move(initial_state));
370 }
371
372 static inline bool all_communications_are_finished()
373 {
374   for (size_t current_actor = 1; current_actor < MC_smx_get_maxpid(); current_actor++) {
375     xbt_dynar_t pattern = xbt_dynar_get_as(incomplete_communications_pattern, current_actor, xbt_dynar_t);
376     if (not xbt_dynar_is_empty(pattern)) {
377       XBT_DEBUG("Some communications are not finished, cannot stop the exploration! State not visited.");
378       return false;
379     }
380   }
381   return true;
382 }
383
384 void CommunicationDeterminismChecker::restoreState()
385 {
386   /* Intermediate backtracking */
387   simgrid::mc::State* state = stack_.back().get();
388   if (state->system_state) {
389     simgrid::mc::restore_snapshot(state->system_state);
390     MC_restore_communications_pattern(state);
391     return;
392   }
393
394   /* Restore the initial state */
395   simgrid::mc::session->restoreInitialState();
396
397   unsigned n = MC_smx_get_maxpid();
398   assert(n == xbt_dynar_length(incomplete_communications_pattern));
399   assert(n == xbt_dynar_length(initial_communications_pattern));
400   for (unsigned j=0; j < n ; j++) {
401     xbt_dynar_reset((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, j, xbt_dynar_t));
402     xbt_dynar_get_as(initial_communications_pattern, j, simgrid::mc::PatternCommunicationList*)->index_comm = 0;
403   }
404
405   /* Traverse the stack from the state at position start and re-execute the transitions */
406   for (std::unique_ptr<simgrid::mc::State> const& state : stack_) {
407     if (state == stack_.back())
408       break;
409
410     int req_num = state->transition.argument;
411     smx_simcall_t saved_req = &state->executed_req;
412     xbt_assert(saved_req);
413
414     /* because we got a copy of the executed request, we have to fetch the
415        real one, pointed by the request field of the issuer process */
416
417     const smx_actor_t issuer = MC_smx_simcall_get_issuer(saved_req);
418     smx_simcall_t req = &issuer->simcall;
419
420     /* TODO : handle test and testany simcalls */
421     e_mc_call_type_t call = MC_get_call_type(req);
422     mc_model_checker->handle_simcall(state->transition);
423     MC_handle_comm_pattern(call, req, req_num, nullptr, 1);
424     mc_model_checker->wait_for_requests();
425
426     /* Update statistics */
427     mc_model_checker->visited_states++;
428     mc_model_checker->executed_transitions++;
429   }
430 }
431
432 void CommunicationDeterminismChecker::real_run()
433 {
434   std::unique_ptr<simgrid::mc::VisitedState> visited_state = nullptr;
435   smx_simcall_t req = nullptr;
436
437   while (not stack_.empty()) {
438     /* Get current state */
439     simgrid::mc::State* state = stack_.back().get();
440
441     XBT_DEBUG("**************************************************");
442     XBT_DEBUG("Exploration depth = %zu (state = %d, interleaved processes = %zu)", stack_.size(), state->num,
443               state->interleaveSize());
444
445     /* Update statistics */
446     mc_model_checker->visited_states++;
447
448     if (stack_.size() <= (std::size_t)_sg_mc_max_depth)
449       req = MC_state_get_request(state);
450     else
451       req = nullptr;
452
453     if (req != nullptr && visited_state == nullptr) {
454
455       int req_num = state->transition.argument;
456
457       XBT_DEBUG("Execute: %s", simgrid::mc::request_to_string(req, req_num, simgrid::mc::RequestType::simix).c_str());
458
459       std::string req_str;
460       if (dot_output != nullptr)
461         req_str = simgrid::mc::request_get_dot_output(req, req_num);
462
463       mc_model_checker->executed_transitions++;
464
465       /* TODO : handle test and testany simcalls */
466       e_mc_call_type_t call = MC_CALL_TYPE_NONE;
467       if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
468         call = MC_get_call_type(req);
469
470       /* Answer the request */
471       mc_model_checker->handle_simcall(state->transition);
472       /* After this call req is no longer useful */
473
474       if (not this->initial_communications_pattern_done)
475         MC_handle_comm_pattern(call, req, req_num, initial_communications_pattern, 0);
476       else
477         MC_handle_comm_pattern(call, req, req_num, nullptr, 0);
478
479       /* Wait for requests (schedules processes) */
480       mc_model_checker->wait_for_requests();
481
482       /* Create the new expanded state */
483       std::unique_ptr<simgrid::mc::State> next_state =
484           std::unique_ptr<simgrid::mc::State>(new simgrid::mc::State(++expandedStatesCount_));
485
486       /* If comm determinism verification, we cannot stop the exploration if some communications are not finished (at
487        * least, data are transferred). These communications  are incomplete and they cannot be analyzed and compared
488        * with the initial pattern. */
489       bool compare_snapshots = all_communications_are_finished() && this->initial_communications_pattern_done;
490
491       if (_sg_mc_max_visited_states != 0)
492         visited_state = visitedStates_.addVisitedState(expandedStatesCount_, next_state.get(), compare_snapshots);
493       else
494         visited_state = nullptr;
495
496       if (visited_state == nullptr) {
497
498         /* Get enabled actors and insert them in the interleave set of the next state */
499         for (auto& actor : mc_model_checker->process().actors())
500           if (simgrid::mc::actor_is_enabled(actor.copy.getBuffer()))
501             next_state->addInterleavingSet(actor.copy.getBuffer());
502
503         if (dot_output != nullptr)
504           fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n",
505             state->num,  next_state->num, req_str.c_str());
506
507       } else if (dot_output != nullptr)
508         fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num,
509                 visited_state->original_num == -1 ? visited_state->num : visited_state->original_num, req_str.c_str());
510
511       stack_.push_back(std::move(next_state));
512
513     } else {
514
515       if (stack_.size() > (std::size_t) _sg_mc_max_depth)
516         XBT_WARN("/!\\ Max depth reached! /!\\ ");
517       else if (visited_state != nullptr)
518         XBT_DEBUG("State already visited (equal to state %d), exploration stopped on this path.",
519             visited_state->original_num == -1 ? visited_state->num : visited_state->original_num);
520       else
521         XBT_DEBUG("There are no more processes to interleave. (depth %zu)", stack_.size());
522
523       if (not this->initial_communications_pattern_done)
524         this->initial_communications_pattern_done = 1;
525
526       /* Trash the current state, no longer needed */
527       XBT_DEBUG("Delete state %d at depth %zu", state->num, stack_.size());
528       stack_.pop_back();
529
530       visited_state = nullptr;
531
532       /* Check for deadlocks */
533       if (mc_model_checker->checkDeadlock()) {
534         MC_show_deadlock();
535         throw simgrid::mc::DeadlockError();
536       }
537
538       while (not stack_.empty()) {
539         std::unique_ptr<simgrid::mc::State> state = std::move(stack_.back());
540         stack_.pop_back();
541         if (state->interleaveSize() && stack_.size() < (std::size_t)_sg_mc_max_depth) {
542           /* We found a back-tracking point, let's loop */
543           XBT_DEBUG("Back-tracking to state %d at depth %zu", state->num, stack_.size() + 1);
544           stack_.push_back(std::move(state));
545
546           this->restoreState();
547
548           XBT_DEBUG("Back-tracking to state %d at depth %zu done", stack_.back()->num, stack_.size());
549
550           break;
551         } else {
552           XBT_DEBUG("Delete state %d at depth %zu", state->num, stack_.size() + 1);
553         }
554       }
555     }
556   }
557
558   simgrid::mc::session->logState();
559 }
560
561 void CommunicationDeterminismChecker::run()
562 {
563   XBT_INFO("Check communication determinism");
564   simgrid::mc::session->initialize();
565
566   this->prepare();
567
568   this->real_run();
569 }
570
571 Checker* createCommunicationDeterminismChecker(Session& session)
572 {
573   return new CommunicationDeterminismChecker(session);
574 }
575
576 }
577 }