/* Note: field `unit' for the last element of parameter `units' should be nullptr. */ static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units, const char *entity_kind, const char *name, const char *error_msg, const char *default_unit) { char* ptr; double res; int i; errno = 0; res = strtod(string, &ptr); if (errno == ERANGE) surf_parse_error("value out of range: %s", string); if (ptr == string) surf_parse_error("cannot parse number: %s", string); if (ptr[0] == '\0') { if (res == 0) return res; // Ok, 0 can be unit-less XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s",string, entity_kind, name, error_msg); ptr = (char*)default_unit; } for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++) { } if (units[i].unit != nullptr) res *= units[i].scale; else surf_parse_error("unknown unit: %s", ptr); return res; }
double surf_parse_get_double(const char *string) { double res; int ret = sscanf(string, "%lg", &res); if (ret != 1) surf_parse_error("%s is not a double", string); return res; }
int surf_parse_get_int(const char *string) { int res; int ret = sscanf(string, "%d", &res); if (ret != 1) surf_parse_error("%s is not an integer", string); return res; }
void STag_surfxml_trace___connect() { simgrid::kernel::routing::TraceConnectCreationArgs trace_connect; trace_connect.element = A_surfxml_trace___connect_element; trace_connect.trace = A_surfxml_trace___connect_trace; switch (A_surfxml_trace___connect_kind) { case AU_surfxml_trace___connect_kind: case A_surfxml_trace___connect_kind_SPEED: trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED; break; case A_surfxml_trace___connect_kind_BANDWIDTH: trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH; break; case A_surfxml_trace___connect_kind_HOST___AVAIL: trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL; break; case A_surfxml_trace___connect_kind_LATENCY: trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY; break; case A_surfxml_trace___connect_kind_LINK___AVAIL: trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL; break; default: surf_parse_error("Invalid trace kind"); break; } sg_platf_trace_connect(&trace_connect); }
/** * \brief Add a "host_link" to the network element list */ static void parse_S_host_link(sg_platf_host_link_cbarg_t host) { RoutingEdge *info = sg_host_edge(sg_host_by_name(host->id)); xbt_assert(info, "Host '%s' not found!", host->id); xbt_assert(current_routing->p_modelDesc == &routing_models[SURF_MODEL_CLUSTER] || current_routing->p_modelDesc == &routing_models[SURF_MODEL_VIVALDI], "You have to be in model Cluster to use tag host_link!"); s_surf_parsing_link_up_down_t link_up_down; link_up_down.link_up = Link::byName(host->link_up); link_up_down.link_down = Link::byName(host->link_down); xbt_assert(link_up_down.link_up, "Link '%s' not found!",host->link_up); xbt_assert(link_up_down.link_down, "Link '%s' not found!",host->link_down); if(!current_routing->p_linkUpDownList) current_routing->p_linkUpDownList = xbt_dynar_new(sizeof(s_surf_parsing_link_up_down_t),NULL); // If dynar is is greater than edge id and if the host_link is already defined if((int)xbt_dynar_length(current_routing->p_linkUpDownList) > info->getId() && xbt_dynar_get_as(current_routing->p_linkUpDownList, info->getId(), void*)) surf_parse_error("Host_link for '%s' is already defined!",host->id); XBT_DEBUG("Push Host_link for host '%s' to position %d", info->getName(), info->getId()); xbt_dynar_set_as(current_routing->p_linkUpDownList, info->getId(), s_surf_parsing_link_up_down_t, link_up_down); }
/* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */ static std::vector<int>* explodesRadical(const char* radicals) { std::vector<int>* exploded = new std::vector<int>(); char* groups; unsigned int iter; // Make all hosts xbt_dynar_t radical_elements = xbt_str_split(radicals, ","); xbt_dynar_foreach (radical_elements, iter, groups) { xbt_dynar_t radical_ends = xbt_str_split(groups, "-"); int start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char*)); int end = 0; switch (xbt_dynar_length(radical_ends)) { case 1: end = start; break; case 2: end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char*)); break; default: surf_parse_error("Malformed radical: %s", groups); break; } for (int i = start; i <= end; i++) exploded->push_back(i); xbt_dynar_free(&radical_ends); }
void ETag_surfxml_actor() { simgrid::kernel::routing::ActorCreationArgs actor; actor.properties = current_property_set; current_property_set = nullptr; actor.args.swap(arguments); actor.host = A_surfxml_actor_host; actor.function = A_surfxml_actor_function; actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time); actor.kill_time = surf_parse_get_double(A_surfxml_actor_kill___time); switch (A_surfxml_actor_on___failure) { case AU_surfxml_actor_on___failure: case A_surfxml_actor_on___failure_DIE: actor.on_failure = simgrid::kernel::routing::ActorOnFailure::DIE; break; case A_surfxml_actor_on___failure_RESTART: actor.on_failure = simgrid::kernel::routing::ActorOnFailure::RESTART; break; default: surf_parse_error("Invalid on failure behavior"); break; } sg_platf_new_actor(&actor); }
void STag_surfxml_link___ctn() { simgrid::kernel::resource::LinkImpl* link = nullptr; switch (A_surfxml_link___ctn_direction) { case AU_surfxml_link___ctn_direction: case A_surfxml_link___ctn_direction_NONE: link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id))->get_impl(); break; case A_surfxml_link___ctn_direction_UP: link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_UP")->get_impl(); break; case A_surfxml_link___ctn_direction_DOWN: link = simgrid::s4u::Link::by_name(std::string(A_surfxml_link___ctn_id) + "_DOWN")->get_impl(); break; default: surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id); break; } const char* dirname = ""; switch (A_surfxml_link___ctn_direction) { case A_surfxml_link___ctn_direction_UP: dirname = " (upward)"; break; case A_surfxml_link___ctn_direction_DOWN: dirname = " (downward)"; break; default: dirname = ""; } surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname); parsed_link_list.push_back(link); }
void ETag_surfxml_link(){ simgrid::kernel::routing::LinkCreationArgs link; link.properties = current_property_set; current_property_set = nullptr; link.id = std::string(A_surfxml_link_id); link.bandwidth = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str()); link.bandwidth_trace = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr; link.latency = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str()); link.latency_trace = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr; link.state_trace = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr; switch (A_surfxml_link_sharing___policy) { case A_surfxml_link_sharing___policy_SHARED: link.policy = simgrid::s4u::Link::SharingPolicy::SHARED; break; case A_surfxml_link_sharing___policy_FATPIPE: link.policy = simgrid::s4u::Link::SharingPolicy::FATPIPE; break; case A_surfxml_link_sharing___policy_FULLDUPLEX: XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead."); link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; break; case A_surfxml_link_sharing___policy_SPLITDUPLEX: link.policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; break; default: surf_parse_error(std::string("Invalid sharing policy in link ") + link.id); break; } sg_platf_new_link(&link); }
void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post) { if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found return; std::string msg = pre + hostname + post + " Existing netpoints: \n"; std::vector<simgrid::kernel::routing::NetPoint*> netpoints = simgrid::s4u::Engine::get_instance()->get_all_netpoints(); std::sort(netpoints.begin(), netpoints.end(), [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) { return a->get_name() < b->get_name(); }); bool first = true; for (auto const& np : netpoints) { if (np->is_netzone()) continue; if (not first) msg += ","; first = false; msg += "'" + np->get_name() + "'"; if (msg.length() > 4096) { msg.pop_back(); // remove trailing quote msg += "...(list truncated)......"; break; } } surf_parse_error(msg); }
int surf_parse_get_int(std::string s) { try { return std::stoi(s); } catch (std::invalid_argument& ia) { surf_parse_error(s + " is not a double"); return -1; } }
/* Note: field `unit' for the last element of parametre `units' should be * NULL. */ static double surf_parse_get_value_with_unit(const char *string, const struct unit_scale *units) { char* ptr; double res; int i; errno = 0; res = strtod(string, &ptr); if (errno == ERANGE) surf_parse_error("value out of range: %s", string); if (ptr == string) surf_parse_error("cannot parse number: %s", string); for (i = 0; units[i].unit != NULL && strcmp(ptr, units[i].unit) != 0; i++) { } if (units[i].unit != NULL) res *= units[i].scale; else surf_parse_error("unknown unit: %s", ptr); return res; }
void STag_surfxml_config() { ZONE_TAG = 0; xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)"); XBT_DEBUG("START configuration name = %s",A_surfxml_config_id); if (_sg_cfg_init_status == 2) { surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, " "<link>, etc)."); } }
NetworkIBModel::NetworkIBModel() : NetworkSmpiModel() { m_haveGap=false; active_nodes=NULL; const char* IB_factors_string=sg_cfg_get_string("smpi/IB_penalty_factors"); xbt_dynar_t radical_elements = xbt_str_split(IB_factors_string, ";"); if(xbt_dynar_length(radical_elements)!=3) surf_parse_error("smpi/IB_penalty_factors should be provided and contain 3 elements, semi-colon separated : for example 0.965;0.925;1.35"); Be = atof(xbt_dynar_get_as(radical_elements, 0, char *)); Bs = atof(xbt_dynar_get_as(radical_elements, 1, char *)); ys = atof(xbt_dynar_get_as(radical_elements, 2, char *)); }
void sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect) { xbt_assert(xbt_dict_get_or_null(traces_set_list, trace_connect->trace), "Cannot connect trace %s to %s: trace unknown", trace_connect->trace, trace_connect->element); switch (trace_connect->kind) { case SURF_TRACE_CONNECT_KIND_HOST_AVAIL: xbt_dict_set(trace_connect_list_host_avail, trace_connect->trace, xbt_strdup(trace_connect->element), NULL); break; case SURF_TRACE_CONNECT_KIND_SPEED: xbt_dict_set(trace_connect_list_host_speed, trace_connect->trace, xbt_strdup(trace_connect->element), NULL); break; case SURF_TRACE_CONNECT_KIND_LINK_AVAIL: xbt_dict_set(trace_connect_list_link_avail, trace_connect->trace, xbt_strdup(trace_connect->element), NULL); break; case SURF_TRACE_CONNECT_KIND_BANDWIDTH: xbt_dict_set(trace_connect_list_link_bw, trace_connect->trace, xbt_strdup(trace_connect->element), NULL); break; case SURF_TRACE_CONNECT_KIND_LATENCY: xbt_dict_set(trace_connect_list_link_lat, trace_connect->trace, xbt_strdup(trace_connect->element), NULL); break; default: surf_parse_error("Cannot connect trace %s to %s: kind of trace unknown", trace_connect->trace, trace_connect->element); break; } }
void ETag_surfxml_cluster(){ simgrid::kernel::routing::ClusterCreationArgs cluster; cluster.properties = current_property_set; current_property_set = nullptr; cluster.id = A_surfxml_cluster_id; cluster.prefix = A_surfxml_cluster_prefix; cluster.suffix = A_surfxml_cluster_suffix; cluster.radicals = explodesRadical(A_surfxml_cluster_radical); cluster.speeds = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id); cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core); cluster.bw = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id); cluster.lat = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id); if(strcmp(A_surfxml_cluster_bb___bw,"")) cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id); if(strcmp(A_surfxml_cluster_bb___lat,"")) cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id); if(strcmp(A_surfxml_cluster_limiter___link,"")) cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id); if(strcmp(A_surfxml_cluster_loopback___bw,"")) cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id); if(strcmp(A_surfxml_cluster_loopback___lat,"")) cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id); switch(AX_surfxml_cluster_topology){ case A_surfxml_cluster_topology_FLAT: cluster.topology = simgrid::kernel::routing::ClusterTopology::FLAT; break; case A_surfxml_cluster_topology_TORUS: cluster.topology = simgrid::kernel::routing::ClusterTopology::TORUS; break; case A_surfxml_cluster_topology_FAT___TREE: cluster.topology = simgrid::kernel::routing::ClusterTopology::FAT_TREE; break; case A_surfxml_cluster_topology_DRAGONFLY: cluster.topology = simgrid::kernel::routing::ClusterTopology::DRAGONFLY; break; default: surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id); break; } cluster.topo_parameters = A_surfxml_cluster_topo___parameters; cluster.router_id = A_surfxml_cluster_router___id; switch (AX_surfxml_cluster_sharing___policy) { case A_surfxml_cluster_sharing___policy_SHARED: cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED; break; case A_surfxml_cluster_sharing___policy_FULLDUPLEX: XBT_WARN("FULLDUPLEX is now deprecated. Please update your platform file to use SPLITDUPLEX instead."); cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; break; case A_surfxml_cluster_sharing___policy_SPLITDUPLEX: cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::SPLITDUPLEX; break; case A_surfxml_cluster_sharing___policy_FATPIPE: cluster.sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE; break; default: surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id); break; } switch (AX_surfxml_cluster_bb___sharing___policy) { case A_surfxml_cluster_bb___sharing___policy_FATPIPE: cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::FATPIPE; break; case A_surfxml_cluster_bb___sharing___policy_SHARED: cluster.bb_sharing_policy = simgrid::s4u::Link::SharingPolicy::SHARED; break; default: surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id); break; } sg_platf_new_cluster(&cluster); }