Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Platform generation : add a function to check if the graph is connected
[simgrid.git] / src / surf / platf_generator.c
index 895e9f8dc25fc3c173e2eb2ebc3dc15d27bd7bef..90047bbb35274076fdd0d34b8f22a0c3b50e0826 100644 (file)
@@ -302,6 +302,21 @@ void platf_graph_interconnect_barabasi(void) {
   }
 }
 
+int platf_graph_is_connected(void) {
+  xbt_dynar_t dynar_nodes = NULL;
+  xbt_node_t graph_node = NULL;
+  context_node_t node_data = NULL;
+  unsigned int i;
+  dynar_nodes = xbt_graph_get_nodes(platform_graph);
+  xbt_dynar_foreach(dynar_nodes, i, graph_node) {
+    node_data = xbt_graph_node_get_data(graph_node);
+    if(node_data->degree==0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
+
 void platf_graph_promote_to_host(context_node_t node, sg_platf_host_cbarg_t parameters) {
   node->kind = HOST;
   memcpy(&(node->host_parameters), parameters, sizeof(s_sg_platf_host_cbarg_t));
@@ -373,7 +388,7 @@ void platf_generate(void) {
 
   unsigned int last_host = 0;
   unsigned int last_router = 0;
-  //unsigned int last_cluster = 0;
+  unsigned int last_cluster = 0;
 
   sg_platf_host_cbarg_t host_parameters;
   s_sg_platf_router_cbarg_t router_parameters; /* This one is not a pointer! */
@@ -383,7 +398,6 @@ void platf_generate(void) {
 
   nodes = xbt_graph_get_nodes(platform_graph);
 
-  sg_platf_init();
   sg_platf_begin();
   surf_parse_init_callbacks();
   routing_register_callbacks();
@@ -396,14 +410,24 @@ void platf_generate(void) {
     switch(node_data->kind) {
       case HOST:
         host_parameters = &node_data->host_parameters;
+        last_host++;
         if(host_parameters->id == NULL) {
-          host_parameters->id = bprintf("host-%d", ++last_host);
+          host_parameters->id = bprintf("host-%d", last_host);
         }
         sg_platf_new_host(host_parameters);
         break;
       case CLUSTER:
         cluster_parameters = &node_data->cluster_parameters;
-        //TODO: handle NULL IDs for clusters
+        last_cluster++;
+        if(cluster_parameters->prefix == NULL) {
+          cluster_parameters->prefix = "host-";
+        }
+        if(cluster_parameters->suffix == NULL) {
+          cluster_parameters->suffix = bprintf(".cluster-%d", last_cluster);
+        }
+        if(cluster_parameters->id == NULL) {
+          cluster_parameters->id = bprintf("cluster-%d", last_cluster);
+        }
         sg_platf_new_cluster(cluster_parameters);
         break;
       case ROUTER: