Logo AND Algorithmique Numérique Distribuée

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