Logo AND Algorithmique Numérique Distribuée

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