Logo AND Algorithmique Numérique Distribuée

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