Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / mc / transition / TransitionAny.cpp
1 /* Copyright (c) 2015-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/transition/TransitionAny.hpp"
7 #include "simgrid/config.h"
8 #include "xbt/asserts.h"
9 #include "xbt/string.hpp"
10
11 #include <sstream>
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_any, mc_transition, "Logging specific to MC WaitAny / TestAny transitions");
14
15 namespace simgrid::mc {
16
17 TestAnyTransition::TestAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream)
18     : Transition(Type::TESTANY, issuer, times_considered)
19 {
20   int size;
21   xbt_assert(stream >> size);
22   for (int i = 0; i < size; i++) {
23     Transition* t = deserialize_transition(issuer, 0, stream);
24     XBT_INFO("TestAny received a transition %s", t->to_string(true).c_str());
25     transitions_.push_back(t);
26   }
27 }
28 std::string TestAnyTransition::to_string(bool verbose) const
29 {
30   auto res = xbt::string_printf("TestAny(%s){ ", this->result() ? "TRUE" : "FALSE");
31   for (auto const* t : transitions_) {
32     res += t->to_string(verbose);
33     res += "; ";
34   }
35   res += " }";
36   return res;
37 }
38 bool TestAnyTransition::depends(const Transition* other) const
39 {
40   // Actions executed by the same actor are always dependent
41   if (other->aid_ == aid_)
42     return true;
43
44   return transitions_[times_considered_]->depends(other);
45 }
46 bool TestAnyTransition::reversible_race(const Transition* other) const
47 {
48   xbt_assert(type_ == Type::TESTANY, "Unexpected transition type %s", to_c_str(type_));
49
50   return true; // TestAny is always enabled
51 }
52
53 WaitAnyTransition::WaitAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream)
54     : Transition(Type::WAITANY, issuer, times_considered)
55 {
56   int size;
57   xbt_assert(stream >> size);
58   for (int i = 0; i < size; i++) {
59     Transition* t = deserialize_transition(issuer, 0, stream);
60     XBT_INFO("WaitAny received transition %d/%d %s", (i + 1), size, t->to_string(true).c_str());
61     transitions_.push_back(t);
62   }
63 }
64 std::string WaitAnyTransition::to_string(bool verbose) const
65 {
66   auto res = xbt::string_printf("WaitAny{ ");
67   for (auto const* t : transitions_)
68     res += t->to_string(verbose);
69   res += " } (times considered = " + std::to_string(times_considered_) + ")";
70   return res;
71 }
72 bool WaitAnyTransition::depends(const Transition* other) const
73 {
74   // Actions executed by the same actor are always dependent
75   if (other->aid_ == aid_)
76     return true;
77   return transitions_[times_considered_]->depends(other);
78 }
79 bool WaitAnyTransition::reversible_race(const Transition* other) const
80 {
81   xbt_assert(type_ == Type::WAITANY, "Unexpected transition type %s", to_c_str(type_));
82
83   // TODO: We need to check if any of the transitions waited on occurred before `e1`
84   return true; // Let's overapproximate to not miss branches
85 }
86
87 } // namespace simgrid::mc