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* send = dynamic_cast<const CommSendTransition*>(other))
51 return send->depends(this);
53 if (auto* recv = dynamic_cast<const CommRecvTransition*>(other))
54 return recv->depends(this);
56 /* Timeouts in wait transitions are not considered by the independence theorem, thus assumed dependent */
57 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
58 if (timeout_ || wait->timeout_)
61 if (src_buff_ == wait->src_buff_ && dst_buff_ == wait->dst_buff_)
63 if (src_buff_ != nullptr && dst_buff_ != nullptr && wait->src_buff_ != nullptr && wait->dst_buff_ != nullptr &&
64 dst_buff_ != wait->src_buff_ && dst_buff_ != wait->dst_buff_ && dst_buff_ != src_buff_)
71 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, char* buffer)
72 : Transition(Type::IRECV, issuer, times_considered)
74 std::stringstream stream(buffer);
75 stream >> mbox_ >> dst_buff_;
77 std::string CommRecvTransition::to_string(bool verbose) const
79 auto res = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_);
81 res += ", buff=" + xbt::string_printf("%p", dst_buff_);
85 bool CommRecvTransition::depends(const Transition* other) const
87 if (aid_ == other->aid_)
90 if (dynamic_cast<const RandomTransition*>(other) != nullptr)
91 return false; // Random is indep with any transition
93 if (const auto* other_irecv = dynamic_cast<const CommRecvTransition*>(other))
94 return mbox_ == other_irecv->mbox_;
96 if (auto* isend = dynamic_cast<const CommSendTransition*>(other))
97 return isend->depends(this);
99 if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
103 if (mbox_ != wait->mbox_)
106 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->dst_buff_ != dst_buff_))
110 /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
113 if (dynamic_cast<ActivityTestSimcall*>(other))
120 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, char* buffer)
121 : Transition(Type::ISEND, issuer, times_considered)
123 std::stringstream stream(buffer);
124 stream >> mbox_ >> src_buff_ >> size_;
125 XBT_DEBUG("SendTransition mbox:%u buff:%p size:%zu", mbox_, src_buff_, size_);
127 std::string CommSendTransition::to_string(bool verbose = false) const
129 auto res = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_);
131 res += ", buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_);
136 bool CommSendTransition::depends(const Transition* other) const
138 if (aid_ == other->aid_)
141 if (dynamic_cast<const RandomTransition*>(other) != nullptr)
142 return false; // Random is indep with any transition
144 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
145 return mbox_ == other_isend->mbox_;
147 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
150 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
154 if (mbox_ != wait->mbox_)
157 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->src_buff_ != src_buff_))
161 /* FIXME: the following rule assumes that the result of the isend/irecv call is not stored in a buffer used in the
164 if (dynamic_cast<ActivityTestSimcall*>(other))
171 Transition* recv_transition(aid_t issuer, int times_considered, Transition::Type simcall, char* buffer)
174 case Transition::Type::COMM_WAIT:
175 return new CommWaitTransition(issuer, times_considered, buffer);
176 case Transition::Type::IRECV:
177 return new CommRecvTransition(issuer, times_considered, buffer);
178 case Transition::Type::ISEND:
179 return new CommSendTransition(issuer, times_considered, buffer);
181 case Transition::Type::RANDOM:
182 return new RandomTransition(issuer, times_considered, buffer);
184 case Transition::Type::UNKNOWN:
185 return new Transition(Transition::Type::UNKNOWN, issuer, times_considered);
187 xbt_die("recv_transition of type %s unimplemented", Transition::to_c_str(simcall));
192 } // namespace simgrid