1 /* Copyright (c) 2013-2023. The SimGrid Team. All rights reserved. */
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. */
6 #include "src/kernel/resource/HostImpl.hpp"
7 #include "src/kernel/resource/NetworkModel.hpp"
15 namespace simgrid::kernel::resource {
21 class XBT_PRIVATE HostL07Model;
22 class XBT_PRIVATE CpuL07Model;
23 class XBT_PRIVATE NetworkL07Model;
25 class XBT_PRIVATE CpuL07;
26 class XBT_PRIVATE LinkL07;
28 class XBT_PRIVATE L07Action;
33 class HostL07Model : public HostModel {
35 HostL07Model(const std::string& name, lmm::System* sys);
36 HostL07Model(const HostL07Model&) = delete;
37 HostL07Model& operator=(const HostL07Model&) = delete;
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,
51 class CpuL07Model : public CpuModel {
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 */
63 CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
64 HostL07Model* hostModel_;
67 class NetworkL07Model : public NetworkModel {
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;
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 */
83 HostL07Model* hostModel_;
90 class CpuL07 : public CpuImpl {
92 using CpuImpl::CpuImpl;
93 CpuL07(const CpuL07&) = delete;
94 CpuL07& operator=(const CpuL07&) = delete;
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
103 CpuAction* sleep(double duration) override;
106 void on_speed_change() override;
109 class LinkL07 : public StandardLinkImpl {
111 LinkL07(const std::string& name, double bandwidth, lmm::System* system);
112 LinkL07(const LinkL07&) = delete;
113 LinkL07& operator=(const LinkL07&) = delete;
115 void apply_event(profile::Event* event, double value) override;
116 void set_bandwidth(double value) override;
117 void set_latency(double value) override;
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
129 const double* communication_amount_; /* pointer to the data that lives in s4u action -- do not free unless if
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);
140 * @brief Calculate the CPU bound for the parallel task
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.
145 double calculate_cpu_bound() const;
148 * @brief Calculate the network bound for the parallel task
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)
153 double calculate_network_bound() const;
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;
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); }
169 } // namespace simgrid::kernel::resource
171 #endif /* HOST_L07_HPP_ */