Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do not consider the memory addresses in MC depends function
[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, bool timeout_, unsigned comm_, aid_t sender_,
22                                        aid_t receiver_, unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_,
23                                        size_t size_)
24     : Transition(Type::COMM_WAIT, issuer, times_considered)
25     , timeout_(timeout_)
26     , comm_(comm_)
27     , mbox_(mbox_)
28     , sender_(sender_)
29     , receiver_(receiver_)
30     , sbuff_(sbuff_)
31     , rbuff_(rbuff_)
32     , size_(size_)
33 {
34 }
35 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
36     : Transition(Type::COMM_WAIT, issuer, times_considered)
37 {
38   xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
39   XBT_DEBUG("CommWaitTransition %s comm:%u, sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
40             " size:%zu",
41             (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
42 }
43 std::string CommWaitTransition::to_string(bool verbose) const
44 {
45   auto res = xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s", sender_, receiver_, mbox_,
46                                 (timeout_ ? "timeout" : "no timeout"));
47   if (verbose) {
48     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
49     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
50   }
51   res += ")";
52   return res;
53 }
54 bool CommWaitTransition::depends(const Transition* other) const
55 {
56   if (other->type_ < type_)
57     return other->depends(this);
58
59   // Actions executed by the same actor are always dependent
60   if (other->aid_ == aid_)
61     return true;
62
63   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
64     if (timeout_ || wait->timeout_)
65       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
66   }
67
68   return false; // Comm transitions are INDEP with non-comm transitions
69 }
70 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, unsigned comm_, aid_t sender_,
71                                        aid_t receiver_, unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_,
72                                        size_t size_)
73     : Transition(Type::COMM_TEST, issuer, times_considered)
74     , comm_(comm_)
75     , mbox_(mbox_)
76     , sender_(sender_)
77     , receiver_(receiver_)
78     , sbuff_(sbuff_)
79     , rbuff_(rbuff_)
80     , size_(size_)
81 {
82 }
83 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
84     : Transition(Type::COMM_TEST, issuer, times_considered)
85 {
86   xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
87   XBT_DEBUG("CommTestTransition comm:%u, sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
88             " size:%zu",
89             comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
90 }
91 std::string CommTestTransition::to_string(bool verbose) const
92 {
93   auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
94   if (verbose) {
95     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
96     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
97   }
98   res += ")";
99   return res;
100 }
101 bool CommTestTransition::depends(const Transition* other) const
102 {
103   if (other->type_ < type_)
104     return other->depends(this);
105
106   // Actions executed by the same actor are always dependent
107   if (other->aid_ == aid_)
108     return true;
109
110   if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
111     return false; // Test & Test are independent
112
113   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
114     if (wait->timeout_)
115       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
116
117     /* Wait & Test are independent */
118     return false;
119   }
120
121   return false; // Comm transitions are INDEP with non-comm transitions
122 }
123
124 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_,
125                                        uintptr_t rbuff_, int tag_)
126     : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
127     , comm_(comm_)
128     , mbox_(mbox_)
129     , rbuff_(rbuff_)
130     , tag_(tag_)
131 {
132 }
133 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
134     : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
135 {
136   xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
137 }
138 std::string CommRecvTransition::to_string(bool verbose) const
139 {
140   auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
141   if (verbose)
142     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
143   res += ")";
144   return res;
145 }
146 bool CommRecvTransition::depends(const Transition* other) const
147 {
148   if (other->type_ < type_)
149     return other->depends(this);
150
151   // Actions executed by the same actor are always dependent
152   if (other->aid_ == aid_)
153     return true;
154
155   if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
156     return mbox_ == recv->mbox_;
157
158   if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
159     return false;
160
161   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
162     if (mbox_ != test->mbox_)
163       return false;
164
165     if ((aid_ != test->sender_) && (aid_ != test->receiver_))
166       return false;
167
168     // If the test is checking a paired comm already, we're independent!
169     // If we happen to make up that pair, then we're dependent...
170     if (test->comm_ != comm_)
171       return false;
172
173     return true; // DEP with other send transitions
174   }
175
176   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
177     if (wait->timeout_)
178       return true;
179
180     if (mbox_ != wait->mbox_)
181       return false;
182
183     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
184       return false;
185
186     // If the wait is waiting on a paired comm already, we're independent!
187     // If we happen to make up that pair, then we're dependent...
188     if ((aid_ != wait->aid_) && wait->comm_ != comm_)
189       return false;
190
191     return true; // DEP with other wait transitions
192   }
193
194   return false; // Comm transitions are INDEP with non-comm transitions
195 }
196
197 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_,
198                                        uintptr_t sbuff_, size_t size_, int tag_)
199     : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
200     , comm_(comm_)
201     , mbox_(mbox_)
202     , sbuff_(sbuff_)
203     , size_(size_)
204     , tag_(tag_)
205 {
206 }
207 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
208     : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
209 {
210   xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
211   XBT_DEBUG("SendTransition comm:%u mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
212 }
213 std::string CommSendTransition::to_string(bool verbose = false) const
214 {
215   auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
216   if (verbose)
217     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
218   res += ")";
219   return res;
220 }
221
222 bool CommSendTransition::depends(const Transition* other) const
223 {
224   if (other->type_ < type_)
225     return other->depends(this);
226
227   // Actions executed by the same actor are always dependent
228   if (other->aid_ == aid_)
229     return true;
230
231   if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
232     return mbox_ == other_isend->mbox_;
233
234   if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
235     return false;
236
237   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
238     if (mbox_ != test->mbox_)
239       return false;
240
241     if ((aid_ != test->sender_) && (aid_ != test->receiver_))
242       return false;
243
244     // If the test is checking a paired comm already, we're independent!
245     // If we happen to make up that pair, then we're dependent...
246     if (test->comm_ != comm_)
247       return false;
248
249     return true; // DEP with other test transitions
250   }
251
252   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
253     if (wait->timeout_)
254       return true;
255
256     if (mbox_ != wait->mbox_)
257       return false;
258
259     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
260       return false;
261
262     // If the wait is waiting on a paired comm already, we're independent!
263     // If we happen to make up that pair, then we're dependent...
264     if ((aid_ != wait->aid_) && wait->comm_ != comm_)
265       return false;
266
267     return true; // DEP with other wait transitions
268   }
269
270   return false; // Comm transitions are INDEP with non-comm transitions
271 }
272
273 } // namespace simgrid::mc