Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Apply the default settings of 'smpi/buffering' too
[simgrid.git] / src / surf / ptask_L07.hpp
1 /* Copyright (c) 2013-2019. 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 #include <cstdlib>
7 #include <vector>
8 #include <xbt/base.h>
9 #include "src/surf/HostImpl.hpp"
10
11 #ifndef HOST_L07_HPP_
12 #define HOST_L07_HPP_
13
14 namespace simgrid {
15 namespace surf {
16
17 /***********
18  * Classes *
19  ***********/
20
21 class XBT_PRIVATE HostL07Model;
22 class XBT_PRIVATE CpuL07Model;
23 class XBT_PRIVATE NetworkL07Model;
24
25 class XBT_PRIVATE CpuL07;
26 class XBT_PRIVATE LinkL07;
27
28 class XBT_PRIVATE L07Action;
29 /*********
30  * Tools *
31  *********/
32
33 /*********
34  * Model *
35  *********/
36 class HostL07Model : public HostModel {
37 public:
38   HostL07Model();
39   HostL07Model(const HostL07Model&) = delete;
40   HostL07Model& operator=(const HostL07Model&) = delete;
41   ~HostL07Model() override;
42
43   double next_occuring_event(double now) override;
44   void update_actions_state(double now, double delta) override;
45   kernel::resource::CpuAction* execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
46                                                 const double* bytes_amount, double rate) override;
47 };
48
49 class CpuL07Model : public kernel::resource::CpuModel {
50 public:
51   CpuL07Model(HostL07Model* hmodel, kernel::lmm::System* sys);
52   CpuL07Model(const CpuL07Model&) = delete;
53   CpuL07Model& operator=(const CpuL07Model&) = delete;
54   ~CpuL07Model();
55
56   kernel::resource::Cpu* create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate, int core) override;
57   HostL07Model *hostModel_;
58 };
59
60 class NetworkL07Model : public kernel::resource::NetworkModel {
61 public:
62   NetworkL07Model(HostL07Model* hmodel, kernel::lmm::System* sys);
63   NetworkL07Model(const NetworkL07Model&) = delete;
64   NetworkL07Model& operator=(const NetworkL07Model&) = delete;
65   ~NetworkL07Model();
66   kernel::resource::LinkImpl* create_link(const std::string& name, const std::vector<double>& bandwidths,
67                                           double latency, s4u::Link::SharingPolicy policy) override;
68
69   kernel::resource::Action* communicate(s4u::Host* src, s4u::Host* dst, double size, double rate) override;
70
71   HostL07Model *hostModel_;
72 };
73
74 /************
75  * Resource *
76  ************/
77
78 class CpuL07 : public kernel::resource::Cpu {
79 public:
80   CpuL07(CpuL07Model* model, s4u::Host* host, const std::vector<double>& speed_per_pstate, int core);
81   CpuL07(const CpuL07&) = delete;
82   CpuL07& operator=(const CpuL07&) = delete;
83   ~CpuL07() override;
84   bool is_used() override;
85   void apply_event(kernel::profile::Event* event, double value) override;
86   kernel::resource::CpuAction* execution_start(double size) override;
87   kernel::resource::CpuAction* execution_start(double, int) override
88   {
89     THROW_UNIMPLEMENTED;
90     return nullptr;
91   }
92   kernel::resource::CpuAction* sleep(double duration) override;
93
94 protected:
95   void on_speed_change() override;
96 };
97
98 class LinkL07 : public kernel::resource::LinkImpl {
99 public:
100   LinkL07(NetworkL07Model* model, const std::string& name, double bandwidth, double latency,
101           s4u::Link::SharingPolicy policy);
102   LinkL07(const LinkL07&) = delete;
103   LinkL07& operator=(const LinkL07&) = delete;
104   ~LinkL07() override;
105   bool is_used() override;
106   void apply_event(kernel::profile::Event* event, double value) override;
107   void set_bandwidth(double value) override;
108   void set_latency(double value) override;
109 };
110
111 /**********
112  * Action *
113  **********/
114 class L07Action : public kernel::resource::CpuAction {
115   friend CpuAction* CpuL07::execution_start(double size);
116   friend CpuAction* CpuL07::sleep(double duration);
117   friend CpuAction* HostL07Model::execute_parallel(const std::vector<s4u::Host*>& host_list, const double* flops_amount,
118                                                    const double* bytes_amount, double rate);
119   friend Action* NetworkL07Model::communicate(s4u::Host* src, s4u::Host* dst, double size, double rate);
120
121 public:
122   L07Action(kernel::resource::Model* model, const std::vector<s4u::Host*>& host_list, const double* flops_amount,
123             const double* bytes_amount, double rate);
124   L07Action(const L07Action&) = delete;
125   L07Action& operator=(const L07Action&) = delete;
126   ~L07Action();
127
128   void updateBound();
129
130   std::vector<s4u::Host*> hostList_;
131   const double* computationAmount_;   /* pointer to the data that lives in s4u action -- do not free unless if
132                                        * free_arrays */
133   const double* communicationAmount_; /* pointer to the data that lives in s4u action -- do not free unless if
134                                        * free_arrays */
135   double latency_;
136   double rate_;
137
138 private:
139   bool free_arrays_ = false; // By default, computationAmount_ and friends are freed by caller. But not for sequential
140                              // exec and regular comms
141 };
142
143 } // namespace surf
144 } // namespace simgrid
145
146 #endif /* HOST_L07_HPP_ */