Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
compile with -Wmissing-declarations to catch more errors
[simgrid.git] / src / surf / surf_routing_cluster_torus.cpp
index 8b7a771..e09daf1 100644 (file)
@@ -1,4 +1,11 @@
-#include "surf_routing_cluster_torus.hpp"
+/* Copyright (c) 2014-2015. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "src/surf/surf_routing_private.hpp"
+#include "src/surf/surf_routing_cluster_torus.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster_torus, surf_route_cluster, "Torus Routing part of surf");
 
@@ -19,19 +26,27 @@ inline unsigned int* rankId_to_coords(int rankId, xbt_dynar_t dimensions) {
 
 AS_t model_torus_cluster_create(void)
 {
-  return new AsClusterTorus();
+  return new simgrid::surf::AsClusterTorus();
 }
 
+namespace simgrid {
+namespace surf {
+
 /* Creation routing model functions */
 AsClusterTorus::AsClusterTorus() : AsCluster()
 {
   p_dimensions = NULL;
 }
 
+/* Creation routing model functions */
+AsClusterTorus::~AsClusterTorus()
+{
+  if(p_dimensions) xbt_dynar_free(&p_dimensions);
+}
 
 
 void AsClusterTorus::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position){
-  s_sg_platf_link_cbarg_t link;
+  s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
   char* link_id;
   unsigned int j = 0;
   /**
@@ -48,26 +63,24 @@ void AsClusterTorus::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int
       memset(&link, 0, sizeof(link));
       current_dimension = xbt_dynar_get_as(p_dimensions, j, int);
       neighbour_rank_id = ( ((int) rank / dim_product) % current_dimension == current_dimension-1) ? rank - (current_dimension-1)*dim_product : rank + dim_product;
-      //name of neighbour is not right for non contiguous cluster radicals (as id != rank in this case)
+      //name of neighbor is not right for non contiguous cluster radicals (as id != rank in this case)
       link_id           = bprintf("%s_link_from_%i_to_%i", cluster->id, id, neighbour_rank_id);
       link.id           = link_id;
       link.bandwidth    = cluster->bw;
       link.latency      = cluster->lat;
-      link.state        = SURF_RESOURCE_ON;
+      link.initiallyOn  = 1;
       link.policy       = cluster->sharing_policy;
       sg_platf_new_link(&link);
       s_surf_parsing_link_up_down_t info;
       if (link.policy == SURF_LINK_FULLDUPLEX) {
           char *tmp_link = bprintf("%s_UP", link_id);
-          info.link_up =
-              xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
+          info.link_up = Link::byName(tmp_link);
           free(tmp_link);
           tmp_link = bprintf("%s_DOWN", link_id);
-          info.link_down =
-              xbt_lib_get_or_null(link_lib, tmp_link, SURF_LINK_LEVEL);
+          info.link_down = Link::byName(tmp_link);
           free(tmp_link);
       } else {
-          info.link_up = xbt_lib_get_or_null(link_lib, link_id, SURF_LINK_LEVEL);
+          info.link_up = Link::byName(link_id);
           info.link_down = info.link_up;
       }
       /**
@@ -88,39 +101,41 @@ void AsClusterTorus::parse_specific_arguments(sg_platf_cluster_cbarg_t cluster){
 
   unsigned int iter;
   char *groups;
-  p_dimensions = xbt_str_split(cluster->topo_parameters, ",");
+  xbt_dynar_t dimensions = xbt_str_split(cluster->topo_parameters, ",");
 
-    if (!xbt_dynar_is_empty(p_dimensions)) {
+    if (!xbt_dynar_is_empty(dimensions)) {
+      p_dimensions= xbt_dynar_new(sizeof(int), NULL);
       /**
        * We are in a torus cluster
        * Parse attribute dimensions="dim1,dim2,dim3,...,dimN"
        * and safe it in a dynarray.
        * Additionally, we need to know how many ranks we have in total
        */
-      xbt_dynar_foreach(p_dimensions, iter, groups) {
-          int tmp = surf_parse_get_int(xbt_dynar_get_as(p_dimensions, iter, char *));
+      xbt_dynar_foreach(dimensions, iter, groups) {
+          int tmp = surf_parse_get_int(xbt_dynar_get_as(dimensions, iter, char *));
           xbt_dynar_set_as(p_dimensions, iter, int, tmp);
       }
 
       p_nb_links_per_node = xbt_dynar_length(p_dimensions);
 
     }
+    xbt_dynar_free(&dimensions);
 }
 
-void AsClusterTorus::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst, sg_platf_route_cbarg_t route, double *lat){
+void AsClusterTorus::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat){
 
   XBT_VERB("torus_get_route_and_latency from '%s'[%d] to '%s'[%d]",
-               src->p_name,src->m_id,
-               dst->p_name,dst->m_id);
+               src->getName(), src->getId(),
+               dst->getName(), dst->getId());
 
