1 /* Copyright (c) 2013-2022. 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/NetworkModel.hpp"
7 #include "src/surf/HostImpl.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;
46 class CpuL07Model : public CpuModel {
48 CpuL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
49 CpuL07Model(const CpuL07Model&) = delete;
50 CpuL07Model& operator=(const CpuL07Model&) = delete;
51 ~CpuL07Model() override;
52 void update_actions_state(double /*now*/, double /*delta*/) override{
53 /* this action is done by HostL07Model which shares the LMM system with the CPU model
54 * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
55 * method in EngineImpl::presolve */
58 CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
59 HostL07Model* hostModel_;
62 class NetworkL07Model : public NetworkModel {
64 NetworkL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
65 NetworkL07Model(const NetworkL07Model&) = delete;
66 NetworkL07Model& operator=(const NetworkL07Model&) = delete;
67 ~NetworkL07Model() 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;
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 HostL07Model which shares the LMM system with the CPU model
74 * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
75 * method in EngineImpl::presolve */
78 HostL07Model* hostModel_;
85 class CpuL07 : public CpuImpl {
87 using CpuImpl::CpuImpl;
88 CpuL07(const CpuL07&) = delete;
89 CpuL07& operator=(const CpuL07&) = delete;
91 void apply_event(profile::Event* event, double value) override;
92 CpuAction* execution_start(double size, double user_bound) override;
93 CpuAction* execution_start(double, int, double) override
98 CpuAction* sleep(double duration) override;
101 void on_speed_change() override;
104 class LinkL07 : public StandardLinkImpl {
106 LinkL07(const std::string& name, double bandwidth, lmm::System* system);
107 LinkL07(const LinkL07&) = delete;
108 LinkL07& operator=(const LinkL07&) = delete;
110 void apply_event(profile::Event* event, double value) override;
111 void set_bandwidth(double value) override;
112 void set_latency(double value) override;
118 class L07Action : public CpuAction {
119 const std::vector<s4u::Host*> host_list_;
120 bool free_arrays_ = false; // By default, computation_amount_ and friends are freed by caller. But not for sequential
121 // exec and regular comms
122 const double* computation_amount_; /* pointer to the data that lives in s4u action -- do not free unless if
124 const double* communication_amount_; /* pointer to the data that lives in s4u action -- do not free unless if
129 friend CpuAction* CpuL07::execution_start(double size, double user_bound);
130 friend CpuAction* CpuL07::sleep(double duration);
131 friend CpuAction* HostL07Model::execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
132 const double* bytes_amount, double rate);
133 friend Action* NetworkL07Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
135 * @brief Calculate the CPU bound for the parallel task
137 * The task is bounded by the slowest CPU running the ptask, considering the current pstate of each CPU.
138 * Return MAX_DOUBLE if ptask has no computation.
140 double calculate_cpu_bound() const;
143 * @brief Calculate the network bound for the parallel task
145 * The network bound depends on the largest latency between the communication in the ptask.
146 * Return MAX_DOUBLE if latency is 0 (or ptask doesn't have any communication)
148 double calculate_network_bound() const;
151 L07Action() = delete;
152 L07Action(Model* model, const std::vector<s4u::Host*>& host_list, const double* flops_amount,
153 const double* bytes_amount, double rate);
154 L07Action(const L07Action&) = delete;
155 L07Action& operator=(const L07Action&) = delete;
156 ~L07Action() override;
158 void update_bound() const;
159 double get_latency() const { return latency_; }
160 void set_latency(double latency) { latency_ = latency; }
161 void update_latency(double delta, double precision) { double_update(&latency_, delta, precision); }
164 } // namespace simgrid::kernel::resource
166 #endif /* HOST_L07_HPP_ */