1 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_S4U_EXEC_HPP
7 #define SIMGRID_S4U_EXEC_HPP
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Activity.hpp>
11 #include <simgrid/s4u/Actor.hpp>
17 /** Computation Activity, representing the asynchronous executions.
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.
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.
32 class XBT_PUBLIC Exec : public Activity_T<Exec> {
34 friend kernel::activity::ExecImpl;
35 friend kernel::EngineImpl; // Auto-completes the execs of maestro (in simDAG)
38 bool parallel_ = false;
41 explicit Exec(kernel::activity::ExecImplPtr pimpl);
42 Exec* do_start() override;
46 static xbt::signal<void(Exec const&)> on_start;
50 Exec(Exec const&) = delete;
51 Exec& operator=(Exec const&) = delete;
53 /*! Signal fired each time that an execution actually starts (no veto) */
54 static void on_start_cb(const std::function<void(Exec const&)>& cb) { on_start.connect(cb); }
55 void fire_this_completion() const { on_completion(*this); }
57 static ExecPtr init();
59 /*! take a vector of s4u::ExecPtr and return when one of them is finished.
60 * The return value is the rank of the first finished ExecPtr. */
61 static ssize_t wait_any(const std::vector<ExecPtr>& execs) { return wait_any_for(execs, -1); }
62 /*! Same as wait_any, but with a timeout. If the timeout occurs, parameter last is returned.*/
63 static ssize_t wait_any_for(const std::vector<ExecPtr>& execs, double timeout);
65 /** @brief On sequential executions, returns the amount of flops that remain to be done; This cannot be used on
66 * parallel executions. */
67 double get_remaining() const override;
68 double get_remaining_ratio() const;
69 ExecPtr set_host(Host* host);
70 ExecPtr set_hosts(const std::vector<Host*>& hosts);
72 ExecPtr unset_hosts() { return unset_host(); }
74 ExecPtr set_flops_amount(double flops_amount);
75 ExecPtr set_flops_amounts(const std::vector<double>& flops_amounts);
76 ExecPtr set_bytes_amounts(const std::vector<double>& bytes_amounts);
78 ExecPtr set_thread_count(int thread_count);
80 ExecPtr set_bound(double bound);
81 ExecPtr set_priority(double priority);
82 ExecPtr update_priority(double priority);
84 Host* get_host() const;
85 unsigned int get_host_number() const;
86 int get_thread_count() const;
87 double get_cost() const;
88 bool is_parallel() const { return parallel_; }
89 bool is_assigned() const override;
93 } // namespace simgrid
95 #endif /* SIMGRID_S4U_EXEC_HPP */