Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2c244f68528f23421e634ad6583eabef748b43e7
[simgrid.git] / src / mc / api / TransitionComm.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_COMM_HPP
8 #define SIMGRID_MC_TRANSITION_COMM_HPP
9
10 #include "src/kernel/actor/SimcallObserver.hpp"
11 #include "src/mc/api/Transition.hpp"
12
13 #include <sstream>
14 #include <string>
15
16 namespace simgrid {
17 namespace mc {
18
19 class CommRecvTransition;
20 class CommSendTransition;
21 class CommTestTransition;
22
23 class CommWaitTransition : public Transition {
24   bool timeout_;
25   uintptr_t comm_;
26   aid_t sender_;
27   aid_t receiver_;
28   unsigned mbox_;
29   uintptr_t sbuff_;
30   uintptr_t rbuff_;
31   size_t size_;
32   friend CommRecvTransition;
33   friend CommSendTransition;
34   friend CommTestTransition;
35
36 public:
37   CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream);
38   std::string to_string(bool verbose) const override;
39   bool depends(const Transition* other) const override;
40
41   bool get_timeout() const { return timeout_; }
42   /** Address of the corresponding Communication object in the application */
43   uintptr_t get_comm() const { return comm_; }
44   /** Sender ID */
45   aid_t get_sender() const { return sender_; }
46   /** Receiver ID */
47   aid_t get_receiver() const { return receiver_; }
48   /** Mailbox ID */
49   unsigned get_mailbox() const { return mbox_; }
50   /** Sender buffer */
51   uintptr_t get_sbuff() const { return sbuff_; }
52   /** Receiver buffer */
53   uintptr_t get_rbuff() const { return rbuff_; }
54   /** data size */
55   size_t get_size() const { return size_; }
56 };
57 class CommTestTransition : public Transition {
58   uintptr_t comm_;
59   aid_t sender_;
60   aid_t receiver_;
61   unsigned mbox_;
62   uintptr_t sbuff_;
63   uintptr_t rbuff_;
64   size_t size_;
65   friend CommSendTransition;
66   friend CommRecvTransition;
67
68 public:
69   CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream);
70   std::string to_string(bool verbose) const override;
71   bool depends(const Transition* other) const override;
72
73   /** Address of the corresponding Communication object in the application */
74   uintptr_t get_comm() const { return comm_; }
75   /** Sender ID */
76   aid_t get_sender() const { return sender_; }
77   /** Receiver ID */
78   aid_t get_receiver() const { return receiver_; }
79   /** Mailbox ID */
80   unsigned get_mailbox() const { return mbox_; }
81   /** Sender buffer */
82   uintptr_t get_sbuff() const { return sbuff_; }
83   /** Receiver buffer */
84   uintptr_t get_rbuff() const { return rbuff_; }
85   /** data size */
86   size_t get_size() const { return size_; }
87 };
88
89 class CommRecvTransition : public Transition {
90   uintptr_t comm_; /* Addr of the CommImpl */
91   unsigned mbox_;
92   uintptr_t rbuff_;
93   int tag_;
94
95 public:
96   CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream);
97   std::string to_string(bool verbose) const override;
98   bool depends(const Transition* other) const override;
99
100   /** Address of the corresponding Communication object in the application */
101   uintptr_t get_comm() const { return comm_; }
102   /** Mailbox ID */
103   unsigned get_mailbox() const { return mbox_; }
104   /** Receiver buffer */
105   uintptr_t get_rbuff() const { return rbuff_; }
106   /** If using SMPI, the tag */
107   int get_tag() const { return tag_; }
108 };
109
110 class CommSendTransition : public Transition {
111   uintptr_t comm_; /* Addr of the CommImpl */
112   unsigned mbox_;
113   uintptr_t sbuff_;
114   size_t size_;
115   int tag_;
116
117 public:
118   CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream);
119   std::string to_string(bool verbose) const override;
120   bool depends(const Transition* other) const override;
121
122   /** Address of the corresponding Communication object in the application */
123   uintptr_t get_comm() const { return comm_; }
124   /** Mailbox ID */
125   unsigned get_mailbox() const { return mbox_; }
126   /** Sender buffer */
127   uintptr_t get_sbuff() const { return sbuff_; }
128   /** data size */
129   size_t get_size() const { return size_; }
130   /** If using SMPI, the tag */
131   int get_tag() const { return tag_; }
132 };
133
134 class TestAnyTransition : public Transition {
135   std::vector<Transition*> transitions_;
136
137 public:
138   TestAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream);
139   std::string to_string(bool verbose) const override;
140   bool depends(const Transition* other) const override;
141
142   Transition* get_current_transition() const { return transitions_.at(times_considered_); }
143 };
144
145 class WaitAnyTransition : public Transition {
146   std::vector<Transition*> transitions_;
147
148 public:
149   WaitAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream);
150   std::string to_string(bool verbose) const override;
151   bool depends(const Transition* other) const override;
152
153   Transition* get_current_transition() const { return transitions_.at(times_considered_); }
154 };
155
156 /** Make a new transition from serialized description */
157 Transition* deserialize_transition(aid_t issuer, int times_considered, std::stringstream& stream);
158
159 } // namespace mc
160 } // namespace simgrid
161
162 #endif