Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reworking user_bound for Exec actions.
[simgrid.git] / src / surf / ptask_L07.hpp
1 /* Copyright (c) 2013-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 #include "src/surf/HostImpl.hpp"
7 #include <cstdlib>
8 #include <vector>
9 #include <xbt/base.h>
10
11 #ifndef HOST_L07_HPP_
12 #define HOST_L07_HPP_
13
14 namespace simgrid {
15 namespace surf {
16
17 /***********
18  * Classes *
19  ***********/
20
21 class XBT_PRIVATE HostL07Model;
22 class XBT_PRIVATE CpuL07Model;
23 class XBT_PRIVATE NetworkL07Model;
24
25 class XBT_PRIVATE CpuL07;
26 class XBT_PRIVATE LinkL07;
27
28 class XBT_PRIVATE L07Action;
29 /*********
30  * Tools *
31  *********/
32
33 /*********
34  * Model *
35  *********/
36 class HostL07Model : public HostModel {
37 public:
38   explicit HostL07Model(const std::string& name);
39   HostL07Model(const HostL07Model&) = delete;
40   HostL07Model& operator=(const HostL07Model&) = delete;
41
42   double next_occurring_event(double now) override;
43   void update_actions_state(double now, double delta) override;
44   kernel::resource::CpuAction* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
45                                                 const double* bytes_amount, double rate) override;
46 };
47
48 class CpuL07Model : public kernel::resource::CpuModel {
49 public:
50   CpuL07Model(const std::string& name, HostL07Model* hmodel, kernel::lmm::System* sys);
51   CpuL07Model(const CpuL07Model&) = delete;
52   CpuL07Model& operator=(const CpuL07Model&) = delete;
53   ~CpuL07Model() override;
54   void update_actions_state(double /*now*/, double /*delta*/) override{
55       /* this action is done by HostL07Model which shares the LMM system with the CPU model
56        * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
57        * method in surf_presolve */
58   };
59
60   kernel::resource::CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
61   HostL07Model* hostModel_;
62 };
63
64 class NetworkL07Model : public kernel::resource::NetworkModel {
65 public:
66   NetworkL07Model(const std::string& name, HostL07Model* hmodel, kernel::lmm::System* sys);
67   NetworkL07Model(const NetworkL07Model&) = delete;
68   NetworkL07Model& operator=(const NetworkL07Model&) = delete;
69   ~NetworkL07Model() override;
70   kernel::resource::LinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) final;
71   kernel::resource::LinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) override;
72
73   kernel::resource::Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
74   void update_actions_state(double /*now*/, double /*delta*/) override{
75       /* this action is done by HostL07Model which shares the LMM system with the CPU model
76        * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
77        * method in surf_presolve */
78   };
79
80   HostL07Model* hostModel_;
81 };
82
83 /************
84  * Resource *
85  ************/
86
87 class CpuL07 : public kernel::resource::CpuImpl {
88 public:
89   using kernel::resource::CpuImpl::CpuImpl;
90   CpuL07(const CpuL07&) = delete;
91   CpuL07& operator=(const CpuL07&) = delete;
92
93   bool is_used() const override;
94   void apply_event(kernel::profile::Event* event, double value) override;
95   kernel::resource::CpuAction* execution_start(double size, double user_bound) override;
96   kernel::resource::CpuAction* execution_start(double, int, double) override
97   {
98     THROW_UNIMPLEMENTED;
99     return nullptr;
100   }
101   kernel::resource::CpuAction* sleep(double duration) override;
102
103 protected:
104   void on_speed_change() override;
105 };
106
107 class LinkL07 : public kernel::resource::LinkImpl {
108 public:
109   LinkL07(const std::string& name, double bandwidth, kernel::lmm::System* system);
110   LinkL07(const LinkL07&) = delete;
111   LinkL07& operator=(const LinkL07&) = delete;
112   ~LinkL07() override;
113   bool is_used() const override;
114   void apply_event(kernel::profile::Event* event, double value) override;
115   void set_bandwidth(double value) override;
116   void set_latency(double value) override;
117 };
118
119 /**********
120  * Action *
121  **********/
122 class L07Action : public kernel::resource::CpuAction {
123   std::vector<s4u::Host*> hostList_;
124   bool free_arrays_ = false; // By default, computationAmount_ and friends are freed by caller. But not for sequential
125                              // exec and regular comms
126   const double* computationAmount_;   /* pointer to the data that lives in s4u action -- do not free unless if
127                                        * free_arrays */
128   const double* communicationAmount_; /* pointer to the data that lives in s4u action -- do not free unless if
129                                        * free_arrays */
130   double latency_;
131   double rate_;
132
133   friend CpuAction* CpuL07::execution_start(double size, double user_bound);
134   friend CpuAction* CpuL07::sleep(double duration);
135   friend CpuAction* HostL07Model::execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
136                                                    const double* bytes_amount, double rate);
137   friend Action* NetworkL07Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
138
139 public:
140   L07Action() = delete;
141   L07Action(kernel::resource::Model* model, const std::vector<s4u::Host*>& host_list, const double* flops_amount,
142             const double* bytes_amount, double rate);
143   L07Action(const L07Action&) = delete;
144   L07Action& operator=(const L07Action&) = delete;
145   ~L07Action() override;
146
147   void updateBound();
148   double get_latency() const { return latency_; }
149   void set_latency(double latency) { latency_ = latency; }
150   void update_latency(double delta, double precision) { double_update(&latency_, delta, precision); }
151 };
152
153 } // namespace surf
154 } // namespace simgrid
155
156 #endif /* HOST_L07_HPP_ */