Logo AND Algorithmique Numérique Distribuée

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