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.

template<class T>
inline std::shared_ptr<T> add(std::shared_ptr<T> t)

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

template<class T>
inline std::shared_ptr<T> add(T *t)

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

Throws:

std::invalid_argument

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:
Throws:

std::invalid_argument

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

Throws:

std::invalid_argument

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:
Throws:

std::invalid_argument

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)

Get the current usage of a particular link.

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

  • link_name – the link’s name

  • record_as_time_stamp – bool signaling whether or not to record a SimulationTimestampLinkUsage object

Throws:

std::invalid_argument

Returns:

a bandwidth usage

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

Throws:

std::invalid_argument

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

Throws:

std::runtime_error

void instantiatePlatformFromString(const std::string &platform)

Instantiate a simulated platform.

Parameters:

platform – the string representation of a SimGrid XML platform description

Throws:

std::runtime_error

void launch()

Launch the simulation.

Throws:

std::runtime_error

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)

inline void stageFile(const std::shared_ptr<DataFile> file, const std::shared_ptr<StorageService> &storage_service)

Creates a file copy on a storage service before the simulation begins.

Parameters:
  • file – a file

  • storage_service – a storage service

inline void stageFile(const std::shared_ptr<DataFile> file, const std::shared_ptr<StorageService> &storage_service, const std::string &path)

@brief Creates a file copy on a storage service before the simulation begins
@param file: a file
@param storage_service: a storage service

Parameters:

path – a path

void stageFile(const std::shared_ptr<FileLocation> &location)

Stage a copy of a file at a location (and add entries to all file registry services, if any)

Parameters:

location – the file location

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

Throws:
  • std::invalid_argument

  • std::runtime_error

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

Throws:
  • std::invalid_argument

  • std::runtime_error

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

Throws:
  • std::invalid_argument

  • std::runtime_error

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

Throws:
  • std::invalid_argument

  • std::runtime_error

Returns:

A pointer to the service instance

Public Static Functions

static std::shared_ptr<DataFile> addFile(const std::string&, double)

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

Throws:

std::invalid_argument

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, double 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

Throws:

std::invalid_argument

Returns:

the DataFile instance (or throws a std::invalid_argument 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 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 double 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::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 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 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 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 isHostOn(const std::string &hostname)

Returns whether a host is on or not.

Parameters:

hostname – the hostname

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 void removeAllFiles()

Remove all files from the simulation (use at your own peril if you’re using the workflow API)

Parameters:

file – : file to remove

static void removeFile(const std::shared_ptr<DataFile> &file)

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