Logo AND Algorithmique Numérique Distribuée

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