Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fixes
[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, double size);
44 };
45
46 class DiskS22Model : public DiskModel {
47 public:
48   DiskS22Model(const std::string& name, HostS22Model* hmodel, lmm::System* sys);
49   DiskS22Model(const DiskS22Model&) = delete;
50   DiskS22Model& operator=(const DiskS22Model&) = delete;
51   ~DiskS22Model() override;
52   void update_actions_state(double /*now*/, double /*delta*/) override{
53       /* this action is done by HostS22Model which shares the LMM system with the Disk model
54        * Overriding to an empty function here allows us to handle the DiskS22Model as a regular
55        * method in EngineImpl::presolve */
56   };
57
58   DiskImpl* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth) override;
59   HostS22Model* hostModel_;
60 };
61
62 class NetworkS22Model : public NetworkModel {
63 public:
64   NetworkS22Model(const std::string& name, HostS22Model* hmodel, lmm::System* sys);
65   NetworkS22Model(const NetworkS22Model&) = delete;
66   NetworkS22Model& operator=(const NetworkS22Model&) = delete;
67   ~NetworkS22Model() override;
68   StandardLinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) final;
69   StandardLinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) override;
70
71   Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
72   void update_actions_state(double /*now*/, double /*delta*/) override{
73       /* this action is done by HostS22Model which shares the LMM system with the Network model
74        * Overriding to an empty function here allows us to handle the NetworkS22Model as a regular
75        * method in EngineImpl::presolve */
76   };
77
78   HostS22Model* hostModel_;
79 };
80
81 /************
82  * Resource *
83  ************/
84
85 class DiskS22 : public DiskImpl {
86 public:
87   using DiskImpl::DiskImpl;
88   DiskS22(const DiskS22&) = delete;
89   DiskS22& operator=(const DiskS22&) = delete;
90
91   void apply_event(profile::Event* event, double value) override;
92   DiskAction* io_start(sg_size_t size, s4u::Io::OpType type) override;
93 };
94
95 class LinkS22 : public StandardLinkImpl {
96 public:
97   LinkS22(const std::string& name, double bandwidth, lmm::System* system);
98   LinkS22(const LinkS22&) = delete;
99   LinkS22& operator=(const LinkS22&) = delete;
100   ~LinkS22() = default;
101
102   void apply_event(profile::Event* event, double value) override;
103   void set_bandwidth(double value) override;
104   void set_latency(double value) override;
105 };
106
107 /**********
108  * Action *
109  **********/
110 class S22Action : public DiskAction {
111   const s4u::Host* src_host_;
112   const DiskImpl* src_disk_;
113   const s4u::Host* dst_host_;
114   const DiskImpl* dst_disk_;
115
116   const double size_;
117
118   double latency_;
119   double rate_;
120
121   friend DiskAction* DiskS22::io_start(sg_size_t size, s4u::Io::OpType type);
122   friend Action* NetworkS22Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
123
124   double calculate_io_read_bound() const;
125   double calculate_io_write_bound() const;
126
127   /**
128    * @brief Calculate the network bound for the parallel task
129    *
130    * The network bound depends on the largest latency between the communication in the ptask.
131    * Return MAX_DOUBLE if latency is 0 (or ptask doesn't have any communication)
132    */
133   double calculate_network_bound() const;
134
135 public:
136   S22Action() = delete;
137   S22Action(Model* model, s4u::Host* src_host, DiskImpl* src_disk, s4u::Host* dst_host, DiskImpl* dst_disk, double size);
138   S22Action(const S22Action&) = delete;
139   S22Action& operator=(const S22Action&) = delete;
140   ~S22Action() = default;
141
142   void update_bound() const;
143   double get_latency() const { return latency_; }
144   void set_latency(double latency) { latency_ = latency; }
145   void update_latency(double delta, double precision) { double_update(&latency_, delta, precision); }
146 };
147
148 } // namespace simgrid::kernel::resource
149
150 #endif /* SIO_S22_HPP_ */