14 #include <string>
15 #include <vector>
16 #include <nlohmann/json.hpp>
17 #include "Version.h"
19 #include <wrench/simulation/SimulationOutput.h>
22 namespace wrench {
24  class StorageService;
25  class Service;
26  class NetworkProximityService;
27  class FileRegistryService;
28  class EnergyMeterService;
29  class BandwidthMeterService;
30  class ComputeService;
31  class BatchComputeService;
32  class BareMetalComputeService;
33  class CloudComputeService;
34  class VirtualizedClusterComputeService;
35  class WMS;
36  class WorkflowFile;
37  class SimulationOutput;
38  class S4U_Simulation;
39  class FileLocation;
46  class Simulation {
48  public:
49  Simulation();
51  ~Simulation();
53  void init(int *, char **);
55  void instantiatePlatform(std::string);
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);
64  void launch();
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  }
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);
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);
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);
95  /***********************/
97  /***********************/
98  double getEnergyConsumed(const std::string &hostname, bool record_as_time_stamp);
99  double getLinkUsage(const std::string &linkname, bool record_as_time_stamp);
100  std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames, bool record_as_time_stamps);
102  static bool doesHostExist(std::string hostname);
103  static bool isHostOn(std::string hostname);
104  static void turnOnHost(std::string hostname);
105  static void turnOffHost(std::string hostname);
106  static bool doesLinkExist(std::string linkname);
107  static bool isLinkOn(std::string linkname);
108  static void turnOnLink(std::string linkname);
109  static void turnOffLink(std::string linkname);
111  // pstate related calls
112  void setPstate(const std::string &hostname, int pstate);
113  static int getCurrentPstate(const std::string &hostname);
115  std::shared_ptr<ComputeService> startNewService(ComputeService *service);
116  std::shared_ptr<StorageService> startNewService(StorageService *service);
117  std::shared_ptr<NetworkProximityService> startNewService(NetworkProximityService *service);
118  std::shared_ptr<FileRegistryService> startNewService(FileRegistryService *service);
120  static double getCurrentSimulatedDate();
122  static void sleep(double duration);
123  static void compute(double flops);
124  /***********************/
126  /***********************/
128  /***********************/
130  /***********************/
131  void readFromDisk(double num_bytes, std::string hostname, std::string mount_point);
132  void readFromDiskAndWriteToDiskConcurrently(double num_bytes_to_read, double num_bytes_to_write,
133  std::string hostname,
134  std::string read_mount_point,
135  std::string write_mount_point);
136  void writeToDisk(double num_bytes, std::string hostname, std::string mount_point);
138  static double getMemoryCapacity();
139  static unsigned long getNumCores();
140  static double getFlopRate();
141  static std::string getHostName();
143  static std::vector<std::string> getLinknameList();
144  static double getLinkUsage(std::string linkname);
145  static double getLinkBandwidth(std::string linkname);
146  /***********************/
148  /***********************/
150  private:
151  SimulationOutput output;
153  std::unique_ptr<S4U_Simulation> s4u_simulation;
155  std::set<std::shared_ptr<WMS>> wmses;
157  std::set<std::shared_ptr<FileRegistryService>> file_registry_services;
159  std::set<std::shared_ptr<EnergyMeterService>> energy_meter_services;
161  std::set<std::shared_ptr<BandwidthMeterService>> bandwidth_meter_services;
163  std::set<std::shared_ptr<NetworkProximityService>> network_proximity_services;
165  std::set<std::shared_ptr<ComputeService>> compute_services;
167  std::set<std::shared_ptr<StorageService>> storage_services;
169  static int unique_disk_sequence_number;
171  void stageFile(WorkflowFile *file, std::shared_ptr<FileLocation> location);
173  void platformSanityCheck();
174  void checkSimulationSetup();
175  bool isRunning();
177  void startAllProcesses();
178  void addService(std::shared_ptr<ComputeService> service);
179  void addService(std::shared_ptr<StorageService> service);
180  void addService(std::shared_ptr<NetworkProximityService> service);
181  void addService(std::shared_ptr<WMS> service);
182  void addService(std::shared_ptr<FileRegistryService> service);
183  void addService(std::shared_ptr<EnergyMeterService> service);
184  void addService(std::shared_ptr<BandwidthMeterService> service);
186  std::string getWRENCHVersionString() { return WRENCH_VERSION_STRING; }
188  bool is_running = false;
190  unsigned int on_state_change_callback_id;
191  };
193 };
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:295
static double getMemoryCapacity()
Get the memory capacity of the host on which the calling process is running.
Definition: Simulation.cpp:827
std::shared_ptr< T > add(T *t)
Method to add a service to the simulation.
Definition: Simulation.h:73
static std::vector< std::string > getLinknameList()
Get the list of names of all the links in the platform.
Definition: Simulation.cpp:242
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:985
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:1007
static std::string getHostName()
Get the name of the host on which the calling process is running.
Definition: Simulation.cpp:851
static double getLinkBandwidth(std::string linkname)
Get the max bandwidth of a particular link.
Definition: Simulation.cpp:252
void instantiatePlatform(std::string)
Instantiate a simulated platform.
Definition: Simulation.cpp:207
void readFromDisk(double num_bytes, std::string hostname, std::string mount_point)
Wrapper enabling timestamps for disk reads.
Definition: Simulation.cpp:645
static int getCurrentPstate(const std::string &hostname)
Get the current power state of a host.
Definition: Simulation.cpp:967
static bool isHostOn(std::string hostname)
Returns whether a host is on or not.
Definition: Simulation.cpp:778
A file registry service (a.k.a. replica catalog) that holds a database of which files are available a...
Definition: FileRegistryService.h:35
static void sleep(double duration)
Make the calling process sleep for a number of (simulated) seconds.
Definition: Simulation.cpp:859
static bool isLinkOn(std::string linkname)
Returns whether a link is on or not.
Definition: Simulation.cpp:803
The storage service base class.
Definition: StorageService.h:36
The compute service base class.
Definition: ComputeService.h:35
double getLinkUsage(const std::string &linkname, bool record_as_time_stamp)
Obtains the current link bandwidth usage on a link and will add SimulationTimestampLinkUsage to simul...
Definition: Simulation.cpp:274
void setPstate(const std::string &hostname, int pstate)
Set the power state of the host.
Definition: Simulation.cpp:948
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:976
static unsigned long getNumCores()
Get the number of cores of the host on which the calling process is running.
Definition: Simulation.cpp:835
static void compute(double flops)
Make the calling process compute.
Definition: Simulation.cpp:867
void launch()
Launch the simulation.
Definition: Simulation.cpp:304
static void turnOnLink(std::string linkname)
Turns on a link.
Definition: Simulation.cpp:819
void init(int *, char **)
Initialize the simulation, which parses out WRENCH-specific and SimGrid-specific command-line argumen...
Definition: Simulation.cpp:92
static void turnOffHost(std::string hostname)
Turns off a host.
Definition: Simulation.cpp:786
static double getHostMemoryCapacity(std::string hostname)
Get the memory capacity of a host given a hostname.
Definition: Simulation.cpp:751
static std::vector< std::string > getHostnameList()
Get the list of names of all the hosts in the platform.
Definition: Simulation.cpp:233
static unsigned long getHostNumCores(std::string hostname)
Get the number of cores of a host given a hostname.
Definition: Simulation.cpp:760
double getEnergyConsumed(const std::string &hostname)
Obtains the current energy consumption of a host.
Definition: Simulation.cpp:885
static bool doesHostExist(std::string hostname)
Wrapper for S4U_Simulation hostExists()
Definition: Simulation.cpp:725
Definition: Simulation.cpp:58
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:578
Definition: Simulation.cpp:75
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:670
void writeToDisk(double num_bytes, std::string hostname, std::string mount_point)
Wrapper enabling timestamps for disk writes.
Definition: Simulation.cpp:705
static void turnOnHost(std::string hostname)
Turns on a host.
Definition: Simulation.cpp:794
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:994
static void turnOffLink(std::string linkname)
Turns off a link.
Definition: Simulation.cpp:811
static double getHostFlopRate(std::string hostname)
Get the flop rate of one core of a host given a hostname.
Definition: Simulation.cpp:769
static bool doesLinkExist(std::string linkname)
Wrapper for S4U_Simulation linkExists()
Definition: Simulation.cpp:734
static int getNumberofPstates(const std::string &hostname)
Get the total number of power states of a host.
Definition: Simulation.cpp:958
SimulationOutput & getOutput()
Get the simulation output object.
Definition: Simulation.cpp:875
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
static double getCurrentSimulatedDate()
Get the current simulated date.
Definition: Simulation.cpp:742
static double getFlopRate()
Get the flop rate of one core of the host on which the calling process is running.
Definition: Simulation.cpp:843