Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / src / mc / mc_state.cpp
1 /* Copyright (c) 2008-2022. 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 "src/mc/mc_state.hpp"
7 #include "src/mc/mc_config.hpp"
8 #include "src/mc/api.hpp"
9
10 #include <boost/range/algorithm.hpp>
11
12 using simgrid::mc::remote;
13 using api = simgrid::mc::Api;
14
15 namespace simgrid {
16 namespace mc {
17
18 State::State(unsigned long state_number) : num_(state_number)
19 {
20   const unsigned long maxpid = api::get().get_maxpid();
21   actor_states_.resize(maxpid);
22   /* Stateful model checking */
23   if ((_sg_mc_checkpoint > 0 && (state_number % _sg_mc_checkpoint == 0)) || _sg_mc_termination) {
24     auto snapshot_ptr = api::get().take_snapshot(num_);
25     system_state_ = std::shared_ptr<simgrid::mc::Snapshot>(snapshot_ptr);
26     if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
27       copy_incomplete_comm_pattern();
28       copy_index_comm_pattern();
29     }
30   }
31 }
32
33 std::size_t State::count_todo() const
34 {
35   return boost::range::count_if(this->actor_states_, [](simgrid::mc::ActorState const& a) { return a.is_todo(); });
36 }
37
38 Transition State::get_transition() const
39 {
40   return this->transition_;
41 }
42
43 void State::copy_incomplete_comm_pattern()
44 {
45   incomplete_comm_pattern_.clear();
46   const unsigned long maxpid = api::get().get_maxpid();
47   for (unsigned long i = 0; i < maxpid; i++) {
48     std::vector<simgrid::mc::PatternCommunication> res;
49     for (auto const& comm : incomplete_communications_pattern[i])
50       res.push_back(comm->dup());
51     incomplete_comm_pattern_.push_back(std::move(res));
52   }
53 }
54
55 void State::copy_index_comm_pattern()
56 {
57   communication_indices_.clear();
58   for (auto const& list_process_comm : initial_communications_pattern)
59     this->communication_indices_.push_back(list_process_comm.index_comm);
60 }
61
62 }
63 }