Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / kernel / resource / models / ptask_L07.hpp
1 /* Copyright (c) 2013-2023. 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 HOST_L07_HPP_
7 #define HOST_L07_HPP_
8
9 #include "src/kernel/resource/HostImpl.hpp"
10 #include "src/kernel/resource/NetworkModel.hpp"
11 #include "src/simgrid/math_utils.h"
12 #include <cstdlib>
13 #include <vector>
14 #include <xbt/base.h>
15
16 namespace simgrid::kernel::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   HostL07Model(const std::string& name, lmm::System* sys);
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   Action* execute_thread(const s4u::Host* host, double flops_amount, int thread_count) override { return nullptr; }
43   CpuAction* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
44                               const double* bytes_amount, double rate) override;
45   Action* io_stream(s4u::Host* src_host, DiskImpl* src_disk, s4u::Host* dst_host, DiskImpl* dst_disk,
46                     double size) override
47   {
48     return nullptr;
49   }
50 };
51
52 class CpuL07Model : public CpuModel {
53 public:
54   CpuL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
55   CpuL07Model(const CpuL07Model&)            = delete;
56   CpuL07Model& operator=(const CpuL07Model&) = delete;
57   ~CpuL07Model() override;
58   void update_actions_state(double /*now*/, double /*delta*/) override{
59       /* this action is done by HostL07Model which shares the LMM system with the CPU model
60        * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
61        * method in EngineImpl::presolve */
62   };
63
64   CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
65   HostL07Model* hostModel_;
66 };
67
68 class NetworkL07Model : public NetworkModel {
69 public:
70   NetworkL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
71   NetworkL07Model(const NetworkL07Model&)            = delete;
72   NetworkL07Model& operator=(const NetworkL07Model&) = delete;
73   ~NetworkL07Model() override;
74   StandardLinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) final;
75   StandardLinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) override;
76
77   Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate, bool streamed) override;
78   void update_actions_state(double /*now*/, double /*delta*/) override{
79       /* this action is done by HostL07Model which shares the LMM system with the CPU model
80        * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
81        * method in EngineImpl::presolve */
82   };
83
84   HostL07Model* hostModel_;
85 };
86
87 /************
88  * Resource *
89  ************/
90
91 class CpuL07 : public CpuImpl {
92 public:
93   using CpuImpl::CpuImpl;
94   CpuL07(const CpuL07&)            = delete;
95   CpuL07& operator=(const CpuL07&) = delete;
96
97   void apply_event(profile::Event* event, double value) override;
98   CpuAction* execution_start(double size, double user_bound) override;
99   CpuAction* execution_start(double, int, double) override
100   {
101     THROW_UNIMPLEMENTED;
102     return nullptr;
103   }
104   CpuAction* sleep(double duration) override;
105
106 protected:
107   void on_speed_change() override;
108 };
109
110 class LinkL07 : public StandardLinkImpl {
111 public:
112   LinkL07(const std::string& name, double bandwidth, lmm::System* system);
113   LinkL07(const LinkL07&)            = delete;
114   LinkL07& operator=(const LinkL07&) = delete;
115   ~LinkL07() override;
116   void apply_event(profile::Event* event, double value) override;
117   void set_bandwidth(double value) override;
118   void set_latency(double value) override;
119 };
120
121 /**********
122  * Action *
123  **********/
124 class L07Action : public CpuAction {
125   const std::vector<s4u::Host*> host_list_;
126   bool free_arrays_ = false; // By default, computation_amount_ and friends are freed by caller. But not for sequential
127                              // exec and regular comms
128   const double* computation_amount_;   /* pointer to the data that lives in s4u action -- do not free unless if
129                                         * free_arrays */
130   const double* communication_amount_; /* pointer to the data that lives in s4u action -- do not free unless if
131                                         * free_arrays */
132   double latency_;
133   double rate_;
134
135   friend CpuAction* CpuL07::execution_start(double size, double user_bound);
136   friend CpuAction* CpuL07::sleep(double duration);
137   friend CpuAction* HostL07Model::execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
138                                                    const double* bytes_amount, double rate);
139   friend Action* NetworkL07Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate, bool streamed);
140   /**
141    * @brief Calculate the CPU bound for the parallel task
142    *
143    * The task is bounded by the slowest CPU running the ptask, considering the current pstate of each CPU.
144    * Return MAX_DOUBLE if ptask has no computation.
145    */
146   double calculate_cpu_bound() const;
147
148   /**
149    * @brief Calculate the network bound for the parallel task
150    *
151    * The network bound depends on the largest latency between the communication in the ptask.
152    * Return MAX_DOUBLE if latency is 0 (or ptask doesn't have any communication)
153    */
154   double calculate_network_bound() const;
155
156 public:
157   L07Action() = delete;
158   L07Action(Model* model, const std::vector<s4u::Host*>& host_list, const double* flops_amount,
159             const double* bytes_amount, double rate);
160   L07Action(const L07Action&)            = delete;
161   L07Action& operator=(const L07Action&) = delete;
162   ~L07Action() override;
163
164   void update_bound() const;
165   double get_latency() const { return latency_; }
166   void set_latency(double latency) { latency_ = latency; }
167   void update_latency(double delta, double precision) { double_update(&latency_, delta, precision); }
168 };
169
170 } // namespace simgrid::kernel::resource
171
172 #endif /* HOST_L07_HPP_ */