Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a8d7cb7311d671ae61a920adfe20d1dc5e441e79
[simgrid.git] / src / surf / sio_S22.hpp
1 /* Copyright (c) 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
7 #include "src/kernel/resource/NetworkModel.hpp"
8 #include "src/surf/HostImpl.hpp"
9 #include <xbt/base.h>
10
11 #ifndef SIO_S22_HPP_
12 #define SIO_S22_HPP_
13
14 namespace simgrid::kernel::resource {
15
16 /***********
17  * Classes *
18  ***********/
19
20 class XBT_PRIVATE HostS22Model;
21 class XBT_PRIVATE DiskS22Model;
22 class XBT_PRIVATE NetworkS22Model;
23
24 class XBT_PRIVATE DiskS22;
25 class XBT_PRIVATE LinkS22;
26
27 class XBT_PRIVATE S22Action;
28
29 /*********
30  * Model *
31  *********/
32 class HostS22Model : public HostModel {
33 public:
34   HostS22Model(const std::string& name, lmm::System* sys);
35   HostS22Model(const HostS22Model&) = delete;
36   HostS22Model& operator=(const HostS22Model&) = delete;
37
38   double next_occurring_event(double now) override;
39   void update_actions_state(double now, double delta) override;
40   Action* execute_thread(const s4u::Host* host, double flops_amount, int thread_count) override { return nullptr; }
41   CpuAction* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
42                               const double* bytes_amount, double rate) override { return nullptr; }
43   DiskAction* io_stream(s4u::Host* src_host, DiskImpl* src_disk, s4u::Host* dst_host, DiskImpl* dst_disk,
44                         double size) override;
45 };
46
47 class DiskS22Model : public DiskModel {
48 public:
49   DiskS22Model(const std::string& name, HostS22Model* hmodel, lmm::System* sys);
50   DiskS22Model(const DiskS22Model&) = delete;
51   DiskS22Model& operator=(const DiskS22Model&) = delete;
52   ~DiskS22Model() override;
53   void update_actions_state(double /*now*/, double /*delta*/) override{
54       /* this action is done by HostS22Model which shares the LMM system with the Disk model
55        * Overriding to an empty function here allows us to handle the DiskS22Model as a regular
56        * method in EngineImpl::presolve */
57   };
58
59   DiskImpl* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) override;
60   HostS22Model* hostModel_;
61 };
62
63 class NetworkS22Model : public NetworkModel {
64 public:
65   NetworkS22Model(const std::string& name, HostS22Model* hmodel, lmm::System* sys);
66   NetworkS22Model(const NetworkS22Model&) = delete;
67   NetworkS22Model& operator=(const NetworkS22Model&) = delete;
68   ~NetworkS22Model() 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 HostS22Model which shares the LMM system with the Network model
75        * Overriding to an empty function here allows us to handle the NetworkS22Model as a regular
76        * method in EngineImpl::presolve */
77   };
78
79   HostS22Model* hostModel_;
80 };
81
82 /************
83  * Resource *
84  ************/
85
86 class DiskS22 : public DiskImpl {
87 public:
88   using DiskImpl::DiskImpl;
89   DiskS22(const DiskS22&) = delete;
90   DiskS22& operator=(const DiskS22&) = delete;
91
92   void apply_event(profile::Event* event, double value) override;
93   DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) override;
94 };
95
96 class LinkS22 : public StandardLinkImpl {
97 public:
98   LinkS22(const std::string& name, double bandwidth, lmm::System* system);
99   LinkS22(const LinkS22&) = delete;
100   LinkS22& operator=(const LinkS22&) = delete;
101   ~LinkS22() = default;
102
103   void apply_event(profile::Event* event, double value) override;
104   void set_bandwidth(double value) override;
105   void set_latency(double value) override;
106 };
107
108 /**********
109  * Action *
110  **********/
111
112 class S22Action : public DiskAction {
113   const s4u::Host* src_host_;
114   const DiskImpl* src_disk_;
115   const s4u::Host* dst_host_;
116   const DiskImpl* dst_disk_;
117
118   const double size_;
119
120   double latency_;
121
122   friend DiskAction* DiskS22::io_start(sg_size_t size, s4u::Io::OpType type);
123   friend Action* NetworkS22Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
124
125   double calculate_io_read_bound() const;
126   double calculate_io_write_bound() const;
127
128   /**
129    * @brief Calculate the network bound for the parallel task
130    *
131    * The network bound depends on the largest latency between the communication in the ptask.
132    * Return MAX_DOUBLE if latency is 0 (or ptask doesn't have any communication)
133    */
134   double calculate_network_bound() const;
135
136 public:
137   S22Action() = delete;
138   S22Action(Model* model, s4u::Host* src_host, DiskImpl* src_disk, s4u::Host* dst_host, DiskImpl* dst_disk, double size);
139   S22Action(const S22Action&) = delete;
140   S22Action& operator=(const S22Action&) = delete;
141   ~S22Action() = default;
142
143   void update_bound() const;
144   double get_latency() const { return latency_; }
145   void set_latency(double latency) { latency_ = latency; }
146   void update_latency(double delta, double precision) { double_update(&latency_, delta, precision); }
147 };
148
149 } // namespace simgrid::kernel::resource
150
151 #endif /* SIO_S22_HPP_ */