wrench::Simulation
-
class Simulation
A class that provides basic simulation methods. Once the simulation object has been explicitly or implicitly destroyed, then any call to the WRENCH APIs has undefied behavior (due to memory_manager_service being de-allocated).
Public Functions
-
~Simulation()
Destructor.
Method to add a service to the simulation.
- Template Parameters:
T – The service class (base class is Service)
- Parameters:
t – the service object (shared ptr)
- Returns:
a shared_ptr to the service object
Method to add a service to the simulation.
- Template Parameters:
T – The service class (base class is Service)
- Parameters:
t – the service object
- Returns:
a shared_ptr to the service object
-
double getEnergyConsumed(const std::string &hostname)
Obtains the current energy consumption of a host.
- Parameters:
hostname – the host name
- Returns:
current energy consumption in joules
-
double getEnergyConsumed(const std::string &hostname, bool record_as_time_stamp)
Obtains the current energy consumption of a host and will add SimulationTimestampEnergyConsumption to simulation output if can_record is set to true.
- Parameters:
hostname – the host name
record_as_time_stamp – bool signaling whether or not to record a SimulationTimestampEnergyConsumption object
- Returns:
current energy consumption in joules
-
std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames)
Obtains the current energy consumption of a host.
- Parameters:
hostnames – the list of hostnames
- Returns:
current energy consumption in joules for each host, as a map indexed by hostnames
-
std::map<std::string, double> getEnergyConsumed(const std::vector<std::string> &hostnames, bool record_as_time_stamps)
Obtains the current energy consumption of a host and will add SimulationTimestampEnergyConsumption to simulation output if can_record is set to true.
- Parameters:
hostnames – the list of hostnames
record_as_time_stamps – whether or not to record a SimulationTimestampEnergyConsumption object for each host when this method is called
- Returns:
current energy consumption in joules for each host, as a map indexed by hostnames
-
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 simulation output if record_as_time_stamp is set to true.
- Parameters:
link_name – the link’s name
record_as_time_stamp – bool signaling whether or not to record a SimulationTimestampLinkUsage object
- Returns:
current bandwidth usage in Bps
-
SimulationOutput &getOutput()
Get the simulation output object.
- Returns:
simulation output object
-
void init(int*, char**)
Initialize the simulation, which parses out WRENCH-specific and SimGrid-specific command-line arguments, if any.
- Parameters:
argc – main()’s argument count
argv – main()’s argument list
-
void instantiatePlatform(const std::function<void()>&)
Instantiate a simulated platform.
- Parameters:
creation_function – void() function to create the platform
-
void instantiatePlatform(const std::string&)
Instantiate a simulated platform.
- Parameters:
filename – the path to a SimGrid XML platform description file
-
void instantiatePlatformFromString(const std::string &platform)
Instantiate a simulated platform.
- Parameters:
platform – the string representation of a SimGrid XML platform description
-
bool isRunning() const
Checks whether the simulation is running or not.
- Returns:
true or false
-
void launch()
Launch the simulation.
-
void readFromDisk(sg_size_t num_bytes, const std::string &hostname, simgrid::s4u::Disk *disk)
Wrapper enabling timestamps for disk reads.
- Parameters:
num_bytes – number of bytes read
hostname – hostname to read from
disk – disk to read from (nullptr if not known)
-
void readFromDiskAndWriteToDiskConcurrently(sg_size_t num_bytes_to_read, sg_size_t num_bytes_to_write, const std::string &hostname, simgrid::s4u::Disk *src_disk, simgrid::s4u::Disk *dst_disk)
Wrapper enabling timestamps for concurrent disk read/writes.
- Parameters:
num_bytes_to_read – - number of bytes read
num_bytes_to_write – - number of bytes written
hostname – - hostname where disk is located
src_disk – source disk (nullptr if not known)
dst_disk – dst disk (nullptr if not known)
-
void setPstate(const std::string &hostname, int pstate)
Set the power state of the host.
- Parameters:
hostname – the host name
pstate – the power state index (as specified in the platform xml description file)
-
std::shared_ptr<ComputeService> startNewService(ComputeService *service)
Starts a new compute service during execution (i.e., one that was not passed to Simulation::add() before Simulation::launch() was called). The simulation takes ownership of the reference and will call the destructor.
- Parameters:
service – An instance of a service
- Returns:
A pointer to the service instance
-
std::shared_ptr<FileRegistryService> startNewService(FileRegistryService *service)
Starts a new file registry service during execution (i.e., one that was not passed to Simulation::add() before Simulation::launch() was called). The simulation takes ownership of the reference and will call the destructor.
- Parameters:
service – An instance of a service
- Returns:
A pointer to the service instance
-
std::shared_ptr<NetworkProximityService> startNewService(NetworkProximityService *service)
Starts a new network proximity service during execution (i.e., one that was not passed to Simulation::add() before Simulation::launch() was called). The simulation takes ownership of the reference and will call the destructor.
- Parameters:
service – An instance of a service
- Returns:
A pointer to the service instance
-
std::shared_ptr<StorageService> startNewService(StorageService *service)
Starts a new storage service during execution (i.e., one that was not passed to Simulation::add() before Simulation::launch() was called). The simulation takes ownership of the reference and will call the destructor.
- Parameters:
service – An instance of a service
- Returns:
A pointer to the service instance
-
void writeToDisk(sg_size_t num_bytes, const std::string &hostname, simgrid::s4u::Disk *disk)
Wrapper enabling timestamps for disk writes.
- Parameters:
num_bytes – number of bytes written
hostname – name of the host to write to
disk – a simgrid disk to write to (nullptr if not known)
Public Static Functions
-
static std::shared_ptr<DataFile> addFile(const std::string &id, const std::string &size)
Add a new file to the simulation (use at your own peril if you’re using the workflow API - use Workflow::addFile() instead)
- Parameters:
id – a unique string id
size – a size as a unit string (e.g., “10MB”)
- Returns:
the DataFile instance
-
static std::shared_ptr<DataFile> addFile(const std::string &id, sg_size_t size)
Add a new file to the simulation (use at your own peril if you’re using the workflow API - use Workflow::addFile() instead)
- Parameters:
id – a unique string id
size – a file size in bytes
- Returns:
the DataFile instance
-
static void compute(double flops)
Make the calling process compute.
- Parameters:
flops – a number of floating point operations
-
static void computeMultiThreaded(unsigned long num_threads, double thread_creation_overhead, double sequential_work, double parallel_per_thread_work)
Simulates a multi-threaded computation.
- Parameters:
num_threads – the number of threads
thread_creation_overhead – the thread creation overhead in seconds
sequential_work – the sequential work (in flops)
parallel_per_thread_work – the parallel per thread work (in flops)
-
static void createNewDisk(const std::string &hostname, const std::string &disk_id, double read_bandwidth_in_bytes_per_sec, double write_bandwidth_in_bytes_per_sec, sg_size_t capacity_in_bytes, const std::string &mount_point)
Method to create a new disk in the platform, which can be handy.
- Parameters:
hostname – the name of the host to which the disk should be attached
disk_id – the nae of the disk
read_bandwidth_in_bytes_per_sec – the disk’s read bandwidth in byte/sec
write_bandwidth_in_bytes_per_sec – the disk’s write bandwidth in byte/sec
capacity_in_bytes – the disk’s capacity in bytes
mount_point – the disk’s mount point (most people use “/”)
-
static std::shared_ptr<Simulation> createSimulation()
Create a simulation.
- Returns:
a simulation
-
static bool doesHostExist(const std::string &hostname)
Wrapper for S4U_Simulation hostExists()
- Parameters:
hostname – - name of host being queried
- Returns:
boolean of existence
-
static bool doesLinkExist(const std::string &link_name)
Wrapper for S4U_Simulation linkExists()
- Parameters:
link_name – - name of link being queried
- Returns:
boolean of existence
-
static int getCurrentPstate(const std::string &hostname)
Get the current power state of a host.
- Parameters:
hostname – the host name
- Returns:
The index of the current pstate of the host (as specified in the platform xml description file)
-
static double getCurrentSimulatedDate()
Get the current simulated date.
- Returns:
a date
-
static std::shared_ptr<DataFile> getFileByID(const std::string &id)
Find a DataFile based on its ID.
- Parameters:
id – a string id
- Returns:
the DataFile instance (or throws a std::invalid_argument if not found)
-
static std::shared_ptr<DataFile> getFileByIDOrNull(const std::string &id)
Find a DataFile based on its ID.
- Parameters:
id – a string id
- Returns:
the DataFile instance (or nullptr if not found)
-
static std::map<std::string, std::shared_ptr<DataFile>> &getFileMap()
Get the list of all files in the simulation.
- Returns:
a reference to the map of files in the simulation, indexed by file ID
-
static double getFlopRate()
Get the flop rate of one core of the host on which the calling process is running.
- Returns:
a flop rate
-
static double getHostFlopRate(const std::string &hostname)
Get the flop rate of one core of a host given a hostname.
- Parameters:
hostname – the hostname
- Returns:
a flop rate (flop / sec)
-
static sg_size_t getHostMemoryCapacity(const std::string &hostname)
Get the memory_manager_service capacity of a host given a hostname.
- Parameters:
hostname – the hostname
- Returns:
a memory_manager_service capacity in bytes
-
static std::string getHostName()
Get the name of the host on which the calling process is running.
- Returns:
a host name
-
static std::vector<std::string> getHostnameList()
Get the list of names of all the physical hosts in the platform.
- Returns:
a vector of hostnames
-
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
- Returns:
a map of lists of hosts, indexed by cluster name
-
static unsigned long getHostNumCores(const std::string &hostname)
Get the number of cores of a host given a hostname.
- Parameters:
hostname – the hostname
- Returns:
a number of cores
-
static double getLinkBandwidth(const std::string &link_name)
Get the max bandwidth of a particular link.
- Parameters:
link_name – the link’s name
- Returns:
a bandwidth in Bps
-
static std::vector<std::string> getLinknameList()
Get the list of names of all the links in the platform.
- Returns:
a vector of link names
-
static double getLinkUsage(const std::string &link_name)
Get the current usage of a particular link.
- Parameters:
link_name – the link’s name
- Returns:
a bandwidth usage
-
static std::vector<int> getListOfPstates(const std::string &hostname)
Get the list of power states available for a host.
- Parameters:
hostname – the host name
- Returns:
a list of power states available for the host (as specified in the platform xml description file)
-
static double getMaxPowerConsumption(const std::string &hostname)
Get the maximum power consumption for the host (i.e., 100% utilization) at its current pstate.
- Parameters:
hostname – the host name
- Returns:
The “100% used” power consumption (as specified in the platform xml description file)
-
static sg_size_t getMemoryCapacity()
Get the memory_manager_service capacity of the host on which the calling process is running.
- Returns:
a memory_manager_service capacity in bytes
-
static double getMinPowerConsumption(const std::string &hostname)
Get the minimum power consumption for the host (i.e., idling) at its current pstate.
- Parameters:
hostname – the host name
- Returns:
The “idling” power consumption (as specified in the platform xml description file)
-
static int getNumberOfPstates(const std::string &hostname)
Get the total number of power states of a host.
- Parameters:
hostname – the host name
- Returns:
The number of power states available for the host (as specified in the platform xml description file)
-
static unsigned long getNumCores()
Get the number of cores of the host on which the calling process is running.
- Returns:
a number of cores
-
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.
- Parameters:
src_host – src hostname
dst_host – dst hostname
- Returns:
a vector of link names
-
static bool hostHasMountPoint(const std::string &hostname, const std::string &scratch_space_mount_point)
Determine if a host has a disk mounted at some mount point.
- Parameters:
hostname – the hostname
mount_point – the mount point
- Returns:
true or false
-
static bool isEnergySimulationEnabled()
Method to check if energy simulation is activated.
- Returns:
true or false
-
static bool isHostOn(const std::string &hostname)
Returns whether a host is on or not.
- Parameters:
hostname – the hostname
- Returns:
true or false
-
static bool isHostShutdownSimulationEnabled()
Method to check if host shutdown simulation is activated.
- Returns:
true or false
-
static bool isInitialized()
Determine if the simulation has been initialized.
- Returns:
true or false
-
static bool isLinkOn(const std::string &link_name)
Returns whether a link is on or not.
- Parameters:
link_name – the link_name
- Returns:
true or false
-
static bool isLinkShutdownSimulationEnabled()
Method to check if link shutdown simulation is activated.
- Returns:
true or false
-
static bool isPageCachingEnabled()
Method to check if page caching is activated.
- Returns:
true or false
-
static bool isSurfPrecisionSetByUser()
Method to check if surf precision was set by the user.
- Returns:
true or false
-
static void removeAllFiles()
Remove all files from the simulation (use at your own peril if you’re using the workflow API)
Remove a file from the simulation (use at your own peril if you’re using the workflow API - use Workflow::removeFile() instead)
- Parameters:
file – : file to remove
-
static void sleep(double duration)
Make the calling process sleep for a number of (simulated) seconds.
- Parameters:
duration – a number of seconds
-
static void turnOffHost(const std::string &hostname)
Turns off a host.
- Parameters:
hostname – the hostname
-
static void turnOffLink(const std::string &link_name)
Turns off a link.
- Parameters:
link_name – the link_name
-
static void turnOnHost(const std::string &hostname)
Turns on a host.
- Parameters:
hostname – the hostname
-
static void turnOnLink(const std::string &link_name)
Turns on a link.
- Parameters:
link_name – the link_name
-
~Simulation()