Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0ff852785b21bf3ba1bee068033f87054da0194d
[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
65 class ExecOp : public Operation {
66 private:
67   simgrid::s4u::Host* host_;
68
69   ExecOp(const std::string& name, double flops, simgrid::s4u::Host* host);
70   void execute();
71
72 public:
73   static ExecOpPtr create(const std::string& name, double flops, simgrid::s4u::Host* host);
74   void set_host(simgrid::s4u::Host* host);
75 };
76
77 class CommOp : public Operation {
78 private:
79   simgrid::s4u::Host* source_;
80   simgrid::s4u::Host* destination_;
81
82   CommOp(const std::string& name, double bytes, simgrid::s4u::Host* source, simgrid::s4u::Host* destination);
83   void execute();
84
85 public:
86   static CommOpPtr create(const std::string& name, double bytes, simgrid::s4u::Host* source,
87                           simgrid::s4u::Host* destination);
88   void set_source(simgrid::s4u::Host* source);
89   void set_destination(simgrid::s4u::Host* destination);
90   
91 };
92 } // namespace simgrid::plugins
93 #endif