Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use assignment to non-trivial class rather than artificial trivialization and memset
[simgrid.git] / src / mc / mc_comm_pattern.cpp
1 /* Copyright (c) 2007-2019. 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 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_comm_pattern, mc,
14                                 "Logging specific to MC communication patterns");
15
16 static void MC_patterns_copy(std::vector<simgrid::mc::PatternCommunication*>& dest,
17                              std::vector<simgrid::mc::PatternCommunication> const& source)
18 {
19   dest.clear();
20   for (simgrid::mc::PatternCommunication const& comm : source) {
21     simgrid::mc::PatternCommunication* copy_comm = new simgrid::mc::PatternCommunication(comm.dup());
22     dest.push_back(copy_comm);
23   }
24 }
25
26 void MC_restore_communications_pattern(simgrid::mc::State* state)
27 {
28   for (unsigned i = 0; i < initial_communications_pattern.size(); i++)
29     initial_communications_pattern[i].index_comm = state->communication_indices_[i];
30
31   for (unsigned i = 0; i < MC_smx_get_maxpid(); i++)
32     MC_patterns_copy(incomplete_communications_pattern[i], state->incomplete_comm_pattern_[i]);
33 }
34
35 void MC_state_copy_incomplete_communications_pattern(simgrid::mc::State* state)
36 {
37   state->incomplete_comm_pattern_.clear();
38   for (unsigned i=0; i < MC_smx_get_maxpid(); i++) {
39     std::vector<simgrid::mc::PatternCommunication> res;
40     for (auto const& comm : incomplete_communications_pattern[i])
41       res.push_back(comm->dup());
42     state->incomplete_comm_pattern_.push_back(std::move(res));
43   }
44 }
45
46 void MC_state_copy_index_communications_pattern(simgrid::mc::State* state)
47 {
48   state->communication_indices_.clear();
49   for (auto const& list_process_comm : initial_communications_pattern)
50     state->communication_indices_.push_back(list_process_comm.index_comm);
51 }
52
53 void MC_handle_comm_pattern(e_mc_call_type_t call_type, smx_simcall_t req, int value, int backtracking)
54 {
55   // HACK, do not rely on the Checker implementation outside of it
56   simgrid::mc::CommunicationDeterminismChecker* checker =
57     (simgrid::mc::CommunicationDeterminismChecker*) mc_model_checker->getChecker();
58
59   switch(call_type) {
60   case MC_CALL_TYPE_NONE:
61     break;
62   case MC_CALL_TYPE_SEND:
63   case MC_CALL_TYPE_RECV:
64     checker->get_comm_pattern(req, call_type, backtracking);
65     break;
66   case MC_CALL_TYPE_WAIT:
67   case MC_CALL_TYPE_WAITANY:
68     {
69     simgrid::mc::RemotePtr<simgrid::kernel::activity::CommImpl> comm_addr{nullptr};
70     if (call_type == MC_CALL_TYPE_WAIT)
71       comm_addr = remote(static_cast<simgrid::kernel::activity::CommImpl*>(simcall_comm_wait__getraw__comm(req)));
72
73     else {
74       simgrid::kernel::activity::ActivityImpl* addr;
75       addr      = mc_model_checker->process().read(remote(simcall_comm_waitany__getraw__comms(req) + value));
76       comm_addr = remote(static_cast<simgrid::kernel::activity::CommImpl*>(addr));
77       }
78       checker->complete_comm_pattern(comm_addr, MC_smx_simcall_get_issuer(req)->get_pid(), backtracking);
79     }
80     break;
81   default:
82     xbt_die("Unexpected call type %i", (int)call_type);
83   }
84
85 }