Logo AND Algorithmique Numérique Distribuée

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