Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Checking access before open is useless (fix race condition).
[simgrid.git] / src / surf / sg_platf.cpp
index 8c30f38..882e3fb 100644 (file)
@@ -25,6 +25,7 @@
 #include "src/surf/HostImpl.hpp"
 #include "src/surf/xml/platf_private.hpp"
 
+#include <algorithm>
 #include <string>
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
@@ -37,6 +38,9 @@ xbt::signal<void(ClusterCreationArgs const&)> on_cluster_creation;
 } // namespace kernel
 } // namespace simgrid
 
+static simgrid::kernel::routing::ClusterZoneCreationArgs
+    zone_cluster; /* temporary store data for irregular clusters, created with <zone routing="Cluster"> */
+
 /** The current NetZone in the parsing */
 static simgrid::kernel::routing::NetZoneImpl* current_routing = nullptr;
 static simgrid::kernel::routing::NetZoneImpl* routing_get_current()
@@ -323,8 +327,8 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA
 
     /* adding routes */
     std::vector<simgrid::s4u::Link*> links_up{limiter, link_up, backbone};
-    links_up.erase(std::remove(links_up.begin(), links_up.end(), nullptr), links_up.end());
     std::vector<simgrid::s4u::Link*> links_down{backbone, link_down, limiter};
+    links_up.erase(std::remove(links_up.begin(), links_up.end(), nullptr), links_up.end());
     links_down.erase(std::remove(links_down.begin(), links_down.end(), nullptr), links_down.end());
 
     zone->add_route(host->get_netpoint(), nullptr, nullptr, nullptr, links_up, false);
@@ -339,6 +343,7 @@ static void sg_platf_new_cluster_flat(simgrid::kernel::routing::ClusterCreationA
   auto* router = zone->create_router(cluster->router_id);
   zone->add_route(router, nullptr, nullptr, nullptr, {});
 
+  zone->seal();
   simgrid::kernel::routing::on_cluster_creation(*cluster);
 }
 
