Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add operation plugin
[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   std::function<void(Operation*)> end_func         = [](Operation*) {};
33
34   void add_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 iteration_limit_          = -1;
43   unsigned int iteration_count_ = 0;
44   bool working_                 = false;
45   simgrid::s4u::ActivityPtr current_activity_;
46   Operation(const std::string& name, double amount);
47   ~Operation() = default;
48   void consume();
49   void call_end();
50
51 public:
52   static void init();
53   std::string get_name();
54   void set_iteration_limit(unsigned int n);
55   void add_successor(OperationPtr op);
56   void on_end(std::function<void(Operation*)> func);
57   virtual void execute() = 0;
58 };
59
60 class ExecOp : public Operation {
61 private:
62   simgrid::s4u::Host* host_;
63
64   ExecOp(const std::string& name, double flops, simgrid::s4u::Host* host);
65
66 public:
67   static ExecOpPtr create(const std::string& name, double flops, simgrid::s4u::Host* host);
68   void execute();
69 };
70
71 class CommOp : public Operation {
72 private:
73   simgrid::s4u::Host* source_;
74   simgrid::s4u::Host* destination_;
75
76   CommOp(const std::string& name, double bytes, simgrid::s4u::Host* source, simgrid::s4u::Host* destination);
77
78 public:
79   static CommOpPtr create(const std::string& name, double bytes, simgrid::s4u::Host* source,
80                           simgrid::s4u::Host* destination);
81   void execute();
82 };
83 } // namespace simgrid::plugins
84 #endif