Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
69b9e5afd1714a84d14a174d2f05bffa4d8fccf5
[simgrid.git] / src / surf / host_ptask_L07.hpp
1 /* Copyright (c) 2013-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <cstdlib>
8
9 #include <vector>
10
11 #include <xbt/base.h>
12
13 #include "host_interface.hpp"
14
15 #ifndef HOST_L07_HPP_
16 #define HOST_L07_HPP_
17
18 namespace simgrid {
19 namespace surf {
20
21 /***********
22  * Classes *
23  ***********/
24
25 class XBT_PRIVATE HostL07Model;
26 class XBT_PRIVATE CpuL07Model;
27 class XBT_PRIVATE NetworkL07Model;
28
29 class XBT_PRIVATE HostL07;
30 class XBT_PRIVATE CpuL07;
31 class XBT_PRIVATE LinkL07;
32
33 class XBT_PRIVATE L07Action;
34 /*********
35  * Tools *
36  *********/
37
38 /*********
39  * Model *
40  *********/
41 class HostL07Model : public HostModel {
42 public:
43   HostL07Model();
44   ~HostL07Model();
45
46   double shareResources(double now) override;
47   void updateActionsState(double now, double delta);
48   Host *createHost(const char *name,RoutingEdge *netElm, Cpu *cpu, xbt_dict_t props) override;
49   Action *executeParallelTask(int host_nb,
50                               sg_host_t *host_list,
51                                                           double *flops_amount,
52                                                           double *bytes_amount,
53                                                           double rate) override;
54   xbt_dynar_t getRoute(Host *src, Host *dst);
55   void addTraces() override;
56 };
57
58 class CpuL07Model : public CpuModel {
59 public:
60   CpuL07Model(HostL07Model *hmodel) : CpuModel() {p_hostModel = hmodel;};
61   ~CpuL07Model() {surf_cpu_model_pm = NULL;};
62
63   Cpu *createCpu(const char *name,  xbt_dynar_t speedPeak,
64                           int pstate, double speedScale,
65                           tmgr_trace_t speedTrace, int core,
66                           e_surf_resource_state_t state_initial,
67                           tmgr_trace_t state_trace) override;
68   void addTraces() override {DIE_IMPOSSIBLE;};
69
70   HostL07Model *p_hostModel;
71 };
72
73 class NetworkL07Model : public NetworkModel {
74 public:
75   NetworkL07Model(HostL07Model *hmodel) : NetworkModel() {p_hostModel = hmodel;};
76   ~NetworkL07Model() {surf_network_model = NULL;};
77   Link* createLink(const char *name,
78                   double bw_initial,
79                   tmgr_trace_t bw_trace,
80                   double lat_initial,
81                   tmgr_trace_t lat_trace,
82                   e_surf_resource_state_t state_initial,
83                   tmgr_trace_t state_trace,
84                   e_surf_link_sharing_policy_t policy,
85                   xbt_dict_t properties) override;
86
87   Action *communicate(RoutingEdge *src, RoutingEdge *dst, double size, double rate) override;
88   void addTraces() override {DIE_IMPOSSIBLE;};
89   bool shareResourcesIsIdempotent() override {return true;}
90
91   HostL07Model *p_hostModel;
92 };
93
94 /************
95  * Resource *
96  ************/
97
98 class HostL07 : public Host {
99 public:
100   HostL07(HostModel *model, const char* name, xbt_dict_t props, RoutingEdge *netElm, Cpu *cpu);
101   ~HostL07();
102   bool isUsed() override {DIE_IMPOSSIBLE;};
103   void updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) override {DIE_IMPOSSIBLE;};
104   Action *execute(double size) override {return p_cpu->execute(size);};
105   Action *sleep(double duration) override {return p_cpu->sleep(duration);};
106   e_surf_resource_state_t getState() override;
107 };
108
109 class CpuL07 : public Cpu {
110   friend void HostL07Model::addTraces();
111   tmgr_trace_event_t p_stateEvent;
112   tmgr_trace_event_t p_speedEvent;
113 public:
114   CpuL07(CpuL07Model *model, const char* name,
115                  double power_scale, double power_initial, tmgr_trace_t power_trace,
116      int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace);
117   ~CpuL07();
118   bool isUsed() override;
119   void updateState(tmgr_trace_event_t event_type, double value, double date) override;
120   Action *execute(double size) override;
121   Action *sleep(double duration) override;
122
123   double getCurrentPowerPeak() override {THROW_UNIMPLEMENTED;};
124   double getPowerPeakAt(int /*pstate_index*/) override {THROW_UNIMPLEMENTED;};
125   int getNbPstates() override {THROW_UNIMPLEMENTED;};
126   void setPstate(int /*pstate_index*/) override {THROW_UNIMPLEMENTED;};
127   int  getPstate() override {THROW_UNIMPLEMENTED;};
128 };
129
130 class LinkL07 : public Link {
131 public:
132   LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
133                   double bw_initial,
134           tmgr_trace_t bw_trace,
135           double lat_initial,
136           tmgr_trace_t lat_trace,
137           e_surf_resource_state_t
138           state_initial,
139           tmgr_trace_t state_trace,
140           e_surf_link_sharing_policy_t policy);
141   ~LinkL07(){ };
142   bool isUsed() override;
143   void updateState(tmgr_trace_event_t event_type, double value, double date) override;
144   double getBandwidth() override;
145   void updateBandwidth(double value, double date=surf_get_clock()) override;
146   void updateLatency(double value, double date=surf_get_clock()) override;
147
148   double m_bwCurrent;
149   tmgr_trace_event_t p_bwEvent;
150 };
151
152 /**********
153  * Action *
154  **********/
155 class L07Action : public HostAction {
156   friend Action *CpuL07::execute(double size);
157   friend Action *CpuL07::sleep(double duration);
158   friend Action *HostL07Model::executeParallelTask(int host_nb,
159                                                    sg_host_t*host_list,
160                                                    double *flops_amount,
161                                                                                                    double *bytes_amount,
162                                                    double rate);
163 public:
164   L07Action(Model *model, double cost, bool failed)
165   : HostAction(model, cost, failed) {};
166  ~L07Action();
167
168   void updateBound();
169
170   int unref() override;
171   void cancel() override;
172   void suspend() override;
173   void resume() override;
174   bool isSuspended() override;
175   void setMaxDuration(double duration) override;
176   void setPriority(double priority) override;
177   double getRemains() override;
178
179   std::vector<RoutingEdge*> * p_edgeList = new std::vector<RoutingEdge*>();
180   double *p_computationAmount;
181   double *p_communicationAmount;
182   double m_latency;
183   double m_rate;
184 };
185
186 }
187 }
188
189 #endif /* HOST_L07_HPP_ */