1 /* Copyright (c) 2015-2022. 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 "xbt/asserts.h"
8 #include <simgrid/config.h>
10 #include "src/mc/ModelChecker.hpp"
11 #include "src/mc/Session.hpp"
12 #include "src/mc/api/State.hpp"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition,
18 "Logging specific to MC transitions about communications");
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 (aid_ == other->aid_)
47 if (other->type_ < type_)
48 return other->depends(this);
50 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
51 if (timeout_ || wait->timeout_)
52 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
54 if (sbuff_ == wait->sbuff_ && rbuff_ == wait->rbuff_)
56 if (sbuff_ != 0 && rbuff_ != 0 && wait->sbuff_ != 0 && wait->rbuff_ != 0 && rbuff_ != wait->sbuff_ &&
57 rbuff_ != wait->rbuff_ && rbuff_ != sbuff_)
63 return false; // Comm transitions are INDEP with non-comm transitions
65 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
66 : Transition(Type::COMM_TEST, issuer, times_considered)
68 xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
69 XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
71 comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
73 std::string CommTestTransition::to_string(bool verbose) const
75 auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
77 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
78 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
83 bool CommTestTransition::depends(const Transition* other) const
85 if (aid_ == other->aid_)
88 if (other->type_ < type_)
89 return other->depends(this);
91 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
92 return false; // Test & Test are independent
94 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
96 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
98 /* Wait & Test are independent */
102 return false; // Comm transitions are INDEP with non-comm transitions
105 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
106 : Transition(Type::COMM_RECV, issuer, times_considered)
108 xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
110 std::string CommRecvTransition::to_string(bool verbose) const
112 auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
114 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
118 bool CommRecvTransition::depends(const Transition* other) const
120 if (aid_ == other->aid_)
123 if (other->type_ < type_)
124 return other->depends(this);
126 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
127 return mbox_ == recv->mbox_;
129 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
132 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
133 if (mbox_ != test->mbox_)
136 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
139 return true; // DEP with other send transitions
142 if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
146 if (mbox_ != wait->mbox_)
149 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
152 return true; // DEP with other wait transitions
155 return false; // Comm transitions are INDEP with non-comm transitions
158 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
159 : Transition(Type::COMM_SEND, issuer, times_considered)
161 xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
162 XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
164 std::string CommSendTransition::to_string(bool verbose = false) const
166 auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
168 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
173 bool CommSendTransition::depends(const Transition* other) const
175 if (aid_ == other->aid_)
178 if (other->type_ < type_)
179 return other->depends(this);
181 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
182 return mbox_ == other_isend->mbox_;
184 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
187 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
188 if (mbox_ != test->mbox_)
191 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
194 return true; // DEP with other test transitions
197 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
201 if (mbox_ != wait->mbox_)
204 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
207 return true; // DEP with other wait transitions
210 return false; // Comm transitions are INDEP with non-comm transitions
214 } // namespace simgrid