Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid into CRTP
[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_T<Exec> {
24   double priority_              = 1.0;
25   double bound_                 = 0.0;
26   double timeout_               = 0.0;
27   std::atomic_int_fast32_t refcount_{0};
28   Host* host_ = nullptr;
29
30 protected:
31   Exec();
32   virtual ~Exec() = default;
33
34 public:
35 #ifndef DOXYGEN
36   Exec(Exec const&) = delete;
37   Exec& operator=(Exec const&) = delete;
38 #endif
39
40   friend ExecSeq;
41   friend ExecPar;
42   friend XBT_PUBLIC void intrusive_ptr_release(Exec* e);
43   friend XBT_PUBLIC void intrusive_ptr_add_ref(Exec* e);
44   static xbt::signal<void(Actor const&)> on_start;
45   static xbt::signal<void(Actor const&)> on_completion;
46
47   virtual Exec* start() override          = 0;
48   virtual double get_remaining_ratio()    = 0;
49   virtual ExecPtr set_host(Host* host)    = 0;
50
51   Exec* wait() override;
52   Exec* wait_for(double timeout) override;
53   bool test() override;
54
55   ExecPtr set_bound(double bound);
56   ExecPtr set_priority(double priority);
57   ExecPtr set_timeout(double timeout);
58   Exec* cancel() override;
59
60   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_priority()") ExecPtr setPriority(double priority)
61   {
62     return set_priority(priority);
63   }
64   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_bound()") ExecPtr setBound(double bound) { return set_bound(bound); }
65   XBT_ATTRIB_DEPRECATED_v324("Please use Exec::wait_for()") void wait(double t) override { wait_for(t); }
66 };
67
68 class XBT_PUBLIC ExecSeq : public Exec {
69   double flops_amount_ = 0.0;
70
71   explicit ExecSeq(sg_host_t host, double flops_amount);
72
73 public:
74   friend XBT_PUBLIC ExecPtr this_actor::exec_init(double flops_amount);
75
76   ~ExecSeq() = default;
77
78   Exec* start() override;
79
80   ExecPtr set_host(Host* host) override;
81   Host* get_host();
82
83   double get_remaining() override;
84   double get_remaining_ratio() override;
85
86 #ifndef DOXYGEN
87   //////////////// Deprecated functions
88   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::set_host()") ExecPtr setHost(Host* host) { return set_host(host); }
89   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::get_host()") Host* getHost() { return get_host(); }
90   XBT_ATTRIB_DEPRECATED_v323("Please use Exec::get_remaining_ratio()") double getRemainingRatio()
91   {
92     return get_remaining_ratio();
93   }
94 #endif
95 };
96
97 class XBT_PUBLIC ExecPar : public Exec {
98   std::vector<s4u::Host*> hosts_;
99   std::vector<double> flops_amounts_;
100   std::vector<double> bytes_amounts_;
101   explicit ExecPar(const std::vector<s4u::Host*>& hosts, const std::vector<double>& flops_amounts,
102                    const std::vector<double>& bytes_amounts);
103   ExecPtr set_host(Host* host) override { return this; }
104
105 public:
106   ~ExecPar() = default;
107   friend XBT_PUBLIC ExecPtr this_actor::exec_init(const std::vector<s4u::Host*>& hosts,
108                                                   const std::vector<double>& flops_amounts,
109                                                   const std::vector<double>& bytes_amounts);
110   double get_remaining() override;
111   double get_remaining_ratio() override;
112   Exec* start() override;
113 };
114
115 } // namespace s4u
116 } // namespace simgrid
117
118 #endif /* SIMGRID_S4U_EXEC_HPP */