Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Mark transitions run by the same actor as dependent
[simgrid.git] / src / mc / transition / TransitionComm.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/TransitionComm.hpp"
7 #include "simgrid/config.h"
8 #include "src/mc/api/RemoteApp.hpp"
9 #include "src/mc/api/State.hpp"
10 #include "xbt/asserts.h"
11 #include "xbt/string.hpp"
12
13 #include <inttypes.h>
14 #include <sstream>
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition,
17                                 "Logging specific to MC transitions about communications");
18
19 namespace simgrid::mc {
20
21 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
22     : Transition(Type::COMM_WAIT, issuer, times_considered)
23 {
24   xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
25   XBT_DEBUG("CommWaitTransition %s comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR
26             " rbuff:%" PRIxPTR " size:%zu",
27             (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
28 }
29 std::string CommWaitTransition::to_string(bool verbose) const
30 {
31   auto res = xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s", sender_, receiver_, mbox_,
32                                 (timeout_ ? "timeout" : "no timeout"));
33   if (verbose) {
34     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
35     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
36   }
37   res += ")";
38   return res;
39 }
40 bool CommWaitTransition::depends(const Transition* other) const
41 {
42   if (other->type_ < type_)
43     return other->depends(this);
44
45   // Actions executed by the same actor are always dependent
46   if (other->aid_ == aid_)
47     return true;
48
49   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
50     if (timeout_ || wait->timeout_)
51       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
52
53     if (sbuff_ == wait->sbuff_ && rbuff_ == wait->rbuff_)
54       return false;
55     if (sbuff_ != 0 && rbuff_ != 0 && wait->sbuff_ != 0 && wait->rbuff_ != 0 && rbuff_ != wait->sbuff_ &&
56         rbuff_ != wait->rbuff_ && rbuff_ != sbuff_)
57       return false;
58
59     return true;
60   }
61
62   return false; // Comm transitions are INDEP with non-comm transitions
63 }
64 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
65     : Transition(Type::COMM_TEST, issuer, times_considered)
66 {
67   xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
68   XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
69             " size:%zu",
70             comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
71 }
72 std::string CommTestTransition::to_string(bool verbose) const
73 {
74   auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
75   if (verbose) {
76     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
77     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
78   }
79   res += ")";
80   return res;
81 }
82 bool CommTestTransition::depends(const Transition* other) const
83 {
84   if (other->type_ < type_)
85     return other->depends(this);
86
87   // Actions executed by the same actor are always dependent
88   if (other->aid_ == aid_)
89     return true;
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_ASYNC_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 (other->type_ < type_)
121     return other->depends(this);
122
123   // Actions executed by the same actor are always dependent
124   if (other->aid_ == aid_)
125     return true;
126
127   if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
128     return mbox_ == recv->mbox_;
129
130   if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
131     return false;
132
133   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
134     if (mbox_ != test->mbox_)
135       return false;
136
137     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
138       return false;
139
140     return true; // DEP with other send transitions
141   }
142
143   if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
144     if (wait->timeout_)
145       return true;
146
147     if (mbox_ != wait->mbox_)
148       return false;
149
150     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
151       return false;
152
153     return true; // DEP with other wait transitions
154   }
155
156   return false; // Comm transitions are INDEP with non-comm transitions
157 }
158
159 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
160     : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
161 {
162   xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
163   XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
164 }
165 std::string CommSendTransition::to_string(bool verbose = false) const
166 {
167   auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
168   if (verbose)
169     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
170   res += ")";
171   return res;
172 }
173
174 bool CommSendTransition::depends(const Transition* other) const
175 {
176   if (other->type_ < type_)
177     return other->depends(this);
178
179   // Actions executed by the same actor are always dependent
180   if (other->aid_ == aid_)
181     return true;
182
183   if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
184     return mbox_ == other_isend->mbox_;
185
186   if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
187     return false;
188
189   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
190     if (mbox_ != test->mbox_)
191       return false;
192
193     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
194       return false;
195
196     return true; // DEP with other test transitions
197   }
198
199   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
200     if (wait->timeout_)
201       return true;
202
203     if (mbox_ != wait->mbox_)
204       return false;
205
206     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
207       return false;
208
209     return true; // DEP with other wait transitions
210   }
211
212   return false; // Comm transitions are INDEP with non-comm transitions
213 }
214
215 } // namespace simgrid::mc