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("%ld: WaitComm(from %ld to %ld, mbox=%u, %s", aid_, 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 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
64 : Transition(Type::COMM_TEST, issuer, times_considered)
66 xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
67 XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
69 comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
71 std::string CommTestTransition::to_string(bool verbose) const
73 auto res = xbt::string_printf("%ld: TestComm(from %ld to %ld, mbox=%u", aid_, sender_, receiver_, mbox_);
75 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
76 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
81 bool CommTestTransition::depends(const Transition* other) const
83 if (aid_ == other->aid_)
86 if (other->type_ < type_)
87 return other->depends(this);
89 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
90 return false; // Test & Test are independent
92 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
94 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
96 /* Wait & Test are independent */
103 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
104 : Transition(Type::COMM_RECV, issuer, times_considered)
106 xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
108 std::string CommRecvTransition::to_string(bool verbose) const
110 auto res = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_);
112 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
116 bool CommRecvTransition::depends(const Transition* other) const
118 if (aid_ == other->aid_)
121 if (other->type_ < type_)
122 return other->depends(this);
124 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
125 return mbox_ == recv->mbox_;
127 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
130 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
131 if (mbox_ != test->mbox_)
134 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
138 if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
142 if (mbox_ != wait->mbox_)
145 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
152 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
153 : Transition(Type::COMM_SEND, issuer, times_considered)
155 xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
156 XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
158 std::string CommSendTransition::to_string(bool verbose = false) const
160 auto res = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_);
162 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
167 bool CommSendTransition::depends(const Transition* other) const
169 if (aid_ == other->aid_)
172 if (other->type_ < type_)
173 return other->depends(this);
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_))
189 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
193 if (mbox_ != wait->mbox_)
196 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
204 } // namespace simgrid