Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move initial state into Session
[simgrid.git] / src / mc / mc_comm_pattern.cpp
1 /* Copyright (c) 2007-2015. 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 <string.h>
8
9 #include <xbt/sysdep.h>
10 #include <xbt/dynar.h>
11 #include <xbt/dynar.hpp>
12
13 #include "src/mc/mc_comm_pattern.h"
14 #include "src/mc/mc_smx.h"
15 #include "src/mc/mc_xbt.hpp"
16
17 using simgrid::mc::remote;
18
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_pattern, mc,
20                                 "Logging specific to MC communication patterns");
21
22 static void MC_patterns_copy(xbt_dynar_t dest,
23   std::vector<simgrid::mc::PatternCommunication> const& source)
24 {
25   xbt_dynar_reset(dest);
26   for (simgrid::mc::PatternCommunication const& comm : source) {
27     simgrid::mc::PatternCommunication* copy_comm = new simgrid::mc::PatternCommunication(comm.dup());
28     xbt_dynar_push(dest, &copy_comm);
29   }
30 }
31
32 void MC_restore_communications_pattern(simgrid::mc::State* state)
33 {
34   simgrid::mc::PatternCommunicationList* list_process_comm;
35   unsigned int cursor;
36
37   xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
38     list_process_comm->index_comm = state->communicationIndices[cursor];
39
40   for (unsigned i = 0; i < MC_smx_get_maxpid(); i++)
41     MC_patterns_copy(
42       xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t),
43       state->incomplete_comm_pattern[i]
44     );
45 }
46
47 void MC_state_copy_incomplete_communications_pattern(simgrid::mc::State* state)
48 {
49   state->incomplete_comm_pattern.clear();
50   for (unsigned i=0; i < MC_smx_get_maxpid(); i++) {
51     xbt_dynar_t patterns = xbt_dynar_get_as(incomplete_communications_pattern, i, xbt_dynar_t);
52     std::vector<simgrid::mc::PatternCommunication> res;
53     simgrid::mc::PatternCommunication* comm;
54     unsigned int cursor;
55     xbt_dynar_foreach(patterns, cursor, comm)
56       res.push_back(comm->dup());
57     state->incomplete_comm_pattern.push_back(std::move(res));
58   }
59 }
60
61 void MC_state_copy_index_communications_pattern(simgrid::mc::State* state)
62 {
63   state->communicationIndices.clear();
64   simgrid::mc::PatternCommunicationList* list_process_comm;
65   unsigned int cursor;
66   xbt_dynar_foreach(initial_communications_pattern, cursor, list_process_comm)
67     state->communicationIndices.push_back(list_process_comm->index_comm);
68 }
69
70 void MC_handle_comm_pattern(
71   e_mc_call_type_t call_type, smx_simcall_t req,
72   int value, xbt_dynar_t pattern, int backtracking)
73 {
74
75   switch(call_type) {
76   case MC_CALL_TYPE_NONE:
77     break;
78   case MC_CALL_TYPE_SEND:
79   case MC_CALL_TYPE_RECV:
80     MC_get_comm_pattern(pattern, req, call_type, backtracking);
81     break;
82   case MC_CALL_TYPE_WAIT:
83   case MC_CALL_TYPE_WAITANY:
84     {
85       smx_synchro_t comm_addr = nullptr;
86       if (call_type == MC_CALL_TYPE_WAIT)
87         comm_addr = simcall_comm_wait__get__comm(req);
88       else
89         // comm_addr = REMOTE(xbt_dynar_get_as(simcall_comm_waitany__get__comms(req), value, smx_synchro_t)):
90         simgrid::mc::read_element(mc_model_checker->process(), &comm_addr,
91           remote(simcall_comm_waitany__get__comms(req)), value, sizeof(comm_addr));
92       MC_complete_comm_pattern(pattern, comm_addr,
93         MC_smx_simcall_get_issuer(req)->pid, backtracking);
94     }
95     break;
96   default:
97     xbt_die("Unexpected call type %i", (int)call_type);
98   }
99
100 }