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::add
std::shared_ptr< T > add(T *t)
Method to add a service to the simulation.
Definition: Simulation.h:85
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::instantiatePlatform
void instantiatePlatform(std::string)
Instantiate a simulated platform.
Definition: Simulation.cpp:277
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::getFileByID
static std::shared_ptr< DataFile > getFileByID(const std::string &id)
Find a DataFile based on its ID.
Definition: Simulation.cpp:1485
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::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::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::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::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::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::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::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::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::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