Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
oops, remove verbose debug output
[simgrid.git] / src / surf / surf_routing.cpp
index 3828ad2..06f6880 100644 (file)
@@ -8,13 +8,15 @@
 #include "surf_routing_private.hpp"
 #include "surf_routing_cluster.hpp"
 #include "surf_routing_cluster_torus.hpp"
-
+#include "surf_routing_cluster_fat_tree.hpp"
 
 #include "simgrid/platf_interface.h"    // platform creation API internal interface
 #include "simgrid/sg_config.h"
+#include "storage_interface.hpp"
 
 #include "surf/surfxml_parse_values.h"
 
+
 /**
  * @ingroup SURF_build_api
  * @brief A library containing all known workstations
@@ -28,6 +30,7 @@ int SIMIX_HOST_LEVEL;           //Simix host level
 int SIMIX_STORAGE_LEVEL;        //Simix storage level
 int MSG_HOST_LEVEL;             //Msg host level
 int MSG_STORAGE_LEVEL;          //Msg storage level
+int MSG_FILE_LEVEL;             //Msg file level
 int SD_HOST_LEVEL;              //Simdag host level
 int SD_STORAGE_LEVEL;           //Simdag storage level
 int COORD_HOST_LEVEL=0;         //Coordinates level
@@ -40,7 +43,6 @@ int NS3_HOST_LEVEL;             //host node for ns3
 xbt_lib_t link_lib;
 int SD_LINK_LEVEL;              //Simdag level
 int SURF_LINK_LEVEL;            //Surf level
-int NS3_LINK_LEVEL;             //link for ns3
 
 xbt_lib_t as_router_lib;
 int ROUTING_ASR_LEVEL;          //Routing level
@@ -86,7 +88,7 @@ typedef enum {
   SURF_MODEL_VIVALDI,
   SURF_MODEL_CLUSTER,
   SURF_MODEL_TORUS_CLUSTER,
-
+  SURF_MODEL_FAT_TREE_CLUSTER,
 } e_routing_types;
 
 struct s_model_type routing_models[] = {
@@ -108,8 +110,10 @@ struct s_model_type routing_models[] = {
    model_vivaldi_create, NULL},
   {"Cluster", "Cluster routing",
    model_cluster_create, NULL},
-   {"Torus_Cluster", "Torus Cluster routing",
-    model_torus_cluster_create, NULL},
+  {"Torus_Cluster", "Torus Cluster routing",
+   model_torus_cluster_create, NULL},
+  {"Fat_Tree_Cluster", "Fat Tree Cluster routing",
+   model_fat_tree_cluster_create, NULL},
   {NULL, NULL, NULL, NULL}
 };
 
@@ -137,7 +141,7 @@ static void parse_S_host_link(sg_platf_host_link_cbarg_t host)
   // 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*))
-    xbt_die("Host_link for '%s' is already defined!",host->id);
+       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);
@@ -319,7 +323,7 @@ static void routing_parse_trace_connect(sg_platf_trace_connect_cbarg_t trace_con
         xbt_strdup(trace_connect->element), NULL);
     break;
   default:
-    xbt_die("Cannot connect trace %s to %s: kind of trace unknown",
+       surf_parse_error("Cannot connect trace %s to %s: kind of trace unknown",
         trace_connect->trace, trace_connect->element);
     break;
   }
@@ -353,14 +357,15 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
 
   /* search the routing model */
   switch(AS->routing){
-    case A_surfxml_AS_routing_Cluster:         model = &routing_models[SURF_MODEL_CLUSTER];break;
-    case A_surfxml_AS_routing_Cluster___torus: model = &routing_models[SURF_MODEL_TORUS_CLUSTER];break;
-    case A_surfxml_AS_routing_Dijkstra:        model = &routing_models[SURF_MODEL_DIJKSTRA];break;
-    case A_surfxml_AS_routing_DijkstraCache:   model = &routing_models[SURF_MODEL_DIJKSTRACACHE];break;
-    case A_surfxml_AS_routing_Floyd:           model = &routing_models[SURF_MODEL_FLOYD];break;
-    case A_surfxml_AS_routing_Full:            model = &routing_models[SURF_MODEL_FULL];break;
-    case A_surfxml_AS_routing_None:            model = &routing_models[SURF_MODEL_NONE];break;
-    case A_surfxml_AS_routing_Vivaldi:         model = &routing_models[SURF_MODEL_VIVALDI];break;
+    case A_surfxml_AS_routing_Cluster:               model = &routing_models[SURF_MODEL_CLUSTER];break;
+    case A_surfxml_AS_routing_Cluster___torus:       model = &routing_models[SURF_MODEL_TORUS_CLUSTER];break;
+    case A_surfxml_AS_routing_Cluster___fat___tree:  model = &routing_models[SURF_MODEL_FAT_TREE_CLUSTER];break;
+    case A_surfxml_AS_routing_Dijkstra:              model = &routing_models[SURF_MODEL_DIJKSTRA];break;
+    case A_surfxml_AS_routing_DijkstraCache:         model = &routing_models[SURF_MODEL_DIJKSTRACACHE];break;
+    case A_surfxml_AS_routing_Floyd:                 model = &routing_models[SURF_MODEL_FLOYD];break;
+    case A_surfxml_AS_routing_Full:                  model = &routing_models[SURF_MODEL_FULL];break;
+    case A_surfxml_AS_routing_None:                  model = &routing_models[SURF_MODEL_NONE];break;
+    case A_surfxml_AS_routing_Vivaldi:               model = &routing_models[SURF_MODEL_VIVALDI];break;
     default: xbt_die("Not a valid model!!!");
     break;
   }
