Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
370dd71328cab6bc9349877a1f172d58baae5902
[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,lmm_system_t sys);
59   ~CpuL07Model();
60
61   Cpu *createCpu(simgrid::Host *host,  xbt_dynar_t speedPeakList,
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, lmm_system_t sys);
74   ~NetworkL07Model();
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, simgrid::Host *host, xbt_dynar_t speedPeakList, int pstate,
102                  double power_scale, 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
111 class LinkL07 : public Link {
112 public:
113   LinkL07(NetworkL07Model *model, const char* name, xbt_dict_t props,
114                   double bw_initial,
115           tmgr_trace_t bw_trace,
116           double lat_initial,
117           tmgr_trace_t lat_trace,
118           e_surf_resource_state_t
119           state_initial,
120           tmgr_trace_t state_trace,
121           e_surf_link_sharing_policy_t policy);
122   ~LinkL07(){ };
123   bool isUsed() override;
124   void updateState(tmgr_trace_event_t event_type, double value, double date) override;
125   double getBandwidth() override;
126   void updateBandwidth(double value, double date=surf_get_clock()) override;
127   void updateLatency(double value, double date=surf_get_clock()) override;
128
129   double m_bwCurrent;
130   tmgr_trace_event_t p_bwEvent;
131 };
132
133 /**********
134  * Action *
135  **********/
136 class L07Action : public CpuAction {
137   friend Action *CpuL07::execute(double size);
138   friend Action *CpuL07::sleep(double duration);
139   friend Action *HostL07Model::executeParallelTask(int host_nb,
140                                                    sg_host_t*host_list,
141                                                    double *flops_amount,
142                                                                                                    double *bytes_amount,
143                                                    double rate);
144 public:
145   L07Action(Model *model, double cost, bool failed)
146   : CpuAction(model, cost, failed) {};
147  ~L07Action();
148
149   void updateBound();
150
151   int unref() override;
152   void cancel() override;
153   void suspend() override;
154   void resume() override;
155   bool isSuspended() override;
156   void setMaxDuration(double duration) override;
157   void setPriority(double priority) override;
158   double getRemains() override;
159
160   std::vector<RoutingEdge*> * p_edgeList = new std::vector<RoutingEdge*>();
161   double *p_computationAmount;
162   double *p_communicationAmount;
163   double m_latency;
164   double m_rate;
165 };
166
167 }
168 }
169
170 #endif /* HOST_L07_HPP_ */