Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reorganize *LinkImpl stuff
[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 kernel {
16 namespace resource {
17
18 /***********
19  * Classes *
20  ***********/
21
22 class XBT_PRIVATE HostL07Model;
23 class XBT_PRIVATE CpuL07Model;
24 class XBT_PRIVATE NetworkL07Model;
25
26 class XBT_PRIVATE CpuL07;
27 class XBT_PRIVATE LinkL07;
28
29 class XBT_PRIVATE L07Action;
30
31 /*********
32  * Model *
33  *********/
34 class HostL07Model : public HostModel {
35 public:
36   explicit HostL07Model(const std::string& name);
37   HostL07Model(const HostL07Model&) = delete;
38   HostL07Model& operator=(const HostL07Model&) = delete;
39
40   double next_occurring_event(double now) override;
41   void update_actions_state(double now, double delta) override;
42   CpuAction* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
43                               const double* bytes_amount, double rate) override;
44 };
45
46 class CpuL07Model : public CpuModel {
47 public:
48   CpuL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
49   CpuL07Model(const CpuL07Model&) = delete;
50   CpuL07Model& operator=(const CpuL07Model&) = delete;
51   ~CpuL07Model() override;
52   void update_actions_state(double /*now*/, double /*delta*/) override{
53       /* this action is done by HostL07Model which shares the LMM system with the CPU model
54        * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
55        * method in EngineImpl::presolve */
56   };
57
58   CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
59   HostL07Model* hostModel_;
60 };
61
62 class NetworkL07Model : public NetworkModel {
63 public:
64   NetworkL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
65   NetworkL07Model(const NetworkL07Model&) = delete;
66   NetworkL07Model& operator=(const NetworkL07Model&) = delete;
67   ~NetworkL07Model() override;
68   StandardLinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) final;
69   StandardLinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) override;
70
71   Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
72   void update_actions_state(double /*now*/, double /*delta*/) override{
73       /* this action is done by HostL07Model which shares the LMM system with the CPU model
74        * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
75        * method in EngineImpl::presolve */
76   };
77
78   HostL07Model* hostModel_;
79 };
80
81 /************
82  * Resource *
83  ************/
84
85 class CpuL07 : public CpuImpl {
86 public:
87   using CpuImpl::CpuImpl;
88   CpuL07(const CpuL07&) = delete;
89   CpuL07& operator=(const CpuL07&) = delete;
90
91   void apply_event(profile::Event* event, double value) override;
92   CpuAction* execution_start(double size, double user_bound) override;
93   CpuAction* execution_start(double, int, double) override
94   {
95     THROW_UNIMPLEMENTED;
96     return nullptr;
97   }
98   CpuAction* sleep(double duration) override;
99
100 protected:
101   void on_speed_change() override;
102 };
103
104 class LinkL07 : public StandardLinkImpl {
105 public:
106   LinkL07(const std::string& name, double bandwidth, lmm::System* system);
107   LinkL07(const LinkL07&) = delete;
108   LinkL07& operator=(const LinkL07&) = delete;
109   ~LinkL07() override;
110   void apply_event(profile::Event* event, double value) override;
111   void set_bandwidth(double value) override;
112   void set_latency(double value) override;
113 };
114
115 /**********
116  * Action *
117  **********/
118 class L07Action : public CpuAction {
119   std::vector<s4u::Host*> hostList_;
120   bool free_arrays_ = false; // By default, computationAmount_ and friends are freed by caller. But not for sequential
121                              // exec and regular comms
122   const double* computationAmount_;   /* pointer to the data that lives in s4u action -- do not free unless if
123                                        * free_arrays */
124   const double* communicationAmount_; /* pointer to the data that lives in s4u action -- do not free unless if
125                                        * free_arrays */
126   double latency_;
127   double rate_;
128
129   friend CpuAction* CpuL07::execution_start(double size, double user_bound);
130   friend CpuAction* CpuL07::sleep(double duration);
131   friend CpuAction* HostL07Model::execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
132                                                    const double* bytes_amount, double rate);
133   friend Action* NetworkL07Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
134   /**
135    * @brief Calculate the CPU bound for the parallel task
136    *
137    * The task is bounded by the slowest CPU running the ptask, considering the current pstate of each CPU.
138    * Return MAX_DOUBLE if ptask has no computation.
139    */
140   double calculateCpuBound();
141
142   /**
143    * @brief Calculate the network bound for the parallel task
144    *
145    * The network bound depends on the largest latency between the communication in the ptask.
146    * Return MAX_DOUBLE if latency is 0 (or ptask doesn't have any communication)
147    */
148   double calculateNetworkBound();
149
150 public:
151   L07Action() = delete;
152   L07Action(Model* model, const std::vector<s4u::Host*>& host_list, const double* flops_amount,
153             const double* bytes_amount, double rate);
154   L07Action(const L07Action&) = delete;
155   L07Action& operator=(const L07Action&) = delete;
156   ~L07Action() override;
157
158   void updateBound();
159   double get_latency() const { return latency_; }
160   void set_latency(double latency) { latency_ = latency; }
161   void update_latency(double delta, double precision) { double_update(&latency_, delta, precision); }
162 };
163
164 } // namespace resource
165 } // namespace kernel
166 } // namespace simgrid
167
168 #endif /* HOST_L07_HPP_ */