Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Split the Comm observers to their own files
[simgrid.git] / src / kernel / actor / CommObserver.hpp
1 /* Copyright (c) 2019-2022. 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_SIMCALL_COMM_OBSERVER_HPP
7 #define SIMGRID_MC_SIMCALL_COMM_OBSERVER_HPP
8
9 #include "simgrid/forward.h"
10 #include "src/kernel/actor/SimcallObserver.hpp"
11 #include "src/mc/transition/Transition.hpp"
12 #include "xbt/asserts.h"
13
14 #include <string>
15
16 namespace simgrid {
17 namespace kernel {
18 namespace actor {
19
20 class ActivityTestSimcall : public ResultingSimcall<bool> {
21   activity::ActivityImpl* const activity_;
22
23 public:
24   ActivityTestSimcall(ActorImpl* actor, activity::ActivityImpl* activity)
25       : ResultingSimcall(actor, true), activity_(activity)
26   {
27   }
28   bool is_visible() const override { return true; }
29   activity::ActivityImpl* get_activity() const { return activity_; }
30   void serialize(std::stringstream& stream) const override;
31 };
32
33 class ActivityTestanySimcall : public ResultingSimcall<ssize_t> {
34   const std::vector<activity::ActivityImpl*>& activities_;
35   std::vector<int> indexes_; // indexes in activities_ pointing to ready activities (=whose test() is positive)
36   int next_value_ = 0;
37
38 public:
39   ActivityTestanySimcall(ActorImpl* actor, const std::vector<activity::ActivityImpl*>& activities);
40   bool is_visible() const override { return true; }
41   bool is_enabled() override { return true; /* can return -1 if no activity is ready */ }
42   void serialize(std::stringstream& stream) const override;
43   int get_max_consider() override;
44   void prepare(int times_considered) override;
45   const std::vector<activity::ActivityImpl*>& get_activities() const { return activities_; }
46   int get_value() const { return next_value_; }
47 };
48
49 class ActivityWaitSimcall : public ResultingSimcall<bool> {
50   activity::ActivityImpl* activity_;
51   const double timeout_;
52
53 public:
54   ActivityWaitSimcall(ActorImpl* actor, activity::ActivityImpl* activity, double timeout)
55       : ResultingSimcall(actor, false), activity_(activity), timeout_(timeout)
56   {
57   }
58   void serialize(std::stringstream& stream) const override;
59   bool is_visible() const override { return true; }
60   bool is_enabled() override;
61   activity::ActivityImpl* get_activity() const { return activity_; }
62   void set_activity(activity::ActivityImpl* activity) { activity_ = activity; }
63   double get_timeout() const { return timeout_; }
64 };
65
66 class ActivityWaitanySimcall : public ResultingSimcall<ssize_t> {
67   const std::vector<activity::ActivityImpl*>& activities_;
68   std::vector<int> indexes_; // indexes in activities_ pointing to ready activities (=whose test() is positive)
69   const double timeout_;
70   int next_value_ = 0;
71
72 public:
73   ActivityWaitanySimcall(ActorImpl* actor, const std::vector<activity::ActivityImpl*>& activities, double timeout);
74   bool is_enabled() override;
75   void serialize(std::stringstream& stream) const override;
76   bool is_visible() const override { return true; }
77   void prepare(int times_considered) override;
78   int get_max_consider() override;
79   const std::vector<activity::ActivityImpl*>& get_activities() const { return activities_; }
80   double get_timeout() const { return timeout_; }
81   int get_value() const { return next_value_; }
82 };
83
84 class CommIsendSimcall : public SimcallObserver {
85   activity::MailboxImpl* mbox_;
86   double payload_size_;
87   double rate_;
88   unsigned char* src_buff_;
89   size_t src_buff_size_;
90   void* payload_;
91   bool detached_;
92   activity::CommImpl* comm_;
93   int tag_;
94
95   bool (*match_fun_)(void*, void*, activity::CommImpl*);
96   void (*clean_fun_)(void*); // used to free the synchro in case of problem after a detached send
97   void (*copy_data_fun_)(activity::CommImpl*, void*, size_t); // used to copy data if not default one
98
99 public:
100   CommIsendSimcall(ActorImpl* actor, activity::MailboxImpl* mbox, double payload_size, double rate,
101                    unsigned char* src_buff, size_t src_buff_size, bool (*match_fun)(void*, void*, activity::CommImpl*),
102                    void (*clean_fun)(void*), // used to free the synchro in case of problem after a detached send
103                    void (*copy_data_fun)(activity::CommImpl*, void*, size_t), // used to copy data if not default one
104                    void* payload, bool detached)
105       : SimcallObserver(actor)
106       , mbox_(mbox)
107       , payload_size_(payload_size)
108       , rate_(rate)
109       , src_buff_(src_buff)
110       , src_buff_size_(src_buff_size)
111       , payload_(payload)
112       , detached_(detached)
113       , match_fun_(match_fun)
114       , clean_fun_(clean_fun)
115       , copy_data_fun_(copy_data_fun)
116   {
117   }
118   void serialize(std::stringstream& stream) const override;
119   bool is_visible() const override { return true; }
120   activity::MailboxImpl* get_mailbox() const { return mbox_; }
121   double get_payload_size() const { return payload_size_; }
122   double get_rate() const { return rate_; }
123   unsigned char* get_src_buff() const { return src_buff_; }
124   size_t get_src_buff_size() const { return src_buff_size_; }
125   void* get_payload() const { return payload_; }
126   bool is_detached() const { return detached_; }
127   void set_comm(activity::CommImpl* comm) { comm_ = comm; }
128   void set_tag(int tag) { tag_ = tag; }
129
130   auto get_match_fun() const { return match_fun_; }
131   auto get_clean_fun() const { return clean_fun_; }
132   auto get_copy_data_fun() const { return copy_data_fun_; }
133 };
134
135 class CommIrecvSimcall : public SimcallObserver {
136   activity::MailboxImpl* mbox_;
137   unsigned char* dst_buff_;
138   size_t* dst_buff_size_;
139   void* payload_;
140   double rate_;
141   int tag_;
142   activity::CommImpl* comm_;
143
144   bool (*match_fun_)(void*, void*, activity::CommImpl*);
145   void (*copy_data_fun_)(activity::CommImpl*, void*, size_t); // used to copy data if not default one
146
147 public:
148   CommIrecvSimcall(ActorImpl* actor, activity::MailboxImpl* mbox, unsigned char* dst_buff, size_t* dst_buff_size,
149                    bool (*match_fun)(void*, void*, activity::CommImpl*),
150                    void (*copy_data_fun)(activity::CommImpl*, void*, size_t), void* payload, double rate)
151       : SimcallObserver(actor)
152       , mbox_(mbox)
153       , dst_buff_(dst_buff)
154       , dst_buff_size_(dst_buff_size)
155       , payload_(payload)
156       , rate_(rate)
157       , match_fun_(match_fun)
158       , copy_data_fun_(copy_data_fun)
159   {
160   }
161   void serialize(std::stringstream& stream) const override;
162   bool is_visible() const override { return true; }
163   activity::MailboxImpl* get_mailbox() const { return mbox_; }
164   double get_rate() const { return rate_; }
165   unsigned char* get_dst_buff() const { return dst_buff_; }
166   size_t* get_dst_buff_size() const { return dst_buff_size_; }
167   void* get_payload() const { return payload_; }
168   void set_comm(activity::CommImpl* comm) { comm_ = comm; }
169   void set_tag(int tag) { tag_ = tag; }
170
171   auto get_match_fun() const { return match_fun_; };
172   auto get_copy_data_fun() const { return copy_data_fun_; }
173 };
174
175 } // namespace actor
176 } // namespace kernel
177 } // namespace simgrid
178
179 #endif