WRENCH  1.10
Cyberinfrastructure Simulation Workbench
Overview Installation Getting Started WRENCH 101 WRENCH 102
Simulation.h
1 
11 #ifndef WRENCH_SIMULATION_H
12 #define WRENCH_SIMULATION_H
13 
14 #include <string>
15 #include <vector>
16 #include <nlohmann/json.hpp>
17 #include "Version.h"
18 #include <wrench/simulation/SimulationOutput.h>
19 
20 
21 namespace wrench {
22 
23  class StorageService;
24  class Service;
25  class NetworkProximityService;
26  class FileRegistryService;
27  class EnergyMeterService;
28  class BandwidthMeterService;
29  class ComputeService;
30  class BatchComputeService;
31  class BareMetalComputeService;
32  class CloudComputeService;
33  class VirtualizedClusterComputeService;
34  class WMS;
35  class WorkflowFile;
36  class SimulationOutput;
37  class S4U_Simulation;
38  class FileLocation;
39  class MemoryManager;
40 
46  class Simulation {
47 
48  public:
49  Simulation();
50 
51  ~Simulation();
52 
53  void init(int *, char **);
54 
55  void instantiatePlatform(std::string);
56  void instantiatePlatform(const std::function<void()>&);
57 
58  static std::vector<std::string> getHostnameList();
59  static std::map<std::string, std::vector<std::string>> getHostnameListByCluster();
60  static double getHostMemoryCapacity(std::string hostname);
61  static unsigned long getHostNumCores(std::string hostname);
62  static double getHostFlopRate(std::string hostname);
63 
64 
65  void launch();
66 
73  template <class T>
74  std::shared_ptr<T> add(T *t) {
75  auto s = std::shared_ptr<T>(t);
76  this->addService(s);
77  return s;
78  }
79 
81 
82  //start energy related calls
83  double getEnergyConsumed(const std::string &hostname);
84  std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames);
85 // double getEnergyTimestamp(const std::string &hostname, bool can_record = false);
86 
87  // pstate related calls
88  static int getNumberofPstates(const std::string &hostname);
89  static double getMinPowerConsumption(const std::string &hostname);
90  static double getMaxPowerConsumption(const std::string &hostname);
91  static std::vector<int> getListOfPstates(const std::string &hostname);
92 
93  void stageFile(WorkflowFile *file, std::shared_ptr<StorageService> ss);
94  void stageFile(WorkflowFile *file, std::shared_ptr<StorageService> ss, std::string directory_absolute_path);
95 
96  /***********************/
98  /***********************/
99  double getEnergyConsumed(const std::string &hostname, bool record_as_time_stamp);
100 
101  static std::vector<std::string> getRoute(std::string &src_host, std::string &dst_host);
102 
103  double getLinkUsage(const std::string &link_name, bool record_as_time_stamp);
104  std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames, bool record_as_time_stamps);
105 
106  static bool doesHostExist(std::string hostname);
107  static bool isHostOn(std::string hostname);
108  static void turnOnHost(std::string hostname);
109  static void turnOffHost(std::string hostname);
110  static bool doesLinkExist(std::string linkname);
111  static bool isLinkOn(std::string linkname);
112  static void turnOnLink(std::string linkname);
113  static void turnOffLink(std::string linkname);
114 
115  // pstate related calls
116  void setPstate(const std::string &hostname, int pstate);
117  static int getCurrentPstate(const std::string &hostname);
118 
119  std::shared_ptr<ComputeService> startNewService(ComputeService *service);
120  std::shared_ptr<StorageService> startNewService(StorageService *service);
121  std::shared_ptr<NetworkProximityService> startNewService(NetworkProximityService *service);
122  std::shared_ptr<FileRegistryService> startNewService(FileRegistryService *service);
123  std::shared_ptr<MemoryManager> startNewService(MemoryManager *service);
124 
125  static double getCurrentSimulatedDate();
126 
127  static void sleep(double duration);
128  static void compute(double flops);
129  /***********************/
131  /***********************/
132 
133  /***********************/
135  /***********************/
136  void readFromDisk(double num_bytes, std::string hostname, std::string mount_point);
137  void readFromDiskAndWriteToDiskConcurrently(double num_bytes_to_read, double num_bytes_to_write,
138  std::string hostname,
139  std::string read_mount_point,
140  std::string write_mount_point);
141  void writeToDisk(double num_bytes, std::string hostname, std::string mount_point);
142 
143  void readWithMemoryCache(WorkflowFile *file, double n_bytes, std::shared_ptr<FileLocation> location);
144  void writebackWithMemoryCache(WorkflowFile *file, double n_bytes, std::shared_ptr<FileLocation> location, bool is_dirty);
145  void writeThroughWithMemoryCache(WorkflowFile *file, double n_bytes, std::shared_ptr<FileLocation> location);
146  MemoryManager* getMemoryManagerByHost(std::string hostname);
147 
148  static double getMemoryCapacity();
149  static unsigned long getNumCores();
150  static double getFlopRate();
151  static std::string getHostName();
152 
153  static std::vector<std::string> getLinknameList();
154  static double getLinkUsage(std::string linkname);
155  static double getLinkBandwidth(std::string linkname);
156  static bool isPageCachingEnabled();
157  static bool isHostShutdownSimulationEnabled();
158  static bool isEnergySimulationEnabled();
159 
160 
161  /***********************/
163  /***********************/
164 
165  private:
166  SimulationOutput output;
167 
168  std::unique_ptr<S4U_Simulation> s4u_simulation;
169 
170  std::set<std::shared_ptr<WMS>> wmses;
171 
172  std::set<std::shared_ptr<FileRegistryService>> file_registry_services;
173 
174  std::set<std::shared_ptr<EnergyMeterService>> energy_meter_services;
175 
176  std::set<std::shared_ptr<BandwidthMeterService>> bandwidth_meter_services;
177 
178  std::set<std::shared_ptr<NetworkProximityService>> network_proximity_services;
179 
180  std::set<std::shared_ptr<ComputeService>> compute_services;
181 
182  std::set<std::shared_ptr<StorageService>> storage_services;
183 
184  std::set<std::shared_ptr<MemoryManager>> memory_managers;
185 
186  static int unique_disk_sequence_number;
187 
188  void stageFile(WorkflowFile *file, std::shared_ptr<FileLocation> location);
189 
190  void platformSanityCheck();
191  void checkSimulationSetup();
192  bool isRunning();
193 
194  void startAllProcesses();
195  void addService(std::shared_ptr<ComputeService> service);
196  void addService(std::shared_ptr<StorageService> service);
197  void addService(std::shared_ptr<NetworkProximityService> service);
198  void addService(std::shared_ptr<WMS> service);
199  void addService(std::shared_ptr<FileRegistryService> service);
200  void addService(std::shared_ptr<EnergyMeterService> service);
201  void addService(std::shared_ptr<BandwidthMeterService> service);
202  void addService(std::shared_ptr<MemoryManager> memory_manager);
203 
204  std::string getWRENCHVersionString() { return WRENCH_VERSION_STRING; }
205 
206  bool is_running = false;
207 
208  bool already_setup = false;
209 
210  unsigned int on_state_change_callback_id;
211 
212  static bool energy_enabled;
213  static bool host_shutdown_enabled;
214  static bool pagecache_enabled;
215  };
216 
217 };
218 
219 #endif //WRENCH_SIMULATION_H
wrench::Simulation::getHostnameListByCluster
static std::map< std::string, std::vector< std::string > > getHostnameListByCluster()
‍**
Definition: Simulation.cpp:402
wrench::Simulation::add
std::shared_ptr< T > add(T *t)
Method to add a service to the simulation.
Definition: Simulation.h:74
wrench::Simulation::getMinPowerConsumption
static double getMinPowerConsumption(const std::string &hostname)
Get the minimum power consumption for the host (i.e., idling) at its current pstate.
Definition: Simulation.cpp:1248
wrench::Simulation::startNewService
std::shared_ptr< ComputeService > startNewService(ComputeService *service)
Starts a new compute service during WMS execution (i.e., one that was not passed to Simulation::add()...
Definition: Simulation.cpp:1270
wrench::Simulation::instantiatePlatform
void instantiatePlatform(std::string)
Instantiate a simulated platform.
Definition: Simulation.cpp:242
wrench::Simulation::getCurrentPstate
static int getCurrentPstate(const std::string &hostname)
Get the current power state of a host.
Definition: Simulation.cpp:1230
wrench::Simulation::isHostOn
static bool isHostOn(std::string hostname)
Returns whether a host is on or not.
Definition: Simulation.cpp:1041
wrench::FileRegistryService
A file registry service (a.k.a. replica catalog) that holds a database of which files are available a...
Definition: FileRegistryService.h:35
wrench::Simulation::sleep
static void sleep(double duration)
Make the calling process sleep for a number of (simulated) seconds.
Definition: Simulation.cpp:1122
wrench::Simulation::isLinkOn
static bool isLinkOn(std::string linkname)
Returns whether a link is on or not.
Definition: Simulation.cpp:1066
wrench::StorageService
The storage service base class.
Definition: StorageService.h:36
wrench::ComputeService
The compute service base class.
Definition: ComputeService.h:33
wrench::Simulation::setPstate
void setPstate(const std::string &hostname, int pstate)
Set the power state of the host.
Definition: Simulation.cpp:1211
wrench
Definition: Alarm.cpp:20
wrench::Simulation::getListOfPstates
static std::vector< int > getListOfPstates(const std::string &hostname)
Get the list of power states available for a host.
Definition: Simulation.cpp:1239
wrench::Simulation::compute
static void compute(double flops)
Make the calling process compute.
Definition: Simulation.cpp:1130
wrench::Simulation::launch
void launch()
Launch the simulation.
Definition: Simulation.cpp:411
wrench::Simulation::getRoute
static std::vector< std::string > getRoute(std::string &src_host, std::string &dst_host)
Get the list of link names on the route between two hosts.
Definition: Simulation.cpp:302
wrench::Simulation::turnOnLink
static void turnOnLink(std::string linkname)
Turns on a link.
Definition: Simulation.cpp:1082
wrench::Simulation::init
void init(int *, char **)
Initialize the simulation, which parses out WRENCH-specific and SimGrid-specific command-line argumen...
Definition: Simulation.cpp:97
wrench::Simulation::turnOffHost
static void turnOffHost(std::string hostname)
Turns off a host.
Definition: Simulation.cpp:1049
wrench::Simulation::getHostMemoryCapacity
static double getHostMemoryCapacity(std::string hostname)
Get the memory_manager_service capacity of a host given a hostname.
Definition: Simulation.cpp:1014
wrench::Simulation::getHostnameList
static std::vector< std::string > getHostnameList()
Get the list of names of all the physical hosts in the platform.
Definition: Simulation.cpp:292
wrench::Simulation::getHostNumCores
static unsigned long getHostNumCores(std::string hostname)
Get the number of cores of a host given a hostname.
Definition: Simulation.cpp:1023
wrench::Simulation::getEnergyConsumed
double getEnergyConsumed(const std::string &hostname)
Obtains the current energy consumption of a host.
Definition: Simulation.cpp:1148
wrench::Simulation::doesHostExist
static bool doesHostExist(std::string hostname)
Wrapper for S4U_Simulation hostExists()
Definition: Simulation.cpp:987
wrench::Simulation::Simulation
Simulation()
Constructor.
Definition: Simulation.cpp:63
wrench::Simulation
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:46
wrench::Simulation::stageFile
void stageFile(WorkflowFile *file, std::shared_ptr< StorageService > ss)
Stage a copy of a file at a storage service in the root of the (unique) mount point.
Definition: Simulation.cpp:701
wrench::Simulation::~Simulation
~Simulation()
Destructor.
Definition: Simulation.cpp:80
wrench::Simulation::turnOnHost
static void turnOnHost(std::string hostname)
Turns on a host.
Definition: Simulation.cpp:1057
wrench::Simulation::getMaxPowerConsumption
static double getMaxPowerConsumption(const std::string &hostname)
Get the maximum power consumption for the host (i.e., 100% utilization) at its current pstate.
Definition: Simulation.cpp:1257
wrench::Simulation::turnOffLink
static void turnOffLink(std::string linkname)
Turns off a link.
Definition: Simulation.cpp:1074
wrench::Simulation::getHostFlopRate
static double getHostFlopRate(std::string hostname)
Get the flop rate of one core of a host given a hostname.
Definition: Simulation.cpp:1032
wrench::Simulation::doesLinkExist
static bool doesLinkExist(std::string linkname)
Wrapper for S4U_Simulation linkExists()
Definition: Simulation.cpp:997
wrench::Simulation::getNumberofPstates
static int getNumberofPstates(const std::string &hostname)
Get the total number of power states of a host.
Definition: Simulation.cpp:1221
wrench::Simulation::getOutput
SimulationOutput & getOutput()
Get the simulation output object.
Definition: Simulation.cpp:1138
wrench::NetworkProximityService
A network proximity service that continuously estimates inter-host latencies and can be queried for s...
Definition: NetworkProximityService.h:26
wrench::SimulationOutput
A class that contains post-mortem simulation-generated data.
Definition: SimulationOutput.h:27
wrench::Simulation::getLinkUsage
double getLinkUsage(const std::string &link_name, bool record_as_time_stamp)
Get the current usage of a particular link.
Definition: Simulation.cpp:331
wrench::WorkflowFile
A data file used/produced by a WorkflowTask in a Workflow.
Definition: WorkflowFile.h:26
wrench::Simulation::getCurrentSimulatedDate
static double getCurrentSimulatedDate()
Get the current simulated date.
Definition: Simulation.cpp:1005