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 "xbt/asserts.h"
9 #include "xbt/string.hpp"
11 #include "src/mc/ModelChecker.hpp"
12 #include "src/mc/api/RemoteApp.hpp"
13 #include "src/mc/api/State.hpp"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition,
19 "Logging specific to MC transitions about communications");
21 namespace simgrid::mc {
23 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
24 : Transition(Type::COMM_WAIT, issuer, times_considered)
26 xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
27 XBT_DEBUG("CommWaitTransition %s comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR
28 " rbuff:%" PRIxPTR " size:%zu",
29 (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
31 std::string CommWaitTransition::to_string(bool verbose) const
33 auto res = xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s", sender_, receiver_, mbox_,
34 (timeout_ ? "timeout" : "no timeout"));
36 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
37 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
42 bool CommWaitTransition::depends(const Transition* other) const
44 if (other->type_ < type_)
45 return other->depends(this);
47 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
48 if (timeout_ || wait->timeout_)
49 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
51 if (sbuff_ == wait->sbuff_ && rbuff_ == wait->rbuff_)
53 if (sbuff_ != 0 && rbuff_ != 0 && wait->sbuff_ != 0 && wait->rbuff_ != 0 && rbuff_ != wait->sbuff_ &&
54 rbuff_ != wait->rbuff_ && rbuff_ != sbuff_)
60 return false; // Comm transitions are INDEP with non-comm transitions
62 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
63 : Transition(Type::COMM_TEST, issuer, times_considered)
65 xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
66 XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
68 comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
70 std::string CommTestTransition::to_string(bool verbose) const
72 auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
74 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
75 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
80 bool CommTestTransition::depends(const Transition* other) const
83 if (other->type_ < type_)
84 return other->depends(this);
86 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
87 return false; // Test & Test are independent
89 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
91 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
93 /* Wait & Test are independent */
97 return false; // Comm transitions are INDEP with non-comm transitions
100 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
101 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
103 xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
105 std::string CommRecvTransition::to_string(bool verbose) const
107 auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
109 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
113 bool CommRecvTransition::depends(const Transition* other) const
115 if (other->type_ < type_)
116 return other->depends(this);
118 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
119 return mbox_ == recv->mbox_;
121 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
124 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
125 if (mbox_ != test->mbox_)
128 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
131 return true; // DEP with other send transitions
134 if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
138 if (mbox_ != wait->mbox_)
141 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
144 return true; // DEP with other wait transitions
147 return false; // Comm transitions are INDEP with non-comm transitions
150 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
151 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
153 xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
154 XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
156 std::string CommSendTransition::to_string(bool verbose = false) const
158 auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
160 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
165 bool CommSendTransition::depends(const Transition* other) const
167 if (other->type_ < type_)
168 return other->depends(this);
170 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
171 return mbox_ == other_isend->mbox_;
173 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
176 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
177 if (mbox_ != test->mbox_)
180 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
183 return true; // DEP with other test transitions
186 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
190 if (mbox_ != wait->mbox_)
193 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
196 return true; // DEP with other wait transitions
199 return false; // Comm transitions are INDEP with non-comm transitions
202 } // namespace simgrid::mc