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_, uintptr_t sbuff_, uintptr_t rbuff_,
24 : Transition(Type::COMM_WAIT, issuer, times_considered)
29 , 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:%u, sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
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, unsigned comm_, aid_t sender_,
71 aid_t receiver_, unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_,
73 : Transition(Type::COMM_TEST, issuer, times_considered)
77 , receiver_(receiver_)
83 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
84 : Transition(Type::COMM_TEST, issuer, times_considered)
86 xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
87 XBT_DEBUG("CommTestTransition comm:%u, sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
89 comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
91 std::string CommTestTransition::to_string(bool verbose) const
93 auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
95 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
96 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
101 bool CommTestTransition::depends(const Transition* other) const
103 if (other->type_ < type_)
104 return other->depends(this);
106 // Actions executed by the same actor are always dependent
107 if (other->aid_ == aid_)
110 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
111 return false; // Test & Test are independent
113 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
115 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
117 /* Wait & Test are independent */
121 return false; // Comm transitions are INDEP with non-comm transitions
124 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_,
125 uintptr_t rbuff_, int tag_)
126 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
133 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
134 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
136 xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
138 std::string CommRecvTransition::to_string(bool verbose) const
140 auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
142 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
146 bool CommRecvTransition::depends(const Transition* other) const
148 if (other->type_ < type_)
149 return other->depends(this);
151 // Actions executed by the same actor are always dependent
152 if (other->aid_ == aid_)
155 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
156 return mbox_ == recv->mbox_;
158 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
161 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
162 if (mbox_ != test->mbox_)
165 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
168 // If the test is checking a paired comm already, we're independent!
169 // If we happen to make up that pair, then we're dependent...
170 if (test->comm_ != comm_)
173 return true; // DEP with other send transitions
176 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
180 if (mbox_ != wait->mbox_)
183 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
186 // If the wait is waiting on a paired comm already, we're independent!
187 // If we happen to make up that pair, then we're dependent...
188 if ((aid_ != wait->aid_) && wait->comm_ != comm_)
191 return true; // DEP with other wait transitions
194 return false; // Comm transitions are INDEP with non-comm transitions
197 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_,
198 uintptr_t sbuff_, size_t size_, int tag_)
199 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
207 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
208 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
210 xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
211 XBT_DEBUG("SendTransition comm:%u mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
213 std::string CommSendTransition::to_string(bool verbose = false) const
215 auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
217 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
222 bool CommSendTransition::depends(const Transition* other) const
224 if (other->type_ < type_)
225 return other->depends(this);
227 // Actions executed by the same actor are always dependent
228 if (other->aid_ == aid_)
231 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
232 return mbox_ == other_isend->mbox_;
234 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
237 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
238 if (mbox_ != test->mbox_)
241 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
244 // If the test is checking a paired comm already, we're independent!
245 // If we happen to make up that pair, then we're dependent...
246 if (test->comm_ != comm_)
249 return true; // DEP with other test transitions
252 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
256 if (mbox_ != wait->mbox_)
259 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
262 // If the wait is waiting on a paired comm already, we're independent!
263 // If we happen to make up that pair, then we're dependent...
264 if ((aid_ != wait->aid_) && wait->comm_ != comm_)
267 return true; // DEP with other wait transitions
270 return false; // Comm transitions are INDEP with non-comm transitions
273 } // namespace simgrid::mc