Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the dependency of inter-comm transitions
[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("WaitComm(from %ld to %ld, mbox=%u, %s", 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     return true;
61   }
62
63   return false; // Comm transitions are INDEP with non-comm transitions
64 }
65 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
66     : Transition(Type::COMM_TEST, issuer, times_considered)
67 {
68   xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
69   XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
70             " size:%zu",
71             comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
72 }
73 std::string CommTestTransition::to_string(bool verbose) const
74 {
75   auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
76   if (verbose) {
77     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
78     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
79   }
80   res += ")";
81   return res;
82 }
83 bool CommTestTransition::depends(const Transition* other) const
84 {
85   if (aid_ == other->aid_)
86     return false;
87
88   if (other->type_ < type_)
89     return other->depends(this);
90
91   if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
92     return false; // Test & Test are independent
93
94   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
95     if (wait->timeout_)
96       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
97
98     /* Wait & Test are independent */
99     return false;
100   }
101
102   return false; // Comm transitions are INDEP with non-comm transitions
103 }
104
105 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
106     : Transition(Type::COMM_RECV, issuer, times_considered)
107 {
108   xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
109 }
110 std::string CommRecvTransition::to_string(bool verbose) const
111 {
112   auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
113   if (verbose)
114     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
115   res += ")";
116   return res;
117 }
118 bool CommRecvTransition::depends(const Transition* other) const
119 {
120   if (aid_ == other->aid_)
121     return false;
122
123   if (other->type_ < type_)
124     return other->depends(this);
125
126   if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
127     return mbox_ == recv->mbox_;
128
129   if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
130     return false;
131
132   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
133     if (mbox_ != test->mbox_)
134       return false;
135
136     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
137       return false;
138
139     return true; // DEP with other send transitions
140   }
141
142   if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
143     if (wait->timeout_)
144       return true;
145
146     if (mbox_ != wait->mbox_)
147       return false;
148
149     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
150       return false;
151
152     return true; // DEP with other wait transitions
153   }
154
155   return false; // Comm transitions are INDEP with non-comm transitions
156 }
157
158 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
159     : Transition(Type::COMM_SEND, issuer, times_considered)
160 {
161   xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
162   XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
163 }
164 std::string CommSendTransition::to_string(bool verbose = false) const
165 {
166   auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
167   if (verbose)
168     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
169   res += ")";
170   return res;
171 }
172
173 bool CommSendTransition::depends(const Transition* other) const
174 {
175   if (aid_ == other->aid_)
176     return false;
177
178   if (other->type_ < type_)
179     return other->depends(this);
180
181   if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
182     return mbox_ == other_isend->mbox_;
183
184   if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
185     return false;
186
187   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
188     if (mbox_ != test->mbox_)
189       return false;
190
191     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
192       return false;
193
194     return true; // DEP with other test transitions
195   }
196
197   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
198     if (wait->timeout_)
199       return true;
200
201     if (mbox_ != wait->mbox_)
202       return false;
203
204     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
205       return false;
206
207     return true; // DEP with other wait transitions
208   }
209
210   return false; // Comm transitions are INDEP with non-comm transitions
211 }
212
213 } // namespace mc
214 } // namespace simgrid