X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5c475d75d7e0238f6f56ad0b98d471fff0a04153..0f0aacb167ddc9427ea1da1c8f1b66ef2d6f532e:/src/mc/explo/odpor/Execution.cpp diff --git a/src/mc/explo/odpor/Execution.cpp b/src/mc/explo/odpor/Execution.cpp index bf5172233e..ba6f7babc5 100644 --- a/src/mc/explo/odpor/Execution.cpp +++ b/src/mc/explo/odpor/Execution.cpp @@ -12,18 +12,25 @@ #include #include +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_odpor_execution, mc_dfs, "ODPOR exploration algorithm of the model-checker"); + namespace simgrid::mc::odpor { std::vector get_textual_trace(const PartialExecution& w) { std::vector trace; for (const auto& t : w) { - const auto a = xbt::string_printf("Actor %ld: %s", t->aid_, t->to_string(true).c_str()); - trace.push_back(std::move(a)); + auto a = xbt::string_printf("Actor %ld: %s", t->aid_, t->to_string(true).c_str()); + trace.emplace_back(std::move(a)); } return trace; } +Execution::Execution(const PartialExecution& w) +{ + push_partial_execution(w); +} + void Execution::push_transition(std::shared_ptr t) { if (t == nullptr) { @@ -39,13 +46,19 @@ void Execution::push_transition(std::shared_ptr t) contents_.push_back(Event({std::move(t), max_clock_vector})); } +void Execution::push_partial_execution(const PartialExecution& w) +{ + for (const auto& t : w) { + push_transition(t); + } +} + std::vector Execution::get_textual_trace() const { std::vector trace; for (const auto& t : this->contents_) { - const auto a = - xbt::string_printf("Actor %ld: %s", t.get_transition()->aid_, t.get_transition()->to_string(true).c_str()); - trace.push_back(std::move(a)); + auto a = xbt::string_printf("Actor %ld: %s", t.get_transition()->aid_, t.get_transition()->to_string(true).c_str()); + trace.emplace_back(std::move(a)); } return trace; } @@ -53,18 +66,22 @@ std::vector Execution::get_textual_trace() const std::unordered_set Execution::get_racing_events_of(Execution::EventHandle target) const { std::unordered_set racing_events; + // This keep tracks of events that happens-before the target std::unordered_set disqualified_events; // For each event of the execution for (auto e_i = target; e_i != std::numeric_limits::max(); e_i--) { // We need `e_i -->_E target` as a necessary condition if (not happens_before(e_i, target)) { + XBT_DEBUG("ODPOR_RACING_EVENTS with `%u` : `%u` discarded because `%u` --\\-->_E `%u`", target, e_i, e_i, target); continue; } // Further, `proc(e_i) != proc(target)` if (get_actor_with_handle(e_i) == get_actor_with_handle(target)) { disqualified_events.insert(e_i); + XBT_DEBUG("ODPOR_RACING_EVENTS with `%u` : `%u` disqualified because proc(`%u`)=proc(`%u`)", target, e_i, e_i, + target); continue; } @@ -75,7 +92,9 @@ std::unordered_set Execution::get_racing_events_of(Execu // 2. disqualified_events.count(e_j) > 0 // then e_i --->_E target indirectly (either through // e_j directly, or transitively through e_j) - if (disqualified_events.count(e_j) > 0 and happens_before(e_i, e_j)) { + if (disqualified_events.count(e_j) > 0 && happens_before(e_i, e_j)) { + XBT_DEBUG("ODPOR_RACING_EVENTS with `%u` : `%u` disqualified because `%u` happens-between `%u`-->`%u`-->`%u`)", + target, e_i, e_j, e_i, e_j, target); disqualified_events.insert(e_i); break; } @@ -87,6 +106,7 @@ std::unordered_set Execution::get_racing_events_of(Execu // it (since this would transitively make it the event // which "happens-between" `target` and `e`) if (disqualified_events.count(e_i) == 0) { + XBT_DEBUG("ODPOR_RACING_EVENTS with `%u` : `%u` is a valid racing event", target, e_i); racing_events.insert(e_i); disqualified_events.insert(e_i); } @@ -152,7 +172,7 @@ Execution::get_missing_source_set_actors_from(EventHandle e, const std::unordere // happen after `e` is a member of `v`. In addition to marking // the event in `v`, we also "simulate" running the action `v` // from E' - if (not happens_before(e, e_prime) or e_prime == next_E_p) { + if (not happens_before(e, e_prime) || e_prime == next_E_p) { // First, push the transition onto the hypothetical execution E_prime_v.push_transition(get_event_with_handle(e_prime).get_transition()); const EventHandle e_prime_in_E_prime_v = E_prime_v.get_latest_event_handle().value(); @@ -194,7 +214,7 @@ Execution::get_missing_source_set_actors_from(EventHandle e, const std::unordere } } } - xbt_assert(!I_E_prime_v.empty(), + xbt_assert(not I_E_prime_v.empty(), "For any non-empty execution, we know that " "at minimum one actor is an initial since " "some execution is possible with respect to a " @@ -221,10 +241,11 @@ std::optional Execution::get_odpor_extension_from(EventHandle } PartialExecution v; + std::vector v_handles; + std::unordered_set WI_E_prime_v; + std::unordered_set disqualified_actors; Execution E_prime_v = get_prefix_before(e); - std::unordered_set disqualified_actors = state_at_e.get_sleeping_actors(); - std::vector v_handles; - bool located_actor_in_initial = false; + const std::unordered_set sleep_E_prime = state_at_e.get_sleeping_actors(); // Note `e + 1` here: `notdep(e, E)` is defined as the // set of events that *occur-after* but don't *happen-after* `e` @@ -240,7 +261,7 @@ std::optional Execution::get_odpor_extension_from(EventHandle // SUBTLE NOTE: Observe that any event that "happens-after" `e'` // must necessarily "happen-after" `e` as well, since `e` and // `e'` are presumed to be in a reversible race. Hence, we know that - // all events `e_star` that `e` "happens-before" cannot affect + // all events `e_star` such that `e` "happens-before" `e_star` cannot affect // the enabledness of `e'`; furthermore, `e'` cannot affect the enabledness // of any event independent with `e` that "occurs-after" `e'` for (auto e_star = e + 1; e_star <= get_latest_event_handle().value(); ++e_star) { @@ -267,25 +288,26 @@ std::optional Execution::get_odpor_extension_from(EventHandle // `-->_[E'.v]` about `E'.v`, we must build `v` relative to `E'` v_handles.push_back(e_star_in_E_prime_v); - if (located_actor_in_initial) { - // It suffices that we find one initial. If we've already found - // one, we simply need to finish building `v` - continue; - } - // Note that we add `q` to v regardless of whether `q` itself has been // disqualified since `q` may itself disqualify other actors // (i.e. even if `q` is disqualified from being an initial, it // is still contained in the sequence `v`) const aid_t q = E_prime_v.get_actor_with_handle(e_star_in_E_prime_v); - if (disqualified_actors.count(q) > 0) { + if (disqualified_actors.count(q) > 0) { // Did we already note that `q` is not an initial? continue; } - const bool is_initial = std::none_of(v_handles.begin(), v_handles.end(), [&](const auto& e_loc) { - return E_prime_v.happens_before(e_loc, e_star_in_E_prime_v); + const bool is_initial = std::none_of(v_handles.begin(), v_handles.end(), [&](const auto& handle) { + return E_prime_v.happens_before(handle, e_star_in_E_prime_v); }); if (is_initial) { - located_actor_in_initial = true; + // If the sleep set already contains `q`, we're done: + // we've found an initial contained in the sleep set and + // so the intersection is non-empty + if (sleep_E_prime.count(q) > 0) { + return std::nullopt; + } else { + WI_E_prime_v.insert(q); + } } else { // If `q` is disqualified as a candidate, clearly // no event occurring after `e_prime` in `E` executed @@ -297,44 +319,44 @@ std::optional Execution::get_odpor_extension_from(EventHandle } // Now we add `e_prime := ` to `E'.v` and repeat the same work - { - v.push_back(get_event_with_handle(e_prime).get_transition()); - - if (not located_actor_in_initial) { - // It's possible `proc(e_prime)` is an initial - E_prime_v.push_transition(get_event_with_handle(e_prime).get_transition()); - const EventHandle e_prime_in_E_prime_v = E_prime_v.get_latest_event_handle().value(); - v_handles.push_back(e_prime_in_E_prime_v); - - const aid_t q = E_prime_v.get_actor_with_handle(e_prime_in_E_prime_v); - located_actor_in_initial = disqualified_actors.count(q) == 0 and - std::none_of(v_handles.begin(), v_handles.end(), [&](const auto& e_loc) { - return E_prime_v.happens_before(e_loc, e_prime_in_E_prime_v); - }); + // It's possible `proc(e_prime)` is an initial + // + // Note the form of `v` in the pseudocode: + // `v := notdep(e, E).e'^ + E_prime_v.push_transition(get_event_with_handle(e_prime).get_transition()); + v.push_back(get_event_with_handle(e_prime).get_transition()); + + const EventHandle e_prime_in_E_prime_v = E_prime_v.get_latest_event_handle().value(); + v_handles.push_back(e_prime_in_E_prime_v); + + const bool is_initial = std::none_of(v_handles.begin(), v_handles.end(), [&](const auto& handle) { + return E_prime_v.happens_before(handle, e_prime_in_E_prime_v); + }); + if (is_initial) { + if (const aid_t q = E_prime_v.get_actor_with_handle(e_prime_in_E_prime_v); sleep_E_prime.count(q) > 0) { + return std::nullopt; + } else { + WI_E_prime_v.insert(q); } } - /** Some actor `p` in `v` is an initial for `E' := pre(e, E)`*/ - if (located_actor_in_initial) { - return v; - } - const Execution pre_E_e = get_prefix_before(e); const auto sleeping_actors = state_at_e.get_sleeping_actors(); - // Otherwise, for each enabled actor also not in the sleep set, check if - // any of them are independent with this execution after `v`. This - // completes the check for weak initials + // Check if any enabled actor that is independent with + // this execution after `v` is contained in the sleep set for (const auto& [aid, astate] : state_at_e.get_actors_list()) { - // TODO: We have to be able to react appropriately here when adding new - // types of transitions (multiple choices can be made :( ) - if (astate.is_enabled() and sleeping_actors.count(aid) == 0 and - pre_E_e.is_independent_with_execution_of(v, astate.get_transition(0))) { - return v; - } + const bool is_in_WI_E = + astate.is_enabled() and pre_E_e.is_independent_with_execution_of(v, astate.get_transition()); + const bool is_in_sleep_set = sleeping_actors.count(aid) > 0; + + // `action(aid)` is in `WI_[E](v)` but also is contained in the sleep set. + // This implies that the intersection between the two is non-empty + if (is_in_WI_E && is_in_sleep_set) + return std::nullopt; } - return std::nullopt; + return v; } bool Execution::is_initial_after_execution_of(const PartialExecution& w, aid_t p) const @@ -395,13 +417,11 @@ std::optional Execution::get_shortest_odpor_sq_subset_insertio auto w_now = w; for (const auto& next_E_p : v) { - const aid_t p = next_E_p->aid_; - // Is `p in `I_[E](w)`? - if (E_v.is_initial_after_execution_of(w_now, p)) { + if (const aid_t p = next_E_p->aid_; E_v.is_initial_after_execution_of(w_now, p)) { // Remove `p` from w and continue - // TODO: If `p` occurs in `w`, it had better refer to the same + // INVARIANT: If `p` occurs in `w`, it had better refer to the same // transition referenced by `v`. Unfortunately, we have two // sources of truth here which can be manipulated at the same // time as arguments to the function. If ODPOR works correctly, @@ -422,7 +442,7 @@ std::optional Execution::get_shortest_odpor_sq_subset_insertio w_now.erase(action_by_p_in_w); } // Is `E ⊢ p ◇ w`? - else if (E_v.is_independent_with_execution_of(w, next_E_p)) { + else if (E_v.is_independent_with_execution_of(w_now, next_E_p)) { // INVARIANT: Note that it is impossible for `p` to be // excluded from the set `I_[E](w)` BUT ALSO be contained in // `w` itself if `E ⊢ p ◇ w` (intuitively, the fact that `E ⊢ p ◇ w` @@ -470,4 +490,4 @@ bool Execution::happens_before(Execution::EventHandle e1_handle, Execution::Even return false; } -} // namespace simgrid::mc::odpor \ No newline at end of file +} // namespace simgrid::mc::odpor