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_ >>
40 XBT_DEBUG("CommWaitTransition %s comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR
41 " rbuff:%" PRIxPTR " size:%zu",
42 (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
44 std::string CommWaitTransition::to_string(bool verbose) const
46 auto res = xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s", sender_, receiver_, mbox_,
47 (timeout_ ? "timeout" : "no timeout"));
49 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
50 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
55 bool CommWaitTransition::depends(const Transition* other) const
57 if (other->type_ < type_)
58 return other->depends(this);
60 // Actions executed by the same actor are always dependent
61 if (other->aid_ == aid_)
64 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
65 if (timeout_ || wait->timeout_)
66 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
69 return false; // Comm transitions are INDEP with non-comm transitions
71 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, uintptr_t comm_, aid_t sender_,
72 aid_t receiver_, unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_,
74 : Transition(Type::COMM_TEST, issuer, times_considered)
77 , receiver_(receiver_)
84 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
85 : Transition(Type::COMM_TEST, issuer, times_considered)
87 xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_ >> user_fun_call_);
88 XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
90 comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
92 std::string CommTestTransition::to_string(bool verbose) const
94 auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
96 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
97 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
102 bool CommTestTransition::depends(const Transition* other) const
104 if (other->type_ < type_)
105 return other->depends(this);
107 // Actions executed by the same actor are always dependent
108 if (other->aid_ == aid_)
111 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
112 return false; // Test & Test are independent
114 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
116 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
118 /* Wait & Test are independent */
122 return false; // Comm transitions are INDEP with non-comm transitions
125 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, uintptr_t comm_, unsigned mbox_,
126 uintptr_t rbuff_, int tag_)
127 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
134 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
135 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
137 xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_ >> user_fun_call_);
139 std::string CommRecvTransition::to_string(bool verbose) const
141 auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
143 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
147 bool CommRecvTransition::depends(const Transition* other) const
149 if (other->type_ < type_)
150 return other->depends(this);
152 // Actions executed by the same actor are always dependent
153 if (other->aid_ == aid_)
156 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
157 return mbox_ == recv->mbox_;
159 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
162 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
163 if (mbox_ != test->mbox_)
166 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
169 // If the test is checking a paired comm already, we're independent!
170 // If we happen to make up that pair, then we're dependent...
171 if (test->comm_ != comm_)
174 return true; // DEP with other send transitions
177 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
181 if (mbox_ != wait->mbox_)
184 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
187 // If the wait is waiting on a paired comm already, we're independent!
188 // If we happen to make up that pair, then we're dependent...
189 if ((aid_ != wait->aid_) && wait->comm_ != comm_)
192 return true; // DEP with other wait transitions
195 return false; // Comm transitions are INDEP with non-comm transitions
198 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, uintptr_t comm_, unsigned mbox_,
199 uintptr_t sbuff_, size_t size_, int tag_)
200 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
208 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
209 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
211 xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_ >> user_fun_call_);
212 XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
214 std::string CommSendTransition::to_string(bool verbose = false) const
216 auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
218 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
223 bool CommSendTransition::depends(const Transition* other) const
225 if (other->type_ < type_)
226 return other->depends(this);
228 // Actions executed by the same actor are always dependent
229 if (other->aid_ == aid_)
232 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
233 return mbox_ == other_isend->mbox_;
235 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
238 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
239 if (mbox_ != test->mbox_)
242 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
245 // If the test is checking a paired comm already, we're independent!
246 // If we happen to make up that pair, then we're dependent...
247 if (test->comm_ != comm_)
250 return true; // DEP with other test transitions
253 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
257 if (mbox_ != wait->mbox_)
260 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
263 // If the wait is waiting on a paired comm already, we're independent!
264 // If we happen to make up that pair, then we're dependent...
265 if ((aid_ != wait->aid_) && wait->comm_ != comm_)
268 return true; // DEP with other wait transitions
271 return false; // Comm transitions are INDEP with non-comm transitions
274 } // namespace simgrid::mc