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 "src/mc/api/RemoteApp.hpp"
9 #include "src/mc/api/State.hpp"
10 #include "xbt/asserts.h"
11 #include "xbt/string.hpp"
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition,
17 "Logging specific to MC transitions about communications");
19 namespace simgrid::mc {
21 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
22 : Transition(Type::COMM_WAIT, issuer, times_considered)
24 xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_ >>
26 XBT_DEBUG("CommWaitTransition %s comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR
27 " rbuff:%" PRIxPTR " size:%zu",
28 (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
30 std::string CommWaitTransition::to_string(bool verbose) const
32 auto res = xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s", sender_, receiver_, mbox_,
33 (timeout_ ? "timeout" : "no timeout"));
35 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
36 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
41 bool CommWaitTransition::depends(const Transition* other) const
43 if (other->type_ < type_)
44 return other->depends(this);
46 // Actions executed by the same actor are always dependent
47 if (other->aid_ == aid_)
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
55 return false; // Comm transitions are INDEP with non-comm transitions
57 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
58 : Transition(Type::COMM_TEST, issuer, times_considered)
60 xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_ >> user_fun_call_);
61 XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
63 comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
65 std::string CommTestTransition::to_string(bool verbose) const
67 auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
69 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
70 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
75 bool CommTestTransition::depends(const Transition* other) const
77 if (other->type_ < type_)
78 return other->depends(this);
80 // Actions executed by the same actor are always dependent
81 if (other->aid_ == aid_)
84 if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
85 return false; // Test & Test are independent
87 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
89 return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
91 /* Wait & Test are independent */
95 return false; // Comm transitions are INDEP with non-comm transitions
98 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
99 : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
101 xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_ >> user_fun_call_);
103 std::string CommRecvTransition::to_string(bool verbose) const
105 auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
107 res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
111 bool CommRecvTransition::depends(const Transition* other) const
113 if (other->type_ < type_)
114 return other->depends(this);
116 // Actions executed by the same actor are always dependent
117 if (other->aid_ == aid_)
120 if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
121 return mbox_ == recv->mbox_;
123 if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
126 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
127 if (mbox_ != test->mbox_)
130 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
133 return true; // DEP with other send transitions
136 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
140 if (mbox_ != wait->mbox_)
143 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
146 return true; // DEP with other wait transitions
149 return false; // Comm transitions are INDEP with non-comm transitions
152 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
153 : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
155 xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_ >> user_fun_call_);
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("iSend(mbox=%u", mbox_);
162 res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
167 bool CommSendTransition::depends(const Transition* other) const
169 if (other->type_ < type_)
170 return other->depends(this);
172 // Actions executed by the same actor are always dependent
173 if (other->aid_ == aid_)
176 if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
177 return mbox_ == other_isend->mbox_;
179 if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
182 if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
183 if (mbox_ != test->mbox_)
186 if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
189 return true; // DEP with other test transitions
192 if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
196 if (mbox_ != wait->mbox_)
199 if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
202 return true; // DEP with other wait transitions
205 return false; // Comm transitions are INDEP with non-comm transitions
208 } // namespace simgrid::mc