Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'udpor-phase6' into 'master'
[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 "xbt/asserts.h"
9 #include "xbt/string.hpp"
10 #if SIMGRID_HAVE_MC
11 #include "src/mc/api/RemoteApp.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::mc {
21
22 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
23     : Transition(Type::COMM_WAIT, issuer, times_considered)
24 {
25   xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
26   XBT_DEBUG("CommWaitTransition %s comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR
27             " rbuff:%" PRIxPTR " size:%zu",
28             (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
29 }
30 std::string CommWaitTransition::to_string(bool verbose) const
31 {
32   auto res = xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s", sender_, receiver_, mbox_,
33                                 (timeout_ ? "timeout" : "no timeout"));
34   if (verbose) {
35     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
36     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
37   }
38   res += ")";
39   return res;
40 }
41 bool CommWaitTransition::depends(const Transition* other) const
42 {
43   if (other->type_ < type_)
44     return other->depends(this);
45
46   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
47     if (timeout_ || wait->timeout_)
48       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
49
50     if (sbuff_ == wait->sbuff_ && rbuff_ == wait->rbuff_)
51       return false;
52     if (sbuff_ != 0 && rbuff_ != 0 && wait->sbuff_ != 0 && wait->rbuff_ != 0 && rbuff_ != wait->sbuff_ &&
53         rbuff_ != wait->rbuff_ && rbuff_ != sbuff_)
54       return false;
55
56     return true;
57   }
58
59   return false; // Comm transitions are INDEP with non-comm transitions
60 }
61 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
62     : Transition(Type::COMM_TEST, issuer, times_considered)
63 {
64   xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
65   XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
66             " size:%zu",
67             comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
68 }
69 std::string CommTestTransition::to_string(bool verbose) const
70 {
71   auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
72   if (verbose) {
73     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
74     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
75   }
76   res += ")";
77   return res;
78 }
79 bool CommTestTransition::depends(const Transition* other) const
80 {
81
82   if (other->type_ < type_)
83     return other->depends(this);
84
85   if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
86     return false; // Test & Test are independent
87
88   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
89     if (wait->timeout_)
90       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
91
92     /* Wait & Test are independent */
93     return false;
94   }
95
96   return false; // Comm transitions are INDEP with non-comm transitions
97 }
98
99 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
100     : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
101 {
102   xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
103 }
104 std::string CommRecvTransition::to_string(bool verbose) const
105 {
106   auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
107   if (verbose)
108     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
109   res += ")";
110   return res;
111 }
112 bool CommRecvTransition::depends(const Transition* other) const
113 {
114   if (other->type_ < type_)
115     return other->depends(this);
116
117   if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
118     return mbox_ == recv->mbox_;
119
120   if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
121     return false;
122
123   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
124     if (mbox_ != test->mbox_)
125       return false;
126
127     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
128       return false;
129
130     return true; // DEP with other send transitions
131   }
132
133   if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
134     if (wait->timeout_)
135       return true;
136
137     if (mbox_ != wait->mbox_)
138       return false;
139
140     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
141       return false;
142
143     return true; // DEP with other wait transitions
144   }
145
146   return false; // Comm transitions are INDEP with non-comm transitions
147 }
148
149 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
150     : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
151 {
152   xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
153   XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
154 }
155 std::string CommSendTransition::to_string(bool verbose = false) const
156 {
157   auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
158   if (verbose)
159     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
160   res += ")";
161   return res;
162 }
163
164 bool CommSendTransition::depends(const Transition* other) const
165 {
166   if (other->type_ < type_)
167     return other->depends(this);
168
169   if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
170     return mbox_ == other_isend->mbox_;
171
172   if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
173     return false;
174
175   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
176     if (mbox_ != test->mbox_)
177       return false;
178
179     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
180       return false;
181
182     return true; // DEP with other test transitions
183   }
184
185   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
186     if (wait->timeout_)
187       return true;
188
189     if (mbox_ != wait->mbox_)
190       return false;
191
192     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
193       return false;
194
195     return true; // DEP with other wait transitions
196   }
197
198   return false; // Comm transitions are INDEP with non-comm transitions
199 }
200
201 } // namespace simgrid::mc