Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
s4u::Exec now has 2 child classes
[simgrid.git] / include / simgrid / s4u / Exec.hpp
1 /* Copyright (c) 2017-2019. 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_S4U_EXEC_HPP
7 #define SIMGRID_S4U_EXEC_HPP
8
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Activity.hpp>
11 #include <xbt/ex.h>
12
13 #include <atomic>
14
15 namespace simgrid {
16 namespace s4u {
17
18 /** Computation Activity, representing the asynchronous executions.
19  *
20  * They are generated from this_actor::exec_init() or Host::execute(), and can be used to model pools of threads or
21  * similar mechanisms.
22  */
23 class XBT_PUBLIC Exec : public Activity {
24   std::string name_             = "";
25   double priority_              = 1.0;
26   double bound_                 = 0.0;
27   double timeout_               = 0.0;
28   std::string tracing_category_ = "";
29   std::atomic_int_fast32_t refcount_{0};
30   Host* host_ = nullptr;
31
32 protected:
33   Exec();
34   virtual ~Exec() = default;
35
36 public:
37 #ifndef DOXYGEN
38   Exec(Exec const&) = delete;
39   Exec& operator=(Exec const&) = delete;
40 #endif
41
42   friend simgrid::s4u::ExecSeq;
43   friend simgrid::s4u::ExecPar;
44   friend XBT_PUBLIC void intrusive_ptr_release(Exec* e);
45   friend XBT_PUBLIC void intrusive_ptr_add_ref(Exec* e);
46   static xbt::signal<void(ActorPtr)> on_start;
47   static xbt::signal<void(ActorPtr)> on_completion;
48
49   virtual double get_remaining()       = 0;
50   virtual double get_remaining_ratio() = 0;
51   virtual Exec* start()                = 0;
52   virtual ExecPtr set_host(Host* host) = 0;
53
54   Exec* wait() override;
55   Exec* wait_for(double timeout) override;
56   bool test() override;
57
58   ExecPtr set_bound(double bound);
59   ExecPtr set_name(std::string name);
60   ExecPtr set_priority(double priority);
61   ExecPtr set_tracing_category(std::string category);
62   ExecPtr set_timeout(double timeout);
63   Exec* cancel() override;
64
65   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_priority()") ExecPtr setPriority(double priority)
66   {
67     return set_priority(priority);
68   }
69   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_bound()") ExecPtr setBound(double bound) { return set_bound(bound); }
70   XBT_ATTRIB_DEPRECATED_v324("Please use Exec::wait_for()") void wait(double t) override { wait_for(t); }
71 };
72
73 class XBT_PUBLIC ExecSeq : public Exec {
74   double flops_amount_ = 0.0;
75
76   explicit ExecSeq(sg_host_t host, double flops_amount);
77
78 public:
79   friend XBT_PUBLIC ExecPtr this_actor::exec_init(double flops_amount);
80
81   ~ExecSeq() = default;
82
83   Exec* start() override;
84
85   ExecPtr set_host(Host* host);
86   Host* get_host();
87
88   double get_remaining() override;
89   double get_remaining_ratio() override;
90
91 #ifndef DOXYGEN
92   //////////////// Deprecated functions
93   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_host()") ExecPtr setHost(Host* host) { return set_host(host); }
94   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::get_host()") Host* getHost() { return get_host(); }
95   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::get_remaining_ratio()") double getRemainingRatio()
96   {
97     return get_remaining_ratio();
98   }
99 #endif
100 };
101
102 class XBT_PUBLIC ExecPar : public Exec {
103   std::vector<s4u::Host*> hosts_;
104   std::vector<double> flops_amounts_;
105   std::vector<double> bytes_amounts_;
106   explicit ExecPar(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
107                    const std::vector<double>& bytes_amounts);
108   ExecPtr set_host(Host* host) { return this; }
109
110 public:
111   ~ExecPar() = default;
112   friend XBT_PUBLIC ExecPtr this_actor::exec_init(const std::vector<s4u::Host*>& hosts,
113                                                   const std::vector<double>& flops_amounts,
114                                                   const std::vector<double>& bytes_amounts);
115   double get_remaining() override;
116   double get_remaining_ratio() override;
117   Exec* start() override;
118 };
119
120 } // namespace s4u
121 } // namespace simgrid
122
123 #endif /* SIMGRID_S4U_EXEC_HPP */