1 /* Copyright (c) 2015-2023. The SimGrid Team. All rights reserved. */
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. */
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"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition,
17 "Logging specific to MC transitions about communications");
19 namespace simgrid::mc {
21 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, bool timeout_, unsigned comm_, aid_t sender_,
22 aid_t receiver_, unsigned mbox_)
23 : Transition(Type::COMM_WAIT, issuer, times_considered)
28 , receiver_(receiver_)
31 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
32 : Transition(Type::COMM_WAIT, issuer, times_considered)
34 xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> call_location_);
35 XBT_DEBUG("CommWaitTransition %s comm:%u, sender:%ld receiver:%ld mbox:%u call_loc:%s",
36 (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, call_location_.c_str());
38 std::string CommWaitTransition::to_string(bool verbose) const
40 return xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s)", sender_, receiver_, mbox_,
41 (timeout_ ? "timeout" : "no timeout"));
43 bool CommWaitTransition::depends(const Transition* other) const
45 if (other->type_ < type_)
46 return other->depends(this);
48 // Actions executed by the same actor are always dependent
49 if (other->aid_ == aid_)
52 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
53 if (timeout_ || wait->timeout_)
54 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
57 return false; // Comm transitions are INDEP with non-comm transitions
59 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, unsigned comm_, aid_t sender_,
60 aid_t receiver_, unsigned mbox_)
61 : Transition(Type::COMM_TEST, issuer, times_considered)
65 , receiver_(receiver_)
68 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
69 : Transition(Type::COMM_TEST, issuer, times_considered)
71 xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> call_location_);
72 XBT_DEBUG("CommTestTransition comm:%u, sender:%ld receiver:%ld mbox:%u call_loc:%s", comm_, sender_, receiver_, mbox_,
73 call_location_.c_str());
75 std::string CommTestTransition::to_string(bool verbose) const
77 return xbt::string_printf("TestComm(from %ld to %ld, mbox=%u)", sender_, receiver_, mbox_);
79 bool CommTestTransition::depends(const Transition* other) const
81 if (other->type_ < type_)
82 return other->depends(this);
84 // Actions executed by the same actor are always dependent
85 if (other->aid_ == aid_)
88 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
89 return false; // Test & Test are independent
91 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
93 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
95 /* Wait & Test are independent */
99 return false; // Comm transitions are INDEP with non-comm transitions
102 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_, int tag_)
103 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered), comm_(comm_), mbox_(mbox_), tag_(tag_)
106 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
107 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
109 xbt_assert(stream >> comm_ >> mbox_ >> tag_ >> call_location_);
110 XBT_DEBUG("CommRecvTransition comm:%u, mbox:%u tag:%d call_loc:%s", comm_, mbox_, tag_, call_location_.c_str());
112 std::string CommRecvTransition::to_string(bool verbose) const
114 return xbt::string_printf("iRecv(mbox=%u)", mbox_);
116 bool CommRecvTransition::depends(const Transition* other) const
118 if (other->type_ < type_)
119 return other->depends(this);
121 // Actions executed by the same actor are always dependent
122 if (other->aid_ == aid_)
125 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
126 return mbox_ == recv->mbox_;
128 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
131 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
132 if (mbox_ != test->mbox_)
135 if ((aid_ != test->sender_) && (aid_ != test->receiver_))
138 // If the test is checking a paired comm already, we're independent!
139 // If we happen to make up that pair, then we're dependent...
140 if (test->comm_ != comm_)
143 return true; // DEP with other send transitions
146 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
150 if (mbox_ != wait->mbox_)
153 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
156 // If the wait is waiting on a paired comm already, we're independent!
157 // If we happen to make up that pair, then we're dependent...
158 if ((aid_ != wait->aid_) && wait->comm_ != comm_)
161 return true; // DEP with other wait transitions
164 return false; // Comm transitions are INDEP with non-comm transitions
167 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_, int tag_)
168 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered), comm_(comm_), mbox_(mbox_), tag_(tag_)
171 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
172 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
174 xbt_assert(stream >> comm_ >> mbox_ >> tag_ >> call_location_);
175 XBT_DEBUG("SendTransition comm:%u mbox:%u tag:%d call_loc:%s", comm_, mbox_, tag_, call_location_.c_str());
177 std::string CommSendTransition::to_string(bool verbose = false) const
179 return xbt::string_printf("iSend(mbox=%u)", mbox_);
182 bool CommSendTransition::depends(const Transition* other) const
184 if (other->type_ < type_)
185 return other->depends(this);
187 // Actions executed by the same actor are always dependent
188 if (other->aid_ == aid_)
191 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
192 return mbox_ == other_isend->mbox_;
194 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
197 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
198 if (mbox_ != test->mbox_)
201 if ((aid_ != test->sender_) && (aid_ != test->receiver_))
204 // If the test is checking a paired comm already, we're independent!
205 // If we happen to make up that pair, then we're dependent...
206 if (test->comm_ != comm_)
209 return true; // DEP with other test transitions
212 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
216 if (mbox_ != wait->mbox_)
219 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_))
222 // If the wait is waiting on a paired comm already, we're independent!
223 // If we happen to make up that pair, then we're dependent...
224 if ((aid_ != wait->aid_) && wait->comm_ != comm_)
227 return true; // DEP with other wait transitions
230 return false; // Comm transitions are INDEP with non-comm transitions
233 } // namespace simgrid::mc