Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix builds with/without MC and with/without clang (hopefully)
[simgrid.git] / src / mc / Transition.hpp
1 /* Copyright (c) 2015-2022. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_TRANSITION_HPP
8 #define SIMGRID_MC_TRANSITION_HPP
9
10 #include "simgrid/forward.h" // aid_t
11
12 #include <string>
13
14 namespace simgrid {
15 namespace mc {
16
17 /** An element in the recorded path
18  *
19  *  At each decision point, we need to record which process transition
20  *  is triggered and potentially which value is associated with this
21  *  transition. The value is used to find which communication is triggered
22  *  in things like waitany and for associating a given value of MC_random()
23  *  calls.
24  */
25 class Transition {
26   /* Textual representation of the transition, to display backtraces */
27   static unsigned long executed_transitions_;
28   static unsigned long replayed_transitions_;
29
30   friend State; // FIXME remove this once we have a proper class to handle the statistics
31
32 protected:
33   std::string textual_ = "";
34
35 public:
36   aid_t aid_ = 0;
37
38   /* Which transition was executed for this simcall
39    *
40    * Some simcalls can lead to different transitions:
41    *
42    * * waitany/testany can trigger on different messages;
43    *
44    * * random can produce different values.
45    */
46   int times_considered_ = 0;
47
48   Transition() = default;
49   virtual ~Transition();
50   Transition(aid_t issuer, int times_considered) : aid_(issuer), times_considered_(times_considered) {}
51
52   void init(aid_t aid, int times_considered);
53
54   virtual std::string to_string(bool verbose = false);
55   const char* to_cstring(bool verbose = false);
56
57   /* Moves the application toward a path that was already explored, but don't change the current transition */
58   void replay() const;
59
60   virtual bool depends(const Transition* other) const { return true; }
61
62   /* Returns the total amount of transitions executed so far (for statistics) */
63   static unsigned long get_executed_transitions() { return executed_transitions_; }
64   /* Returns the total amount of transitions replayed so far while backtracing (for statistics) */
65   static unsigned long get_replayed_transitions() { return replayed_transitions_; }
66 };
67
68 } // namespace mc
69 } // namespace simgrid
70
71 #endif