Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill the now useless 'cleanup' parameter of routing_get_route_and_latency
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Nov 2011 01:35:50 +0000 (02:35 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Nov 2011 01:35:50 +0000 (02:35 +0100)
Instead, if route == NULL we won't bother collecting the route, so
freeing is useless.
If *route == NULL, we create a short-lived dynar (equivalent to the
result of having cleanup=1 previously
else, we fill that route without messing with it

src/include/surf/surf.h
src/instr/instr_interface.c
src/instr/instr_routing.c
src/surf/network.c
src/surf/network_im.c
src/surf/surf_private.h
src/surf/surf_routing.c
src/surf/surf_routing_dijkstra.c
src/surf/surf_routing_floyd.c
src/surf/workstation_ptask_L07.c
teshsuite/simdag/platforms/flatifier.c

index f1a8832..fe9b4f3 100644 (file)
@@ -176,7 +176,7 @@ typedef struct surf_network_model_extension_public {
   surf_action_t(*communicate) (const char *src_name,
                                const char *dst_name,
                                double size, double rate);
-  xbt_dynar_t(*get_route) (const char *src_name, const char *dst_name);
+  xbt_dynar_t(*get_route) (const char *src_name, const char *dst_name); //FIXME: kill field? That is done by the routing nowadays
   double (*get_link_bandwidth) (const void *link);
   double (*get_link_latency) (const void *link);
   int (*link_shared) (const void *link);
@@ -208,6 +208,7 @@ typedef struct surf_workstation_model_extension_public {
    surf_action_t(*communicate) (void *workstation_src,                                     /**< Execute a communication amount between two workstations */
                                 void *workstation_dst, double size,
                                 double max_rate);
+   // FIXME: kill next field, which duplicates the routing
    xbt_dynar_t(*get_route) (void *workstation_src, void *workstation_dst);                 /**< Get the list of links between two ws */
 
    surf_action_t(*execute_parallel_task) (int workstation_nb,                              /**< Execute a parallel task on several workstations */
index b0ac44e..7a27800 100644 (file)
@@ -138,8 +138,8 @@ static void instr_user_srcdst_variable(double time,
                               double value,
                               InstrUserVariable what)
 {
-  xbt_dynar_t route;
-  routing_get_route_and_latency (src, dst, &route,NULL,1);
+  xbt_dynar_t route=NULL;
+  routing_get_route_and_latency (src, dst, &route,NULL);
   unsigned int i;
   void *link;
   xbt_dynar_foreach (route, i, link) {
index f009b2a..6c0528f 100644 (file)
@@ -113,7 +113,7 @@ static void recursiveGraphExtraction (AS_t rc, container_t container, xbt_dict_t
         xbt_ex_t e;
 
         TRY {
-          routing_get_route_and_latency(child1_name, child2_name, &route, NULL, 1);
+          routing_get_route_and_latency(child1_name, child2_name, &route, NULL);
         } CATCH(e) {
           xbt_ex_free(e);
         }
@@ -421,9 +421,9 @@ static void recursiveXBTGraphExtraction (xbt_graph_t graph, xbt_dict_t nodes, xb
           (child2->kind == INSTR_HOST  || child2->kind == INSTR_ROUTER) &&
           strcmp (child1_name, child2_name) != 0){
 
-        // FIXME factorize route creation once possible
-        xbt_dynar_t route;
-        routing_get_route_and_latency (child1_name, child2_name,&route,NULL,1);
+        // FIXME factorize route creation with else branch below (once possible)
+        xbt_dynar_t route=NULL;
+        routing_get_route_and_latency (child1_name, child2_name,&route,NULL);
         if (TRACE_onelink_only()){
           if (xbt_dynar_length (route) > 1) continue;
         }
index 8753f1a..9abdaf3 100644 (file)
@@ -413,8 +413,8 @@ static void net_update_actions_state(double now, double delta)
     }
 #ifdef HAVE_TRACING
     if (TRACE_is_enabled()) {
-      xbt_dynar_t route;
-      routing_get_route_and_latency(action->src_name, action->dst_name,&route,NULL,1);
+      xbt_dynar_t route=NULL;
+      routing_get_route_and_latency(action->src_name, action->dst_name,&route,NULL);
       link_CM02_t link;
       unsigned int i;
       xbt_dynar_foreach(route, i, link) {
@@ -585,12 +585,13 @@ static surf_action_t net_communicate(const char *src_name,
 
   xbt_dynar_t back_route = NULL;
   int constraints_per_variable = 0;
-  xbt_dynar_t route;
-  // I need to have the forward and backward routes at the same time, so I don't ask the routing to cleanup the route right away for me
-  routing_get_route_and_latency(src_name, dst_name, &route, &latency, 0);
+  xbt_dynar_t route = xbt_dynar_new(sizeof(void*),NULL);
+  // I need to have the forward and backward routes at the same time, so allocate "route". That way, the routing wont clean it up
+  routing_get_route_and_latency(src_name, dst_name, &route, &latency);
 
   if (sg_network_fullduplex == 1) {
-    routing_get_route_and_latency(dst_name, src_name, &back_route,NULL,1);
+    // FIXME: fill route directly
+    routing_get_route_and_latency(dst_name, src_name, &back_route,NULL);
   }
 
   /* LARGE PLATFORMS HACK:
@@ -723,8 +724,8 @@ static surf_action_t net_communicate(const char *src_name,
 
 static xbt_dynar_t net_get_route(const char *src, const char *dst)
 {
-  xbt_dynar_t route;
-  routing_get_route_and_latency(src, dst,&route, NULL,1);
+  xbt_dynar_t route=NULL;
+  routing_get_route_and_latency(src, dst,&route, NULL);
   return route;
 }
 
index a8c6e7f..9b4ef5b 100644 (file)
@@ -605,13 +605,13 @@ static surf_action_t im_net_communicate(const char *src_name,
 
   xbt_dynar_t back_route = NULL;
   int constraints_per_variable = 0;
-  // I will need this route for some time so let's call get_route with 0 as last argument to preserve it
-  xbt_dynar_t route;
-  routing_get_route_and_latency(src_name, dst_name,&route,NULL,0);
+  // I need to have the forward and backward routes at the same time, so allocate "route". That way, the routing wont clean it up
+  xbt_dynar_t route=xbt_dynar_new(global_routing->size_of_link,NULL);
+  routing_get_route_and_latency(src_name, dst_name,&route,NULL);
 
 
   if (sg_network_fullduplex == 1) {
-    routing_get_route_and_latency(dst_name, src_name, &back_route, NULL,1);
+    routing_get_route_and_latency(dst_name, src_name, &back_route, NULL);
   }
 
   /* LARGE PLATFORMS HACK:
@@ -748,8 +748,8 @@ static surf_action_t im_net_communicate(const char *src_name,
 
 static xbt_dynar_t im_net_get_route(const char *src, const char *dst)
 {
-  xbt_dynar_t route;
-  routing_get_route_and_latency(src, dst,&route,NULL,1);
+  xbt_dynar_t route=NULL;
+  routing_get_route_and_latency(src, dst,&route,NULL);
   return route;
 }
 
index fc8e8dc..b527e5c 100644 (file)
@@ -173,10 +173,11 @@ XBT_PUBLIC(void) routing_model_create(size_t size_of_link, void *loopback);
 XBT_PUBLIC(void) routing_exit(void);
 XBT_PUBLIC(void) routing_register_callbacks(void);
 XBT_PUBLIC(void) generic_free_route(route_t route); // FIXME rename to routing_route_free
+ // FIXME: make previous function private to routing again?
 
 
-XBT_PUBLIC(void) routing_get_route_and_latency(const char *src, const char *dst, //FIXME too much functions avail?
-                              xbt_dynar_t * route, double *latency, int cleanup);
+XBT_PUBLIC(void) routing_get_route_and_latency(const char *src, const char *dst,
+                              xbt_dynar_t * route, double *latency);
 
 /**
  * Resource protected methods
index 5f3e568..65539ef 100644 (file)
@@ -478,7 +478,7 @@ static void elements_father(const char *src, const char *dst,
  *
  * \param src the source host name 
  * \param dst the destination host name
- * \param *e_route the route where the links are stored
+ * \param *route the route where the links are stored.
  * \param *latency the latency, if needed
  * 
  * This function is called by "get_route" and "get_latency". It allows to walk
@@ -631,26 +631,29 @@ static void _get_route_and_latency(const char *src, const char *dst,
  *
  * \param src the source host name
  * \param dst the destination host name
- * \param route where to store the list of links (or NULL if you are not interested in it)
+ * \param route where to store the list of links. If route=NULL, we don't care about the route.
+ *              If *route=NULL, create a short lived dynar. Else, fill the provided dynar
  * \param latency where to store the latency experienced on the path (or NULL if not interested)
- * \param cleanup boolean whether the dynar should be automatically destroyed or not
  *
  * walk through the routing components tree and find a route between hosts
  * by calling the differents "get_route" functions in each routing component.
  */
 void routing_get_route_and_latency(const char *src, const char *dst,
-                              xbt_dynar_t * route, double *latency, int cleanup)
+                                   xbt_dynar_t * route, double *latency)
 {
   static xbt_dynar_t last_route = NULL;
+  int need_cleanup = route && !(*route);
+
+  if (need_cleanup) {
+    xbt_dynar_free(&last_route);
+    last_route = *route = xbt_dynar_new(global_routing->size_of_link,NULL);
+  }
 
   _get_route_and_latency(src, dst, route, latency);
+
   xbt_assert(!route || *route, "no route between \"%s\" and \"%s\"", src, dst);
   xbt_assert(!latency || *latency >= 0.0,
-             "latency error on route between \"%s\" and \"%s\"", src, dst);
-  if (route) {
-    xbt_dynar_free(&last_route);
-    last_route = cleanup ? *route : NULL;
-  }
+             "negative latency on route between \"%s\" and \"%s\"", src, dst);
 }
 
 static xbt_dynar_t recursive_get_onelink_routes(AS_t rc)
index b77cfaf..2c65d60 100644 (file)
@@ -360,8 +360,8 @@ static void dijkstra_get_route(AS_t asg,
 
     if (asg->hierarchy == SURF_ROUTING_RECURSIVE && v != dst_node_id
         && strcmp(gw_dst, prev_gw_src)) {
-      xbt_dynar_t e_route_as_to_as;
-      routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL,1);
+      xbt_dynar_t e_route_as_to_as=NULL;
+      routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL);
       xbt_assert(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
                   gw_dst, prev_gw_src);
       links = e_route_as_to_as;
index cd869e9..a17aabc 100644 (file)
@@ -108,8 +108,8 @@ static void floyd_get_route(AS_t asg, const char *src, const char *dst, route_t
 
     if (asg->hierarchy == SURF_ROUTING_RECURSIVE && !first
         && strcmp(gw_dst, prev_gw_src)) {
-      xbt_dynar_t e_route_as_to_as;
-      routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL,1);
+      xbt_dynar_t e_route_as_to_as=NULL;
+      routing_get_route_and_latency(gw_dst, prev_gw_src,&e_route_as_to_as,NULL);
       xbt_assert(e_route_as_to_as, "no route between \"%s\" and \"%s\"",
                   gw_dst, prev_gw_src);
       links = e_route_as_to_as;
index 714590b..ce71a99 100644 (file)
@@ -81,11 +81,11 @@ static void ptask_update_action_bound(surf_action_workstation_L07_t action)
 
   for (i = 0; i < workstation_nb; i++) {
     for (j = 0; j < workstation_nb; j++) {
-      xbt_dynar_t route;
+      xbt_dynar_t route=NULL;
       routing_get_route_and_latency(surf_resource_name
           (action->workstation_list[i]),
           surf_resource_name(action->workstation_list[j]),
-          &route, NULL,1);
+          &route, NULL);
 
       // FIXME do we really need to recompute the latency here?
       double lat = 0.0;
@@ -462,11 +462,11 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb,
   for (i = 0; i < workstation_nb; i++) {
     for (j = 0; j < workstation_nb; j++) {
       link_L07_t link;
-      xbt_dynar_t route;
+      xbt_dynar_t route=NULL;
       routing_get_route_and_latency(
           surf_resource_name(workstation_list[i]),
           surf_resource_name(workstation_list[j]),
-          &route,NULL,1); // FIXME: do we want to recompute the latency?
+          &route,NULL); // FIXME: do we want to recompute the latency?
       double lat = 0.0;
 
       if (communication_amount[i * workstation_nb + j] > 0)
@@ -516,11 +516,11 @@ static surf_action_t ptask_execute_parallel_task(int workstation_nb,
   for (i = 0; i < workstation_nb; i++) {
     for (j = 0; j < workstation_nb; j++) {
       link_L07_t link;
-      xbt_dynar_t route;
+      xbt_dynar_t route=NULL;
       routing_get_route_and_latency(
           surf_resource_name(workstation_list[i]),
           surf_resource_name(workstation_list[j]),
-          &route,NULL,1);
+          &route,NULL);
 
       if (communication_amount[i * workstation_nb + j] == 0.0)
         continue;
@@ -591,10 +591,10 @@ static surf_action_t ptask_action_sleep(void *cpu, double duration)
 
 static xbt_dynar_t ptask_get_route(void *src, void *dst) // FIXME: kill that callback kind?
 {
-  xbt_dynar_t route;
+  xbt_dynar_t route=NULL;
   routing_get_route_and_latency(
       surf_resource_name(src), surf_resource_name(dst),
-      &route,NULL,1);
+      &route,NULL);
   return route;
 }
 
index 7e7bb7f..1f1c663 100644 (file)
@@ -136,8 +136,8 @@ int main(int argc, char **argv)
                                printf("  <route src=\"%s\" dst=\"%s\">\n       "
                                          ,src
                                          ,dst);
-                               xbt_dynar_t route;
-                               routing_get_route_and_latency(src,dst,&route,NULL,1);
+                               xbt_dynar_t route=NULL;
+                               routing_get_route_and_latency(src,dst,&route,NULL);
                                for(i=0;i<xbt_dynar_length(route) ;i++)
                                {
                                        void *link = xbt_dynar_get_as(route,i,void *);
@@ -154,8 +154,8 @@ int main(int argc, char **argv)
                                printf("  <route src=\"%s\" dst=\"%s\">\n       "
                                          ,src
                                          ,dst);
-                               xbt_dynar_t route;
-                               routing_get_route_and_latency(src,dst,&route,NULL,1);
+                               xbt_dynar_t route=NULL;
+                               routing_get_route_and_latency(src,dst,&route,NULL);
                                for(i=0;i<xbt_dynar_length(route) ;i++)
                                {
                                        void *link = xbt_dynar_get_as(route,i,void *);
@@ -178,8 +178,8 @@ int main(int argc, char **argv)
                                printf("  <route src=\"%s\" dst=\"%s\">\n       "
                                          ,src
                                          ,dst);
-                               xbt_dynar_t route;
-                               routing_get_route_and_latency(src,dst,&route,NULL,1);
+                               xbt_dynar_t route=NULL;
+                               routing_get_route_and_latency(src,dst,&route,NULL);
                                for(i=0;i<xbt_dynar_length(route) ;i++)
                                {
                                        void *link = xbt_dynar_get_as(route,i,void *);
@@ -195,8 +195,8 @@ int main(int argc, char **argv)
                  {
                                printf("  <route src=\"%s\" dst=\"%s\">\n       "
                                          ,src, dst);
-                               xbt_dynar_t route;
-                               routing_get_route_and_latency(src,dst,&route, NULL,1);
+                               xbt_dynar_t route=NULL;
+                               routing_get_route_and_latency(src,dst,&route, NULL);
                                for(i=0;i<xbt_dynar_length(route) ;i++)
                                {
                                        void *link = xbt_dynar_get_as(route,i,void *);