-     if (dst->p_rcType == SURF_NETWORK_ELEMENT_ROUTER || src->p_rcType == SURF_NETWORK_ELEMENT_ROUTER) return;
+     if (dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_NETWORK_ELEMENT_ROUTER) return;
 
-     if((src->m_id == dst->m_id) && p_has_loopback  ){
-       s_surf_parsing_link_up_down_t info = xbt_dynar_get_as(p_linkUpDownList, src->m_id * p_nb_links_per_node, s_surf_parsing_link_up_down_t);
+     if((src->getId() == dst->getId()) && p_has_loopback  ){
+       s_surf_parsing_link_up_down_t info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node, s_surf_parsing_link_up_down_t);
        xbt_dynar_push_as(route->link_list, void *, info.link_up);
 
        if (lat)
-         *lat += static_cast<NetworkLinkPtr>(info.link_up)->getLatency();
+         *lat += static_cast<Link*>(info.link_up)->getLatency();
        return;
      }
 
@@ -130,8 +145,8 @@ void AsClusterTorus::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst,
       * TODO Change to dynamic assignment
       */
      unsigned int j, cur_dim, dim_product   = 1;
-     long current_node    = src->m_id;
-     long unsigned next_node       = 0;
+     int current_node    = src->getId();
+     int unsigned next_node       = 0;
      /**
       * Arrays that hold the coordinates of the current node and
       * the target; comparing the values at the i-th position of
@@ -139,8 +154,8 @@ void AsClusterTorus::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst,
       * into this dimension or not.
       */
      unsigned int* myCoords, *targetCoords;
-     myCoords     = rankId_to_coords(src->m_id, p_dimensions);
-     targetCoords = rankId_to_coords(dst->m_id, p_dimensions);
+     myCoords     = rankId_to_coords(src->getId(), p_dimensions);
+     targetCoords = rankId_to_coords(dst->getId(), p_dimensions);
      /**
       * linkOffset describes the offset where the link
       * we want to use is stored
@@ -148,18 +163,18 @@ void AsClusterTorus::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst,
       * which can only be the case if src->m_id == dst->m_id -- see above
       * for this special case)
       */
-     long nodeOffset = (xbt_dynar_length(p_dimensions)+1)*src->m_id;
+     int nodeOffset = (xbt_dynar_length(p_dimensions)+1)*src->getId();
 
-     long linkOffset = nodeOffset;
+     int linkOffset = nodeOffset;
      bool use_lnk_up          = false; // Is this link of the form "cur -> next" or "next -> cur"?
                                        // false means: next -> cur
-     while (current_node != dst->m_id) {
+     while (current_node != dst->getId()) {
        dim_product = 1; // First, we will route in x-dimension
        for (j = 0; j < xbt_dynar_length(p_dimensions); j++) {
            cur_dim = xbt_dynar_get_as(p_dimensions, j, int);
 
            // current_node/dim_product = position in current dimension
-           if ((current_node/dim_product) % cur_dim != (dst->m_id/dim_product) % cur_dim) {
+           if ((current_node/dim_product) % cur_dim != (dst->getId()/dim_product) % cur_dim) {
 
                if (( targetCoords[j] > myCoords[j] && targetCoords[j] <= myCoords[j]+cur_dim/2) // Is the target node on the right, without the wrap-around?
                    || ( myCoords[j] > cur_dim/2 && (myCoords[j]+cur_dim/2)%cur_dim >= targetCoords[j] )) { // Or do we need to use the wrap around to reach it?
@@ -187,7 +202,7 @@ void AsClusterTorus::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst,
 
                  assert(linkOffset >= 0);
                }
-               XBT_DEBUG("torus_get_route_and_latency - current_node: %lu, next_node: %lu, linkOffset is %lu",
+               XBT_DEBUG("torus_get_route_and_latency - current_node: %i, next_node: %u, linkOffset is %i",
                current_node, next_node, linkOffset);
 
                break;
@@ -205,11 +220,17 @@ void AsClusterTorus::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst,
 
        info = xbt_dynar_get_as(p_linkUpDownList,linkOffset, s_surf_parsing_link_up_down_t);
 
-       if (use_lnk_up == false)
+       if (use_lnk_up == false){
            xbt_dynar_push_as(route->link_list,void*,info.link_down);
-       else
+
+       if (lat)
+         *lat += static_cast<Link*>(info.link_down)->getLatency();
+       }else{
            xbt_dynar_push_as(route->link_list,void*,info.link_up);
 
+       if (lat)
+         *lat += static_cast<Link*>(info.link_up)->getLatency();
+       }
        current_node = next_node;
        next_node = 0;
      }
@@ -220,3 +241,6 @@ void AsClusterTorus::getRouteAndLatency(RoutingEdgePtr src, RoutingEdgePtr dst,
 
   return;
 }
+
+}
+}