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/api/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, char* buffer)
24 : Transition(Type::COMM_WAIT, issuer, times_considered)
26 std::stringstream stream(buffer);
27 stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_;
28 XBT_DEBUG("CommWaitTransition %s comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu",
29 (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, src_buff_, dst_buff_, 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 += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
37 res += ", dst_buff=" + xbt::string_printf("%p", dst_buff_);
42 bool CommWaitTransition::depends(const Transition* other) const
44 if (aid_ == other->aid_)
47 if (dynamic_cast<const RandomTransition*>(other) != nullptr)
48 return false; // Random is indep with any transition
50 if (auto* recv = dynamic_cast<const CommRecvTransition*>(other))
51 return recv->depends(this);
53 if (auto* send = dynamic_cast<const CommSendTransition*>(other))
54 return send->depends(this);
56 if (auto* test = dynamic_cast<const CommTestTransition*>(other))
57 return test->depends(this);
59 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
60 if (timeout_ || wait->timeout_)
61 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
63 if (src_buff_ == wait->src_buff_ && dst_buff_ == wait->dst_buff_)
65 if (src_buff_ != nullptr && dst_buff_ != nullptr && wait->src_buff_ != nullptr && wait->dst_buff_ != nullptr &&
66 dst_buff_ != wait->src_buff_ && dst_buff_ != wait->dst_buff_ && dst_buff_ != src_buff_)
72 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, char* buffer)
73 : Transition(Type::COMM_TEST, issuer, times_considered)
75 std::stringstream stream(buffer);
76 stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_;
77 XBT_DEBUG("CommTestTransition comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu", comm_, sender_,
78 receiver_, mbox_, src_buff_, dst_buff_, size_);
80 std::string CommTestTransition::to_string(bool verbose) const
82 auto res = xbt::string_printf("%ld: TestComm(from %ld to %ld, mbox=%u", aid_, sender_, receiver_, mbox_);
84 res += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
85 res += ", dst_buff=" + xbt::string_printf("%p", dst_buff_);
90 bool CommTestTransition::depends(const Transition* other) const
92 if (aid_ == other->aid_)
95 if (dynamic_cast<const RandomTransition*>(other) != nullptr)
96 return false; // Test & Random are independent (Random is independent with anything)
98 if (auto* recv = dynamic_cast<const CommRecvTransition*>(other))
99 return recv->depends(this); // Recv < Test (alphabetical ordering)
101 if (auto* send = dynamic_cast<const CommSendTransition*>(other))
102 return send->depends(this); // Send < Test (alphabetical ordering)
104 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
105 return false; // Test & Test are independent
107 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
109 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
111 /* Wait & Test are independent */
118 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, char* buffer)
119 : Transition(Type::COMM_RECV, issuer, times_considered)
121 std::stringstream stream(buffer);
122 stream >> mbox_ >> dst_buff_;
124 std::string CommRecvTransition::to_string(bool verbose) const
126 auto res = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_);
128 res += ", buff=" + xbt::string_printf("%p", dst_buff_);
132 bool CommRecvTransition::depends(const Transition* other) const
134 if (aid_ == other->aid_)
137 if (dynamic_cast<const RandomTransition*>(other) != nullptr)
138 return false; // Random is indep with any transition
140 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
141 return mbox_ == recv->mbox_;
143 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
146 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
147 if (mbox_ != test->mbox_)
150 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->dst_buff_ != dst_buff_))
154 if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
158 if (mbox_ != wait->mbox_)
161 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->dst_buff_ != dst_buff_))
168 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, char* buffer)
169 : Transition(Type::COMM_SEND, issuer, times_considered)
171 std::stringstream stream(buffer);
172 stream >> mbox_ >> src_buff_ >> size_;
173 XBT_DEBUG("SendTransition mbox:%u buff:%p size:%zu", mbox_, src_buff_, size_);
175 std::string CommSendTransition::to_string(bool verbose = false) const
177 auto res = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_);
179 res += ", buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
184 bool CommSendTransition::depends(const Transition* other) const
186 if (aid_ == other->aid_)
189 if (dynamic_cast<const RandomTransition*>(other) != nullptr)
190 return false; // Random is indep with any transition
192 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
193 return mbox_ == other_isend->mbox_;
195 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
198 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
199 if (mbox_ != test->mbox_)
202 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->src_buff_ != src_buff_))
206 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
210 if (mbox_ != wait->mbox_)
213 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->src_buff_ != src_buff_))
220 Transition* recv_transition(aid_t issuer, int times_considered, Transition::Type simcall, char* buffer)
223 case Transition::Type::COMM_RECV:
224 return new CommRecvTransition(issuer, times_considered, buffer);
225 case Transition::Type::COMM_SEND:
226 return new CommSendTransition(issuer, times_considered, buffer);
227 case Transition::Type::COMM_TEST:
228 return new CommTestTransition(issuer, times_considered, buffer);
229 case Transition::Type::COMM_WAIT:
230 return new CommWaitTransition(issuer, times_considered, buffer);
232 case Transition::Type::RANDOM:
233 return new RandomTransition(issuer, times_considered, buffer);
235 case Transition::Type::UNKNOWN:
236 return new Transition(Transition::Type::UNKNOWN, issuer, times_considered);
238 xbt_die("recv_transition of type %s unimplemented", Transition::to_c_str(simcall));
243 } // namespace simgrid