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. */
9 #include "src/kernel/resource/HostImpl.hpp"
10 #include "src/kernel/resource/NetworkModel.hpp"
11 #include "src/simgrid/math_utils.h"
16 namespace simgrid::kernel::resource {
22 class XBT_PRIVATE HostL07Model;
23 class XBT_PRIVATE CpuL07Model;
24 class XBT_PRIVATE NetworkL07Model;
26 class XBT_PRIVATE CpuL07;
27 class XBT_PRIVATE LinkL07;
29 class XBT_PRIVATE L07Action;
34 class HostL07Model : public HostModel {
36 HostL07Model(const std::string& name, lmm::System* sys);
37 HostL07Model(const HostL07Model&) = delete;
38 HostL07Model& operator=(const HostL07Model&) = delete;
40 double next_occurring_event(double now) override;
41 void update_actions_state(double now, double delta) override;
42 Action* execute_thread(const s4u::Host* host, double flops_amount, int thread_count) override { return nullptr; }
43 CpuAction* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
44 const double* bytes_amount, double rate) override;
45 Action* io_stream(s4u::Host* src_host, DiskImpl* src_disk, s4u::Host* dst_host, DiskImpl* dst_disk,
52 class CpuL07Model : public CpuModel {
54 CpuL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
55 CpuL07Model(const CpuL07Model&) = delete;
56 CpuL07Model& operator=(const CpuL07Model&) = delete;
57 ~CpuL07Model() override;
58 void update_actions_state(double /*now*/, double /*delta*/) override{
59 /* this action is done by HostL07Model which shares the LMM system with the CPU model
60 * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
61 * method in EngineImpl::presolve */
64 CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
65 HostL07Model* hostModel_;
68 class NetworkL07Model : public NetworkModel {
70 NetworkL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
71 NetworkL07Model(const NetworkL07Model&) = delete;
72 NetworkL07Model& operator=(const NetworkL07Model&) = delete;
73 ~NetworkL07Model() override;
74 StandardLinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths) final;
75 StandardLinkImpl* create_wifi_link(const std::string& name, const std::vector<double>& bandwidths) override;
77 Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate, bool streamed) override;
78 void update_actions_state(double /*now*/, double /*delta*/) override{
79 /* this action is done by HostL07Model which shares the LMM system with the CPU model
80 * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
81 * method in EngineImpl::presolve */
84 HostL07Model* hostModel_;
91 class CpuL07 : public CpuImpl {
93 using CpuImpl::CpuImpl;
94 CpuL07(const CpuL07&) = delete;
95 CpuL07& operator=(const CpuL07&) = delete;
97 void apply_event(profile::Event* event, double value) override;
98 CpuAction* execution_start(double size, double user_bound) override;
99 CpuAction* execution_start(double, int, double) override
104 CpuAction* sleep(double duration) override;
107 void on_speed_change() override;
110 class LinkL07 : public StandardLinkImpl {
112 LinkL07(const std::string& name, double bandwidth, lmm::System* system);
113 LinkL07(const LinkL07&) = delete;
114 LinkL07& operator=(const LinkL07&) = delete;
116 void apply_event(profile::Event* event, double value) override;
117 void set_bandwidth(double value) override;
118 void set_latency(double value) override;
124 class L07Action : public CpuAction {
125 const std::vector<s4u::Host*> host_list_;
126 bool free_arrays_ = false; // By default, computation_amount_ and friends are freed by caller. But not for sequential
127 // exec and regular comms
128 const double* computation_amount_; /* pointer to the data that lives in s4u action -- do not free unless if
130 const double* communication_amount_; /* pointer to the data that lives in s4u action -- do not free unless if
135 friend CpuAction* CpuL07::execution_start(double size, double user_bound);
136 friend CpuAction* CpuL07::sleep(double duration);
137 friend CpuAction* HostL07Model::execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
138 const double* bytes_amount, double rate);
139 friend Action* NetworkL07Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate, bool streamed);
141 * @brief Calculate the CPU bound for the parallel task
143 * The task is bounded by the slowest CPU running the ptask, considering the current pstate of each CPU.
144 * Return MAX_DOUBLE if ptask has no computation.
146 double calculate_cpu_bound() const;
149 * @brief Calculate the network bound for the parallel task
151 * The network bound depends on the largest latency between the communication in the ptask.
152 * Return MAX_DOUBLE if latency is 0 (or ptask doesn't have any communication)
154 double calculate_network_bound() const;
157 L07Action() = delete;
158 L07Action(Model* model, const std::vector<s4u::Host*>& host_list, const double* flops_amount,
159 const double* bytes_amount, double rate);
160 L07Action(const L07Action&) = delete;
161 L07Action& operator=(const L07Action&) = delete;
162 ~L07Action() override;
164 void update_bound() const;
165 double get_latency() const { return latency_; }
166 void set_latency(double latency) { latency_ = latency; }
167 void update_latency(double delta, double precision) { double_update(&latency_, delta, precision); }
170 } // namespace simgrid::kernel::resource
172 #endif /* HOST_L07_HPP_ */