Logo AND Algorithmique Numérique Distribuée

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