Logo AND Algorithmique Numérique Distribuée

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