Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add reversible race implementations for Comm actions
[simgrid.git] / src / mc / explo / odpor / ReversibleRaceCalculator.cpp
1 /* Copyright (c) 2008-2023. 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/explo/odpor/ReversibleRaceCalculator.hpp"
7 #include "src/mc/explo/odpor/Execution.hpp"
8
9 #include <functional>
10 #include <unordered_map>
11 #include <xbt/asserts.h>
12 #include <xbt/ex.h>
13
14 namespace simgrid::mc::odpor {
15
16 bool ReversibleRaceCalculator::is_race_reversible(const Execution& E, Execution::EventHandle e1,
17                                                   Execution::EventHandle e2)
18 {
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>;
22
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}};
27
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);
31   } else {
32     xbt_assert(false,
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 "
38                "in the meantime",
39                e2_action->to_string().c_str());
40     DIE_IMPOSSIBLE;
41   }
42 }
43
44 bool ReversibleRaceCalculator::is_race_reversible_CommRecv(const Execution&, Execution::EventHandle e1,
45                                                            const Transition* e2)
46 {
47   // CommRecv is always enabled
48   return true;
49 }
50
51 bool ReversibleRaceCalculator::is_race_reversible_CommSend(const Execution&, Execution::EventHandle e1,
52                                                            const Transition* e2)
53 {
54   // CommSend is always enabled
55   return true;
56 }
57
58 bool ReversibleRaceCalculator::is_race_reversible_CommWait(const Execution& E, Execution::EventHandle e1,
59                                                            const Transition* e2)
60 {
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;
65 }
66
67 bool ReversibleRaceCalculator::is_race_reversible_CommTest(const Execution&, Execution::EventHandle e1,
68                                                            const Transition* e2)
69 {
70   return false;
71 }
72
73 } // namespace simgrid::mc::odpor