@@ -398,7 +403,7 @@ void routing_AS_begin(sg_platf_AS_cbarg_t AS)
     /* add to the father element list */
     info->setId(current_routing->parseAS(info));
   } else {
-    THROWF(arg_error, 0, "All defined components must be belong to a AS");
+    THROWF(arg_error, 0, "All defined components must belong to a AS");
   }
 
   xbt_lib_set(as_router_lib, info->getName(), ROUTING_ASR_LEVEL,
@@ -628,7 +633,7 @@ xbt_dynar_t RoutingPlatf::getOneLinkRoutes(){
 
 xbt_dynar_t RoutingPlatf::recursiveGetOneLinkRoutes(AsPtr rc)
 {
-  xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free);
+  xbt_dynar_t ret = xbt_dynar_new(sizeof(OnelinkPtr), xbt_free_f);
 
   //adding my one link routes
   xbt_dynar_t onelink_mine = rc->getOneLinkRoutes();
@@ -833,7 +838,15 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
     AS.routing = A_surfxml_AS_routing_Cluster___torus;
     sg_platf_new_AS_begin(&AS);
     ((AsClusterTorusPtr)current_routing)->parse_specific_arguments(cluster);
-  }else{
+  }
+  else if (cluster->topology == SURF_CLUSTER_FAT_TREE) {
+    XBT_DEBUG("<AS id=\"%s\"\trouting=\"Fat_Tree_Cluster\">", cluster->id);
+    AS.routing = A_surfxml_AS_routing_Cluster___fat___tree;
+    sg_platf_new_AS_begin(&AS);
+    ((AsClusterFatTree*)current_routing)->parse_specific_arguments(cluster);
+  }
+
+  else{
     XBT_DEBUG("<AS id=\"%s\"\trouting=\"Cluster\">", cluster->id);
     AS.routing = A_surfxml_AS_routing_Cluster;
     sg_platf_new_AS_begin(&AS);
@@ -881,6 +894,15 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
 
       memset(&host, 0, sizeof(host));
       host.id = host_id;
+      if ((cluster->properties != NULL) && (!xbt_dict_is_empty(cluster->properties))) {
+         xbt_dict_cursor_t cursor=NULL;
+         char *key,*data;
+         host.properties = xbt_dict_new();
+
+         xbt_dict_foreach(cluster->properties,cursor,key,data) {
+                 xbt_dict_set(host.properties, key, xbt_strdup(data),free);
+         }
+      }
       if (cluster->availability_trace && strcmp(cluster->availability_trace, "")) {
         xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL);
         char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns);
@@ -972,12 +994,15 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
 
 
       //call the cluster function that adds the others links
-
+      if (cluster->topology == SURF_CLUSTER_FAT_TREE) {
+        ((AsClusterFatTree*) current_routing)->addProcessingNode(i);
+      }
+      else {
       ((AsClusterPtr)current_routing)->create_links_for_node(cluster, i, rankId, rankId*
           ((AsClusterPtr)current_routing)->p_nb_links_per_node
           + ((AsClusterPtr)current_routing)->p_has_loopback
           + ((AsClusterPtr)current_routing)->p_has_limiter );
-
+      }
       xbt_free(link_id);
       xbt_free(host_id);
       rankId++;
@@ -987,6 +1012,10 @@ static void routing_parse_cluster(sg_platf_cluster_cbarg_t cluster)
   }
   xbt_dynar_free(&radical_elements);
 
