Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move kernel timers from simix:: to kernel::timer::
[simgrid.git] / src / surf / sg_platf.cpp
index 021a989fdb520f3837172ba7f629a3e1a5c1ad98..8d8d4f104283a834816d4b0ee05c801a2f847f22 100644 (file)
@@ -38,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()
@@ -360,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) {
@@ -374,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());
@@ -390,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;
@@ -407,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)");
@@ -421,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)
 {
@@ -485,7 +500,7 @@ void sg_platf_new_actor(simgrid::kernel::routing::ActorCreationArgs* actor)
                                                  auto_restart);
 
     XBT_DEBUG("Process %s@%s will be started at time %f", arg->name.c_str(), arg->host->get_cname(), start_time);
-    simgrid::simix::Timer::set(start_time, [arg, auto_restart]() {
+    simgrid::kernel::timer::Timer::set(start_time, [arg, auto_restart]() {
       simgrid::kernel::actor::ActorImplPtr new_actor =
           simgrid::kernel::actor::ActorImpl::create(arg->name.c_str(), arg->code, arg->data, arg->host, nullptr);
       new_actor->set_properties(arg->properties);
@@ -562,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;
 }
@@ -583,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;