Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
push up a method in the surf::Host hierarchy
[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   void addTraces() override;
55 };
56
57 class CpuL07Model : public CpuModel {
58 public:
59   CpuL07Model(HostL07Model *hmodel) : CpuModel() {p_hostModel = hmodel;};
60   ~CpuL07Model() {surf_cpu_model_pm = NULL;};
61
62   Cpu *createCpu(const char *name,  xbt_dynar_t speedPeak,
63                           int pstate, double speedScale,
64                           tmgr_trace_t speedTrace, int core,
65                           e_surf_resource_state_t state_initial,
66                           tmgr_trace_t state_trace) override;
67   void addTraces() override {DIE_IMPOSSIBLE;};
68
69   HostL07Model *p_hostModel;
70 };
71
72 class NetworkL07Model : public NetworkModel {
73 public:
74   NetworkL07Model(HostL07Model *hmodel) : NetworkModel() {p_hostModel = hmodel;};
75   ~NetworkL07Model() {surf_network_model = NULL;};
76   Link* createLink(const char *name,
77                   double bw_initial,
78                   tmgr_trace_t bw_trace,
79                   double lat_initial,
80                   tmgr_trace_t lat_trace,
81                   e_surf_resource_state_t state_initial,
82                   tmgr_trace_t state_trace,
83                   e_surf_link_sharing_policy_t policy,
84                   xbt_dict_t properties) override;
85
86   Action *communicate(RoutingEdge *src, RoutingEdge *dst, double size, double rate) override;
87   void addTraces() override {DIE_IMPOSSIBLE;};
88   bool shareResourcesIsIdempotent() override {return true;}
89
90   HostL07Model *p_hostModel;
91 };
92
93 /************
94  * Resource *
95  ************/
96
97 class HostL07 : public Host {
98 public:
99   HostL07(HostModel *model, const char* name, xbt_dict_t props, RoutingEdge *netElm, Cpu *cpu);
100   ~HostL07();
101   bool isUsed() override {DIE_IMPOSSIBLE;};
102   void updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, double /*date*/) override {DIE_IMPOSSIBLE;};
103   Action *execute(double size) override {return p_cpu->execute(size);};
104   Action *sleep(double duration) override {return p_cpu->sleep(duration);};
105 };
106
107 class CpuL07 : public Cpu {
108   friend void HostL07Model::addTraces();
109   tmgr_trace_event_t p_stateEvent;
110   tmgr_trace_event_t p_speedEvent;
111 public:
112   CpuL07(CpuL07Model *model, const char* name,
113                  double power_scale, double power_initial, tmgr_trace_t power_trace,
114      int core, e_surf_resource_state_t state_initial, tmgr_trace_t state_trace);
115   ~CpuL07();
116   bool isUsed() override;
117   void updateState(tmgr_trace_event_t event_type, double value, double date) override;
118   Action *execute(double size) override;
119   Action *sleep(double duration) override;
120
121   double getCurrentPowerPeak() override {THROW_UNIMPLEMENTED;};
122   double getPowerPeakAt(int /*pstate_index*/) override {THROW_UNIMPLEMENTED;};
123   int getNbPstates() override {THROW_UNIMPLEMENTED;};
124   void setPstate(int /*pstate_index*/) override {THROW_UNIMPLEMENTED;};
125   int  getPstate() override {THROW_UNIMPLEMENTED;};
126 };
127
128 class LinkL07 : public Link {
129 public:
130   LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
131                   double bw_initial,
132           tmgr_trace_t bw_trace,
133           double lat_initial,
134           tmgr_trace_t lat_trace,
135           e_surf_resource_state_t
136           state_initial,
137           tmgr_trace_t state_trace,
138           e_surf_link_sharing_policy_t policy);
139   ~LinkL07(){ };
140   bool isUsed() override;
141   void updateState(tmgr_trace_event_t event_type, double value, double date) override;
142   double getBandwidth() override;
143   void updateBandwidth(double value, double date=surf_get_clock()) override;
144   void updateLatency(double value, double date=surf_get_clock()) override;
145
146   double m_bwCurrent;
147   tmgr_trace_event_t p_bwEvent;
148 };
149
150 /**********
151  * Action *
152  **********/
153 class L07Action : public HostAction {
154   friend Action *CpuL07::execute(double size);
155   friend Action *CpuL07::sleep(double duration);
156   friend Action *HostL07Model::executeParallelTask(int host_nb,
157                                                    sg_host_t*host_list,
158                                                    double *flops_amount,
159                                                                                                    double *bytes_amount,
160                                                    double rate);
161 public:
162   L07Action(Model *model, double cost, bool failed)
163   : HostAction(model, cost, failed) {};
164  ~L07Action();
165
166   void updateBound();
167
168   int unref() override;
169   void cancel() override;
170   void suspend() override;
171   void resume() override;
172   bool isSuspended() override;
173   void setMaxDuration(double duration) override;
174   void setPriority(double priority) override;
175   double getRemains() override;
176
177   std::vector<RoutingEdge*> * p_edgeList = new std::vector<RoutingEdge*>();
178   double *p_computationAmount;
179   double *p_communicationAmount;
180   double m_latency;
181   double m_rate;
182 };
183
184 }
185 }
186
187 #endif /* HOST_L07_HPP_ */