+  // For fat trees, the links must be created once all nodes have been added
+  if(cluster->topology == SURF_CLUSTER_FAT_TREE) {
+    ((AsClusterFatTree*)current_routing)->create_links();
+  }
   // Add a router. It is magically used thanks to the way in which surf_routing_cluster is written,
   // and it's very useful to connect clusters together
   XBT_DEBUG(" ");
@@ -1238,6 +1267,22 @@ static void routing_parse_peer(sg_platf_peer_cbarg_t peer)
 //   }
 // }
 
+static void check_disk_attachment()
+{
+  xbt_lib_cursor_t cursor;
+  char *key;
+  void **data;
+  RoutingEdgePtr host_elm;
+  xbt_lib_foreach(storage_lib, cursor, key, data) {
+    if(xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL) != NULL) {
+         StoragePtr storage = static_cast<StoragePtr>(xbt_lib_get_level(xbt_lib_get_elm_or_null(storage_lib, key), SURF_STORAGE_LEVEL));
+         host_elm = sg_routing_edge_by_name_or_null(storage->p_attach);
+         if(!host_elm)
+                 surf_parse_error("Unable to attach storage %s: host %s doesn't exist.", storage->getName(), storage->p_attach);
+    }
+  }
+}
+
 void routing_register_callbacks()
 {
   sg_platf_host_add_cb(parse_S_host);
@@ -1253,6 +1298,7 @@ void routing_register_callbacks()
 
   sg_platf_peer_add_cb(routing_parse_peer);
   sg_platf_postparse_add_cb(routing_parse_postparse);
+  sg_platf_postparse_add_cb(check_disk_attachment);
 
   /* we care about the ASes while parsing the platf. Incredible, isnt it? */
   sg_platf_AS_end_add_cb(routing_AS_end);
@@ -1305,6 +1351,32 @@ const char *surf_AS_get_name(AsPtr as) {
   return as->p_name;
 }
 
+static AsPtr surf_AS_recursive_get_by_name(AsPtr current, const char * name) {
+  xbt_dict_cursor_t cursor = NULL;
+  char *key;
+  AS_t elem;
+  AsPtr tmp = NULL;
+
+  if(!strcmp(current->p_name, name))
+    return current;
+
+  xbt_dict_foreach(current->p_routingSons, cursor, key, elem) {
+    tmp = surf_AS_recursive_get_by_name(elem, name);
+    if(tmp != NULL ) {
+        break;
+    }
+  }
+  return tmp;
+}
+
+
+AsPtr surf_AS_get_by_name(const char * name) {
+  AsPtr as = surf_AS_recursive_get_by_name(routing_platf->p_root, name);
+  if(as == NULL)
+    XBT_WARN("Impossible to find an AS with name %s, please check your input", name);
+  return as;
+}
+
 xbt_dict_t surf_AS_get_routing_sons(AsPtr as) {
   return as->p_routingSons;
 }