Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / include / simgrid / s4u / Exec.hpp
1 /* Copyright (c) 2017-2022. 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 #ifndef DOXYGEN
34   friend kernel::activity::ExecImpl;
35   friend kernel::EngineImpl; // Auto-completes the execs of maestro (in simDAG)
36 #endif
37
38   bool parallel_ = false;
39
40 protected:
41   explicit Exec(kernel::activity::ExecImplPtr pimpl);
42
43   void reset() const;
44
45   static xbt::signal<void(Exec const&)> on_start;
46
47 public:
48 #ifndef DOXYGEN
49   Exec(Exec const&) = delete;
50   Exec& operator=(Exec const&) = delete;
51 #endif
52   /*! Signal fired each time that an execution actually starts (no veto) */
53   static void on_start_cb(const std::function<void(Exec const&)>& cb) { on_start.connect(cb); }
54
55   static ExecPtr init();
56   Exec* start() override;
57
58   /*! take a vector of s4u::ExecPtr and return when one of them is finished.
59    * The return value is the rank of the first finished ExecPtr. */
60   static ssize_t wait_any(const std::vector<ExecPtr>& execs) { return wait_any_for(execs, -1); }
61   /*! Same as wait_any, but with a timeout. If the timeout occurs, parameter last is returned.*/
62   static ssize_t wait_any_for(const std::vector<ExecPtr>& execs, double timeout);
63
64 #ifndef DOXYGEN
65   XBT_ATTRIB_DEPRECATED_v332("Please use a plain vector for parameter")
66   static int wait_any(std::vector<ExecPtr>* execs) { return static_cast<int>(wait_any_for(*execs, -1)); }
67   XBT_ATTRIB_DEPRECATED_v332("Please use a plain vector for first parameter")
68   static int wait_any_for(std::vector<ExecPtr>* execs, double timeout) { return static_cast<int>(wait_any_for(*execs, timeout)); }
69 #endif
70
71   /** @brief On sequential executions, returns the amount of flops that remain to be done; This cannot be used on
72    * parallel executions. */
73   double get_remaining() const override;
74   double get_remaining_ratio() const;
75   ExecPtr set_host(Host* host);
76   ExecPtr set_hosts(const std::vector<Host*>& hosts);
77   ExecPtr unset_host();
78   ExecPtr unset_hosts() { return unset_host(); }
79
80   ExecPtr set_flops_amount(double flops_amount);
81   ExecPtr set_flops_amounts(const std::vector<double>& flops_amounts);
82   ExecPtr set_bytes_amounts(const std::vector<double>& bytes_amounts);
83
84   ExecPtr set_bound(double bound);
85   ExecPtr set_priority(double priority);
86   ExecPtr update_priority(double priority);
87
88   Host* get_host() const;
89   unsigned int get_host_number() const;
90   double get_cost() const;
91   bool is_parallel() const { return parallel_; }
92   bool is_assigned() const override;
93 };
94
95 } // namespace s4u
96 } // namespace simgrid
97
98 #endif /* SIMGRID_S4U_EXEC_HPP */