From: mlaurent Date: Sat, 18 Mar 2023 13:05:13 +0000 (+0100) Subject: BasicGuide handle next_transition if asked to X-Git-Tag: v3.34~240^2~20 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/39a55a31e73d079c92a37793c58453f219c341aa BasicGuide handle next_transition if asked to --- diff --git a/src/mc/api/State.cpp b/src/mc/api/State.cpp index ba6c78784d..008a8443a4 100644 --- a/src/mc/api/State.cpp +++ b/src/mc/api/State.cpp @@ -78,7 +78,6 @@ Transition* State::get_transition() const return transition_; } -// This should be intierely done in GuidedState aid_t State::next_transition() const { XBT_DEBUG("Search for an actor to run. %zu actors to consider", guide->actors_to_run_.size()); @@ -103,6 +102,11 @@ aid_t State::next_transition() const return -1; } +std::pair State::next_transition_guided() const +{ + return guide->next_transition(); +} + // This should be done in GuidedState, or at least interact with it void State::execute_next(aid_t next, RemoteApp& app) { diff --git a/src/mc/api/State.hpp b/src/mc/api/State.hpp index a9dd2c43d0..5415ac809a 100644 --- a/src/mc/api/State.hpp +++ b/src/mc/api/State.hpp @@ -55,6 +55,9 @@ public: explicit State(RemoteApp& remote_app, const State* parent_state); /* Returns a positive number if there is another transition to pick, or -1 if not */ aid_t next_transition() const; + /* Same as next_transition, but choice is now guided, and a double corresponding to the + internal cost of the transition is returned */ + std::pair next_transition_guided() const; /* Explore a new path on the remote app; the parameter 'next' must be the result of a previous call to * next_transition() */ diff --git a/src/mc/api/guide/BasicGuide.hpp b/src/mc/api/guide/BasicGuide.hpp index 631db3360b..4fcd9f61ae 100644 --- a/src/mc/api/guide/BasicGuide.hpp +++ b/src/mc/api/guide/BasicGuide.hpp @@ -12,8 +12,20 @@ namespace simgrid::mc { // Not Yet fully implemented class BasicGuide : public GuidedState { public: - std::pair next_transition() const override { return std::make_pair(0, 0); } - virtual void execute_next(aid_t aid) override { return; } + std::pair next_transition() const override + { + + for (auto const& [aid, actor] : actors_to_run_) { + /* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application */ + if (not actor.is_todo() || not actor.is_enabled() || actor.is_done()) { + continue; + } + + return std::make_pair(aid, 1.0); + } + return std::make_pair(-1, 0.0); + } + void execute_next(aid_t aid, RemoteApp& app) override { return; } }; } // namespace simgrid::mc diff --git a/src/mc/api/guide/GuidedState.hpp b/src/mc/api/guide/GuidedState.hpp index 81dc19bd74..6eb3a96afa 100644 --- a/src/mc/api/guide/GuidedState.hpp +++ b/src/mc/api/guide/GuidedState.hpp @@ -9,13 +9,14 @@ namespace simgrid::mc { class GuidedState { +protected: /** State's exploration status by actor. Not all the actors are there, only the ones that are ready-to-run in this * state */ std::map actors_to_run_; public: virtual std::pair next_transition() const = 0; - virtual void execute_next(aid_t aid) = 0; + virtual void execute_next(aid_t aid, RemoteApp& app) = 0; friend class State; }; diff --git a/src/mc/explo/DFSExplorer.cpp b/src/mc/explo/DFSExplorer.cpp index 84753958e4..ad1bd08250 100644 --- a/src/mc/explo/DFSExplorer.cpp +++ b/src/mc/explo/DFSExplorer.cpp @@ -128,19 +128,19 @@ void DFSExplorer::run() } // Search for the next transition - aid_t next = state->next_transition(); + // next_transition returns a pair in case we want to consider multiple state + auto [next, _] = state->next_transition_guided(); if (next < 0) { // If there is no more transition in the current state, backtrack. XBT_DEBUG("There remains %lu actors, but none to interleave (depth %zu).", state->get_actor_count(), stack_.size() + 1); - + if (state->get_actor_count() == 0) { get_remote_app().finalize_app(); XBT_VERB("Execution came to an end at %s (state: %ld, depth: %zu)", get_record_trace().to_string().c_str(), state->get_num(), stack_.size()); - } - + this->backtrack(); continue; } @@ -167,7 +167,6 @@ void DFSExplorer::run() on_state_creation_signal(next_state.get(), get_remote_app()); - if (_sg_mc_termination) this->check_non_termination(next_state.get()); @@ -209,12 +208,12 @@ void DFSExplorer::backtrack() /* We may backtrack from somewhere either because it's leaf, or because every enabled process are in done/sleep set. * In the first case, we need to remove the last transition corresponding to the Finalize */ if (stack_.back()->get_transition()->aid_ == 0) - stack_.pop_back(); - + stack_.pop_back(); + /* Traverse the stack backwards until a state with a non empty interleave set is found, deleting all the states that * have it empty in the way. For each deleted state, check if the request that has generated it (from its - * predecessor state) depends on any other previous request executed before it on another process. If there exists one, - * find the more recent, and add its process to the interleave set. If the process is not enabled at this point, + * predecessor state) depends on any other previous request executed before it on another process. If there exists + * one, find the more recent, and add its process to the interleave set. If the process is not enabled at this point, * then add every enabled process to the interleave */ bool found_backtracking_point = false; while (not stack_.empty() && not found_backtracking_point) { @@ -265,7 +264,8 @@ void DFSExplorer::backtrack() } else { XBT_DEBUG("Back-tracking to state %ld at depth %zu: %lu transitions left to be explored", state->get_num(), stack_.size() + 1, state->count_todo()); - stack_.push_back(std::move(state)); // Put it back on the stack so we can explore the next transition of the interleave + stack_.push_back( + std::move(state)); // Put it back on the stack so we can explore the next transition of the interleave found_backtracking_point = true; } }