Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add ex(C) example with a small program
[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   uintptr_t comm_;
25   aid_t sender_;
26   aid_t receiver_;
27   unsigned mbox_;
28   uintptr_t sbuff_;
29   uintptr_t rbuff_;
30   size_t size_;
31   friend CommRecvTransition;
32   friend CommSendTransition;
33   friend CommTestTransition;
34
35 public:
36   CommWaitTransition(aid_t issuer, int times_considered, bool timeout_, uintptr_t comm_, aid_t sender_, aid_t receiver_,
37                      unsigned mbox_, uintptr_t sbuff_, uintptr_t rbuff_, size_t size_);
38   CommWaitTransition(aid_t issuer, int times_considered, std::stringstream& stream);
39   std::string to_string(bool verbose) const override;
40   bool depends(const Transition* other) const override;
41
42   bool get_timeout() const { return timeout_; }
43   /** Address of the corresponding Communication object in the application */
44   uintptr_t get_comm() const { return comm_; }
45   /** Sender ID */
46   aid_t get_sender() const { return sender_; }
47   /** Receiver ID */
48   aid_t get_receiver() const { return receiver_; }
49   /** Mailbox ID */
50   unsigned get_mailbox() const { return mbox_; }
51   /** Sender buffer */
52   uintptr_t get_sbuff() const { return sbuff_; }
53   /** Receiver buffer */
54   uintptr_t get_rbuff() const { return rbuff_; }
55   /** data size */
56   size_t get_size() const { return size_; }
57 };
58 class CommTestTransition : public Transition {
59   uintptr_t comm_;
60   aid_t sender_;
61   aid_t receiver_;
62   unsigned mbox_;
63   uintptr_t sbuff_;
64   uintptr_t rbuff_;
65   size_t size_;
66   friend CommSendTransition;
67   friend CommRecvTransition;
68
69 public:
70   CommTestTransition(aid_t issuer, int times_considered, std::stringstream& stream);
71   std::string to_string(bool verbose) const override;
72   bool depends(const Transition* other) const override;
73
74   /** Address of the corresponding Communication object in the application */
75   uintptr_t get_comm() const { return comm_; }
76   /** Sender ID */
77   aid_t get_sender() const { return sender_; }
78   /** Receiver ID */
79   aid_t get_receiver() const { return receiver_; }
80   /** Mailbox ID */
81   unsigned get_mailbox() const { return mbox_; }
82   /** Sender buffer */
83   uintptr_t get_sbuff() const { return sbuff_; }
84   /** Receiver buffer */
85   uintptr_t get_rbuff() const { return rbuff_; }
86   /** data size */
87   size_t get_size() const { return size_; }
88 };
89
90 class CommRecvTransition : public Transition {
91   uintptr_t comm_; /* Addr of the CommImpl */
92   unsigned mbox_;
93   uintptr_t rbuff_;
94   int tag_;
95
96 public:
97   CommRecvTransition(aid_t issuer, int times_considered, uintptr_t comm_, unsigned mbox_, uintptr_t rbuff_, int tag_);
98   CommRecvTransition(aid_t issuer, int times_considered, std::stringstream& stream);
99   std::string to_string(bool verbose) const override;
100   bool depends(const Transition* other) const override;
101
102   /** Address of the corresponding Communication object in the application */
103   uintptr_t get_comm() const { return comm_; }
104   /** Mailbox ID */
105   unsigned get_mailbox() const { return mbox_; }
106   /** Receiver buffer */
107   uintptr_t get_rbuff() const { return rbuff_; }
108   /** If using SMPI, the tag */
109   int get_tag() const { return tag_; }
110 };
111
112 class CommSendTransition : public Transition {
113   uintptr_t comm_; /* Addr of the CommImpl */
114   unsigned mbox_;
115   uintptr_t sbuff_;
116   size_t size_;
117   int tag_;
118
119 public:
120   CommSendTransition(aid_t issuer, int times_considered, uintptr_t comm_, unsigned mbox_, uintptr_t sbuff_,
121                      size_t size_, int tag_);
122   CommSendTransition(aid_t issuer, int times_considered, std::stringstream& stream);
123   std::string to_string(bool verbose) const override;
124   bool depends(const Transition* other) const override;
125
126   /** Address of the corresponding Communication object in the application */
127   uintptr_t get_comm() const { return comm_; }
128   /** Mailbox ID */
129   unsigned get_mailbox() const { return mbox_; }
130   /** Sender buffer */
131   uintptr_t get_sbuff() const { return sbuff_; }
132   /** data size */
133   size_t get_size() const { return size_; }
134   /** If using SMPI, the tag */
135   int get_tag() const { return tag_; }
136 };
137
138 /** Make a new transition from serialized description */
139 Transition* deserialize_transition(aid_t issuer, int times_considered, std::stringstream& stream);
140
141 } // namespace simgrid::mc
142
143 #endif