Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the RST inclusions in doxygen comments
[simgrid.git] / include / simgrid / s4u / Exec.hpp
1 /* Copyright (c) 2017-2021. 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 <simgrid/s4u/Actor.hpp>
12 #include <xbt/ex.h>
13
14 namespace simgrid {
15 namespace s4u {
16
17 /** Computation Activity, representing the asynchronous executions.
18  *
19  * @beginrst
20  * Most of them are created with :cpp:func:`simgrid::s4u::this_actor::exec_init()` or
21  * :cpp:func:`simgrid::s4u::Host::execute()`, and represent a classical (sequential) execution. This can be used to
22  * simulate some computation occurring in another thread when the calling actor is not blocked during the execution.
23  *
24  * You can also use :cpp:func:`simgrid::s4u::this_actor::parallel_execute()` to create *parallel* executions. These
25  * objects represent distributed computations involving computations on several hosts and communications between them.
26  * Such objects can for example represent a matrix multiplication done with ScaLAPACK on a real system. Once created,
27  * parallel Exec are very similar to the sequential ones. The only difference is that you cannot migrate them, and their
28  * remaining amount of work can only be defined as a ratio. See the doc of :cpp:func:`simgrid::s4u::Exec::get_remaining`
29  * and :cpp:func:`simgrid::s4u::Exec::get_remaining_ratio` for more info.
30  * @endrst
31  */
32 class XBT_PUBLIC Exec : public Activity_T<Exec> {
33   friend kernel::activity::ExecImpl;
34   double priority_              = 1.0;
35   double bound_                 = 0.0;
36   double timeout_               = -1.0; // Infinite timeout by default
37   std::vector<double> flops_amounts_;
38   std::vector<double> bytes_amounts_;
39   std::vector<Host*> hosts_;
40   bool parallel_ = false;
41   double start_time_ = -1.0;
42   double finish_time_ = -1.0;
43
44 protected:
45   explicit Exec(kernel::activity::ExecImplPtr pimpl);
46
47 public:
48   ~Exec() override = default;
49 #ifndef DOXYGEN
50   Exec(Exec const&) = delete;
51   Exec& operator=(Exec const&) = delete;
52
53 #endif
54   static xbt::signal<void(Exec const&)> on_start;
55   static xbt::signal<void(Exec const&)> on_completion;
56
57   static ExecPtr init();
58   Exec* start() override;
59   /** @brief On sequential executions, returns the amount of flops that remain to be done; This cannot be used on
60    * parallel executions. */
61   double get_remaining() const override;
62   double get_remaining_ratio() const;
63   ExecPtr set_host(Host* host);
64   ExecPtr set_hosts(const std::vector<Host*>& hosts);
65
66   ExecPtr set_flops_amount(double flops_amount);
67   ExecPtr set_flops_amounts(const std::vector<double>& flops_amounts);
68   ExecPtr set_bytes_amounts(const std::vector<double>& bytes_amounts);
69
70   Exec* wait() override;
71   Exec* wait_for(double timeout) override;
72   /*! take a vector of s4u::ExecPtr and return when one of them is finished.
73    * The return value is the rank of the first finished ExecPtr. */
74   static int wait_any(std::vector<ExecPtr>* execs) { return wait_any_for(execs, -1); }
75   /*! Same as wait_any, but with a timeout. If the timeout occurs, parameter last is returned.*/
76   static int wait_any_for(std::vector<ExecPtr>* execs, double timeout);
77
78   ExecPtr set_bound(double bound);
79   ExecPtr set_priority(double priority);
80   XBT_ATTRIB_DEPRECATED_v329("Please use exec_init(...)->wait_for(timeout)") ExecPtr set_timeout(double timeout);
81
82   Exec* cancel() override;
83   Host* get_host() const;
84   unsigned int get_host_number() const;
85   double get_start_time() const { return start_time_; }
86   double get_finish_time() const { return finish_time_; }
87   void set_finish_time(double finish_time) { finish_time_ = finish_time; }
88   double get_cost() const;
89   bool is_parallel() const { return parallel_; }
90   bool is_assigned() const override { return not hosts_.empty(); }
91 };
92
93 } // namespace s4u
94 } // namespace simgrid
95
96 #endif /* SIMGRID_S4U_EXEC_HPP */