Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4a8025167c45e17fc30443ff5ede9d67b925a11a
[simgrid.git] / src / mc / transition / Transition.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/Transition.hpp"
7 #include "src/kernel/actor/Simcall.hpp"
8 #include "src/mc/explo/Exploration.hpp"
9 #include "src/mc/transition/TransitionActorJoin.hpp"
10 #include "src/mc/transition/TransitionAny.hpp"
11 #include "src/mc/transition/TransitionComm.hpp"
12 #include "src/mc/transition/TransitionObjectAccess.hpp"
13 #include "src/mc/transition/TransitionRandom.hpp"
14 #include "src/mc/transition/TransitionSynchro.hpp"
15 #include "xbt/asserts.h"
16 #include "xbt/string.hpp"
17
18 #include <sstream>
19
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_transition, mc, "Logging specific to MC transitions");
21
22 namespace simgrid::mc {
23 unsigned long Transition::executed_transitions_ = 0;
24 unsigned long Transition::replayed_transitions_ = 0;
25
26 // Do not move this to the header, to ensure that we have a vtable for Transition
27 Transition::~Transition() = default;
28
29 std::string Transition::to_string(bool) const
30 {
31   return "";
32 }
33 std::string Transition::dot_string() const
34 {
35   static constexpr std::array<const char*, 13> colors{{"blue", "red", "green3", "goldenrod", "brown", "purple",
36                                                        "magenta", "turquoise4", "gray25", "forestgreen", "hotpink",
37                                                        "lightblue", "tan"}};
38   const char* color = colors[(aid_ - 1) % colors.size()];
39
40   return xbt::string_printf("label = \"[(%ld)] %s\", color = %s, fontcolor = %s", aid_, Transition::to_c_str(type_),
41                             color, color);
42 }
43 void Transition::replay(RemoteApp& app) const
44 {
45   replayed_transitions_++;
46   app.handle_simcall(aid_, times_considered_, false);
47   app.wait_for_requests();
48 }
49
50 Transition* deserialize_transition(aid_t issuer, int times_considered, std::stringstream& stream)
51 {
52   short type;
53   xbt_assert(stream >> type);
54
55   switch (auto simcall = static_cast<Transition::Type>(type)) {
56     case Transition::Type::BARRIER_ASYNC_LOCK:
57     case Transition::Type::BARRIER_WAIT:
58       return new BarrierTransition(issuer, times_considered, simcall, stream);
59
60     case Transition::Type::COMM_ASYNC_RECV:
61       return new CommRecvTransition(issuer, times_considered, stream);
62     case Transition::Type::COMM_ASYNC_SEND:
63       return new CommSendTransition(issuer, times_considered, stream);
64     case Transition::Type::COMM_TEST:
65       return new CommTestTransition(issuer, times_considered, stream);
66     case Transition::Type::COMM_WAIT:
67       return new CommWaitTransition(issuer, times_considered, stream);
68
69     case Transition::Type::TESTANY:
70       return new TestAnyTransition(issuer, times_considered, stream);
71     case Transition::Type::WAITANY:
72       return new WaitAnyTransition(issuer, times_considered, stream);
73
74     case Transition::Type::RANDOM:
75       return new RandomTransition(issuer, times_considered, stream);
76
77     case Transition::Type::MUTEX_TRYLOCK:
78     case Transition::Type::MUTEX_ASYNC_LOCK:
79     case Transition::Type::MUTEX_TEST:
80     case Transition::Type::MUTEX_WAIT:
81     case Transition::Type::MUTEX_UNLOCK:
82       return new MutexTransition(issuer, times_considered, simcall, stream);
83
84     case Transition::Type::SEM_ASYNC_LOCK:
85     case Transition::Type::SEM_UNLOCK:
86     case Transition::Type::SEM_WAIT:
87       return new SemaphoreTransition(issuer, times_considered, simcall, stream);
88
89     case Transition::Type::ACTOR_JOIN:
90       return new ActorJoinTransition(issuer, times_considered, stream);
91
92     case Transition::Type::OBJECT_ACCESS:
93       return new ObjectAccessTransition(issuer, times_considered, stream);
94
95     case Transition::Type::UNKNOWN:
96       return new Transition(Transition::Type::UNKNOWN, issuer, times_considered);
97
98     default:
99       break;
100   }
101   xbt_die("Invalid transition type %d received. Did you implement a new observer in the app without implementing the "
102           "corresponding transition in the checker?",
103           type);
104 }
105
106 } // namespace simgrid::mc