Logo AND Algorithmique Numérique Distribuée

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