1 /* Copyright (c) 2008-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 #include "src/mc/explo/odpor/ReversibleRaceCalculator.hpp"
7 #include "src/mc/explo/odpor/Execution.hpp"
10 #include <unordered_map>
11 #include <xbt/asserts.h>
14 namespace simgrid::mc::odpor {
16 bool ReversibleRaceCalculator::is_race_reversible(const Execution& E, Execution::EventHandle e1,
17 Execution::EventHandle e2)
19 using Action = Transition::Type;
20 using Handler = std::function<bool(const Execution&, Execution::EventHandle, const Transition*)>;
21 using HandlerMap = std::unordered_map<Action, Handler>;
23 const static HandlerMap handlers =
24 HandlerMap{{Action::COMM_ASYNC_RECV, &ReversibleRaceCalculator::is_race_reversible_CommRecv},
25 {Action::COMM_ASYNC_SEND, &ReversibleRaceCalculator::is_race_reversible_CommSend},
26 {Action::COMM_WAIT, &ReversibleRaceCalculator::is_race_reversible_CommWait}};
28 const auto e2_action = E.get_transition_for_handle(e2);
29 if (const auto handler = handlers.find(e2_action->type_); handler != handlers.end()) {
30 return handler->second(E, e1, e2_action);
33 "There is currently no specialized computation for the transition "
34 "'%s' for computing reversible races in ODPOR, so the model checker cannot "
35 "determine how to proceed. Please submit a bug report requesting "
36 "that the transition be supported in SimGrid using ODPPR and consider "
37 "using the other model-checking algorithms supported by SimGrid instead "
39 e2_action->to_string().c_str());
44 bool ReversibleRaceCalculator::is_race_reversible_CommRecv(const Execution&, Execution::EventHandle e1,
47 // CommRecv is always enabled
51 bool ReversibleRaceCalculator::is_race_reversible_CommSend(const Execution&, Execution::EventHandle e1,
54 // CommSend is always enabled
58 bool ReversibleRaceCalculator::is_race_reversible_CommWait(const Execution& E, Execution::EventHandle e1,
61 // If the other event communication event, then we
62 // are not reversible. Otherwise we are reversible.
63 const auto e1_action = E.get_transition_for_handle(e1)->type_;
64 return e1_action != Transition::Type::COMM_ASYNC_SEND and e1_action != Transition::Type::COMM_ASYNC_RECV;
67 bool ReversibleRaceCalculator::is_race_reversible_CommTest(const Execution&, Execution::EventHandle e1,
73 } // namespace simgrid::mc::odpor