From: Bruno Donassolo Date: Thu, 8 Apr 2021 16:47:41 +0000 (+0200) Subject: s4u::Host::create_disk, human-friendly string version X-Git-Tag: v3.28~455^2~100 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/49d2b43b4a1132169df9baa44b51defb6528004b s4u::Host::create_disk, human-friendly string version --- diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index eee859606a..4ecd0d5857 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -165,7 +165,20 @@ public: Host* set_pstate(int pstate_index); std::vector get_disks() const; + /** + * @brief Create and add disk in the host + * + * @param name Disk name + * @param read_bandwidth Reading speed of the disk + * @param write_bandwidth Writing speed of the disk + */ Disk* create_disk(const std::string& name, double read_bandwidth, double write_bandwidth); + /** + * @brief Human-friendly version of create_disk function. + * + * @throw std::invalid_argument if read/write speeds are incorrect + */ + Disk* create_disk(const std::string& name, const std::string& read_bandwidth, const std::string& write_bandwidth); void add_disk(const Disk* disk); void remove_disk(const std::string& disk_name); diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index 44ef6a1aa1..ced3915c92 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -317,6 +317,24 @@ Disk* Host::create_disk(const std::string& name, double read_bandwidth, double w }); } +Disk* Host::create_disk(const std::string& name, const std::string& read_bandwidth, const std::string& write_bandwidth) +{ + double d_read, d_write; + try { + d_read = xbt_parse_get_bandwidth("", 0, read_bandwidth.c_str(), nullptr, ""); + } catch (const simgrid::ParseError&) { + throw std::invalid_argument(std::string("Impossible to create disk: ") + name.c_str() + + std::string(". Invalid read bandwidth: ") + read_bandwidth); + } + try { + d_write = xbt_parse_get_bandwidth("", 0, write_bandwidth.c_str(), nullptr, ""); + } catch (const simgrid::ParseError&) { + throw std::invalid_argument(std::string("Impossible to create disk: ") + name.c_str() + + std::string(". Invalid write bandwidth: ") + write_bandwidth); + } + return create_disk(name, d_read, d_write); +} + void Host::add_disk(const Disk* disk) { kernel::actor::simcall([this, disk] { this->pimpl_->add_disk(disk); });