Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
clang-format
[simgrid.git] / include / simgrid / plugins / operation.hpp
1 #ifndef SIMGRID_PLUGINS_OPERATION_H_
2 #define SIMGRID_PLUGINS_OPERATION_H_
3
4 #include <simgrid/s4u/Activity.hpp>
5 #include <xbt/Extendable.hpp>
6
7 #include <map>
8 #include <set>
9
10 namespace simgrid::plugins {
11
12 class Operation;
13 using OperationPtr = std::shared_ptr<Operation>;
14 class ExecOp;
15 using ExecOpPtr = std::shared_ptr<ExecOp>;
16 class CommOp;
17 using CommOpPtr = std::shared_ptr<CommOp>;
18
19 class ExtendedAttributeActivity {
20 public:
21   static simgrid::xbt::Extension<simgrid::s4u::Activity, ExtendedAttributeActivity> EXTENSION_ID;
22   Operation* operation_;
23
24   ExtendedAttributeActivity(){};
25 };
26
27 class Operation {
28 private:
29   static bool inited_;
30   std::set<Operation*> successors_                 = {};
31   std::map<Operation*, unsigned int> predecessors_ = {};
32
33   void add_predecessor(Operation* predecessor);
34   void remove_predecessor(Operation* predecessor);
35   bool ready_to_run() const;
36   void receive(Operation* source);
37   void complete();
38
39 protected:
40   std::string name_;
41   double amount_;
42   int queued_execs_ = 0;
43   int count_        = 0;
44   bool working_     = false;
45   simgrid::s4u::ActivityPtr current_activity_;
46   std::function<void(Operation*)> end_func_   = [](Operation*) {};
47   std::function<void(Operation*)> start_func_ = [](Operation*) {};
48   Operation(const std::string& name, double amount);
49   ~Operation()           = default;
50   virtual void execute() = 0;
51
52 public:
53   static void init();
54   std::string get_name();
55   void enqueue_execs(int n);
56   void set_amount(double amount);
57   void add_successor(OperationPtr op);
58   void remove_successor(OperationPtr op);
59   void on_start(std::function<void(Operation*)> func);
60   void on_end(std::function<void(Operation*)> func);
61   int get_count();
62 };
63
64 class ExecOp : public Operation {
65 private:
66   simgrid::s4u::Host* host_;
67
68   ExecOp(const std::string& name, double flops, simgrid::s4u::Host* host);
69   void execute();
70
71 public:
72   static ExecOpPtr create(const std::string& name, double flops, simgrid::s4u::Host* host);
73   void set_host(simgrid::s4u::Host* host);
74 };
75
76 class CommOp : public Operation {
77 private:
78   simgrid::s4u::Host* source_;
79   simgrid::s4u::Host* destination_;
80
81   CommOp(const std::string& name, double bytes, simgrid::s4u::Host* source, simgrid::s4u::Host* destination);
82   void execute();
83
84 public:
85   static CommOpPtr create(const std::string& name, double bytes, simgrid::s4u::Host* source,
86                           simgrid::s4u::Host* destination);
87   void set_source(simgrid::s4u::Host* source);
88   void set_destination(simgrid::s4u::Host* destination);
89 };
90 } // namespace simgrid::plugins
91 #endif