Logo AND Algorithmique Numérique Distribuée

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