Combine parameters 'entity_kind' and 'name'.
Also rename surf_parse_* to xbt_parse_*.
#ifndef SIMGRID_XBT_PARSE_UNITS_HPP
#define SIMGRID_XBT_PARSE_UNITS_HPP
-double xbt_parse_get_time(const std::string& filename, int lineno, const char* string, const char* entity_kind,
- const std::string& name);
-double surf_parse_get_size(const std::string& filename, int lineno, const char* string, const char* entity_kind,
- const std::string& name);
-double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const char* string, const char* entity_kind,
- const std::string& name);
-std::vector<double> xbt_parse_get_bandwidths(const std::string& filename, int lineno, const char* string,
- const char* entity_kind, const std::string& name);
-double xbt_parse_get_speed(const std::string& filename, int lineno, const char* string, const char* entity_kind,
- const std::string& name);
-std::vector<double> xbt_parse_get_all_speeds(const std::string& filename, int lineno, char* speeds,
- const char* entity_kind, const std::string& id);
+#include <string>
+
+double xbt_parse_get_time(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind);
+double xbt_parse_get_size(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind);
+double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind);
+std::vector<double> xbt_parse_get_bandwidths(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind);
+double xbt_parse_get_speed(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind);
+std::vector<double> xbt_parse_get_all_speeds(const std::string& filename, int lineno, const std::string& speeds,
+ const std::string& entity_kind);
#endif
type = lua_gettable(L, -2);
lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
"Attribute 'bandwidth' must be specified for backbone and must either be a string (in the right format; see docs) or a number.");
- link->bandwidths.push_back(xbt_parse_get_bandwidth(ar.short_src, ar.currentline, lua_tostring(L, -1),
- "bandwidth of backbone", link->id.c_str()));
+ link->bandwidths.push_back(
+ xbt_parse_get_bandwidth(ar.short_src, ar.currentline, lua_tostring(L, -1), "bandwidth of backbone " + link->id));
lua_pop(L, 1);
lua_pushstring(L, "lat");
lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
"Attribute 'lat' must be specified for backbone and must either be a string (in the right format; see docs) or a number.");
link->latency =
- xbt_parse_get_time(ar.short_src, ar.currentline, lua_tostring(L, -1), "latency of backbone", link->id.c_str());
+ xbt_parse_get_time(ar.short_src, ar.currentline, lua_tostring(L, -1), "latency of backbone " + link->id);
lua_pop(L, 1);
lua_pushstring(L, "sharing_policy");
host.speed_per_pstate.push_back(lua_tonumber(L, -1));
else // LUA_TSTRING
host.speed_per_pstate.push_back(
- xbt_parse_get_speed(ar.short_src, ar.currentline, lua_tostring(L, -1), "speed of host", host.id));
+ xbt_parse_get_speed(ar.short_src, ar.currentline, lua_tostring(L, -1), "speed of host " + host.id));
lua_pop(L, 1);
// get core
if (type == LUA_TNUMBER)
link.bandwidths.push_back(lua_tonumber(L, -1));
else // LUA_TSTRING
- link.bandwidths.push_back(xbt_parse_get_bandwidth(ar.short_src, ar.currentline, lua_tostring(L, -1),
- "bandwidth of link", link.id.c_str()));
+ link.bandwidths.push_back(
+ xbt_parse_get_bandwidth(ar.short_src, ar.currentline, lua_tostring(L, -1), "bandwidth of link " + link.id));
lua_pop(L, 1);
//get latency value
if (type == LUA_TNUMBER)
link.latency = lua_tonumber(L, -1);
else // LUA_TSTRING
- link.latency =
- xbt_parse_get_time(ar.short_src, ar.currentline, lua_tostring(L, -1), "latency of link", link.id.c_str());
+ link.latency = xbt_parse_get_time(ar.short_src, ar.currentline, lua_tostring(L, -1), "latency of link " + link.id);
lua_pop(L, 1);
/*Optional Arguments */
const char* size_str = ptr->get_property("size");
std::string dummyfile;
if (size_str)
- size_ = surf_parse_get_size(dummyfile, -1, size_str, "disk size", ptr->get_name());
+ size_ = xbt_parse_get_size(dummyfile, -1, size_str, "disk size " + ptr->get_name());
const char* current_mount_str = ptr->get_property("mount");
if (current_mount_str)
speed_list.reserve(speed_per_state.size());
for (const auto& speed_str : speed_per_state) {
try {
- double speed = xbt_parse_get_speed("", 0, speed_str.c_str(), nullptr, "");
+ double speed = xbt_parse_get_speed("", 0, speed_str, "");
speed_list.push_back(speed);
} catch (const simgrid::ParseError&) {
throw std::invalid_argument(std::string("Invalid speed value: ") + speed_str);
{
double d_read;
try {
- d_read = xbt_parse_get_bandwidth("", 0, read_bandwidth.c_str(), nullptr, "");
+ d_read = xbt_parse_get_bandwidth("", 0, read_bandwidth, "");
} catch (const simgrid::ParseError&) {
throw std::invalid_argument(std::string("Impossible to create disk: ") + name +
std::string(". Invalid read bandwidth: ") + read_bandwidth);
}
double d_write;
try {
- d_write = xbt_parse_get_bandwidth("", 0, write_bandwidth.c_str(), nullptr, "");
+ d_write = xbt_parse_get_bandwidth("", 0, write_bandwidth, "");
} catch (const simgrid::ParseError&) {
throw std::invalid_argument(std::string("Impossible to create disk: ") + name +
std::string(". Invalid write bandwidth: ") + write_bandwidth);
{
double d_value = 0.0;
try {
- d_value = xbt_parse_get_time("", 0, value.c_str(), nullptr, "");
+ d_value = xbt_parse_get_time("", 0, value, "");
} catch (const simgrid::ParseError&) {
throw std::invalid_argument(std::string("Impossible to set latency for link: ") + get_name() +
std::string(". Invalid value: ") + value);
bw.reserve(bandwidths.size());
for (const auto& speed_str : bandwidths) {
try {
- double speed = xbt_parse_get_bandwidth("", 0, speed_str.c_str(), nullptr, "");
+ double speed = xbt_parse_get_bandwidth("", 0, speed_str, "");
bw.push_back(speed);
} catch (const simgrid::ParseError&) {
throw std::invalid_argument(std::string("Impossible to create link: ") + name +
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_config, smpi, "Logging specific to SMPI (config)");
simgrid::config::Flag<std::string> _smpi_cfg_host_speed_string{
- "smpi/host-speed",
- "Speed of the host running the simulation (in flop/s). "
- "Used to bench the operations.",
- "20000f", [](const std::string& str) {
- _smpi_cfg_host_speed = xbt_parse_get_speed("smpi/host-speed", 1, str.c_str(), "option", "smpi/host-speed");
+ "smpi/host-speed", "Speed of the host running the simulation (in flop/s). Used to bench the operations.", "20000f",
+ [](const std::string& str) {
+ _smpi_cfg_host_speed = xbt_parse_get_speed("smpi/host-speed", 1, str, "option smpi/host-speed");
xbt_assert(_smpi_cfg_host_speed > 0.0, "Invalid value (%s) for 'smpi/host-speed': it must be positive.",
_smpi_cfg_host_speed_string.get().c_str());
}};
}
} else {
try {
- fact.values.push_back(
- xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, (*factor_iter).c_str(), "smpi factor", ""));
+ fact.values.push_back(xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, *factor_iter, ""));
} catch (const std::invalid_argument&) {
throw std::invalid_argument(std::string("Invalid factor value ") + std::to_string(iteration) + " in chunk " +
std::to_string(smpi_factor.size() + 1) + ": " + *factor_iter);
property_sets.emplace_back();
host.id = A_surfxml_host_id;
- host.speed_per_pstate =
- xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_host_speed, "speed of host", host.id);
+ host.speed_per_pstate = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_host_speed,
+ "speed of host " + host.id);
XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
host.core_amount = surf_parse_get_int(A_surfxml_host_core);
disk.id = A_surfxml_disk_id;
disk.read_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_read___bw,
- "read_bw of disk ", disk.id);
+ "read_bw of disk " + disk.id);
disk.write_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_disk_write___bw,
- "write_bw of disk ", disk.id);
+ "write_bw of disk " + disk.id);
sg_platf_new_disk(&disk);
}
cluster.suffix = A_surfxml_cluster_suffix;
explodesRadical(A_surfxml_cluster_radical, &cluster.radicals);
- cluster.speeds = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_speed,
- "speed of cluster", cluster.id);
+ cluster.speeds = xbt_parse_get_all_speeds(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_speed,
+ "speed of cluster " + cluster.id);
cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
- cluster.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bw, "bw of cluster",
- cluster.id);
- cluster.lat =
- xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_lat, "lat of cluster", cluster.id);
+ cluster.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bw,
+ "bw of cluster " + cluster.id);
+ cluster.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_lat,
+ "lat of cluster " + cluster.id);
if(strcmp(A_surfxml_cluster_bb___bw,""))
cluster.bb_bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___bw,
- "bb_bw of cluster", cluster.id);
+ "bb_bw of cluster " + cluster.id);
if(strcmp(A_surfxml_cluster_bb___lat,""))
cluster.bb_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_bb___lat,
- "bb_lat of cluster", cluster.id);
+ "bb_lat of cluster " + cluster.id);
if(strcmp(A_surfxml_cluster_limiter___link,""))
cluster.limiter_link =
xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_limiter___link,
- "limiter_link of cluster", cluster.id);
+ "limiter_link of cluster " + cluster.id);
if(strcmp(A_surfxml_cluster_loopback___bw,""))
- cluster.loopback_bw = xbt_parse_get_bandwidth(
- surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
+ cluster.loopback_bw =
+ xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___bw,
+ "loopback_bw of cluster " + cluster.id);
if(strcmp(A_surfxml_cluster_loopback___lat,""))
cluster.loopback_lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cluster_loopback___lat,
- "loopback_lat of cluster", cluster.id);
+ "loopback_lat of cluster " + cluster.id);
switch(AX_surfxml_cluster_topology){
case A_surfxml_cluster_topology_FLAT:
cabinet.prefix = A_surfxml_cabinet_prefix;
cabinet.suffix = A_surfxml_cabinet_suffix;
cabinet.speed = xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_speed,
- "speed of cabinet", cabinet.id.c_str());
- cabinet.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_bw, "bw of cabinet",
- cabinet.id.c_str());
- cabinet.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_lat, "lat of cabinet",
- cabinet.id.c_str());
+ "speed of cabinet " + cabinet.id);
+ cabinet.bw = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_bw,
+ "bw of cabinet " + cabinet.id);
+ cabinet.lat = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_cabinet_lat,
+ "lat of cabinet " + cabinet.id);
explodesRadical(A_surfxml_cabinet_radical, &cabinet.radicals);
sg_platf_new_cabinet(&cabinet);
simgrid::kernel::routing::PeerCreationArgs peer;
peer.id = std::string(A_surfxml_peer_id);
- peer.speed = xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_speed, "speed of peer",
- peer.id.c_str());
- peer.bw_in = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___in, "bw_in of peer",
- peer.id.c_str());
- peer.bw_out = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___out,
- "bw_out of peer", peer.id.c_str());
+ peer.speed =
+ xbt_parse_get_speed(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_speed, "speed of peer " + peer.id);
+ peer.bw_in = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___in,
+ "bw_in of peer " + peer.id);
+ peer.bw_out = xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno, A_surfxml_peer_bw___out,
+ "bw_out of peer " + peer.id);
peer.coord = A_surfxml_peer_coordinates;
peer.speed_trace = nullptr;
if (A_surfxml_peer_availability___file[0] != '\0') {
link.id = std::string(A_surfxml_link_id);
link.bandwidths = xbt_parse_get_bandwidths(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_bandwidth,
- "bandwidth of link", link.id.c_str());
+ "bandwidth of link " + link.id);
link.bandwidth_trace = A_surfxml_link_bandwidth___file[0]
? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_bandwidth___file)
: nullptr;
- link.latency = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_latency, "latency of link",
- link.id.c_str());
+ link.latency =
+ xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_link_latency, "latency of link " + link.id);
link.latency_trace = A_surfxml_link_latency___file[0]
? simgrid::kernel::profile::Profile::from_file(A_surfxml_link_latency___file)
: nullptr;
auto link = std::make_unique<simgrid::kernel::routing::LinkCreationArgs>();
link->id = std::string(A_surfxml_backbone_id);
- link->bandwidths.push_back(xbt_parse_get_bandwidth(surf_parsed_filename, surf_parse_lineno,
- A_surfxml_backbone_bandwidth, "bandwidth of backbone",
- link->id.c_str()));
+ link->bandwidths.push_back(xbt_parse_get_bandwidth(
+ surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_bandwidth, "bandwidth of backbone " + link->id));
link->latency = xbt_parse_get_time(surf_parsed_filename, surf_parse_lineno, A_surfxml_backbone_latency,
- "latency of backbone", link->id.c_str());
+ "latency of backbone " + link->id);
link->policy = simgrid::s4u::Link::SharingPolicy::SHARED;
routing_cluster_add_backbone(std::move(link));
}
}
-/* Note: no warning is issued for unit-less values when `name' is empty. */
-static double surf_parse_get_value_with_unit(const std::string& filename, int lineno, const char* string,
- const unit_scale& units, const char* entity_kind, const std::string& name,
- const char* error_msg, const char* default_unit)
+/* Note: no warning is issued for unit-less values when `entity_kind' is empty. */
+static double xbt_parse_get_value_with_unit(const std::string& filename, int lineno, const std::string& string,
+ const unit_scale& units, const std::string& entity_kind,
+ const char* error_msg, const char* default_unit)
{
char* endptr;
errno = 0;
- double res = strtod(string, &endptr);
+ double res = strtod(string.c_str(), &endptr);
const char* ptr = endptr; // for const-correctness
if (errno == ERANGE)
throw simgrid::ParseError(filename, lineno, std::string("value out of range: ") + string);
throw simgrid::ParseError(filename, lineno, std::string("cannot parse number:") + string);
if (ptr[0] == '\0') {
// Ok, 0 can be unit-less
- if (res != 0 && not name.empty())
- XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
+ if (res != 0 && not entity_kind.empty())
+ XBT_WARN("Deprecated unit-less value '%s' for %s. %s", string.c_str(), entity_kind.c_str(), error_msg);
ptr = default_unit;
}
auto u = units.find(ptr);
return res * u->second;
}
-double xbt_parse_get_time(const std::string& filename, int lineno, const char* string, const char* entity_kind,
- const std::string& name)
+double xbt_parse_get_time(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind)
{
static const unit_scale units{std::make_pair("w", 7 * 24 * 60 * 60),
std::make_pair("d", 24 * 60 * 60),
std::make_pair("us", 1e-6),
std::make_pair("ns", 1e-9),
std::make_pair("ps", 1e-12)};
- return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name,
- "Append 's' to your time to get seconds", "s");
+ return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind,
+ "Append 's' to your time to get seconds", "s");
}
-double surf_parse_get_size(const std::string& filename, int lineno, const char* string, const char* entity_kind,
- const std::string& name)
+double xbt_parse_get_size(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind)
{
static const unit_scale units{std::make_tuple("b", 0.125, 2, true), std::make_tuple("b", 0.125, 10, true),
std::make_tuple("B", 1.0, 2, true), std::make_tuple("B", 1.0, 10, true)};
- return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name,
- "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
+ return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind,
+ "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
}
-double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const char* string, const char* entity_kind,
- const std::string& name)
+double xbt_parse_get_bandwidth(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind)
{
static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
- return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name,
- "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)",
- "Bps");
+ return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind,
+ "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)",
+ "Bps");
}
-std::vector<double> xbt_parse_get_bandwidths(const std::string& filename, int lineno, const char* string,
- const char* entity_kind, const std::string& name)
+std::vector<double> xbt_parse_get_bandwidths(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind)
{
static const unit_scale units{std::make_tuple("bps", 0.125, 2, true), std::make_tuple("bps", 0.125, 10, true),
std::make_tuple("Bps", 1.0, 2, true), std::make_tuple("Bps", 1.0, 10, true)};
std::vector<std::string> tokens;
boost::split(tokens, string, boost::is_any_of(";,"));
for (auto const& token : tokens) {
- bandwidths.push_back(surf_parse_get_value_with_unit(
- filename, lineno, token.c_str(), units, entity_kind, name,
+ bandwidths.push_back(xbt_parse_get_value_with_unit(
+ filename, lineno, token.c_str(), units, entity_kind,
"Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps"));
}
return bandwidths;
}
-double xbt_parse_get_speed(const std::string& filename, int lineno, const char* string, const char* entity_kind,
- const std::string& name)
+double xbt_parse_get_speed(const std::string& filename, int lineno, const std::string& string,
+ const std::string& entity_kind)
{
static const unit_scale units{std::make_tuple("f", 1.0, 10, true), std::make_tuple("flops", 1.0, 10, false)};
- return surf_parse_get_value_with_unit(filename, lineno, string, units, entity_kind, name,
- "Append 'f' or 'flops' to your speed to get flop per second", "f");
+ return xbt_parse_get_value_with_unit(filename, lineno, string, units, entity_kind,
+ "Append 'f' or 'flops' to your speed to get flop per second", "f");
}
-std::vector<double> xbt_parse_get_all_speeds(const std::string& filename, int lineno, char* speeds,
- const char* entity_kind, const std::string& id)
+std::vector<double> xbt_parse_get_all_speeds(const std::string& filename, int lineno, const std::string& speeds,
+ const std::string& entity_kind)
{
std::vector<double> speed_per_pstate;
- if (strchr(speeds, ',') == nullptr) {
- double speed = xbt_parse_get_speed(filename, lineno, speeds, entity_kind, id);
+ if (speeds.find('.') == std::string::npos) {
+ double speed = xbt_parse_get_speed(filename, lineno, speeds, entity_kind);
speed_per_pstate.push_back(speed);
} else {
std::vector<std::string> pstate_list;
boost::split(pstate_list, speeds, boost::is_any_of(","));
for (auto speed_str : pstate_list) {
boost::trim(speed_str);
- double speed = xbt_parse_get_speed(filename, lineno, speed_str.c_str(), entity_kind, id);
+ double speed = xbt_parse_get_speed(filename, lineno, speed_str, entity_kind);
speed_per_pstate.push_back(speed);
XBT_DEBUG("Speed value: %f", speed);
}