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 
19 #include <wrench/simulation/SimulationOutput.h>
20 
21 
22 namespace wrench {
23 
24  class StorageService;
25  class Service;
26  class NetworkProximityService;
27  class FileRegistryService;
28  class ComputeService;
29  class BatchComputeService;
30  class BareMetalComputeService;
31  class CloudComputeService;
32  class VirtualizedClusterComputeService;
33  class WMS;
34  class WorkflowFile;
35  class SimulationOutput;
36  class S4U_Simulation;
37  class FileLocation;
38 
39 
45  class Simulation {
46 
47  public:
48  Simulation();
49 
50  ~Simulation();
51 
52  void init(int *, char **);
53 
54  void instantiatePlatform(std::string);
55 
56  static std::vector<std::string> getHostnameList();
57  static std::map<std::string, std::vector<std::string>> getHostnameListByCluster();
58  static double getHostMemoryCapacity(std::string hostname);
59  static unsigned long getHostNumCores(std::string hostname);
60  static double getHostFlopRate(std::string hostname);
61 
62  void launch();
63 
70  template <class T>
71  std::shared_ptr<T> add(T *t) {
72  auto s = std::shared_ptr<T>(t);
73  this->addService(s);
74  return s;
75  }
76 
77 
79 
80  //start energy related calls
81  double getEnergyConsumed(const std::string &hostname, bool record_as_time_stamp = false);
82  std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames, bool record_as_time_stamps = false);
83 // double getEnergyTimestamp(const std::string &hostname, bool can_record = false);
84 
85  // pstate related calls
86  static int getNumberofPstates(const std::string &hostname);
87  static double getMinPowerConsumption(const std::string &hostname);
88  static double getMaxPowerConsumption(const std::string &hostname);
89  static std::vector<int> getListOfPstates(const std::string &hostname);
90 
91  void stageFile(WorkflowFile *file, std::shared_ptr<StorageService> ss);
92  void stageFile(WorkflowFile *file, std::shared_ptr<StorageService> ss, std::string directory_absolute_path);
93 
94 
95  /***********************/
97  /***********************/
98 
99  static bool isHostOn(std::string hostname);
100  static void turnOnHost(std::string hostname);
101  static void turnOffHost(std::string hostname);
102  static bool isLinkOn(std::string linkname);
103  static void turnOnLink(std::string linkname);
104  static void turnOffLink(std::string linkname);
105 
106  // pstate related calls
107  void setPstate(const std::string &hostname, int pstate);
108  static int getCurrentPstate(const std::string &hostname);
109 
110 
111  std::shared_ptr<ComputeService> startNewService(ComputeService *service);
112  std::shared_ptr<StorageService> startNewService(StorageService *service);
113  std::shared_ptr<NetworkProximityService> startNewService(NetworkProximityService *service);
114  std::shared_ptr<FileRegistryService> startNewService(FileRegistryService *service);
115 
116 
117  static double getMemoryCapacity();
118  static unsigned long getNumCores();
119  static double getFlopRate();
120  static std::string getHostName();
121 
122  static double getCurrentSimulatedDate();
123 
124 
125 
126  static void sleep(double duration);
127  static void compute(double flops);
128 
129  /***********************/
131  /***********************/
132 
133  private:
134 
135  SimulationOutput output;
136 
137  std::unique_ptr<S4U_Simulation> s4u_simulation;
138 
139  std::set<std::shared_ptr<WMS>> wmses;
140 
141  std::set<std::shared_ptr<FileRegistryService>> file_registry_services;
142 
143  std::set<std::shared_ptr<NetworkProximityService>> network_proximity_services;
144 
145  std::set<std::shared_ptr<ComputeService>> compute_services;
146 
147  std::set<std::shared_ptr<StorageService>> storage_services;
148 
149  void stageFile(WorkflowFile *file, std::shared_ptr<FileLocation> location);
150 
151 
152  void platformSanityCheck();
153  void checkSimulationSetup();
154  bool isRunning();
155 
156  void startAllProcesses();
157  void addService(std::shared_ptr<ComputeService> service);
158  void addService(std::shared_ptr<StorageService> service);
159  void addService(std::shared_ptr<NetworkProximityService> service);
160  void addService(std::shared_ptr<WMS> service);
161  void addService(std::shared_ptr<FileRegistryService> service);
162 
163  std::string getWRENCHVersionString() { return WRENCH_VERSION_STRING; }
164 
165  bool is_running = false;
166 
167  unsigned int on_state_change_callback_id;
168 
169 
170  };
171 
172 };
173 
174 #endif //WRENCH_SIMULATION_H
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:498
static void turnOnLink(std::string linkname)
Turns on a link.
Definition: Simulation.cpp:641
static void turnOnHost(std::string hostname)
Turns on a host.
Definition: Simulation.cpp:615
void instantiatePlatform(std::string)
Instantiate a simulated platform.
Definition: Simulation.cpp:198
static bool isLinkOn(std::string linkname)
Returns whether a link is on or not.
Definition: Simulation.cpp:625
static std::vector< std::string > getHostnameList()
Get the list of names of all the hosts in the platform.
Definition: Simulation.cpp:225
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:235
static double getHostMemoryCapacity(std::string hostname)
Get the memory capacity of a host given a hostname.
Definition: Simulation.cpp:572
std::shared_ptr< T > add(T *t)
Method to add a service to the simulation.
Definition: Simulation.h:71
static unsigned long getHostNumCores(std::string hostname)
Get the number of cores of a host given a hostname.
Definition: Simulation.cpp:581
static std::string getHostName()
Get the name of the host on which the calling process is running.
Definition: Simulation.cpp:674
~Simulation()
Destructor.
Definition: Simulation.cpp:75
static double getMemoryCapacity()
Get the memory capacity of the host on which the calling process is running.
Definition: Simulation.cpp:650
static double getFlopRate()
Get the flop rate of one core of the host on which the calling process is running.
Definition: Simulation.cpp:666
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:801
A data file used/produced by a WorkflowTask in a Workflow.
Definition: WorkflowFile.h:26
A class that contains post-mortem simulation-generated data.
Definition: SimulationOutput.h:27
static void compute(double flops)
Make the calling process compute.
Definition: Simulation.cpp:691
static void turnOffHost(std::string hostname)
Turns off a host.
Definition: Simulation.cpp:607
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:45
static double getHostFlopRate(std::string hostname)
Get the flop rate of one core of a host given a hostname.
Definition: Simulation.cpp:590
The compute service base class.
Definition: ComputeService.h:35
SimulationOutput & getOutput()
Get the simulation output object.
Definition: Simulation.cpp:699
double getEnergyConsumed(const std::string &hostname, bool record_as_time_stamp=false)
Obtains the current energy consumption of a host and will add SimulationTimestampEnergyConsumption to...
Definition: Simulation.cpp:711
static int getCurrentPstate(const std::string &hostname)
Get the current power state of a host.
Definition: Simulation.cpp:773
A file registry service (a.k.a. replica catalog) that holds a database of which files are available a...
Definition: FileRegistryService.h:36
A network proximity service that continuously estimates inter-host latencies and can be queried for s...
Definition: NetworkProximityService.h:26
static void sleep(double duration)
Make the calling process sleep for a number of (simulated) seconds.
Definition: Simulation.cpp:683
void launch()
Launch the simulation.
Definition: Simulation.cpp:244
static unsigned long getNumCores()
Get the number of cores of the host on which the calling process is running.
Definition: Simulation.cpp:658
static int getNumberofPstates(const std::string &hostname)
Get the total number of power states of a host.
Definition: Simulation.cpp:764
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:792
Simulation()
Constructor.
Definition: Simulation.cpp:56
void setPstate(const std::string &hostname, int pstate)
Set the power state of the host.
Definition: Simulation.cpp:753
void init(int *, char **)
Initialize the simulation, which parses out WRENCH-specific and SimGrid-specific command-line argumen...
Definition: Simulation.cpp:92
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:816
static double getCurrentSimulatedDate()
Get the current simulated date.
Definition: Simulation.cpp:563
The storage service base class.
Definition: StorageService.h:36
static std::vector< int > getListOfPstates(const std::string &hostname)
Get the list of power states available for a host.
Definition: Simulation.cpp:782
Definition: Alarm.cpp:19
static bool isHostOn(std::string hostname)
Returns whether a host is on or not.
Definition: Simulation.cpp:599
static void turnOffLink(std::string linkname)
Turns off a link.
Definition: Simulation.cpp:633