1 /* Copyright (c) 2007-2023. 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 #ifndef SIMGRID_MC_PATTERN_H
7 #define SIMGRID_MC_PATTERN_H
9 #include "src/kernel/activity/CommImpl.hpp"
10 #include "src/mc/remote/RemotePtr.hpp"
15 namespace simgrid::mc {
17 /* On every state, each actor has an entry of the following type.
18 * This usually represents both the actor and its transition because
19 * most of the time an actor cannot have more than one enabled transition
20 * at a given time. However, certain transitions have multiple "paths"
21 * that can be followed, which means that a given actor may be able
22 * to do more than one thing at a time.
24 * Formally, at this state multiple transitions would exist all of
25 * which happened to be executed by the same actor. This distinction
26 * is important in cases
31 * @brief The transitions that the actor is allowed to execute from this
34 * TODO: If a single transition is taken at a time in a concurrent system,
35 * then nearly all of the transitions from in a state `s'` after taking
36 * an action `t` from state `s` (i.e. s -- t --> s') are the same
37 * sans for the new transition of the actor which just executed t.
38 * This means there may be a way to store the list once and apply differences
39 * rather than repeating elements frequently.
41 std::vector<std::unique_ptr<Transition>> pending_transitions_;
43 /* Possible exploration status of an actor transition in a state.
44 * Either the checker did not consider the transition, or it was considered and still to do, or considered and
47 enum class InterleavingType {
48 /** This actor transition is not considered by the checker (yet?) */
50 /** The checker algorithm decided that this actor transitions should be done at some point */
52 /** The checker algorithm decided that this should be done, but it was done in the meanwhile */
56 /** Exploration control information */
57 InterleavingType state_ = InterleavingType::disabled;
59 /** The ID of that actor */
62 /** Number of times that the actor was considered to be executed in previous explorations of the state space */
63 unsigned int times_considered_ = 0;
64 /** Maximal amount of times that the actor can be considered for execution in this state.
65 * If times_considered==max_consider, we fully explored that part of the state space */
66 unsigned int max_consider_ = 0;
68 /** Whether that actor is initially enabled in this state */
72 ActorState(aid_t aid, bool enabled, unsigned int max_consider) : ActorState(aid, enabled, max_consider, {}) {}
74 ActorState(aid_t aid, bool enabled, unsigned int max_consider, std::vector<std::unique_ptr<Transition>> transitions)
75 : aid_(aid), max_consider_(max_consider), enabled_(enabled), pending_transitions_(std::move(transitions))
79 unsigned int do_consider()
81 if (max_consider_ <= times_considered_ + 1)
83 return times_considered_++;
85 unsigned int get_times_considered() const { return times_considered_; }
86 aid_t get_aid() const { return aid_; }
88 /* returns whether the actor is marked as enabled in the application side */
89 bool is_enabled() const { return enabled_; }
90 /* returns whether the actor is marked as disabled by the exploration algorithm */
91 bool is_disabled() const { return this->state_ == InterleavingType::disabled; }
92 bool is_done() const { return this->state_ == InterleavingType::done; }
93 bool is_todo() const { return this->state_ == InterleavingType::todo; }
94 /** Mark that we should try executing this process at some point in the future of the checker algorithm */
97 this->state_ = InterleavingType::todo;
98 this->times_considered_ = 0;
100 void set_done() { this->state_ = InterleavingType::done; }
102 Transition* get_transition(unsigned times_considered)
104 xbt_assert(times_considered <= this->pending_transitions_.size(),
105 "Actor %lu does not have a state available transition with `times_considered = %d`,\n"
106 "yet one was asked for",
107 aid_, times_considered);
108 return this->pending_transitions_[times_considered].get();
112 } // namespace simgrid::mc