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 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)

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

Stage a copy of a file at a storage service in the root of the (unique) mount point.

Parameters
  • file – a file to stage on a storage service

  • storage_service – a storage service

Throws
  • std::runtime_error

  • std::invalid_argument

void stageFile(const std::shared_ptr<DataFile> &file, std::shared_ptr<StorageService> ss, std::string directory_absolute_path)

Stage a copy of a file at a storage service in a particular directory.

Parameters
  • file – a file to stage on a storage service

  • storage_service – a storage service

  • directory_absolute_path – the absolute path of the directory where the file should be stored

Throws
  • std::runtime_error

  • std::invalid_argument

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<MemoryManager> startNewService(MemoryManager *service)

Starts a new memory_manager_service manager 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 createFile(const std::shared_ptr<DataFile> &file, const std::shared_ptr<FileLocation> &location)

Store a file at a particular mount point ex-nihilo. Doesn’t notify a file registry service and will do nothing (and won’t complain) if the file already exists at that location.

Parameters
  • file – a file

  • location – a file location

Throws

std::invalid_argument

static void createFile(const std::shared_ptr<DataFile> &file, const std::shared_ptr<StorageService> &server)

Store a file on a particular file server ex-nihilo. Doesn’t notify a file registry service and will do nothing (and won’t complain) if the file already exists at that location.

Parameters
  • file – a file

  • service – a storage service

Throws

std::invalid_argument

static std::shared_ptr<Simulation> createSimulation()

Create a simulation.

Returns

a simulation

static bool doesHostExist(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 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 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