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_, 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)
28 , receiver_(receiver_)
35 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
36 : Transition(Type::COMM_WAIT, issuer, times_considered)
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_);
43 std::string CommWaitTransition::to_string(bool verbose) const
45 auto res = xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s", sender_, receiver_, mbox_,
46 (timeout_ ? "timeout" : "no timeout"));
48 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
49 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
54 bool CommWaitTransition::depends(const Transition* other) const
56 if (other->type_ < type_)
57 return other->depends(this);
59 // Actions executed by the same actor are always dependent
60 if (other->aid_ == aid_)
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
68 return false; // Comm transitions are INDEP with non-comm transitions
70 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
71 : Transition(Type::COMM_TEST, issuer, times_considered)
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
76 comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
78 std::string CommTestTransition::to_string(bool verbose) const
80 auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
82 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
83 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
88 bool CommTestTransition::depends(const Transition* other) const
90 if (other->type_ < type_)
91 return other->depends(this);
93 // Actions executed by the same actor are always dependent
94 if (other->aid_ == aid_)
97 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
98 return false; // Test & Test are independent
100 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
102 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
104 /* Wait & Test are independent */
108 return false; // Comm transitions are INDEP with non-comm transitions
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)
120 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
121 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
123 xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
125 std::string CommRecvTransition::to_string(bool verbose) const
127 auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
129 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
133 bool CommRecvTransition::depends(const Transition* other) const
135 if (other->type_ < type_)
136 return other->depends(this);
138 // Actions executed by the same actor are always dependent
139 if (other->aid_ == aid_)
142 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
143 return mbox_ == recv->mbox_;
145 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
148 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
149 if (mbox_ != test->mbox_)
152 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
155 return true; // DEP with other send transitions
158 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
162 if (mbox_ != wait->mbox_)
165 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
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_)
173 return true; // DEP with other wait transitions
176 return false; // Comm transitions are INDEP with non-comm transitions
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)
189 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
190 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
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_);
195 std::string CommSendTransition::to_string(bool verbose = false) const
197 auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
199 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
204 bool CommSendTransition::depends(const Transition* other) const
206 if (other->type_ < type_)
207 return other->depends(this);
209 // Actions executed by the same actor are always dependent
210 if (other->aid_ == aid_)
213 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
214 return mbox_ == other_isend->mbox_;
216 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
219 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
220 if (mbox_ != test->mbox_)
223 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
226 return true; // DEP with other test transitions
229 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
233 if (mbox_ != wait->mbox_)
236 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
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_)
244 return true; // DEP with other wait transitions
247 return false; // Comm transitions are INDEP with non-comm transitions
250 } // namespace simgrid::mc