X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4118c5ef84abd079c5b785e9e72bb5a1a9ac129d..34bbd19b02db1fb34e82247af7ed00c0fc10d41d:/src/mc/api/TransitionComm.cpp diff --git a/src/mc/api/TransitionComm.cpp b/src/mc/api/TransitionComm.cpp index 2f86ceaa44..0a5d871e66 100644 --- a/src/mc/api/TransitionComm.cpp +++ b/src/mc/api/TransitionComm.cpp @@ -23,17 +23,17 @@ namespace mc { CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream) : Transition(Type::COMM_WAIT, issuer, times_considered) { - stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_; - XBT_DEBUG("CommWaitTransition %s comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu", - (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, src_buff_, dst_buff_, size_); + xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_); + XBT_DEBUG("CommWaitTransition %s comm:%lx, sender:%ld receiver:%ld mbox:%u sbuff:%lx rbuff:%lx size:%zu", + (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_); } std::string CommWaitTransition::to_string(bool verbose) const { auto res = xbt::string_printf("%ld: WaitComm(from %ld to %ld, mbox=%u, %s", aid_, sender_, receiver_, mbox_, (timeout_ ? "timeout" : "no timeout")); if (verbose) { - res += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_); - res += ", dst_buff=" + xbt::string_printf("%p", dst_buff_); + res += ", sbuff=" + xbt::string_printf("%lx", sbuff_) + ", size=" + std::to_string(size_); + res += ", rbuff=" + xbt::string_printf("%lx", rbuff_); } res += ")"; return res; @@ -43,26 +43,17 @@ bool CommWaitTransition::depends(const Transition* other) const if (aid_ == other->aid_) return false; - if (dynamic_cast(other) != nullptr) - return false; // Random is indep with any transition - - if (auto* recv = dynamic_cast(other)) - return recv->depends(this); - - if (auto* send = dynamic_cast(other)) - return send->depends(this); - - if (auto* test = dynamic_cast(other)) - return test->depends(this); + if (other->type_ < type_) + return other->depends(this); if (const auto* wait = dynamic_cast(other)) { if (timeout_ || wait->timeout_) return true; // Timeouts are not considered by the independence theorem, thus assumed dependent - if (src_buff_ == wait->src_buff_ && dst_buff_ == wait->dst_buff_) + if (sbuff_ == wait->sbuff_ && rbuff_ == wait->rbuff_) return false; - if (src_buff_ != nullptr && dst_buff_ != nullptr && wait->src_buff_ != nullptr && wait->dst_buff_ != nullptr && - dst_buff_ != wait->src_buff_ && dst_buff_ != wait->dst_buff_ && dst_buff_ != src_buff_) + if (sbuff_ != 0 && rbuff_ != 0 && wait->sbuff_ != 0 && wait->rbuff_ != 0 && rbuff_ != wait->sbuff_ && + rbuff_ != wait->rbuff_ && rbuff_ != sbuff_) return false; } @@ -71,16 +62,16 @@ bool CommWaitTransition::depends(const Transition* other) const CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream) : Transition(Type::COMM_TEST, issuer, times_considered) { - stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> src_buff_ >> dst_buff_ >> size_; - XBT_DEBUG("CommTestTransition comm:%p, sender:%ld receiver:%ld mbox:%u sbuff:%p rbuff:%p size:%zu", comm_, sender_, - receiver_, mbox_, src_buff_, dst_buff_, size_); + xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_); + XBT_DEBUG("CommTestTransition comm:%lx, sender:%ld receiver:%ld mbox:%u sbuff:%lx rbuff:%lx size:%zu", comm_, sender_, + receiver_, mbox_, sbuff_, rbuff_, size_); } std::string CommTestTransition::to_string(bool verbose) const { auto res = xbt::string_printf("%ld: TestComm(from %ld to %ld, mbox=%u", aid_, sender_, receiver_, mbox_); if (verbose) { - res += ", src_buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_); - res += ", dst_buff=" + xbt::string_printf("%p", dst_buff_); + res += ", sbuff=" + xbt::string_printf("%lx", sbuff_) + ", size=" + std::to_string(size_); + res += ", rbuff=" + xbt::string_printf("%lx", rbuff_); } res += ")"; return res; @@ -90,14 +81,8 @@ bool CommTestTransition::depends(const Transition* other) const if (aid_ == other->aid_) return false; - if (dynamic_cast(other) != nullptr) - return false; // Test & Random are independent (Random is independent with anything) - - if (auto* recv = dynamic_cast(other)) - return recv->depends(this); // Recv < Test (alphabetical ordering) - - if (auto* send = dynamic_cast(other)) - return send->depends(this); // Send < Test (alphabetical ordering) + if (other->type_ < type_) + return other->depends(this); if (dynamic_cast(other) != nullptr) return false; // Test & Test are independent @@ -116,13 +101,13 @@ bool CommTestTransition::depends(const Transition* other) const CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream) : Transition(Type::COMM_RECV, issuer, times_considered) { - stream >> mbox_ >> dst_buff_; + xbt_assert(stream >> comm_ >> mbox_ >> rbuff_); } std::string CommRecvTransition::to_string(bool verbose) const { auto res = xbt::string_printf("%ld: iRecv(mbox=%u", aid_, mbox_); if (verbose) - res += ", buff=" + xbt::string_printf("%p", dst_buff_); + res += ", rbuff=" + xbt::string_printf("%lx", rbuff_); res += ")"; return res; } @@ -131,8 +116,8 @@ bool CommRecvTransition::depends(const Transition* other) const if (aid_ == other->aid_) return false; - if (dynamic_cast(other) != nullptr) - return false; // Random is indep with any transition + if (other->type_ < type_) + return other->depends(this); if (const auto* recv = dynamic_cast(other)) return mbox_ == recv->mbox_; @@ -144,7 +129,7 @@ bool CommRecvTransition::depends(const Transition* other) const if (mbox_ != test->mbox_) return false; - if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->dst_buff_ != dst_buff_)) + if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_)) return false; } @@ -155,7 +140,7 @@ bool CommRecvTransition::depends(const Transition* other) const if (mbox_ != wait->mbox_) return false; - if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->dst_buff_ != dst_buff_)) + if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_)) return false; } @@ -165,25 +150,70 @@ bool CommRecvTransition::depends(const Transition* other) const CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream) : Transition(Type::COMM_SEND, issuer, times_considered) { - stream >> mbox_ >> src_buff_ >> size_; - XBT_DEBUG("SendTransition mbox:%u buff:%p size:%zu", mbox_, src_buff_, size_); + xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_); + XBT_DEBUG("SendTransition comm:%lx mbox:%u sbuff:%lx size:%zu", comm_, mbox_, sbuff_, size_); } std::string CommSendTransition::to_string(bool verbose = false) const { auto res = xbt::string_printf("%ld: iSend(mbox=%u", aid_, mbox_); if (verbose) - res += ", buff=" + xbt::string_printf("%p", src_buff_) + ", size=" + std::to_string(size_); + res += ", sbuff=" + xbt::string_printf("%lx", sbuff_) + ", size=" + std::to_string(size_); res += ")"; return res; } +TestAnyTransition::TestAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream) + : Transition(Type::TESTANY, issuer, times_considered) +{ + int size; + xbt_assert(stream >> size); + for (int i = 0; i < size; i++) { + Transition* t = deserialize_transition(issuer, 0, stream); + XBT_DEBUG("TestAny received a transition %s", t->to_string(true).c_str()); + transitions_.push_back(t); + } +} +std::string TestAnyTransition::to_string(bool verbose) const +{ + auto res = xbt::string_printf("%ld: TestAny{ ", aid_); + for (auto const* t : transitions_) + res += t->to_string(verbose); + res += "}"; + return res; +} +bool TestAnyTransition::depends(const Transition* other) const +{ + return transitions_[times_considered_]->depends(other); +} +WaitAnyTransition::WaitAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream) + : Transition(Type::WAITANY, issuer, times_considered) +{ + int size; + xbt_assert(stream >> size); + for (int i = 0; i < size; i++) { + Transition* t = deserialize_transition(issuer, 0, stream); + transitions_.push_back(t); + } +} +std::string WaitAnyTransition::to_string(bool verbose) const +{ + auto res = xbt::string_printf("%ld: WaitAny{ ", aid_); + for (auto const* t : transitions_) + res += t->to_string(verbose); + res += "}"; + return res; +} +bool WaitAnyTransition::depends(const Transition* other) const +{ + return transitions_[times_considered_]->depends(other); +} bool CommSendTransition::depends(const Transition* other) const { if (aid_ == other->aid_) return false; - if (dynamic_cast(other) != nullptr) - return false; // Random is indep with any transition + if (other->type_ < type_) + return other->depends(this); if (const auto* other_isend = dynamic_cast(other)) return mbox_ == other_isend->mbox_; @@ -195,7 +225,7 @@ bool CommSendTransition::depends(const Transition* other) const if (mbox_ != test->mbox_) return false; - if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->src_buff_ != src_buff_)) + if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_)) return false; } @@ -206,19 +236,21 @@ bool CommSendTransition::depends(const Transition* other) const if (mbox_ != wait->mbox_) return false; - if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->src_buff_ != src_buff_)) + if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_)) return false; } return true; } -Transition* recv_transition(aid_t issuer, int times_considered, char* buffer) +Transition* deserialize_transition(aid_t issuer, int times_considered, std::stringstream& stream) { - std::stringstream stream(buffer); short type; - stream >> type; - Transition::Type simcall = static_cast(type); + xbt_assert(stream >> type); + xbt_assert(type >= 0 && type <= static_cast(Transition::Type::UNKNOWN), "Invalid transition type %d received", + type); + + auto simcall = static_cast(type); switch (simcall) { case Transition::Type::COMM_RECV: @@ -230,14 +262,18 @@ Transition* recv_transition(aid_t issuer, int times_considered, char* buffer) case Transition::Type::COMM_WAIT: return new CommWaitTransition(issuer, times_considered, stream); + case Transition::Type::TESTANY: + return new TestAnyTransition(issuer, times_considered, stream); + case Transition::Type::WAITANY: + return new WaitAnyTransition(issuer, times_considered, stream); + case Transition::Type::RANDOM: return new RandomTransition(issuer, times_considered, stream); case Transition::Type::UNKNOWN: return new Transition(Transition::Type::UNKNOWN, issuer, times_considered); - default: - xbt_die("recv_transition of type %s unimplemented", Transition::to_c_str(simcall)); } + THROW_IMPOSSIBLE; // Some compilers don't detect that each branch of the above switch has a return } } // namespace mc