1 /* Copyright (c) 2008-2022. The SimGrid Team. All rights reserved. */
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. */
6 #include "src/mc/mc_state.hpp"
7 #include "src/mc/Session.hpp"
8 #include "src/mc/api.hpp"
9 #include "src/mc/mc_config.hpp"
11 #include <boost/range/algorithm.hpp>
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_state, mc, "Logging specific to MC states");
15 using simgrid::mc::remote;
16 using api = simgrid::mc::Api;
21 State::State(unsigned long state_number) : num_(state_number)
23 const unsigned long maxpid = api::get().get_maxpid();
24 actor_states_.resize(maxpid);
25 /* Stateful model checking */
26 if ((_sg_mc_checkpoint > 0 && (state_number % _sg_mc_checkpoint == 0)) || _sg_mc_termination) {
27 auto snapshot_ptr = api::get().take_snapshot(num_);
28 system_state_ = std::shared_ptr<simgrid::mc::Snapshot>(snapshot_ptr);
29 if (_sg_mc_comms_determinism || _sg_mc_send_determinism) {
30 copy_incomplete_comm_pattern();
31 copy_index_comm_pattern();
36 std::size_t State::count_todo() const
38 return boost::range::count_if(this->actor_states_, [](simgrid::mc::ActorState const& a) { return a.is_todo(); });
41 Transition State::get_transition() const
43 return this->transition_;
46 int State::next_transition() const
48 std::vector<ActorInformation>& actors = mc_model_checker->get_remote_process().actors();
49 XBT_DEBUG("Search for an actor to run. %zu actors to consider", actors.size());
50 for (unsigned int i = 0; i < actors.size(); i++) {
51 aid_t aid = actors[i].copy.get_buffer()->get_pid();
52 const ActorState* actor_state = &actor_states_[aid];
54 /* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application*/
55 if (not actor_state->is_todo() || not simgrid::mc::session_singleton->actor_is_enabled(aid))
63 void State::copy_incomplete_comm_pattern()
65 incomplete_comm_pattern_.clear();
66 const unsigned long maxpid = api::get().get_maxpid();
67 for (unsigned long i = 0; i < maxpid; i++) {
68 std::vector<simgrid::mc::PatternCommunication> res;
69 for (auto const& comm : incomplete_communications_pattern[i])
70 res.push_back(comm->dup());
71 incomplete_comm_pattern_.push_back(std::move(res));
75 void State::copy_index_comm_pattern()
77 communication_indices_.clear();
78 for (auto const& list_process_comm : initial_communications_pattern)
79 this->communication_indices_.push_back(list_process_comm.index_comm);