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>
14 namespace simgrid::s4u {
16 /** Computation Activity, representing the asynchronous executions.
19 * Most of them are created with :cpp:func:`simgrid::s4u::this_actor::exec_init()` or
20 * :cpp:func:`simgrid::s4u::Host::execute()`, and represent a classical (sequential) execution. This can be used to
21 * simulate some computation occurring in another thread when the calling actor is not blocked during the execution.
23 * You can also use :cpp:func:`simgrid::s4u::this_actor::parallel_execute()` to create *parallel* executions. These
24 * objects represent distributed computations involving computations on several hosts and communications between them.
25 * Such objects can for example represent a matrix multiplication done with ScaLAPACK on a real system. Once created,
26 * parallel Exec are very similar to the sequential ones. The only difference is that you cannot migrate them, and their
27 * remaining amount of work can only be defined as a ratio. See the doc of :cpp:func:`simgrid::s4u::Exec::get_remaining`
28 * and :cpp:func:`simgrid::s4u::Exec::get_remaining_ratio` for more info.
31 class XBT_PUBLIC Exec : public Activity_T<Exec> {
33 friend kernel::activity::ExecImpl;
34 friend kernel::EngineImpl; // Auto-completes the execs of maestro (in simDAG)
37 bool parallel_ = false;
40 explicit Exec(kernel::activity::ExecImplPtr pimpl);
41 Exec* do_start() override;
47 Exec(Exec const&) = delete;
48 Exec& operator=(Exec const&) = delete;
50 /*! \static Initiate the creation of an Exec. Setters have to be called afterwards */
51 static ExecPtr init();
53 /** @brief On sequential executions, returns the amount of flops that remain to be done; This cannot be used on
54 * parallel executions. */
55 double get_remaining() const override;
56 double get_remaining_ratio() const;
57 ExecPtr set_host(Host* host);
58 ExecPtr set_hosts(const std::vector<Host*>& hosts);
60 ExecPtr unset_hosts() { return unset_host(); }
62 ExecPtr set_flops_amount(double flops_amount);
63 ExecPtr set_flops_amounts(const std::vector<double>& flops_amounts);
64 ExecPtr set_bytes_amounts(const std::vector<double>& bytes_amounts);
66 ExecPtr set_thread_count(int thread_count);
68 ExecPtr set_bound(double bound);
69 ExecPtr set_priority(double priority);
70 ExecPtr update_priority(double priority);
72 Host* get_host() const;
73 unsigned int get_host_number() const;
74 int get_thread_count() const;
75 double get_cost() const;
76 bool is_parallel() const { return parallel_; }
77 bool is_assigned() const override;
80 static ssize_t deprecated_wait_any_for(const std::vector<ExecPtr>& execs, double timeout); // XBT_ATTRIB_DEPRECATED_v339
82 XBT_ATTRIB_DEPRECATED_v339("Please use ActivitySet instead") static ssize_t
83 wait_any(const std::vector<ExecPtr>& execs) { return deprecated_wait_any_for(execs, -1); }
84 XBT_ATTRIB_DEPRECATED_v339("Please use ActivitySet instead") static ssize_t
85 wait_any_for(const std::vector<ExecPtr>& execs, double timeout) { return deprecated_wait_any_for(execs, timeout); }
89 } // namespace simgrid::s4u
91 #endif /* SIMGRID_S4U_EXEC_HPP */