WRENCH  1.11
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 <wrench/services/compute/bare_metal/BareMetalComputeServiceOneShot.h>
18 
19 #include "Version.h"
20 #include "wrench/simulation/SimulationOutput.h"
21 
22 
23 namespace wrench {
24 
25  class StorageService;
26  class Service;
27  class NetworkProximityService;
28  class FileRegistryService;
29  class EnergyMeterService;
30  class BandwidthMeterService;
31  class ComputeService;
32  class BatchComputeService;
33  class BareMetalComputeService;
34  class CloudComputeService;
35  class VirtualizedClusterComputeService;
36  class ExecutionController;
37  class DataFile;
38  class SimulationOutput;
39  class S4U_Simulation;
40  class FileLocation;
41  class MemoryManager;
42 
48  class Simulation {
49 
50  public:
51 
52  static std::shared_ptr<Simulation> createSimulation();
53 
54  ~Simulation();
55 
56  void init(int *, char **);
57 
58  static bool isInitialized();
59 
60  void instantiatePlatform(std::string);
61  void instantiatePlatform(const std::function<void()>&);
62 
63  static std::vector<std::string> getHostnameList();
64  static std::map<std::string, std::vector<std::string>> getHostnameListByCluster();
65  static double getHostMemoryCapacity(std::string hostname);
66  static unsigned long getHostNumCores(std::string hostname);
67  static double getHostFlopRate(std::string hostname);
68 
69  static std::map<std::string, std::shared_ptr<DataFile>> &getFileMap();
70  static void removeFile(std::shared_ptr<DataFile>file);
71  static std::shared_ptr<DataFile> getFileByID(const std::string &id);
72  static std::shared_ptr<DataFile> addFile(std::string, double);
73 
74 
75 
76  void launch();
77 
84  template <class T>
85  std::shared_ptr<T> add(T *t) {
86  auto s = std::shared_ptr<T>(t);
87  this->addService(s);
88  return s;
89  }
90 
92 
93  //start energy related calls
94  double getEnergyConsumed(const std::string &hostname);
95  std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames);
96 // double getEnergyTimestamp(const std::string &hostname, bool can_record = false);
97 
98  // pstate related calls
99  static int getNumberofPstates(const std::string &hostname);
100  static double getMinPowerConsumption(const std::string &hostname);
101  static double getMaxPowerConsumption(const std::string &hostname);
102  static std::vector<int> getListOfPstates(const std::string &hostname);
103 
104  void stageFile(std::shared_ptr<DataFile>file, std::shared_ptr<StorageService> ss);
105  void stageFile(std::shared_ptr<DataFile>file, std::shared_ptr<StorageService> ss, std::string directory_absolute_path);
106 
107  /***********************/
109  /***********************/
110  double getEnergyConsumed(const std::string &hostname, bool record_as_time_stamp);
111 
112  static std::vector<std::string> getRoute(std::string &src_host, std::string &dst_host);
113 
114  double getLinkUsage(const std::string &link_name, bool record_as_time_stamp);
115  std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames, bool record_as_time_stamps);
116 
117  static bool doesHostExist(std::string hostname);
118  static bool isHostOn(std::string hostname);
119  static void turnOnHost(std::string hostname);
120  static void turnOffHost(std::string hostname);
121  static bool doesLinkExist(std::string linkname);
122  static bool isLinkOn(std::string linkname);
123  static void turnOnLink(std::string linkname);
124  static void turnOffLink(std::string linkname);
125 
126  // pstate related calls
127  void setPstate(const std::string &hostname, int pstate);
128  static int getCurrentPstate(const std::string &hostname);
129 
130  std::shared_ptr<ComputeService> startNewService(ComputeService *service);
131  std::shared_ptr<StorageService> startNewService(StorageService *service);
132  std::shared_ptr<NetworkProximityService> startNewService(NetworkProximityService *service);
133  std::shared_ptr<FileRegistryService> startNewService(FileRegistryService *service);
134  std::shared_ptr<MemoryManager> startNewService(MemoryManager *service);
135 
136  static double getCurrentSimulatedDate();
137 
138  static void sleep(double duration);
139  static void compute(double flops);
140  /***********************/
142  /***********************/
143 
144  /***********************/
146  /***********************/
147  void readFromDisk(double num_bytes, std::string hostname, std::string mount_point);
148  void readFromDiskAndWriteToDiskConcurrently(double num_bytes_to_read, double num_bytes_to_write,
149  std::string hostname,
150  std::string read_mount_point,
151  std::string write_mount_point);
152  void writeToDisk(double num_bytes, std::string hostname, std::string mount_point);
153 
154  void readWithMemoryCache(std::shared_ptr<DataFile>file, double n_bytes, std::shared_ptr<FileLocation> location);
155  void writebackWithMemoryCache(std::shared_ptr<DataFile>file, double n_bytes, std::shared_ptr<FileLocation> location, bool is_dirty);
156  void writeThroughWithMemoryCache(std::shared_ptr<DataFile>file, double n_bytes, std::shared_ptr<FileLocation> location);
157  MemoryManager* getMemoryManagerByHost(std::string hostname);
158 
159  static double getMemoryCapacity();
160  static unsigned long getNumCores();
161  static double getFlopRate();
162  static std::string getHostName();
163 
164  static std::vector<std::string> getLinknameList();
165  static double getLinkUsage(std::string linkname);
166  static double getLinkBandwidth(std::string linkname);
167  static bool isPageCachingEnabled();
168  static bool isHostShutdownSimulationEnabled();
169  static bool isEnergySimulationEnabled();
170 
171 
172  /***********************/
174  /***********************/
175 
176  private:
177 
178  Simulation();
179 
180  SimulationOutput output;
181 
182  std::unique_ptr<S4U_Simulation> s4u_simulation;
183 
184  std::set<std::shared_ptr<ExecutionController>> execution_controllers;
185 
186  std::set<std::shared_ptr<FileRegistryService>> file_registry_services;
187 
188  std::set<std::shared_ptr<EnergyMeterService>> energy_meter_services;
189 
190  std::set<std::shared_ptr<BandwidthMeterService>> bandwidth_meter_services;
191 
192  std::set<std::shared_ptr<NetworkProximityService>> network_proximity_services;
193 
194  std::set<std::shared_ptr<ComputeService>> compute_services;
195 
196  std::set<std::shared_ptr<StorageService>> storage_services;
197 
198  std::set<std::shared_ptr<MemoryManager>> memory_managers;
199 
200  static int unique_disk_sequence_number;
201 
202  void stageFile(std::shared_ptr<DataFile>file, std::shared_ptr<FileLocation> location);
203 
204  void platformSanityCheck();
205  void checkSimulationSetup();
206  bool isRunning();
207 
208  void startAllProcesses();
209  void addService(std::shared_ptr<ComputeService> service);
210  void addService(std::shared_ptr<StorageService> service);
211  void addService(std::shared_ptr<NetworkProximityService> service);
212  void addService(std::shared_ptr<ExecutionController> service);
213  void addService(std::shared_ptr<FileRegistryService> service);
214  void addService(std::shared_ptr<EnergyMeterService> service);
215  void addService(std::shared_ptr<BandwidthMeterService> service);
216  void addService(std::shared_ptr<MemoryManager> memory_manager);
217 
218  std::string getWRENCHVersionString() { return WRENCH_VERSION_STRING; }
219 
220  bool is_running = false;
221 
222  bool already_setup = false;
223 
224  unsigned int on_state_change_callback_id;
225 
226 
227  static bool energy_enabled;
228  static bool host_shutdown_enabled;
229  static bool pagecache_enabled;
230 
231  static bool initialized;
232 
233  private:
234  /* Map of files */
235  static std::map<std::string, std::shared_ptr<DataFile>> data_files;
236 
237  };
238 
239 
240 
241 };
242 
243 #endif //WRENCH_SIMULATION_H
wrench::Simulation::getHostnameListByCluster
static std::map< std::string, std::vector< std::string > > getHostnameListByCluster()
‍**
Definition: Simulation.cpp:437
wrench::Simulation::getMemoryCapacity
static double getMemoryCapacity()
Get the memory_manager_service capacity of the host on which the calling process is running.
Definition: Simulation.cpp:1076
wrench::Simulation::add
std::shared_ptr< T > add(T *t)
Method to add a service to the simulation.
Definition: Simulation.h:85
wrench::Simulation::getLinknameList
static std::vector< std::string > getLinknameList()
Get the list of names of all the links in the platform.
Definition: Simulation.cpp:346
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:1234
wrench::Simulation::startNewService
std::shared_ptr< ComputeService > startNewService(ComputeService *service)
Starts a new compute service during execution (i.e., one that was not passed to Simulation::add() bef...
Definition: Simulation.cpp:1256
wrench::Simulation::getHostName
static std::string getHostName()
Get the name of the host on which the calling process is running.
Definition: Simulation.cpp:1100
wrench::Simulation::getLinkBandwidth
static double getLinkBandwidth(std::string linkname)
Get the max bandwidth of a particular link.
Definition: Simulation.cpp:356
wrench::Simulation::instantiatePlatform
void instantiatePlatform(std::string)
Instantiate a simulated platform.
Definition: Simulation.cpp:277
wrench::Simulation::isPageCachingEnabled
static bool isPageCachingEnabled()
Method to check if page caching is activated.
Definition: Simulation.cpp:397
wrench::Simulation::readFromDisk
void readFromDisk(double num_bytes, std::string hostname, std::string mount_point)
Wrapper enabling timestamps for disk reads.
Definition: Simulation.cpp:754
wrench::Simulation::getCurrentPstate
static int getCurrentPstate(const std::string &hostname)
Get the current power state of a host.
Definition: Simulation.cpp:1216
wrench::Simulation::isHostOn
static bool isHostOn(std::string hostname)
Returns whether a host is on or not.
Definition: Simulation.cpp:1027
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::getMemoryManagerByHost
MemoryManager * getMemoryManagerByHost(std::string hostname)
Find MemoryManager running on a host based on hostname.
Definition: Simulation.cpp:958
wrench::Simulation::writebackWithMemoryCache
void writebackWithMemoryCache(std::shared_ptr< DataFile >file, double n_bytes, std::shared_ptr< FileLocation > location, bool is_dirty)
Write a file locally with writeback strategy, only available if writeback is activated.
Definition: Simulation.cpp:881
wrench::Simulation::sleep
static void sleep(double duration)
Make the calling process sleep for a number of (simulated) seconds.
Definition: Simulation.cpp:1108
wrench::MemoryManager
A class that implemnets a MemoryManager service to simulate Linux in-memory page caching for I/O oper...
Definition: MemoryManager.h:29
wrench::Simulation::isLinkOn
static bool isLinkOn(std::string linkname)
Returns whether a link is on or not.
Definition: Simulation.cpp:1052
wrench::Simulation::getFileByID
static std::shared_ptr< DataFile > getFileByID(const std::string &id)
Find a DataFile based on its ID.
Definition: Simulation.cpp:1485
wrench::Simulation::isEnergySimulationEnabled
static bool isEnergySimulationEnabled()
Method to check if energy simulation is activated.
Definition: Simulation.cpp:413
wrench::Simulation::addFile
static std::shared_ptr< DataFile > addFile(std::string, double)
Add a new file to the simulation (use at your own peril if you're using the workflow API - use Workfl...
Definition: Simulation.cpp:1503
wrench::StorageService
The storage service base class.
Definition: StorageService.h:36
wrench::ComputeService
The compute service base class.
Definition: ComputeService.h:34
wrench::Simulation::setPstate
void setPstate(const std::string &hostname, int pstate)
Set the power state of the host.
Definition: Simulation.cpp:1197
wrench::Simulation::createSimulation
static std::shared_ptr< Simulation > createSimulation()
Create a simulation.
Definition: Simulation.cpp:1546
wrench
Definition: Action.cpp:28
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:1225
wrench::Simulation::getNumCores
static unsigned long getNumCores()
Get the number of cores of the host on which the calling process is running.
Definition: Simulation.cpp:1084
wrench::Simulation::compute
static void compute(double flops)
Make the calling process compute.
Definition: Simulation.cpp:1116
wrench::Simulation::launch
void launch()
Launch the simulation.
Definition: Simulation.cpp:446
wrench::Simulation::stageFile
void stageFile(std::shared_ptr< DataFile >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:693
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:337
wrench::Simulation::turnOnLink
static void turnOnLink(std::string linkname)
Turns on a link.
Definition: Simulation.cpp:1068
wrench::Simulation::init
void init(int *, char **)
Initialize the simulation, which parses out WRENCH-specific and SimGrid-specific command-line argumen...
Definition: Simulation.cpp:100
wrench::Simulation::turnOffHost
static void turnOffHost(std::string hostname)
Turns off a host.
Definition: Simulation.cpp:1035
wrench::Simulation::getHostMemoryCapacity
static double getHostMemoryCapacity(std::string hostname)
Get the memory_manager_service capacity of a host given a hostname.
Definition: Simulation.cpp:1000
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:327
wrench::Simulation::getHostNumCores
static unsigned long getHostNumCores(std::string hostname)
Get the number of cores of a host given a hostname.
Definition: Simulation.cpp:1009
wrench::Simulation::getEnergyConsumed
double getEnergyConsumed(const std::string &hostname)
Obtains the current energy consumption of a host.
Definition: Simulation.cpp:1134
wrench::Simulation::doesHostExist
static bool doesHostExist(std::string hostname)
Wrapper for S4U_Simulation hostExists()
Definition: Simulation.cpp:973
wrench::Simulation::isInitialized
static bool isInitialized()
Determine if the simulation has been initialized.
Definition: Simulation.cpp:1538
wrench::Simulation
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:48
wrench::Simulation::~Simulation
~Simulation()
Destructor.
Definition: Simulation.cpp:86
wrench::Simulation::readFromDiskAndWriteToDiskConcurrently
void readFromDiskAndWriteToDiskConcurrently(double num_bytes_to_read, double num_bytes_to_write, std::string hostname, std::string read_mount_point, std::string write_mount_point)
Wrapper enabling timestamps for concurrent disk read/writes.
Definition: Simulation.cpp:779
wrench::Simulation::removeFile
static void removeFile(std::shared_ptr< DataFile >file)
Remove a file from the simulation (use at your own peril if you're using the workflow API - use Workf...
Definition: Simulation.cpp:1527
wrench::Simulation::writeToDisk
void writeToDisk(double num_bytes, std::string hostname, std::string mount_point)
Wrapper enabling timestamps for disk writes.
Definition: Simulation.cpp:814
wrench::Simulation::turnOnHost
static void turnOnHost(std::string hostname)
Turns on a host.
Definition: Simulation.cpp:1043
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:1243
wrench::Simulation::getFileMap
static std::map< std::string, std::shared_ptr< DataFile > > & getFileMap()
Get the list of all files in the simulation.
Definition: Simulation.cpp:1472
wrench::Simulation::turnOffLink
static void turnOffLink(std::string linkname)
Turns off a link.
Definition: Simulation.cpp:1060
wrench::Simulation::readWithMemoryCache
void readWithMemoryCache(std::shared_ptr< DataFile >file, double n_bytes, std::shared_ptr< FileLocation > location)
Read file locally, only available if writeback is activated.
Definition: Simulation.cpp:836
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:1018
wrench::Simulation::doesLinkExist
static bool doesLinkExist(std::string linkname)
Wrapper for S4U_Simulation linkExists()
Definition: Simulation.cpp:983
wrench::Simulation::getNumberofPstates
static int getNumberofPstates(const std::string &hostname)
Get the total number of power states of a host.
Definition: Simulation.cpp:1207
wrench::Simulation::getOutput
SimulationOutput & getOutput()
Get the simulation output object.
Definition: Simulation.cpp:1124
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)
Obtains the current link bandwidth usage on a link and will add SimulationTimestampLinkUsage to simul...
Definition: Simulation.cpp:378
wrench::Simulation::isHostShutdownSimulationEnabled
static bool isHostShutdownSimulationEnabled()
Method to check if host shutdown simulation is activated.
Definition: Simulation.cpp:405
wrench::Simulation::writeThroughWithMemoryCache
void writeThroughWithMemoryCache(std::shared_ptr< DataFile >file, double n_bytes, std::shared_ptr< FileLocation > location)
Write-through a file locally, only available if writeback is activated.
Definition: Simulation.cpp:931
wrench::Simulation::getCurrentSimulatedDate
static double getCurrentSimulatedDate()
Get the current simulated date.
Definition: Simulation.cpp:991
wrench::Simulation::getFlopRate
static double getFlopRate()
Get the flop rate of one core of the host on which the calling process is running.
Definition: Simulation.cpp:1092