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, std::stringstream& stream)
22 : Transition(Type::COMM_WAIT, issuer, times_considered)
24 xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
25 XBT_DEBUG("CommWaitTransition %s comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR
26 " rbuff:%" PRIxPTR " size:%zu",
27 (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
29 std::string CommWaitTransition::to_string(bool verbose) const
31 auto res = xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s", sender_, receiver_, mbox_,
32 (timeout_ ? "timeout" : "no timeout"));
34 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
35 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
40 bool CommWaitTransition::depends(const Transition* other) const
42 if (other->type_ < type_)
43 return other->depends(this);
45 // Actions executed by the same actor are always dependent
46 if (other->aid_ == aid_)
49 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
50 if (timeout_ || wait->timeout_)
51 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
54 return false; // Comm transitions are INDEP with non-comm transitions
56 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
57 : Transition(Type::COMM_TEST, issuer, times_considered)
59 xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
60 XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
62 comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
64 std::string CommTestTransition::to_string(bool verbose) const
66 auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
68 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
69 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
74 bool CommTestTransition::depends(const Transition* other) const
76 if (other->type_ < type_)
77 return other->depends(this);
79 // Actions executed by the same actor are always dependent
80 if (other->aid_ == aid_)
83 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
84 return false; // Test & Test are independent
86 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
88 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
90 /* Wait & Test are independent */
94 return false; // Comm transitions are INDEP with non-comm transitions
97 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
98 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
100 xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
102 std::string CommRecvTransition::to_string(bool verbose) const
104 auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
106 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
110 bool CommRecvTransition::depends(const Transition* other) const
112 if (other->type_ < type_)
113 return other->depends(this);
115 // Actions executed by the same actor are always dependent
116 if (other->aid_ == aid_)
119 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
120 return mbox_ == recv->mbox_;
122 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
125 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
126 if (mbox_ != test->mbox_)
129 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
132 return true; // DEP with other send transitions
135 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
139 if (mbox_ != wait->mbox_)
142 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
145 return true; // DEP with other wait transitions
148 return false; // Comm transitions are INDEP with non-comm transitions
151 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
152 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
154 xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
155 XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
157 std::string CommSendTransition::to_string(bool verbose = false) const
159 auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
161 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
166 bool CommSendTransition::depends(const Transition* other) const
168 if (other->type_ < type_)
169 return other->depends(this);
171 // Actions executed by the same actor are always dependent
172 if (other->aid_ == aid_)
175 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
176 return mbox_ == other_isend->mbox_;
178 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
181 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
182 if (mbox_ != test->mbox_)
185 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
188 return true; // DEP with other test transitions
191 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
195 if (mbox_ != wait->mbox_)
198 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
201 return true; // DEP with other wait transitions
204 return false; // Comm transitions are INDEP with non-comm transitions
207 } // namespace simgrid::mc