Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
introduce thread_execute
[simgrid.git] / src / kernel / activity / ExecImpl.hpp
1 /* Copyright (c) 2007-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_KERNEL_ACTIVITY_EXEC_HPP
7 #define SIMGRID_KERNEL_ACTIVITY_EXEC_HPP
8
9 #include <simgrid/s4u/Exec.hpp>
10
11 #include "src/kernel/activity/ActivityImpl.hpp"
12 #include "src/kernel/context/Context.hpp"
13
14 namespace simgrid {
15 namespace kernel {
16 namespace activity {
17
18 class XBT_PUBLIC ExecImpl : public ActivityImpl_T<ExecImpl> {
19   std::unique_ptr<resource::Action, std::function<void(resource::Action*)>> timeout_detector_{
20       nullptr, [](resource::Action* a) { a->unref(); }};
21   double sharing_penalty_             = 1.0;
22   double bound_                       = 0.0;
23   std::vector<s4u::Host*> hosts_;
24   std::vector<double> flops_amounts_;
25   std::vector<double> bytes_amounts_;
26   int thread_count_ = 1;
27   int cb_id_ = -1; // callback id from Host::on_state_change.connect()
28
29 public:
30   ExecImpl();
31
32   ExecImpl& set_timeout(double timeout) override;
33   ExecImpl& set_bound(double bound);
34   ExecImpl& set_sharing_penalty(double sharing_penalty);
35   ExecImpl& update_sharing_penalty(double sharing_penalty);
36
37   void set_cb_id(unsigned int cb_id) { cb_id_ = cb_id; }
38
39   ExecImpl& set_flops_amount(double flop_amount);
40   ExecImpl& set_host(s4u::Host* host);
41   s4u::Host* get_host() const { return hosts_.front(); }
42   const std::vector<s4u::Host*>& get_hosts() const { return hosts_; }
43
44   ExecImpl& set_flops_amounts(const std::vector<double>& flops_amounts);
45   ExecImpl& set_bytes_amounts(const std::vector<double>& bytes_amounts);
46   ExecImpl& set_thread_count(int thread_count);
47   ExecImpl& set_hosts(const std::vector<s4u::Host*>& hosts);
48
49   unsigned int get_host_number() const { return hosts_.size(); }
50   double get_seq_remaining_ratio();
51   double get_par_remaining_ratio();
52   double get_remaining() const override;
53   virtual ActivityImpl* migrate(s4u::Host* to);
54
55   ExecImpl* start();
56   void post() override;
57   void set_exception(actor::ActorImpl* issuer) override;
58   void finish() override;
59
60   void reset();
61
62   static xbt::signal<void(ExecImpl const&, s4u::Host*)> on_migration;
63 };
64 } // namespace activity
65 } // namespace kernel
66 } // namespace simgrid
67 #endif