Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7dd9704a95e51e297e80e5e80ddf3bd5cec43f01
[simgrid.git] / src / mc / mc_comm_pattern.cpp
1 /* Copyright (c) 2007-2020. 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 "src/mc/checker/CommunicationDeterminismChecker.hpp"
9 #include "src/mc/mc_smx.hpp"
10
11 using simgrid::mc::remote;
12
13 static void MC_patterns_copy(std::vector<simgrid::mc::PatternCommunication*>& dest,
14                              std::vector<simgrid::mc::PatternCommunication> const& source)
15 {
16   dest.clear();
17   for (simgrid::mc::PatternCommunication const& comm : source) {
18     auto* copy_comm = new simgrid::mc::PatternCommunication(comm.dup());
19     dest.push_back(copy_comm);
20   }
21 }
22
23 void MC_restore_communications_pattern(simgrid::mc::State* state)
24 {
25   for (unsigned i = 0; i < initial_communications_pattern.size(); i++)
26     initial_communications_pattern[i].index_comm = state->communication_indices_[i];
27
28   for (unsigned i = 0; i < MC_smx_get_maxpid(); i++)
29     MC_patterns_copy(incomplete_communications_pattern[i], state->incomplete_comm_pattern_[i]);
30 }
31
32 void MC_handle_comm_pattern(simgrid::mc::CallType call_type, smx_simcall_t req, int value, int backtracking)
33 {
34   // HACK, do not rely on the Checker implementation outside of it
35   auto* checker = static_cast<simgrid::mc::CommunicationDeterminismChecker*>(mc_model_checker->getChecker());
36
37   using simgrid::mc::CallType;
38   switch(call_type) {
39     case CallType::NONE:
40       break;
41     case CallType::SEND:
42     case CallType::RECV:
43       checker->get_comm_pattern(req, call_type, backtracking);
44       break;
45     case CallType::WAIT:
46     case CallType::WAITANY: {
47       simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr{nullptr};
48       if (call_type == CallType::WAIT)
49         comm_addr = remote(simcall_comm_wait__getraw__comm(req));
50
51       else {
52         simgrid::kernel::activity::ActivityImpl* addr;
53         addr = mc_model_checker->get_remote_simulation().read(remote(simcall_comm_waitany__getraw__comms(req) + value));
54         comm_addr = remote(static_cast<simgrid::kernel::activity::CommImpl*>(addr));
55       }
56       checker->complete_comm_pattern(comm_addr, MC_smx_simcall_get_issuer(req)->get_pid(), backtracking);
57     } break;
58   default:
59     xbt_die("Unexpected call type %i", (int)call_type);
60   }
61 }