Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix non-MC builds when MC-only dependencies are missing
[simgrid.git] / src / mc / transition / TransitionComm.cpp
1 /* Copyright (c) 2015-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
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"
12
13 #include <inttypes.h>
14 #include <sstream>
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_comm, mc_transition,
17                                 "Logging specific to MC transitions about communications");
18
19 namespace simgrid::mc {
20
21 CommWaitTransition::CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream)
22     : Transition(Type::COMM_WAIT, issuer, times_considered)
23 {
24   xbt_assert(stream >> timeout_ >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
25   XBT_DEBUG("CommWaitTransition %s comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR
26             " rbuff:%" PRIxPTR " size:%zu",
27             (timeout_ ? "timeout" : "no-timeout"), comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
28 }
29 std::string CommWaitTransition::to_string(bool verbose) const
30 {
31   auto res = xbt::string_printf("WaitComm(from %ld to %ld, mbox=%u, %s", sender_, receiver_, mbox_,
32                                 (timeout_ ? "timeout" : "no timeout"));
33   if (verbose) {
34     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
35     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
36   }
37   res += ")";
38   return res;
39 }
40 bool CommWaitTransition::depends(const Transition* other) const
41 {
42   if (other->type_ < type_)
43     return other->depends(this);
44
45   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
46     if (timeout_ || wait->timeout_)
47       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
48
49     if (sbuff_ == wait->sbuff_ && rbuff_ == wait->rbuff_)
50       return false;
51     if (sbuff_ != 0 && rbuff_ != 0 && wait->sbuff_ != 0 && wait->rbuff_ != 0 && rbuff_ != wait->sbuff_ &&
52         rbuff_ != wait->rbuff_ && rbuff_ != sbuff_)
53       return false;
54
55     return true;
56   }
57
58   return false; // Comm transitions are INDEP with non-comm transitions
59 }
60 CommTestTransition::CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream)
61     : Transition(Type::COMM_TEST, issuer, times_considered)
62 {
63   xbt_assert(stream >> comm_ >> sender_ >> receiver_ >> mbox_ >> sbuff_ >> rbuff_ >> size_);
64   XBT_DEBUG("CommTestTransition comm:%" PRIxPTR ", sender:%ld receiver:%ld mbox:%u sbuff:%" PRIxPTR " rbuff:%" PRIxPTR
65             " size:%zu",
66             comm_, sender_, receiver_, mbox_, sbuff_, rbuff_, size_);
67 }
68 std::string CommTestTransition::to_string(bool verbose) const
69 {
70   auto res = xbt::string_printf("TestComm(from %ld to %ld, mbox=%u", sender_, receiver_, mbox_);
71   if (verbose) {
72     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
73     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
74   }
75   res += ")";
76   return res;
77 }
78 bool CommTestTransition::depends(const Transition* other) const
79 {
80   if (other->type_ < type_)
81     return other->depends(this);
82
83   if (dynamic_cast<const CommTestTransition*>(other) != nullptr)
84     return false; // Test & Test are independent
85
86   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
87     if (wait->timeout_)
88       return true; // Timeouts are not considered by the independence theorem, thus assumed dependent
89
90     /* Wait & Test are independent */
91     return false;
92   }
93
94   return false; // Comm transitions are INDEP with non-comm transitions
95 }
96
97 CommRecvTransition::CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream)
98     : Transition(Type::COMM_ASYNC_RECV, issuer, times_considered)
99 {
100   xbt_assert(stream >> comm_ >> mbox_ >> rbuff_ >> tag_);
101 }
102 std::string CommRecvTransition::to_string(bool verbose) const
103 {
104   auto res = xbt::string_printf("iRecv(mbox=%u", mbox_);
105   if (verbose)
106     res += ", rbuff=" + xbt::string_printf("%" PRIxPTR, rbuff_);
107   res += ")";
108   return res;
109 }
110 bool CommRecvTransition::depends(const Transition* other) const
111 {
112   if (other->type_ < type_)
113     return other->depends(this);
114
115   if (const auto* recv = dynamic_cast<const CommRecvTransition*>(other))
116     return mbox_ == recv->mbox_;
117
118   if (dynamic_cast<const CommSendTransition*>(other) != nullptr)
119     return false;
120
121   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
122     if (mbox_ != test->mbox_)
123       return false;
124
125     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->rbuff_ != rbuff_))
126       return false;
127
128     return true; // DEP with other send transitions
129   }
130
131   if (auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
132     if (wait->timeout_)
133       return true;
134
135     if (mbox_ != wait->mbox_)
136       return false;
137
138     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->rbuff_ != rbuff_))
139       return false;
140
141     return true; // DEP with other wait transitions
142   }
143
144   return false; // Comm transitions are INDEP with non-comm transitions
145 }
146
147 CommSendTransition::CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream)
148     : Transition(Type::COMM_ASYNC_SEND, issuer, times_considered)
149 {
150   xbt_assert(stream >> comm_ >> mbox_ >> sbuff_ >> size_ >> tag_);
151   XBT_DEBUG("SendTransition comm:%" PRIxPTR " mbox:%u sbuff:%" PRIxPTR " size:%zu", comm_, mbox_, sbuff_, size_);
152 }
153 std::string CommSendTransition::to_string(bool verbose = false) const
154 {
155   auto res = xbt::string_printf("iSend(mbox=%u", mbox_);
156   if (verbose)
157     res += ", sbuff=" + xbt::string_printf("%" PRIxPTR, sbuff_) + ", size=" + std::to_string(size_);
158   res += ")";
159   return res;
160 }
161
162 bool CommSendTransition::depends(const Transition* other) const
163 {
164   if (other->type_ < type_)
165     return other->depends(this);
166
167   if (const auto* other_isend = dynamic_cast<const CommSendTransition*>(other))
168     return mbox_ == other_isend->mbox_;
169
170   if (dynamic_cast<const CommRecvTransition*>(other) != nullptr)
171     return false;
172
173   if (const auto* test = dynamic_cast<const CommTestTransition*>(other)) {
174     if (mbox_ != test->mbox_)
175       return false;
176
177     if ((aid_ != test->sender_) && (aid_ != test->receiver_) && (test->sbuff_ != sbuff_))
178       return false;
179
180     return true; // DEP with other test transitions
181   }
182
183   if (const auto* wait = dynamic_cast<const CommWaitTransition*>(other)) {
184     if (wait->timeout_)
185       return true;
186
187     if (mbox_ != wait->mbox_)
188       return false;
189
190     if ((aid_ != wait->sender_) && (aid_ != wait->receiver_) && (wait->sbuff_ != sbuff_))
191       return false;
192
193     return true; // DEP with other wait transitions
194   }
195
196   return false; // Comm transitions are INDEP with non-comm transitions
197 }
198
199 } // namespace simgrid::mc