Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Split TransitionAny and TransitionRandom to their own files
[simgrid.git] / src / mc / transition / TransitionComm.cpp
1 /* Copyright (c) 2015-2022. 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/TransitionComm.hpp"
7 #include "xbt/asserts.h"
8 #include <simgrid/config.h>
9 #if SIMGRID_HAVE_MC
10 #include "src/mc/ModelChecker.hpp"
11 #include "src/mc/Session.hpp"
12 #include "src/mc/api/State.hpp"
13 #endif
14
15 #include <sstream>
16
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition,
18                                 "Logging specific to MC transitions about communications");
19
20 namespace simgrid {
21 namespace mc {
22
23 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
24     : Transition(Type::COMM_WAIT, issuer, times_considered)
25 {
26   xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
27   XBT_DEBUG("CommWaitTransition %s comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR
28             " rbuff:%" PRIxPTR " size:%zu",
29             (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
30 }
31 std::string CommWaitTransition::to_string(bool verbose) const
32 {
33   auto res = xbt::string_printf("%ld: WaitComm(from %ld to %ld, mbox=%u, %s", aid_, sender_, receiver_, mbox_,
34                                 (timeout_ ? "timeout" : "no timeout"));
35   if (verbose) {
36     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
37     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
38   }
39   res += ")";
40   return res;
41 }
42 bool CommWaitTransition::depends(const Transition* other) const
43 {
44   if (aid_ == other->aid_)
45     return false;
46
47   if (other->type_ < type_)
48     return other->depends(this);
49
50   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
51     if (timeout_ || wait->timeout_)
52       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
53
54     if (sbuff_ == wait->sbuff_ && rbuff_ == wait->rbuff_)
55       return false;
56     if (sbuff_ != 0 && rbuff_ != 0 && wait->sbuff_ != 0 && wait->rbuff_ != 0 && rbuff_ != wait->sbuff_ &&
57         rbuff_ != wait->rbuff_ && rbuff_ != sbuff_)
58       return false;
59   }
60
61   return true;
62 }
63 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
64     : Transition(Type::COMM_TEST, issuer, times_considered)
65 {
66   xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
67   XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
68             " size:%zu",
69             comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
70 }
71 std::string CommTestTransition::to_string(bool verbose) const
72 {
73   auto res = xbt::string_printf("%ld: TestComm(from %ld to %ld, mbox=%u", aid_, sender_, receiver_, mbox_);
74   if (verbose) {
75     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
76     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
77   }
78   res += ")";
79   return res;
80 }
81 bool CommTestTransition::depends(const Transition* other) const
82 {
83   if (aid_ == other->aid_)
84     return false;
85
86   if (other->type_ < type_)
87     return other->depends(this);
88
89   if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
90     return false; // Test & Test are independent
91
92   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
93     if (wait->timeout_)
94       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
95
96     /* Wait & Test are independent */
97     return false;
98   }
99
100   return true;
101 }
102
103 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
104     : Transition(Type::COMM_RECV, issuer, times_considered)
105 {
106   xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
107 }
108 std::string CommRecvTransition::to_string(bool verbose) const
109 {
110   auto res = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_);
111   if (verbose)
112     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
113   res += ")";
114   return res;
115 }
116 bool CommRecvTransition::depends(const Transition* other) const
117 {
118   if (aid_ == other->aid_)
119     return false;
120
121   if (other->type_ < type_)
122     return other->depends(this);
123
124   if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
125     return mbox_ == recv->mbox_;
126
127   if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
128     return false;
129
130   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
131     if (mbox_ != test->mbox_)
132       return false;
133
134     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
135       return false;
136   }
137
138   if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
139     if (wait->timeout_)
140       return true;
141
142     if (mbox_ != wait->mbox_)
143       return false;
144
145     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
146       return false;
147   }
148
149   return true;
150 }
151
152 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
153     : Transition(Type::COMM_SEND, issuer, times_considered)
154 {
155   xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
156   XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
157 }
158 std::string CommSendTransition::to_string(bool verbose = false) const
159 {
160   auto res = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_);
161   if (verbose)
162     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
163   res += ")";
164   return res;
165 }
166
167 bool CommSendTransition::depends(const Transition* other) const
168 {
169   if (aid_ == other->aid_)
170     return false;
171
172   if (other->type_ < type_)
173     return other->depends(this);
174
175   if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
176     return mbox_ == other_isend->mbox_;
177
178   if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
179     return false;
180
181   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
182     if (mbox_ != test->mbox_)
183       return false;
184
185     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
186       return false;
187   }
188
189   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
190     if (wait->timeout_)
191       return true;
192
193     if (mbox_ != wait->mbox_)
194       return false;
195
196     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
197       return false;
198   }
199
200   return true;
201 }
202
203 } // namespace mc
204 } // namespace simgrid