Logo AND Algorithmique Numérique Distribuée

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