Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: move the reversible_race logic to the Transition class
[simgrid.git] / src / mc / transition / TransitionComm.hpp
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 #ifndef SIMGRID_MC_TRANSITION_COMM_HPP
7 #define SIMGRID_MC_TRANSITION_COMM_HPP
8
9 #include "src/kernel/actor/SimcallObserver.hpp"
10 #include "src/mc/transition/Transition.hpp"
11
12 #include <cstdint>
13 #include <sstream>
14 #include <string>
15
16 namespace simgrid::mc {
17
18 class CommRecvTransition;
19 class CommSendTransition;
20 class CommTestTransition;
21
22 class CommWaitTransition : public Transition {
23   bool timeout_;
24   unsigned comm_;
25   unsigned mbox_;
26   aid_t sender_;
27   aid_t receiver_;
28   friend CommRecvTransition;
29   friend CommSendTransition;
30   friend CommTestTransition;
31
32 public:
33   CommWaitTransition(aid_t issuer, int times_considered, bool timeout_, unsigned comm_, aid_t sender_, aid_t receiver_,
34                      unsigned mbox_);
35   CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream);
36   std::string to_string(bool verbose) const override;
37   bool depends(const Transition* other) const override;
38   bool reversible_race(const Transition* other) const override;
39
40   bool get_timeout() const { return timeout_; }
41   /** ID of the corresponding Communication object in the application, or 0 if unknown */
42   unsigned get_comm() const { return comm_; }
43   /** Sender ID */
44   aid_t get_sender() const { return sender_; }
45   /** Receiver ID */
46   aid_t get_receiver() const { return receiver_; }
47   /** Mailbox ID */
48   unsigned get_mailbox() const { return mbox_; }
49 };
50 class CommTestTransition : public Transition {
51   unsigned comm_;
52   unsigned mbox_;
53   aid_t sender_;
54   aid_t receiver_;
55   friend CommSendTransition;
56   friend CommRecvTransition;
57
58 public:
59   CommTestTransition(aid_t issuer, int times_considered, unsigned comm_, aid_t sender_, aid_t receiver_,
60                      unsigned mbox_);
61   CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream);
62   std::string to_string(bool verbose) const override;
63   bool depends(const Transition* other) const override;
64   bool reversible_race(const Transition* other) const override;
65
66   /** ID of the corresponding Communication object in the application, or 0 if unknown */
67   unsigned get_comm() const { return comm_; }
68   /** Sender ID */
69   aid_t get_sender() const { return sender_; }
70   /** Receiver ID */
71   aid_t get_receiver() const { return receiver_; }
72   /** Mailbox ID */
73   unsigned get_mailbox() const { return mbox_; }
74 };
75
76 class CommRecvTransition : public Transition {
77   unsigned comm_; /* ID of the CommImpl or 0 if not known */
78   unsigned mbox_;
79   int tag_;
80
81 public:
82   CommRecvTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_, int tag_);
83   CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream);
84   std::string to_string(bool verbose) const override;
85   bool depends(const Transition* other) const override;
86   bool reversible_race(const Transition* other) const override;
87
88   /** ID of the corresponding Communication object in the application (or 0 if unknown)*/
89   unsigned get_comm() const { return comm_; }
90   /** Mailbox ID */
91   unsigned get_mailbox() const { return mbox_; }
92   /** If using SMPI, the tag */
93   int get_tag() const { return tag_; }
94 };
95
96 class CommSendTransition : public Transition {
97   unsigned comm_;
98   unsigned mbox_;
99   int tag_;
100
101 public:
102   CommSendTransition(aid_t issuer, int times_considered, unsigned comm_, unsigned mbox_, int tag_);
103   CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream);
104   std::string to_string(bool verbose) const override;
105   bool depends(const Transition* other) const override;
106   bool reversible_race(const Transition* other) const override;
107
108   /** ID of the corresponding Communication object in the application, or 0 if unknown */
109   unsigned get_comm() const { return comm_; }
110   /** Mailbox ID */
111   unsigned get_mailbox() const { return mbox_; }
112   /** If using SMPI, the tag */
113   int get_tag() const { return tag_; }
114 };
115
116 /** Make a new transition from serialized description */
117 Transition* deserialize_transition(aid_t issuer, int times_considered, std::stringstream& stream);
118
119 } // namespace simgrid::mc
120
121 #endif