Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Add more smx_process_t MCer/MCed translations
[simgrid.git] / src / mc / mc_comm_determinism.c
1 /* Copyright (c) 2008-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "mc_state.h"
8 #include "mc_comm_pattern.h"
9 #include "mc_request.h"
10 #include "mc_safety.h"
11 #include "mc_private.h"
12 #include "mc_record.h"
13 #include "mc_smx.h"
14
15 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_determinism, mc,
16                                 "Logging specific to MC communication determinism detection");
17
18 /********** Global variables **********/
19
20 xbt_dynar_t initial_communications_pattern;
21 xbt_dynar_t incomplete_communications_pattern;
22
23 /********** Static functions ***********/
24
25 static void comm_pattern_free(mc_comm_pattern_t p)
26 {
27   xbt_free(p->rdv);
28   xbt_free(p->data);
29   xbt_free(p);
30   p = NULL;
31 }
32
33 static void list_comm_pattern_free(mc_list_comm_pattern_t l)
34 {
35   xbt_dynar_free(&(l->list));
36   xbt_free(l);
37   l = NULL;
38 }
39
40 static e_mc_comm_pattern_difference_t compare_comm_pattern(mc_comm_pattern_t comm1, mc_comm_pattern_t comm2) {
41   if(comm1->type != comm2->type)
42     return TYPE_DIFF;
43   if (strcmp(comm1->rdv, comm2->rdv) != 0)
44     return RDV_DIFF;
45   if (comm1->src_proc != comm2->src_proc)
46     return SRC_PROC_DIFF;
47   if (comm1->dst_proc != comm2->dst_proc)
48     return DST_PROC_DIFF;
49   if (comm1->data_size != comm2->data_size)
50     return DATA_SIZE_DIFF;
51   if(comm1->data == NULL && comm2->data == NULL)
52     return 0;
53   /*if(comm1->data != NULL && comm2->data !=NULL) {
54     if (!memcmp(comm1->data, comm2->data, comm1->data_size))
55       return 0;
56     return DATA_DIFF;
57   }else{
58     return DATA_DIFF;
59   }*/
60   return 0;
61 }
62
63 static void print_determinism_result(e_mc_comm_pattern_difference_t diff, int process, mc_comm_pattern_t comm, unsigned int cursor) {
64   if (_sg_mc_comms_determinism && !initial_global_state->comm_deterministic) {
65     XBT_INFO("****************************************************");
66     XBT_INFO("***** Non-deterministic communications pattern *****");
67     XBT_INFO("****************************************************");
68     XBT_INFO("The communications pattern of the process %d is different!",  process);
69     switch(diff) {
70     case TYPE_DIFF:
71       XBT_INFO("Different communication type for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
72       break;
73     case RDV_DIFF:
74       XBT_INFO("Different communication rdv for communication %s at index %d",  comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
75       break;
76     case SRC_PROC_DIFF:
77         XBT_INFO("Different communication source process for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
78       break;
79     case DST_PROC_DIFF:
80         XBT_INFO("Different communication destination process for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
81       break;
82     case DATA_SIZE_DIFF:
83       XBT_INFO("Different communication data size for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
84       break;
85     case DATA_DIFF:
86       XBT_INFO("Different communication data for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
87       break;
88     default:
89       break;
90     }
91     MC_print_statistics(mc_stats);
92     xbt_abort();
93   } else if (_sg_mc_send_determinism && !initial_global_state->send_deterministic) {
94     XBT_INFO("*********************************************************");
95     XBT_INFO("***** Non-send-deterministic communications pattern *****");
96     XBT_INFO("*********************************************************");
97     XBT_INFO("The communications pattern of the process %d is different!",  process);
98     switch(diff) {
99     case TYPE_DIFF:
100       XBT_INFO("Different communication type for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
101       break;
102     case RDV_DIFF:
103       XBT_INFO("Different communication rdv for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
104       break;
105     case SRC_PROC_DIFF:
106         XBT_INFO("Different communication source process for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
107       break;
108     case DST_PROC_DIFF:
109         XBT_INFO("Different communication destination process for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
110       break;
111     case DATA_SIZE_DIFF:
112       XBT_INFO("Different communication data size for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
113       break;
114     case DATA_DIFF:
115       XBT_INFO("Different communication data for communication %s at index %d", comm->type == SIMIX_COMM_SEND ? "Send" : "Recv", cursor);
116       break;
117     default:
118       break;
119     }
120     MC_print_statistics(mc_stats);
121     xbt_abort();
122   }
123 }
124
125 static void print_communications_pattern()
126 {
127   unsigned int cursor = 0, cursor2 = 0;
128   mc_comm_pattern_t current_comm;
129   mc_list_comm_pattern_t current_list;
130   unsigned int current_process = 1;
131   while (current_process < simix_process_maxpid) {
132     current_list = (mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, current_process, mc_list_comm_pattern_t);
133     XBT_INFO("Communications from the process %u:", current_process);
134     while(cursor2 < current_list->index_comm){
135       current_comm = (mc_comm_pattern_t)xbt_dynar_get_as(current_list->list, cursor2, mc_comm_pattern_t);
136       if (current_comm->type == SIMIX_COMM_SEND) {
137         XBT_INFO("(%u) [(%lu) %s -> (%lu) %s] %s ", cursor,current_comm->src_proc,
138                  current_comm->src_host, current_comm->dst_proc,
139                  current_comm->dst_host, "iSend");
140       } else {
141         XBT_INFO("(%u) [(%lu) %s <- (%lu) %s] %s ", cursor, current_comm->dst_proc,
142                  current_comm->dst_host, current_comm->src_proc,
143                  current_comm->src_host, "iRecv");
144       }
145       cursor2++;
146     }
147     current_process++;
148     cursor = 0;
149     cursor2 = 0;
150   }
151 }
152
153 static void print_incomplete_communications_pattern(){
154   unsigned int cursor = 0;
155   unsigned int current_process = 1;
156   xbt_dynar_t current_pattern;
157   mc_comm_pattern_t comm;
158   while (current_process < simix_process_maxpid) {
159     current_pattern = (xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, current_process, xbt_dynar_t);
160     XBT_INFO("Incomplete communications from the process %u:", current_process);
161     xbt_dynar_foreach(current_pattern, cursor, comm) {
162       XBT_DEBUG("(%u) Communication %p", cursor, comm);
163     }
164     current_process++;
165     cursor = 0;
166   }
167 }
168
169 // FIXME, remote comm
170 static void update_comm_pattern(mc_comm_pattern_t comm_pattern, smx_synchro_t comm)
171 {
172   mc_process_t process = &mc_model_checker->process;
173   void *addr_pointed;
174   smx_process_t src_proc = MC_smx_resolve_process(comm->comm.src_proc);
175   smx_process_t dst_proc = MC_smx_resolve_process(comm->comm.dst_proc);
176   comm_pattern->src_proc = src_proc->pid;
177   comm_pattern->dst_proc = dst_proc->pid;
178   // TODO, resolve host name
179   comm_pattern->src_host = MC_smx_process_get_host_name(src_proc);
180   comm_pattern->dst_host = MC_smx_process_get_host_name(dst_proc);
181   if (comm_pattern->data_size == -1 && comm->comm.src_buff != NULL) {
182     comm_pattern->data_size = *(comm->comm.dst_buff_size);
183     comm_pattern->data = xbt_malloc0(comm_pattern->data_size);
184     addr_pointed = *(void **) comm->comm.src_buff;
185     if (addr_pointed > (void*) process->heap_address
186         && addr_pointed < MC_process_get_heap(process)->breakval)
187       memcpy(comm_pattern->data, addr_pointed, comm_pattern->data_size);
188     else
189       memcpy(comm_pattern->data, comm->comm.src_buff, comm_pattern->data_size);
190   }
191 }
192
193 static void deterministic_comm_pattern(int process, mc_comm_pattern_t comm, int backtracking) {
194
195   mc_list_comm_pattern_t list_comm_pattern = (mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, process, mc_list_comm_pattern_t);
196
197   if(!backtracking){
198     mc_comm_pattern_t initial_comm = xbt_dynar_get_as(list_comm_pattern->list, comm->index, mc_comm_pattern_t);
199     e_mc_comm_pattern_difference_t diff;
200     
201     if((diff = compare_comm_pattern(initial_comm, comm)) != NONE_DIFF){
202       if (comm->type == SIMIX_COMM_SEND)
203         initial_global_state->send_deterministic = 0;
204       initial_global_state->comm_deterministic = 0;
205       print_determinism_result(diff, process, comm, list_comm_pattern->index_comm + 1);
206     }
207   }
208     
209   list_comm_pattern->index_comm++;
210   comm_pattern_free(comm);
211
212 }
213
214 /********** Non Static functions ***********/
215
216 void comm_pattern_free_voidp(void *p) {
217   comm_pattern_free((mc_comm_pattern_t) * (void **) p);
218 }
219
220 void list_comm_pattern_free_voidp(void *p) {
221   list_comm_pattern_free((mc_list_comm_pattern_t) * (void **) p);
222 }
223
224 void get_comm_pattern(const xbt_dynar_t list, const smx_simcall_t request, const e_mc_call_type_t call_type)
225 {
226   mc_process_t process = &mc_model_checker->process;
227   mc_comm_pattern_t pattern = NULL;
228   pattern = xbt_new0(s_mc_comm_pattern_t, 1);
229   pattern->data_size = -1;
230   pattern->data = NULL;
231
232   const smx_process_t issuer = MC_smx_simcall_get_issuer(request);
233   mc_list_comm_pattern_t initial_pattern =
234     (mc_list_comm_pattern_t) xbt_dynar_get_as(initial_communications_pattern, issuer->pid, mc_list_comm_pattern_t);
235   xbt_dynar_t incomplete_pattern =
236     (xbt_dynar_t) xbt_dynar_get_as(incomplete_communications_pattern, issuer->pid, xbt_dynar_t);
237   pattern->index =
238     initial_pattern->index_comm + xbt_dynar_length(incomplete_pattern);
239   
240   void *addr_pointed;
241   
242   if (call_type == MC_CALL_TYPE_SEND) {
243     /* Create comm pattern */
244     pattern->type = SIMIX_COMM_SEND;
245     pattern->comm = simcall_comm_isend__get__result(request);
246     // FIXME, remote access to rdv->name
247     pattern->rdv = (pattern->comm->comm.rdv != NULL) ? strdup(pattern->comm->comm.rdv->name) : strdup(pattern->comm->comm.rdv_cpy->name);
248     pattern->src_proc = MC_smx_resolve_process(pattern->comm->comm.src_proc)->pid;
249     pattern->src_host = MC_smx_process_get_host_name(issuer);
250     if(pattern->comm->comm.src_buff != NULL){
251       pattern->data_size = pattern->comm->comm.src_buff_size;
252       pattern->data = xbt_malloc0(pattern->data_size);
253       addr_pointed = *(void **) pattern->comm->comm.src_buff;
254       if (addr_pointed > (void*) process->heap_address
255           && addr_pointed < MC_process_get_heap(process)->breakval)
256         memcpy(pattern->data, addr_pointed, pattern->data_size);
257       else
258         memcpy(pattern->data, pattern->comm->comm.src_buff, pattern->data_size);
259     }
260   } else if (call_type == MC_CALL_TYPE_RECV) {                      
261     pattern->type = SIMIX_COMM_RECEIVE;
262     pattern->comm = simcall_comm_irecv__get__result(request);
263     // TODO, remote access
264     pattern->rdv = (pattern->comm->comm.rdv != NULL) ? strdup(pattern->comm->comm.rdv->name) : strdup(pattern->comm->comm.rdv_cpy->name);
265     pattern->dst_proc = MC_smx_resolve_process(pattern->comm->comm.dst_proc)->pid;
266     // FIXME, remote process access
267     pattern->dst_host = MC_smx_process_get_host_name(issuer);
268   } else {
269     xbt_die("Unexpected call_type %i", (int) call_type);
270   }
271
272   xbt_dynar_push((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, issuer->pid, xbt_dynar_t), &pattern);
273
274   XBT_DEBUG("Insert incomplete comm pattern %p for process %lu", pattern, issuer->pid);
275 }
276
277 void complete_comm_pattern(xbt_dynar_t list, smx_synchro_t comm, int backtracking) {
278   mc_comm_pattern_t current_comm_pattern;
279   unsigned int cursor = 0;
280
281   smx_process_t src_proc = MC_smx_resolve_process(comm->comm.src_proc);
282   smx_process_t dst_proc = MC_smx_resolve_process(comm->comm.dst_proc);
283   unsigned int src = src_proc->pid;
284   unsigned int dst = dst_proc->pid;
285
286   mc_comm_pattern_t src_comm_pattern;
287   mc_comm_pattern_t dst_comm_pattern;
288   int src_completed = 0, dst_completed = 0;
289
290   /* Complete comm pattern */
291   xbt_dynar_foreach((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, src, xbt_dynar_t), cursor, current_comm_pattern) {
292     if (current_comm_pattern-> comm == comm) {
293       update_comm_pattern(current_comm_pattern, comm);
294       src_completed = 1;
295       xbt_dynar_remove_at((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, src, xbt_dynar_t), cursor, &src_comm_pattern);
296       XBT_DEBUG("Remove incomplete comm pattern for process %u at cursor %u", src, cursor);
297       break;
298     }
299   }
300   if(!src_completed)
301     xbt_die("Corresponding communication for the source process not found!");
302
303   cursor = 0;
304
305   xbt_dynar_foreach((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, dst, xbt_dynar_t), cursor, current_comm_pattern) {
306     if (current_comm_pattern-> comm == comm) {
307       update_comm_pattern(current_comm_pattern, comm);
308       dst_completed = 1;
309       xbt_dynar_remove_at((xbt_dynar_t)xbt_dynar_get_as(incomplete_communications_pattern, dst, xbt_dynar_t), cursor, &dst_comm_pattern);
310       XBT_DEBUG("Remove incomplete comm pattern for process %u at cursor %u", dst, cursor);
311       break;
312     }
313   }
314   if(!dst_completed)
315     xbt_die("Corresponding communication for the destination process not found!");
316   
317   if (!initial_global_state->initial_communications_pattern_done) {
318     /* Store comm pattern */
319     if(src_comm_pattern->index < xbt_dynar_length(((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, src, mc_list_comm_pattern_t))->list)){
320       xbt_dynar_set(((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, src, mc_list_comm_pattern_t))->list, src_comm_pattern->index, &src_comm_pattern);
321       ((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, src, mc_list_comm_pattern_t))->list->used++;
322     } else {
323       xbt_dynar_insert_at(((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, src, mc_list_comm_pattern_t))->list, src_comm_pattern->index, &src_comm_pattern);
324     }
325     
326     if(dst_comm_pattern->index < xbt_dynar_length(((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, dst, mc_list_comm_pattern_t))->list)) {
327       xbt_dynar_set(((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, dst, mc_list_comm_pattern_t))->list, dst_comm_pattern->index, &dst_comm_pattern);
328       ((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, dst, mc_list_comm_pattern_t))->list->used++;
329     } else {
330       xbt_dynar_insert_at(((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, dst, mc_list_comm_pattern_t))->list, dst_comm_pattern->index, &dst_comm_pattern);
331     }
332     ((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, src, mc_list_comm_pattern_t))->index_comm++;
333     ((mc_list_comm_pattern_t)xbt_dynar_get_as(initial_communications_pattern, dst, mc_list_comm_pattern_t))->index_comm++;
334   } else {
335     /* Evaluate comm determinism */
336     deterministic_comm_pattern(src, src_comm_pattern, backtracking);
337     deterministic_comm_pattern(dst, dst_comm_pattern, backtracking);
338   }
339 }
340
341 /************************ Main algorithm ************************/
342
343 void MC_pre_modelcheck_comm_determinism(void)
344 {
345   MC_SET_MC_HEAP;
346
347   mc_state_t initial_state = NULL;
348   smx_process_t process;
349   int i;
350
351   if (_sg_mc_visited > 0)
352     visited_states = xbt_dynar_new(sizeof(mc_visited_state_t), visited_state_free_voidp);
353  
354   initial_communications_pattern = xbt_dynar_new(sizeof(mc_list_comm_pattern_t), list_comm_pattern_free_voidp);
355   for (i=0; i<simix_process_maxpid; i++){
356     mc_list_comm_pattern_t process_list_pattern = xbt_new0(s_mc_list_comm_pattern_t, 1);
357     process_list_pattern->list = xbt_dynar_new(sizeof(mc_comm_pattern_t), comm_pattern_free_voidp);
358     process_list_pattern->index_comm = 0;
359     xbt_dynar_insert_at(initial_communications_pattern, i, &process_list_pattern);
360   }
361   incomplete_communications_pattern = xbt_dynar_new(sizeof(xbt_dynar_t), xbt_dynar_free_voidp);
362   for (i=0; i<simix_process_maxpid; i++){
363     xbt_dynar_t process_pattern = xbt_dynar_new(sizeof(mc_comm_pattern_t), NULL);
364     xbt_dynar_insert_at(incomplete_communications_pattern, i, &process_pattern);
365   }
366
367   initial_state = MC_state_new();
368   MC_SET_STD_HEAP;
369   
370   XBT_DEBUG("********* Start communication determinism verification *********");
371
372   /* Wait for requests (schedules processes) */
373   MC_wait_for_requests();
374
375   MC_SET_MC_HEAP;
376
377   /* Get an enabled process and insert it in the interleave set of the initial state */
378   MC_EACH_SIMIX_PROCESS(process,
379     if (MC_process_is_enabled(process)) {
380       MC_state_interleave_process(initial_state, process);
381     }
382   );
383
384   xbt_fifo_unshift(mc_stack, initial_state);
385
386   MC_SET_STD_HEAP;
387
388 }
389
390 void MC_modelcheck_comm_determinism(void)
391 {
392
393   char *req_str = NULL;
394   int value;
395   mc_visited_state_t visited_state = NULL;
396   smx_simcall_t req = NULL;
397   smx_process_t process = NULL;
398   mc_state_t state = NULL, next_state = NULL;
399
400   while (xbt_fifo_size(mc_stack) > 0) {
401
402     /* Get current state */
403     state = (mc_state_t) xbt_fifo_get_item_content(xbt_fifo_get_first_item(mc_stack));
404
405     XBT_DEBUG("**************************************************");
406     XBT_DEBUG("Exploration depth = %d (state = %d, interleaved processes = %d)",
407               xbt_fifo_size(mc_stack), state->num,
408               MC_state_interleave_size(state));
409
410     /* Update statistics */
411     mc_stats->visited_states++;
412
413     if ((xbt_fifo_size(mc_stack) <= _sg_mc_max_depth)
414         && (req = MC_state_get_request(state, &value))
415         && (visited_state == NULL)) {
416
417       req_str = MC_request_to_string(req, value);  
418       XBT_DEBUG("Execute: %s", req_str);                 
419       xbt_free(req_str);
420       
421       if (dot_output != NULL) {
422         MC_SET_MC_HEAP;
423         req_str = MC_request_get_dot_output(req, value);
424         MC_SET_STD_HEAP;
425       }
426
427       MC_state_set_executed_request(state, req, value);
428       mc_stats->executed_transitions++;
429
430       /* TODO : handle test and testany simcalls */
431       e_mc_call_type_t call = MC_CALL_TYPE_NONE;
432       if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
433         call = mc_get_call_type(req);
434       }
435
436       /* Answer the request */
437       MC_simcall_handle(req, value);    /* After this call req is no longer useful */
438
439       MC_SET_MC_HEAP;
440       if(!initial_global_state->initial_communications_pattern_done)
441         handle_comm_pattern(call, req, value, initial_communications_pattern, 0);
442       else
443         handle_comm_pattern(call, req, value, NULL, 0);
444       MC_SET_STD_HEAP;
445
446       /* Wait for requests (schedules processes) */
447       MC_wait_for_requests();
448
449       /* Create the new expanded state */
450       MC_SET_MC_HEAP;
451
452       next_state = MC_state_new();
453
454       if ((visited_state = is_visited_state(next_state)) == NULL) {
455
456         /* Get enabled processes and insert them in the interleave set of the next state */
457         MC_EACH_SIMIX_PROCESS(process,
458           if (MC_process_is_enabled(process)) {
459             MC_state_interleave_process(next_state, process);
460           }
461         );
462
463         if (dot_output != NULL)
464           fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num,  next_state->num, req_str);
465
466       } else {
467
468         if (dot_output != NULL)
469           fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", state->num, visited_state->other_num == -1 ? visited_state->num : visited_state->other_num, req_str);
470
471       }
472
473       xbt_fifo_unshift(mc_stack, next_state);
474
475       if (dot_output != NULL)
476         xbt_free(req_str);
477
478       MC_SET_STD_HEAP;
479
480     } else {
481
482       if (xbt_fifo_size(mc_stack) > _sg_mc_max_depth) {
483         XBT_WARN("/!\\ Max depth reached ! /!\\ ");
484       } else if (visited_state != NULL) {
485         XBT_DEBUG("State already visited (equal to state %d), exploration stopped on this path.", visited_state->other_num == -1 ? visited_state->num : visited_state->other_num);
486       } else {
487         XBT_DEBUG("There are no more processes to interleave. (depth %d)", xbt_fifo_size(mc_stack));
488       }
489
490       MC_SET_MC_HEAP;
491
492       if (!initial_global_state->initial_communications_pattern_done) 
493         initial_global_state->initial_communications_pattern_done = 1;
494
495       /* Trash the current state, no longer needed */
496       xbt_fifo_shift(mc_stack);
497       MC_state_delete(state, !state->in_visited_states ? 1 : 0);
498       XBT_DEBUG("Delete state %d at depth %d", state->num, xbt_fifo_size(mc_stack) + 1);
499
500       MC_SET_STD_HEAP;
501
502       visited_state = NULL;
503
504       /* Check for deadlocks */
505       if (MC_deadlock_check()) {
506         MC_show_deadlock(NULL);
507         return;
508       }
509
510       MC_SET_MC_HEAP;
511
512       while ((state = xbt_fifo_shift(mc_stack)) != NULL) {
513         if (MC_state_interleave_size(state) && xbt_fifo_size(mc_stack) < _sg_mc_max_depth) {
514           /* We found a back-tracking point, let's loop */
515           XBT_DEBUG("Back-tracking to state %d at depth %d", state->num, xbt_fifo_size(mc_stack) + 1);
516           xbt_fifo_unshift(mc_stack, state);
517           MC_SET_STD_HEAP;
518
519           MC_replay(mc_stack);
520
521           XBT_DEBUG("Back-tracking to state %d at depth %d done", state->num, xbt_fifo_size(mc_stack));
522
523           break;
524         } else {
525           XBT_DEBUG("Delete state %d at depth %d", state->num, xbt_fifo_size(mc_stack) + 1);
526           MC_state_delete(state, !state->in_visited_states ? 1 : 0);
527         }
528       }
529
530       MC_SET_STD_HEAP;
531     }
532   }
533
534   MC_print_statistics(mc_stats);
535   MC_SET_STD_HEAP;
536
537   return;
538 }