@@ -358,8 +363,9 @@ void sg_platf_new_tag_cluster(simgrid::kernel::routing::ClusterCreationArgs* clu
 /*************************************************************************************************/
 /** @brief Set the links for internal node inside a Cluster(Star) */
 static void sg_platf_cluster_set_hostlink(simgrid::kernel::routing::StarZone* zone,
-                                          simgrid::kernel::routing::NetPoint* netpoint, simgrid::s4u::Link* link_up,
-                                          simgrid::s4u::Link* link_down, simgrid::kernel::resource::LinkImpl* backbone)
+                                          simgrid::kernel::routing::NetPoint* netpoint,
+                                          const simgrid::s4u::Link* link_up, const simgrid::s4u::Link* link_down,
+                                          simgrid::kernel::resource::LinkImpl* backbone)
 {
   XBT_DEBUG("Push Host_link for host '%s' to position %u", netpoint->get_cname(), netpoint->id());
   if (backbone) {
@@ -372,9 +378,9 @@ static void sg_platf_cluster_set_hostlink(simgrid::kernel::routing::StarZone* zo
 }
 
 /** @brief Add a link connecting a host to the rest of its StarZone */
-static void sg_platf_new_hostlink(simgrid::kernel::routing::StarZone* zone,
-                                  const simgrid::kernel::routing::HostLinkCreationArgs* hostlink,
-                                  simgrid::kernel::resource::LinkImpl* backbone)
+static void sg_platf_build_hostlink(simgrid::kernel::routing::StarZone* zone,
+                                    const simgrid::kernel::routing::HostLinkCreationArgs* hostlink,
+                                    simgrid::kernel::resource::LinkImpl* backbone)
 {
   simgrid::kernel::routing::NetPoint* netpoint = simgrid::s4u::Host::by_name(hostlink->id)->get_netpoint();
   xbt_assert(netpoint, "Host '%s' not found!", hostlink->id.c_str());
@@ -388,9 +394,9 @@ static void sg_platf_new_hostlink(simgrid::kernel::routing::StarZone* zone,
 }
 
 /** @brief Create a cabinet (set of hosts) inside a Cluster(StarZone) */
-static void sg_platf_new_cabinet(simgrid::kernel::routing::StarZone* zone,
-                                 const simgrid::kernel::routing::CabinetCreationArgs* args,
-                                 simgrid::kernel::resource::LinkImpl* backbone)
+static void sg_platf_build_cabinet(simgrid::kernel::routing::StarZone* zone,
+                                   const simgrid::kernel::routing::CabinetCreationArgs* args,
+                                   simgrid::kernel::resource::LinkImpl* backbone)
 {
   for (int const& radical : args->radicals) {
     std::string id   = args->prefix + std::to_string(radical) + args->suffix;
@@ -405,7 +411,7 @@ static void sg_platf_new_cabinet(simgrid::kernel::routing::StarZone* zone,
   }
 }
 
-void sg_platf_zone_cluster_populate(simgrid::kernel::routing::ClusterZoneCreationArgs* cluster)
+static void sg_platf_zone_cluster_populate(const simgrid::kernel::routing::ClusterZoneCreationArgs* cluster)
 {
   auto* zone = dynamic_cast<simgrid::kernel::routing::StarZone*>(current_routing);
   xbt_assert(zone, "Host_links are only valid for Cluster(Star)");
@@ -419,15 +425,26 @@ void sg_platf_zone_cluster_populate(simgrid::kernel::routing::ClusterZoneCreatio
 
   /* create host_links for hosts */
   for (auto const& hostlink : cluster->host_links) {
-    sg_platf_new_hostlink(zone, &hostlink, backbone);
+    sg_platf_build_hostlink(zone, &hostlink, backbone);
   }
 
   /* create cabinets */
   for (auto const& cabinet : cluster->cabinets) {
-    sg_platf_new_cabinet(zone, &cabinet, backbone);
+    sg_platf_build_cabinet(zone, &cabinet, backbone);
   }
 }
 
+void routing_cluster_add_backbone(std::unique_ptr<simgrid::kernel::routing::LinkCreationArgs> link)
+{
+  zone_cluster.backbone = std::move(link);
+}
+
+void sg_platf_new_cabinet(const simgrid::kernel::routing::CabinetCreationArgs* args)
+{
+  xbt_assert(args, "Invalid nullptr argument");
+  zone_cluster.cabinets.emplace_back(*args);
+}
+
 /*************************************************************************************************/
 void sg_platf_new_route(simgrid::kernel::routing::RouteCreationArgs* route)
 {
@@ -560,7 +577,8 @@ sg_platf_create_zone(const simgrid::kernel::routing::ZoneCreationArgs* zone)
  */
 simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(const simgrid::kernel::routing::ZoneCreationArgs* zone)
 {
-  current_routing = sg_platf_create_zone(zone);
+  zone_cluster.routing = zone->routing;
+  current_routing      = sg_platf_create_zone(zone);
 
   return current_routing;
 }
@@ -581,10 +599,24 @@ void sg_platf_new_Zone_set_properties(const std::unordered_map<std::string, std:
 void sg_platf_new_Zone_seal()
 {
   xbt_assert(current_routing, "Cannot seal the current Zone: none under construction");
+  if (strcasecmp(zone_cluster.routing.c_str(), "Cluster") == 0) {
+    sg_platf_zone_cluster_populate(&zone_cluster);
+    zone_cluster.routing = "";
+    zone_cluster.host_links.clear();
+    zone_cluster.cabinets.clear();
+    zone_cluster.backbone.reset();
+  }
   current_routing->seal();
   current_routing = current_routing->get_parent();
 }
 
+/** @brief Add a link connecting a host to the rest of its Zone (which must be cluster or vivaldi) */
+void sg_platf_new_hostlink(const simgrid::kernel::routing::HostLinkCreationArgs* hostlink)
+{
+  xbt_assert(hostlink, "Invalid nullptr parameter");
+  zone_cluster.host_links.emplace_back(*hostlink);
+}
+
 void sg_platf_new_trace(simgrid::kernel::routing::ProfileCreationArgs* args)
 {
   simgrid::kernel::profile::Profile* profile;