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 
57  static std::vector<std::string> getHostnameList();
58  static std::map<std::string, std::vector<std::string>> getHostnameListByCluster();
59  static double getHostMemoryCapacity(std::string hostname);
60  static unsigned long getHostNumCores(std::string hostname);
61  static double getHostFlopRate(std::string hostname);
62 
63 
64  void launch();
65 
72  template <class T>
73  std::shared_ptr<T> add(T *t) {
74  auto s = std::shared_ptr<T>(t);
75  this->addService(s);
76  return s;
77  }
78 
80 
81  //start energy related calls
82  double getEnergyConsumed(const std::string &hostname);
83  std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames);
84 // double getEnergyTimestamp(const std::string &hostname, bool can_record = false);
85 
86  // pstate related calls
87  static int getNumberofPstates(const std::string &hostname);
88  static double getMinPowerConsumption(const std::string &hostname);
89  static double getMaxPowerConsumption(const std::string &hostname);
90  static std::vector<int> getListOfPstates(const std::string &hostname);
91 
92  void stageFile(WorkflowFile *file, std::shared_ptr<StorageService> ss);
93  void stageFile(WorkflowFile *file, std::shared_ptr<StorageService> ss, std::string directory_absolute_path);
94 
95  /***********************/
97  /***********************/
98  double getEnergyConsumed(const std::string &hostname, bool record_as_time_stamp);
99 
100  static std::vector<std::string> getRoute(std::string &src_host, std::string &dst_host);
101 
102  double getLinkUsage(const std::string &link_name, bool record_as_time_stamp);
103  std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames, bool record_as_time_stamps);
104 
105  static bool doesHostExist(std::string hostname);
106  static bool isHostOn(std::string hostname);
107  static void turnOnHost(std::string hostname);
108  static void turnOffHost(std::string hostname);
109  static bool doesLinkExist(std::string linkname);
110  static bool isLinkOn(std::string linkname);
111  static void turnOnLink(std::string linkname);
112  static void turnOffLink(std::string linkname);
113 
114  // pstate related calls
115  void setPstate(const std::string &hostname, int pstate);
116  static int getCurrentPstate(const std::string &hostname);
117 
118  std::shared_ptr<ComputeService> startNewService(ComputeService *service);
119  std::shared_ptr<StorageService> startNewService(StorageService *service);
120  std::shared_ptr<NetworkProximityService> startNewService(NetworkProximityService *service);
121  std::shared_ptr<FileRegistryService> startNewService(FileRegistryService *service);
122  std::shared_ptr<MemoryManager> startNewService(MemoryManager *service);
123 
124  static double getCurrentSimulatedDate();
125 
126  static void sleep(double duration);
127  static void compute(double flops);
128  /***********************/
130  /***********************/
131 
132  /***********************/
134  /***********************/
135  void readFromDisk(double num_bytes, std::string hostname, std::string mount_point);
136  void readFromDiskAndWriteToDiskConcurrently(double num_bytes_to_read, double num_bytes_to_write,
137  std::string hostname,
138  std::string read_mount_point,
139  std::string write_mount_point);
140  void writeToDisk(double num_bytes, std::string hostname, std::string mount_point);
141 
142  void readWithMemoryCache(WorkflowFile *file, double n_bytes, std::shared_ptr<FileLocation> location);
143  void writebackWithMemoryCache(WorkflowFile *file, double n_bytes, std::shared_ptr<FileLocation> location, bool is_dirty);
144  void writeThroughWithMemoryCache(WorkflowFile *file, double n_bytes, std::shared_ptr<FileLocation> location);
145  MemoryManager* getMemoryManagerByHost(std::string hostname);
146 
147  static double getMemoryCapacity();
148  static unsigned long getNumCores();
149  static double getFlopRate();
150  static std::string getHostName();
151 
152  static std::vector<std::string> getLinknameList();
153  static double getLinkUsage(std::string linkname);
154  static double getLinkBandwidth(std::string linkname);
155  static bool isPageCachingEnabled();
156 
157  /***********************/
159  /***********************/
160 
161  private:
162  SimulationOutput output;
163 
164  std::unique_ptr<S4U_Simulation> s4u_simulation;
165 
166  std::set<std::shared_ptr<WMS>> wmses;
167 
168  std::set<std::shared_ptr<FileRegistryService>> file_registry_services;
169 
170  std::set<std::shared_ptr<EnergyMeterService>> energy_meter_services;
171 
172  std::set<std::shared_ptr<BandwidthMeterService>> bandwidth_meter_services;
173 
174  std::set<std::shared_ptr<NetworkProximityService>> network_proximity_services;
175 
176  std::set<std::shared_ptr<ComputeService>> compute_services;
177 
178  std::set<std::shared_ptr<StorageService>> storage_services;
179 
180  std::set<std::shared_ptr<MemoryManager>> memory_managers;
181 
182  static int unique_disk_sequence_number;
183 
184  void stageFile(WorkflowFile *file, std::shared_ptr<FileLocation> location);
185 
186  void platformSanityCheck();
187  void checkSimulationSetup();
188  bool isRunning();
189 
190  void startAllProcesses();
191  void addService(std::shared_ptr<ComputeService> service);
192  void addService(std::shared_ptr<StorageService> service);
193  void addService(std::shared_ptr<NetworkProximityService> service);
194  void addService(std::shared_ptr<WMS> service);
195  void addService(std::shared_ptr<FileRegistryService> service);
196  void addService(std::shared_ptr<EnergyMeterService> service);
197  void addService(std::shared_ptr<BandwidthMeterService> service);
198  void addService(std::shared_ptr<MemoryManager> memory_manager);
199 
200  std::string getWRENCHVersionString() { return WRENCH_VERSION_STRING; }
201 
202  bool is_running = false;
203 
204  unsigned int on_state_change_callback_id;
205 
206  static bool pagecache_enabled;
207  };
208 
209 };
210 
211 #endif //WRENCH_SIMULATION_H
static std::map< std::string, std::vector< std::string > > getHostnameListByCluster()
Get the list of names of all the hosts in each cluster composing the platform.
Definition: Simulation.cpp:337
std::shared_ptr< T > add(T *t)
Method to add a service to the simulation.
Definition: Simulation.h:73
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:1178
void instantiatePlatform(std::string)
Instantiate a simulated platform.
Definition: Simulation.cpp:217
A file registry service (a.k.a. replica catalog) that holds a database of which files are available a...
Definition: FileRegistryService.h:35
The storage service base class.
Definition: StorageService.h:36
The compute service base class.
Definition: ComputeService.h:33
Definition: Alarm.cpp:20
static std::vector< int > getListOfPstates(const std::string &hostname)
Get the list of power states available for a host.
Definition: Simulation.cpp:1169
void launch()
Launch the simulation.
Definition: Simulation.cpp:346
void init(int *, char **)
Initialize the simulation, which parses out WRENCH-specific and SimGrid-specific command-line argumen...
Definition: Simulation.cpp:96
static double getHostMemoryCapacity(std::string hostname)
Get the memory_manager_service capacity of a host given a hostname.
Definition: Simulation.cpp:944
static std::vector< std::string > getHostnameList()
Get the list of names of all the hosts in the platform.
Definition: Simulation.cpp:243
static unsigned long getHostNumCores(std::string hostname)
Get the number of cores of a host given a hostname.
Definition: Simulation.cpp:953
double getEnergyConsumed(const std::string &hostname)
Obtains the current energy consumption of a host.
Definition: Simulation.cpp:1078
Simulation()
Constructor.
Definition: Simulation.cpp:62
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:46
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:637
~Simulation()
Destructor.
Definition: Simulation.cpp:79
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:1187
static double getHostFlopRate(std::string hostname)
Get the flop rate of one core of a host given a hostname.
Definition: Simulation.cpp:962
static int getNumberofPstates(const std::string &hostname)
Get the total number of power states of a host.
Definition: Simulation.cpp:1151
SimulationOutput & getOutput()
Get the simulation output object.
Definition: Simulation.cpp:1068
A network proximity service that continuously estimates inter-host latencies and can be queried for s...
Definition: NetworkProximityService.h:26
A class that contains post-mortem simulation-generated data.
Definition: SimulationOutput.h:27
A data file used/produced by a WorkflowTask in a Workflow.
Definition: WorkflowFile.h:26