Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid shadowing outer variables.
[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(smx_simcall_t request, e_mc_call_type_t call_type,
171                                                        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     simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr, unsigned int issuer, int backtracking)
261 {
262   simgrid::mc::PatternCommunication* current_comm_pattern;
263   unsigned int cursor = 0;
264   std::unique_ptr<simgrid::mc::PatternCommunication> comm_pattern;
265   int completed = 0;
266
267   /* Complete comm pattern */
268   xbt_dynar_foreach(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, current_comm_pattern)
269     if (remote(current_comm_pattern->comm_addr) == comm_addr) {
270       update_comm_pattern(current_comm_pattern, comm_addr);
271       completed = 1;
272       simgrid::mc::PatternCommunication* temp;
273       xbt_dynar_remove_at(xbt_dynar_get_as(incomplete_communications_pattern, issuer, xbt_dynar_t), cursor, &temp);
274       comm_pattern = std::unique_ptr<simgrid::mc::PatternCommunication>(temp);
275       XBT_DEBUG("Remove incomplete comm pattern for process %u at cursor %u", issuer, cursor);
276       break;
277     }
278
279   if (not completed)
280     xbt_die("Corresponding communication not found!");
281
282   simgrid::mc::PatternCommunicationList* pattern =
283       xbt_dynar_get_as(initial_communications_pattern, issuer, simgrid::mc::PatternCommunicationList*);
284
285   if (not this->initial_communications_pattern_done)
286     /* Store comm pattern */
287     pattern->list.push_back(std::move(comm_pattern));
288   else {
289     /* Evaluate comm determinism */
290     this->deterministic_comm_pattern(issuer, comm_pattern.get(), backtracking);
291     pattern->index_comm++;
292   }
293 }
294
295 CommunicationDeterminismChecker::CommunicationDeterminismChecker(Session& s) : Checker(s)
296 {
297 }
298
299 CommunicationDeterminismChecker::~CommunicationDeterminismChecker() = default;
300
301 RecordTrace CommunicationDeterminismChecker::getRecordTrace() // override
302 {
303   RecordTrace res;
304   for (auto const& state : stack_)
305     res.push_back(state->getTransition());
306   return res;
307 }
308
309 std::vector<std::string> CommunicationDeterminismChecker::getTextualTrace() // override
310 {
311   std::vector<std::string> trace;
312   for (auto const& state : stack_) {
313     smx_simcall_t req = &state->executed_req;
314     if (req)
315       trace.push_back(
316           simgrid::mc::request_to_string(req, state->transition.argument, simgrid::mc::RequestType::executed));
317   }
318   return trace;
319 }
320
321 void CommunicationDeterminismChecker::logState() // override
322 {
323   if (_sg_mc_comms_determinism && not this->recv_deterministic && this->send_deterministic) {
324     XBT_INFO("******************************************************");
325     XBT_INFO("**** Only-send-deterministic communication pattern ****");
326     XBT_INFO("******************************************************");
327     XBT_INFO("%s", this->recv_diff);
328   } else if (_sg_mc_comms_determinism && not this->send_deterministic && this->recv_deterministic) {
329     XBT_INFO("******************************************************");
330     XBT_INFO("**** Only-recv-deterministic communication pattern ****");
331     XBT_INFO("******************************************************");
332     XBT_INFO("%s", this->send_diff);
333   }
334   XBT_INFO("Expanded states = %lu", expandedStatesCount_);
335   XBT_INFO("Visited states = %lu", mc_model_checker->visited_states);
336   XBT_INFO("Executed transitions = %lu", mc_model_checker->executed_transitions);
337   XBT_INFO("Send-deterministic : %s", not this->send_deterministic ? "No" : "Yes");
338   if (_sg_mc_comms_determinism)
339     XBT_INFO("Recv-deterministic : %s", not this->recv_deterministic ? "No" : "Yes");
340 }
341
342 void CommunicationDeterminismChecker::prepare()
343 {
344   const int maxpid = MC_smx_get_maxpid();
345
346   // Create initial_communications_pattern elements:
347   initial_communications_pattern = simgrid::xbt::newDeleteDynar<simgrid::mc::PatternCommunicationList*>();
348   for (int i = 0; i < maxpid; i++) {
349     simgrid::mc::PatternCommunicationList* process_list_pattern = new simgrid::mc::PatternCommunicationList();
350     xbt_dynar_insert_at(initial_communications_pattern, i, &process_list_pattern);
351   }
352
353   // Create incomplete_communications_pattern elements:
354   incomplete_communications_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
355   for (int i = 0; i < maxpid; i++) {
356     xbt_dynar_t process_pattern = xbt_dynar_new(sizeof(simgrid::mc::PatternCommunication*), nullptr);
357     xbt_dynar_insert_at(incomplete_communications_pattern, i, &process_pattern);
358   }
359
360   std::unique_ptr<simgrid::mc::State> initial_state =
361       std::unique_ptr<simgrid::mc::State>(new simgrid::mc::State(++expandedStatesCount_));
362
363   XBT_DEBUG("********* Start communication determinism verification *********");
364
365   /* Get an enabled actor and insert it in the interleave set of the initial state */
366   for (auto& actor : mc_model_checker->process().actors())
367     if (simgrid::mc::actor_is_enabled(actor.copy.getBuffer()))
368       initial_state->addInterleavingSet(actor.copy.getBuffer());
369
370   stack_.push_back(std::move(initial_state));
371 }
372
373 static inline bool all_communications_are_finished()
374 {
375   for (size_t current_actor = 1; current_actor < MC_smx_get_maxpid(); current_actor++) {
376     xbt_dynar_t pattern = xbt_dynar_get_as(incomplete_communications_pattern, current_actor, xbt_dynar_t);
377     if (not xbt_dynar_is_empty(pattern)) {
378       XBT_DEBUG("Some communications are not finished, cannot stop the exploration! State not visited.");
379       return false;
380     }
381   }
382   return true;
383 }
384
385 void CommunicationDeterminismChecker::restoreState()
386 {
387   /* Intermediate backtracking */
388   simgrid::mc::State* last_state = stack_.back().get();
389   if (last_state->system_state) {
390     simgrid::mc::restore_snapshot(last_state->system_state);
391     MC_restore_communications_pattern(last_state);
392     return;
393   }
394
395   /* Restore the initial state */
396   simgrid::mc::session->restoreInitialState();
397
398   unsigned n = MC_smx_get_maxpid();
399   assert(n == xbt_dynar_length(incomplete_communications_pattern));
400   assert(n == xbt_dynar_length(initial_communications_pattern));
401   for (unsigned j=0; j < n ; j++) {
402     xbt_dynar_reset((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, j, xbt_dynar_t));
403     xbt_dynar_get_as(initial_communications_pattern, j, simgrid::mc::PatternCommunicationList*)->index_comm = 0;
404   }
405
406   /* Traverse the stack from the state at position start and re-execute the transitions */
407   for (std::unique_ptr<simgrid::mc::State> const& state : stack_) {
408     if (state == stack_.back())
409       break;
410
411     int req_num = state->transition.argument;
412     smx_simcall_t saved_req = &state->executed_req;
413     xbt_assert(saved_req);
414
415     /* because we got a copy of the executed request, we have to fetch the
416        real one, pointed by the request field of the issuer process */
417
418     const smx_actor_t issuer = MC_smx_simcall_get_issuer(saved_req);
419     smx_simcall_t req = &issuer->simcall;
420
421     /* TODO : handle test and testany simcalls */
422     e_mc_call_type_t call = MC_get_call_type(req);
423     mc_model_checker->handle_simcall(state->transition);
424     MC_handle_comm_pattern(call, req, req_num, 1);
425     mc_model_checker->wait_for_requests();
426
427     /* Update statistics */
428     mc_model_checker->visited_states++;
429     mc_model_checker->executed_transitions++;
430   }
431 }
432
433 void CommunicationDeterminismChecker::real_run()
434 {
435   std::unique_ptr<simgrid::mc::VisitedState> visited_state = nullptr;
436   smx_simcall_t req = nullptr;
437
438   while (not stack_.empty()) {
439     /* Get current state */
440     simgrid::mc::State* cur_state = stack_.back().get();
441
442     XBT_DEBUG("**************************************************");
443     XBT_DEBUG("Exploration depth = %zu (state = %d, interleaved processes = %zu)", stack_.size(), cur_state->num,
444               cur_state->interleaveSize());
445
446     /* Update statistics */
447     mc_model_checker->visited_states++;
448
449     if (stack_.size() <= (std::size_t)_sg_mc_max_depth)
450       req = MC_state_get_request(cur_state);
451     else
452       req = nullptr;
453
454     if (req != nullptr && visited_state == nullptr) {
455
456       int req_num = cur_state->transition.argument;
457
458       XBT_DEBUG("Execute: %s", simgrid::mc::request_to_string(req, req_num, simgrid::mc::RequestType::simix).c_str());
459
460       std::string req_str;
461       if (dot_output != nullptr)
462         req_str = simgrid::mc::request_get_dot_output(req, req_num);
463
464       mc_model_checker->executed_transitions++;
465
466       /* TODO : handle test and testany simcalls */
467       e_mc_call_type_t call = MC_CALL_TYPE_NONE;
468       if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
469         call = MC_get_call_type(req);
470
471       /* Answer the request */
472       mc_model_checker->handle_simcall(cur_state->transition);
473       /* After this call req is no longer useful */
474
475       MC_handle_comm_pattern(call, req, req_num, 0);
476
477       /* Wait for requests (schedules processes) */
478       mc_model_checker->wait_for_requests();
479
480       /* Create the new expanded state */
481       std::unique_ptr<simgrid::mc::State> next_state =
482           std::unique_ptr<simgrid::mc::State>(new simgrid::mc::State(++expandedStatesCount_));
483
484       /* If comm determinism verification, we cannot stop the exploration if some communications are not finished (at
485        * least, data are transferred). These communications  are incomplete and they cannot be analyzed and compared
486        * with the initial pattern. */
487       bool compare_snapshots = all_communications_are_finished() && this->initial_communications_pattern_done;
488
489       if (_sg_mc_max_visited_states != 0)
490         visited_state = visitedStates_.addVisitedState(expandedStatesCount_, next_state.get(), compare_snapshots);
491       else
492         visited_state = nullptr;
493
494       if (visited_state == nullptr) {
495
496         /* Get enabled actors and insert them in the interleave set of the next state */
497         for (auto& actor : mc_model_checker->process().actors())
498           if (simgrid::mc::actor_is_enabled(actor.copy.getBuffer()))
499             next_state->addInterleavingSet(actor.copy.getBuffer());
500
501         if (dot_output != nullptr)
502           fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", cur_state->num, next_state->num, req_str.c_str());
503
504       } else if (dot_output != nullptr)
505         fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", cur_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", cur_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->real_run();
566 }
567
568 Checker* createCommunicationDeterminismChecker(Session& s)
569 {
570   return new CommunicationDeterminismChecker(s);
571 }
572
573 }
574 }