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/surf/HostImpl.hpp"
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;
47 class CpuL07Model : public CpuModel {
49 CpuL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
50 CpuL07Model(const CpuL07Model&) = delete;
51 CpuL07Model& operator=(const CpuL07Model&) = delete;
52 ~CpuL07Model() override;
53 void update_actions_state(double /*now*/, double /*delta*/) override{
54 /* this action is done by HostL07Model which shares the LMM system with the CPU model
55 * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
56 * method in EngineImpl::presolve */
59 CpuImpl* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate) override;
60 HostL07Model* hostModel_;
63 class NetworkL07Model : public NetworkModel {
65 NetworkL07Model(const std::string& name, HostL07Model* hmodel, lmm::System* sys);
66 NetworkL07Model(const NetworkL07Model&) = delete;
67 NetworkL07Model& operator=(const NetworkL07Model&) = delete;
68 ~NetworkL07Model() 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;
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 HostL07Model which shares the LMM system with the CPU model
75 * Overriding to an empty function here allows us to handle the Cpu07Model as a regular
76 * method in EngineImpl::presolve */
79 HostL07Model* hostModel_;
86 class CpuL07 : public CpuImpl {
88 using CpuImpl::CpuImpl;
89 CpuL07(const CpuL07&) = delete;
90 CpuL07& operator=(const CpuL07&) = delete;
92 void apply_event(profile::Event* event, double value) override;
93 CpuAction* execution_start(double size, double user_bound) override;
94 CpuAction* execution_start(double, int, double) override
99 CpuAction* sleep(double duration) override;
102 void on_speed_change() override;
105 class LinkL07 : public StandardLinkImpl {
107 LinkL07(const std::string& name, double bandwidth, lmm::System* system);
108 LinkL07(const LinkL07&) = delete;
109 LinkL07& operator=(const LinkL07&) = delete;
111 void apply_event(profile::Event* event, double value) override;
112 void set_bandwidth(double value) override;
113 void set_latency(double value) override;
119 class L07Action : public CpuAction {
120 std::vector<s4u::Host*> hostList_;
121 bool free_arrays_ = false; // By default, computationAmount_ and friends are freed by caller. But not for sequential
122 // exec and regular comms
123 const double* computationAmount_; /* pointer to the data that lives in s4u action -- do not free unless if
125 const double* communicationAmount_; /* pointer to the data that lives in s4u action -- do not free unless if
130 friend CpuAction* CpuL07::execution_start(double size, double user_bound);
131 friend CpuAction* CpuL07::sleep(double duration);
132 friend CpuAction* HostL07Model::execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
133 const double* bytes_amount, double rate);
134 friend Action* NetworkL07Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
136 * @brief Calculate the CPU bound for the parallel task
138 * The task is bounded by the slowest CPU running the ptask, considering the current pstate of each CPU.
139 * Return MAX_DOUBLE if ptask has no computation.
141 double calculateCpuBound();
144 * @brief Calculate the network bound for the parallel task
146 * The network bound depends on the largest latency between the communication in the ptask.
147 * Return MAX_DOUBLE if latency is 0 (or ptask doesn't have any communication)
149 double calculateNetworkBound();
152 L07Action() = delete;
153 L07Action(Model* model, const std::vector<s4u::Host*>& host_list, const double* flops_amount,
154 const double* bytes_amount, double rate);
155 L07Action(const L07Action&) = delete;
156 L07Action& operator=(const L07Action&) = delete;
157 ~L07Action() override;
160 double get_latency() const { return latency_; }
161 void set_latency(double latency) { latency_ = latency; }
162 void update_latency(double delta, double precision) { double_update(&latency_, delta, precision); }
165 } // namespace resource
166 } // namespace kernel
167 } // namespace simgrid
169 #endif /* HOST_L07_HPP_ */