Logo AND Algorithmique Numérique Distribuée

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