Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'dev-get-hostname-faster' into 'master'
[simgrid.git] / src / mc / api / 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/api/State.hpp"
7 #include "src/mc/api.hpp"
8 #include "src/mc/mc_config.hpp"
9
10 #include <boost/range/algorithm.hpp>
11
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_state, mc, "Logging specific to MC states");
13
14 namespace simgrid::mc {
15
16 long State::expended_states_ = 0;
17
18 State::State() : num_(++expended_states_)
19 {
20   const unsigned long maxpid = Api::get().get_maxpid();
21   actor_states_.resize(maxpid);
22   transition_.reset(new Transition());
23   /* Stateful model checking */
24   if ((_sg_mc_checkpoint > 0 && (num_ % _sg_mc_checkpoint == 0)) || _sg_mc_termination) {
25     auto snapshot_ptr = Api::get().take_snapshot(num_);
26     system_state_     = std::shared_ptr<simgrid::mc::Snapshot>(snapshot_ptr);
27   }
28 }
29
30 std::size_t State::count_todo() const
31 {
32   return boost::range::count_if(this->actor_states_, [](simgrid::mc::ActorState const& a) { return a.is_todo(); });
33 }
34
35 Transition* State::get_transition() const
36 {
37   return transition_.get();
38 }
39
40 int State::next_transition() const
41 {
42   std::vector<ActorInformation>& actors = mc_model_checker->get_remote_process().actors();
43   XBT_DEBUG("Search for an actor to run. %zu actors to consider", actors.size());
44   for (unsigned int i = 0; i < actors.size(); i++) {
45     /* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application*/
46     if (aid_t aid = actors[i].copy.get_buffer()->get_pid();
47         not actor_states_[aid].is_todo() || not Api::get().get_session().actor_is_enabled(aid))
48       continue;
49
50     return i;
51   }
52   return -1;
53 }
54 void State::execute_next(int next)
55 {
56   std::vector<ActorInformation>& actors = mc_model_checker->get_remote_process().actors();
57   const kernel::actor::ActorImpl* actor = actors[next].copy.get_buffer();
58   const aid_t aid                       = actor->get_pid();
59
60   /* This actor is ready to be executed. Prepare its execution when simcall_handle will be called on it */
61   const unsigned times_considered = actor_states_[aid].do_consider(actor->simcall_.mc_max_consider_);
62
63   XBT_DEBUG("Let's run actor %ld (times_considered = %u)", aid, times_considered);
64
65   Transition::executed_transitions_++;
66
67   transition_.reset(mc_model_checker->handle_simcall(aid, times_considered, true));
68   mc_model_checker->wait_for_requests();
69 }
70 } // namespace simgrid::mc