Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Extract the routing logic into its own object.
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 1 Jul 2009 20:31:57 +0000 (20:31 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 1 Jul 2009 20:31:57 +0000 (20:31 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6431 48e7efb5-ca39-0410-a469-dd3cf9ba447f

ChangeLog
src/Makefile.am
src/include/surf/surf.h
src/surf/network.c
src/surf/network_constant.c
src/surf/network_private.h
src/surf/surf_private.h
src/surf/surf_routing.c [new file with mode: 0644]
src/surf/workstation.c
src/surf/workstation_private.h
src/surf/workstation_ptask_L07.c

index 4eef32e..29fe81f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,10 @@ SimGrid (3.3.2-svn) unstable; urgency=low
     MPI_Waitany, MPI_Waitall, MPI_Allreduce
 
  SURF: 
     MPI_Waitany, MPI_Waitall, MPI_Allreduce
 
  SURF: 
+  * Extract the routing logic into its own object.
+    - Was dupplicated in network.c and workstation_LV07.c
+    - We may want to implement other ways of storing that info
+    => kill now useless network_card concept
   * Declare common_public as an embeeded struct to reduce redirections
     and mallocs
   * Factorize model_init/exit between models
   * Declare common_public as an embeeded struct to reduce redirections
     and mallocs
   * Factorize model_init/exit between models
@@ -16,9 +20,6 @@ SimGrid (3.3.2-svn) unstable; urgency=low
   * Embeed every fields of common_public directly into s_surf_model_t
   * Implement a generic resource; use it as ancestor to specific ones
     Allows to kill duplicated code in models
   * Embeed every fields of common_public directly into s_surf_model_t
   * Implement a generic resource; use it as ancestor to specific ones
     Allows to kill duplicated code in models
-    The drawback is that network cards are more fat since they don't
-     use the model field of their ancestor. 
-    But hell, we wont fight for 8 bytes per host, will we?
     TODO: integrate the properties into that ancestor
   * Rename model methods:
     action_free -> action_unref
     TODO: integrate the properties into that ancestor
   * Rename model methods:
     action_free -> action_unref
index 66155e6..b1e72d7 100644 (file)
@@ -171,6 +171,7 @@ SURF_SRC= \
   surf/surf_model.c                                                          \
   surf/surf_resource.c                                                       \
   surf/surf_action.c                                                         \
   surf/surf_model.c                                                          \
   surf/surf_resource.c                                                       \
   surf/surf_action.c                                                         \
+  surf/surf_routing.c                                                        \
   surf/surf_config.c                                                         \
   surf/maxmin.c                                                              \
   surf/fair_bottleneck.c                                                     \
   surf/surf_config.c                                                         \
   surf/maxmin.c                                                              \
   surf/fair_bottleneck.c                                                     \
index 5fc2982..1cb37e5 100644 (file)
@@ -120,6 +120,8 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table,
 /***************************/
 /* Generic model object */
 /***************************/
 /***************************/
 /* Generic model object */
 /***************************/
+     typedef struct s_routing s_routing_t, *routing_t;
+     XBT_PUBLIC_DATA(routing_t) used_routing;
 
 /** \brief Private data available on all models
  *  \ingroup SURF_models
 
 /** \brief Private data available on all models
  *  \ingroup SURF_models
@@ -167,9 +169,9 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table,
       *  Public functions specific to the network model
       */
      typedef struct surf_network_model_extension_public {
       *  Public functions specific to the network model
       */
      typedef struct surf_network_model_extension_public {
-       surf_action_t(*communicate) (void *src, void *dst, double size,
-                                    double max_rate);
-       xbt_dynar_t (*get_route) (void *src, void *dst);
+       surf_action_t(*communicate) (const char *src_name,const char *dst_name,int src, int dst, double size,
+           double rate);
+       xbt_dynar_t (*get_route) (int src, int dst);
        double (*get_link_bandwidth) (const void *link);
        double (*get_link_latency) (const void *link);
        int (*link_shared) (const void *link);
        double (*get_link_bandwidth) (const void *link);
        double (*get_link_latency) (const void *link);
        int (*link_shared) (const void *link);
@@ -190,13 +192,13 @@ XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table,
        surf_action_t(*communicate) (void *workstation_src,                                 /**< Execute a communication amount between two workstations */
                                     void *workstation_dst, double size,
                                     double max_rate);
        surf_action_t(*communicate) (void *workstation_src,                                 /**< Execute a communication amount between two workstations */
                                     void *workstation_dst, double size,
                                     double max_rate);
+       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 */
                                               void **workstation_list,
                                               double *computation_amount,
                                               double *communication_amount,
                                               double amount, double rate);
 
        surf_action_t(*execute_parallel_task) (int workstation_nb,                          /**< Execute a parallel task on several workstations */
                                               void **workstation_list,
                                               double *computation_amount,
                                               double *communication_amount,
                                               double amount, double rate);
-       xbt_dynar_t (*get_route) (void *src, void *dst);                                   /**< Return the network link list between two workstations */
        double (*get_link_bandwidth) (const void *link);                                    /**< Return the current bandwidth of a network link */
        double (*get_link_latency) (const void *link);                                      /**< Return the current latency of a network link */
        int (*link_shared) (const void *link);
        double (*get_link_bandwidth) (const void *link);                                    /**< Return the current bandwidth of a network link */
        double (*get_link_latency) (const void *link);                                      /**< Return the current latency of a network link */
        int (*link_shared) (const void *link);
@@ -611,7 +613,7 @@ XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_bandwidth;
 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
 
 
 XBT_PUBLIC_DATA(xbt_dict_t) trace_connect_list_latency;
 
 
-XBT_PUBLIC_DATA(double) get_cpu_power(const char *power);
+XBT_PUBLIC(double) get_cpu_power(const char *power);
 
 
 SG_END_DECL()
 
 
 SG_END_DECL()
index e388546..4b828ca 100644 (file)
@@ -22,23 +22,10 @@ double bandwidth_factor = 1.0;  /* default value */
 double weight_S_parameter = 0.0;        /* default value */
 
 int card_number = 0;
 double weight_S_parameter = 0.0;        /* default value */
 
 int card_number = 0;
-int host_number = 0;
-xbt_dynar_t *routing_table = NULL;
-static link_CM02_t loopback = NULL;
+int host_count = 0;
 double sg_tcp_gamma = 0.0;
 
 
 double sg_tcp_gamma = 0.0;
 
 
-static void create_routing_table(void)
-{
-  int i,j;
-  routing_table = xbt_new0(xbt_dynar_t,       /*card_number * card_number */
-                           host_number * host_number);
-  for (i=0;i<host_number;i++)
-    for (j=0;j<host_number;j++)
-      ROUTE(i,j) = xbt_dynar_new(sizeof(link_CM02_t),NULL);
-
-}
-
 static void link_free(void *nw_link)
 {
   xbt_dict_free(&(((link_CM02_t) nw_link)->properties));
 static void link_free(void *nw_link)
 {
   xbt_dict_free(&(((link_CM02_t) nw_link)->properties));
@@ -91,21 +78,6 @@ static link_CM02_t link_new(char *name,
   return nw_link;
 }
 
   return nw_link;
 }
 
-static int network_card_new(const char *card_name)
-{
-  network_card_CM02_t card =
-    surf_model_resource_by_name(surf_network_model, card_name);
-
-  if (!card) {
-    card = xbt_new0(s_network_card_CM02_t, 1);
-    card->generic_resource.name = xbt_strdup(card_name);
-    card->id = host_number++;
-    xbt_dict_set(surf_model_resource_set(surf_network_model), card_name, card,
-                 surf_resource_free);
-  }
-  return card->id;
-}
-
 static void parse_link_init(void)
 {
   char *name_link;
 static void parse_link_init(void)
 {
   char *name_link;
@@ -145,87 +117,6 @@ static void parse_link_init(void)
 
 }
 
 
 }
 
-static int src_id = -1;
-static int dst_id = -1;
-
-static void parse_route_set_endpoints(void)
-{
-  src_id = network_card_new(A_surfxml_route_src);
-  dst_id = network_card_new(A_surfxml_route_dst);
-  route_action = A_surfxml_route_action;
-}
-
-static void parse_route_set_route(void)
-{
-  char *name;
-  if (src_id != -1 && dst_id != -1) {
-    name = bprintf("%x#%x", src_id, dst_id);
-    manage_route(route_table, name, route_action, 0);
-    free(name);
-  }
-}
-
-static void add_loopback(void)
-{
-  int i;
-  /* Adding loopback if needed */
-  for (i = 0; i < host_number; i++)
-    if (!xbt_dynar_length(ROUTE(i, i))) {
-      if (!loopback)
-        loopback = link_new(xbt_strdup("__MSG_loopback__"),
-                            498000000, NULL, 0.000015, NULL,
-                            SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL);
-      ROUTE(i, i) = xbt_dynar_new(sizeof(link_CM02_t),NULL);
-      xbt_dynar_push(ROUTE(i,i),&loopback);
-    }
-}
-
-static void add_route(void)
-{
-  xbt_ex_t e;
-  int nb_link = 0;
-  unsigned int cpt = 0;
-  xbt_dict_cursor_t cursor = NULL;
-  char *key, *data, *end;
-  const char *sep = "#";
-  xbt_dynar_t links, keys;
-
-  if (routing_table == NULL)
-    create_routing_table();
-
-  xbt_dict_foreach(route_table, cursor, key, data) {
-    char *link_name = NULL;
-    nb_link = 0;
-    links = (xbt_dynar_t) data;
-    keys = xbt_str_split_str(key, sep);
-
-    src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
-    dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
-    xbt_dynar_free(&keys);
-
-    xbt_dynar_foreach(links, cpt, link_name) {
-      TRY {
-        link_CM02_t link = xbt_dict_get(link_set, link_name);
-        xbt_dynar_push(ROUTE(src_id,dst_id),&link);
-      }
-      CATCH(e) {
-        RETHROW1("Link %s not found (dict raised this exception: %s)", link_name);
-      }
-    }
-  }
-
-  int i,j;
-  for (i=0;i<host_number;i++)
-    for (j=0;j<host_number;j++)
-      xbt_dynar_shrink(ROUTE(i,j),0);
-}
-
-static void count_hosts(void)
-{
-  host_number++;
-}
-
-
 static void add_traces(void)
 {
   xbt_dict_cursor_t cursor = NULL;
 static void add_traces(void)
 {
   xbt_dict_cursor_t cursor = NULL;
@@ -277,14 +168,8 @@ static void add_traces(void)
 static void define_callbacks(const char *file)
 {
   /* Figuring out the network links */
 static void define_callbacks(const char *file)
 {
   /* Figuring out the network links */
-  surfxml_add_callback(STag_surfxml_host_cb_list, &count_hosts);
   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
-  surfxml_add_callback(STag_surfxml_route_cb_list,
-                       &parse_route_set_endpoints);
-  surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
 }
 
 static int resource_used(void *resource_id)
 }
 
 static int resource_used(void *resource_id)
@@ -469,26 +354,24 @@ static void update_resource_state(void *id,
   return;
 }
 
   return;
 }
 
-static surf_action_t communicate(void *src, void *dst, double size,
+static surf_action_t communicate(const char *src_name, const char *dst_name,int src, int dst, double size,
                                  double rate)
 {
   surf_action_network_CM02_t action = NULL;
   /* LARGE PLATFORMS HACK:
      Add a link_CM02_t *link and a int link_nb to network_card_CM02_t. It will represent local links for this node
      Use the cluster_id for ->id */
                                  double rate)
 {
   surf_action_network_CM02_t action = NULL;
   /* LARGE PLATFORMS HACK:
      Add a link_CM02_t *link and a int link_nb to network_card_CM02_t. It will represent local links for this node
      Use the cluster_id for ->id */
-  network_card_CM02_t card_src = src;
-  network_card_CM02_t card_dst = dst;
-  xbt_dynar_t route = ROUTE(card_src->id, card_dst->id);
+  xbt_dynar_t route = used_routing->get_route(src, dst);
   /* LARGE PLATFORMS HACK:
      total_route_size = route_size + src->link_nb + dst->nb */
   unsigned int i;
 
   /* LARGE PLATFORMS HACK:
      total_route_size = route_size + src->link_nb + dst->nb */
   unsigned int i;
 
-  XBT_IN4("(%s,%s,%g,%g)", card_src->generic_resource.name, card_dst->generic_resource.name, size, rate);
+  XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
   /* LARGE PLATFORMS HACK:
      assert on total_route_size */
   xbt_assert2(xbt_dynar_length(route),
   /* LARGE PLATFORMS HACK:
      assert on total_route_size */
   xbt_assert2(xbt_dynar_length(route),
-              "You're trying to send data from %s to %s but there is no connection between these two cards.",
-              card_src->generic_resource.name, card_dst->generic_resource.name);
+              "You're trying to send data from %s to %s but there is no connection between these two hosts.",
+              src_name, dst_name);
 
   action = xbt_new0(s_surf_action_network_CM02_t, 1);
 
 
   action = xbt_new0(s_surf_action_network_CM02_t, 1);
 
@@ -567,14 +450,6 @@ static surf_action_t communicate(void *src, void *dst, double size,
   return (surf_action_t) action;
 }
 
   return (surf_action_t) action;
 }
 
-/* returns an array of link_CM02_t */
-static xbt_dynar_t get_route(void *src, void *dst)
-{
-  network_card_CM02_t card_src = src;
-  network_card_CM02_t card_dst = dst;
-  return ROUTE(card_src->id, card_dst->id);
-}
-
 static double get_link_bandwidth(const void *link)
 {
   return ((link_CM02_t) link)->bw_current;
 static double get_link_bandwidth(const void *link)
 {
   return ((link_CM02_t) link)->bw_current;
@@ -626,26 +501,20 @@ static void action_set_max_duration(surf_action_t action, double duration)
 
 static void finalize(void)
 {
 
 static void finalize(void)
 {
-  int i, j;
-
   xbt_dict_free(&link_set);
 
   surf_model_exit(surf_network_model);
   surf_network_model = NULL;
 
   xbt_dict_free(&link_set);
 
   surf_model_exit(surf_network_model);
   surf_network_model = NULL;
 
-  loopback = NULL;
-  for (i = 0; i < host_number; i++)
-    for (j = 0; j < host_number; j++)
-      xbt_dynar_free(&ROUTE(i, j));
-  free(routing_table);
-  routing_table = NULL;
-  host_number = 0;
+  used_routing->finalize();
+  host_count = 0;
   lmm_system_free(network_maxmin_system);
   network_maxmin_system = NULL;
 }
 
 static void surf_network_model_init_internal(void)
 {
   lmm_system_free(network_maxmin_system);
   network_maxmin_system = NULL;
 }
 
 static void surf_network_model_init_internal(void)
 {
+  link_set = xbt_dict_new();
   surf_network_model = surf_model_init();
 
   surf_network_model->name = "network";
   surf_network_model = surf_model_init();
 
   surf_network_model->name = "network";
@@ -667,7 +536,6 @@ static void surf_network_model_init_internal(void)
   surf_cpu_model->set_max_duration = action_set_max_duration;
 
   surf_network_model->extension.network.communicate = communicate;
   surf_cpu_model->set_max_duration = action_set_max_duration;
 
   surf_network_model->extension.network.communicate = communicate;
-  surf_network_model->extension.network.get_route = get_route;
   surf_network_model->extension.network.get_link_bandwidth =
     get_link_bandwidth;
   surf_network_model->extension.network.get_link_latency = get_link_latency;
   surf_network_model->extension.network.get_link_bandwidth =
     get_link_bandwidth;
   surf_network_model->extension.network.get_link_latency = get_link_latency;
@@ -675,10 +543,13 @@ static void surf_network_model_init_internal(void)
 
   surf_network_model->get_properties = get_properties;
 
 
   surf_network_model->get_properties = get_properties;
 
-  link_set = xbt_dict_new();
-
   if (!network_maxmin_system)
     network_maxmin_system = lmm_system_new();
   if (!network_maxmin_system)
     network_maxmin_system = lmm_system_new();
+
+  routing_model_full_create(sizeof(link_CM02_t),
+      link_new(xbt_strdup("__loopback__"),
+          498000000, NULL, 0.000015, NULL,
+          SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL));
 }
 
 /************************************************************************/
 }
 
 /************************************************************************/
index eba71de..bc6f1bc 100644 (file)
@@ -163,14 +163,12 @@ static void update_resource_state(void *id,
   DIE_IMPOSSIBLE;
 }
 
   DIE_IMPOSSIBLE;
 }
 
-static surf_action_t communicate(void *src, void *dst, double size,
-                                 double rate)
+static surf_action_t communicate(const char *src_name,const char *dst_name,int src, int dst, double size,
+    double rate)
 {
   surf_action_network_Constant_t action = NULL;
 {
   surf_action_network_Constant_t action = NULL;
-  network_card_Constant_t card_src = src;
-  network_card_Constant_t card_dst = dst;
 
 
-  XBT_IN4("(%s,%s,%g,%g)", card_src->generic_resource.name, card_dst->generic_resource.name, size, rate);
+  XBT_IN4("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
 
   action = xbt_new0(s_surf_action_network_Constant_t, 1);
 
 
   action = xbt_new0(s_surf_action_network_Constant_t, 1);
 
@@ -279,7 +277,6 @@ static void surf_network_model_init_internal(void)
   surf_cpu_model->set_max_duration = action_set_max_duration;
 
   surf_network_model->extension.network.communicate = communicate;
   surf_cpu_model->set_max_duration = action_set_max_duration;
 
   surf_network_model->extension.network.communicate = communicate;
-  surf_network_model->extension.network.get_route = get_route;
   surf_network_model->extension.network.get_link_bandwidth =
     get_link_bandwidth;
   surf_network_model->extension.network.get_link_latency = get_link_latency;
   surf_network_model->extension.network.get_link_bandwidth =
     get_link_bandwidth;
   surf_network_model->extension.network.get_link_latency = get_link_latency;
index bf4c664..eeac6d0 100644 (file)
@@ -28,11 +28,6 @@ typedef struct network_link_CM02 {
 } s_link_CM02_t, *link_CM02_t;
 
 
 } s_link_CM02_t, *link_CM02_t;
 
 
-typedef struct network_card_CM02 {
-  s_surf_resource_t generic_resource; /* must remain first to allow casts */
-  int id;
-} s_network_card_CM02_t, *network_card_CM02_t;
-
 typedef struct surf_action_network_CM02 {
   s_surf_action_t generic_action;
   double latency;
 typedef struct surf_action_network_CM02 {
   s_surf_action_t generic_action;
   double latency;
@@ -41,13 +36,10 @@ typedef struct surf_action_network_CM02 {
   lmm_variable_t variable;
   double rate;
   int suspended;
   lmm_variable_t variable;
   double rate;
   int suspended;
-  network_card_CM02_t src;
-  network_card_CM02_t dst;
+#ifdef KILLME
+  int src;
+  int dst;
+#endif
 } s_surf_action_network_CM02_t, *surf_action_network_CM02_t;
 
 } s_surf_action_network_CM02_t, *surf_action_network_CM02_t;
 
-extern int card_number;
-extern xbt_dynar_t *routing_table;
-
-#define ROUTE(i,j) routing_table[(i)+(j)*host_number]
-
 #endif /* _SURF_NETWORK_PRIVATE_H */
 #endif /* _SURF_NETWORK_PRIVATE_H */
index 659bf9d..95b0cf3 100644 (file)
@@ -85,4 +85,17 @@ const char *__surf_get_initial_path(void);
  */
 int __surf_is_absolute_file_path(const char *file_path);
 
  */
 int __surf_is_absolute_file_path(const char *file_path);
 
+/*
+ * Routing logic
+ */
+struct s_routing {
+  const char *name;
+  xbt_dict_t host_id; /* char* -> int* */
+
+  xbt_dynar_t (*get_route)(int src, int dst);
+  void (*finalize)(void);
+  int host_count;
+};
+XBT_PUBLIC(routing_t) routing_model_full_create(size_t size_of_link,void *loopback);
+
 #endif /* _SURF_SURF_PRIVATE_H */
 #endif /* _SURF_SURF_PRIVATE_H */
diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c
new file mode 100644 (file)
index 0000000..077027a
--- /dev/null
@@ -0,0 +1,149 @@
+/* Copyright (c) 2009 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 "surf_private.h"
+#include "xbt/dynar.h"
+#include "xbt/str.h"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route,surf,"Routing part of surf");// FIXME: connect this under windows
+
+typedef struct {
+  s_routing_t generic_routing;
+  xbt_dynar_t *routing_table;
+  void *loopback;
+  size_t size_of_link;
+}s_routing_full_t,*routing_full_t;
+
+routing_t used_routing = NULL;
+/* ************************************************************************** */
+/* *************************** FULL ROUTING ********************************* */
+
+#define ROUTE_FULL(i,j) ((routing_full_t)used_routing)->routing_table[(i)+(j)*(used_routing)->host_count]
+
+/*
+ * Parsing
+ */
+static void routing_full_parse_Shost(void) {
+  int *val = xbt_malloc(sizeof(int));
+  DEBUG2("Seen host %s (#%d)",A_surfxml_host_id,used_routing->host_count);
+  *val = used_routing->host_count++;
+  xbt_dict_set(used_routing->host_id,A_surfxml_host_id,val,xbt_free);
+}
+static int src_id = -1;
+static int dst_id = -1;
+static void routing_full_parse_Sroute_set_endpoints(void)
+{
+  src_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_src);
+  dst_id = *(int*)xbt_dict_get(used_routing->host_id,A_surfxml_route_dst);
+  DEBUG4("Route %s %d -> %s %d",A_surfxml_route_src,src_id,A_surfxml_route_dst,dst_id);
+  route_action = A_surfxml_route_action;
+}
+static void routing_full_parse_Eroute(void)
+{
+  char *name;
+  if (src_id != -1 && dst_id != -1) {
+    name = bprintf("%x#%x", src_id, dst_id);
+    manage_route(route_table, name, route_action, 0);
+    free(name);
+  }
+}
+
+
+static void routing_full_parse_end(void) {
+  routing_full_t routing = (routing_full_t) used_routing;
+  int nb_link = 0;
+  unsigned int cpt = 0;
+  xbt_dict_cursor_t cursor = NULL;
+  char *key, *data, *end;
+  const char *sep = "#";
+  xbt_dynar_t links, keys;
+  char *link_name = NULL;
+  int i,j;
+
+  int host_count = routing->generic_routing.host_count;
+
+  /* Create the routing table */
+  routing->routing_table = xbt_new0(xbt_dynar_t, host_count * host_count);
+  for (i=0;i<host_count;i++)
+    for (j=0;j<host_count;j++)
+      ROUTE_FULL(i,j) = xbt_dynar_new(routing->size_of_link,NULL);
+
+  /* Put the routes in position */
+  xbt_dict_foreach(route_table, cursor, key, data) {
+    nb_link = 0;
+    links = (xbt_dynar_t) data;
+    keys = xbt_str_split_str(key, sep);
+
+    src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
+    dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
+    xbt_dynar_free(&keys);
+
+    DEBUG4("Handle %d %d (from %d hosts): %ld links",
+        src_id,dst_id,routing->generic_routing.host_count,xbt_dynar_length(links));
+    xbt_dynar_foreach(links, cpt, link_name) {
+      void* link = xbt_dict_get_or_null(link_set, link_name);
+      if (link)
+        xbt_dynar_push(ROUTE_FULL(src_id,dst_id),&link);
+      else
+        THROW1(mismatch_error,0,"Link %s not found", link_name);
+    }
+  }
+
+  /* Add the loopback if needed */
+  for (i = 0; i < host_count; i++)
+    if (!xbt_dynar_length(ROUTE_FULL(i, i)))
+      xbt_dynar_push(ROUTE_FULL(i,i),&routing->loopback);
+
+  /* Shrink the dynar routes (save unused slots) */
+  for (i=0;i<host_count;i++)
+    for (j=0;j<host_count;j++)
+      xbt_dynar_shrink(ROUTE_FULL(i,j),0);
+}
+
+/*
+ * Business methods
+ */
+static xbt_dynar_t routing_full_get_route(int src,int dst) {
+  return ROUTE_FULL(src,dst);
+}
+
+static void routing_full_finalize(void) {
+  routing_full_t routing = (routing_full_t)used_routing;
+  int i,j;
+
+  if (routing) {
+    for (i = 0; i < used_routing->host_count; i++)
+      for (j = 0; j < used_routing->host_count; j++)
+        xbt_dynar_free(&ROUTE_FULL(i, j));
+    free(routing->routing_table);
+    xbt_dict_free(&used_routing->host_id);
+    free(routing);
+    routing=NULL;
+  }
+}
+
+routing_t routing_model_full_create(size_t size_of_link,void *loopback) {
+  /* initialize our structure */
+  routing_full_t res = xbt_new0(s_routing_full_t,1);
+  res->generic_routing.name = "Full";
+  res->generic_routing.host_count = 0;
+  res->generic_routing.get_route = routing_full_get_route;
+  res->generic_routing.finalize = routing_full_finalize;
+  res->size_of_link = size_of_link;
+  res->loopback = loopback;
+
+  /* Set it in position */
+  used_routing = (routing_t) res;
+
+  /* Setup the parsing callbacks we need */
+  used_routing->host_id = xbt_dict_new();
+  surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
+  surfxml_add_callback(ETag_surfxml_platform_cb_list, &routing_full_parse_end);
+  surfxml_add_callback(STag_surfxml_route_cb_list,
+                       &routing_full_parse_Sroute_set_endpoints);
+  surfxml_add_callback(ETag_surfxml_route_cb_list, &routing_full_parse_Eroute);
+
+  return used_routing;
+}
index ebe0a00..1fb8397 100644 (file)
@@ -18,14 +18,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
 surf_model_t surf_workstation_model = NULL;
 
 static workstation_CLM03_t workstation_new(const char *name,
 surf_model_t surf_workstation_model = NULL;
 
 static workstation_CLM03_t workstation_new(const char *name,
-                                           void *cpu, void *card)
+                                           void *cpu, int id)
 {
   workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
 
   workstation->generic_resource.model = surf_workstation_model;
   workstation->generic_resource.name = xbt_strdup(name);
   workstation->cpu = cpu;
 {
   workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1);
 
   workstation->generic_resource.model = surf_workstation_model;
   workstation->generic_resource.name = xbt_strdup(name);
   workstation->cpu = cpu;
-  workstation->network_card = card;
+  workstation->id = id;
 
   xbt_dict_set(surf_model_resource_set(surf_workstation_model), name,
                workstation, surf_resource_free);
 
   xbt_dict_set(surf_model_resource_set(surf_workstation_model), name,
                workstation, surf_resource_free);
@@ -38,13 +38,12 @@ void create_workstations(void)
   xbt_dict_cursor_t cursor = NULL;
   char *name = NULL;
   void *cpu = NULL;
   xbt_dict_cursor_t cursor = NULL;
   char *name = NULL;
   void *cpu = NULL;
-  void *nw_card = NULL;
 
   xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, cpu) {
 
   xbt_dict_foreach(surf_model_resource_set(surf_cpu_model), cursor, name, cpu) {
-    nw_card = surf_model_resource_by_name(surf_network_model, name);
-    xbt_assert1(nw_card, "No corresponding card found for %s", name);
+    int *id = xbt_dict_get_or_null(used_routing->host_id,name);
+    xbt_assert1(id, "No host %s found in the platform file", name);
 
 
-    workstation_new(name, cpu, nw_card);
+    workstation_new(name, cpu, *id);
   }
 }
 
   }
 }
 
@@ -185,10 +184,12 @@ static surf_action_t communicate(void *workstation_src,
                                  void *workstation_dst, double size,
                                  double rate)
 {
                                  void *workstation_dst, double size,
                                  double rate)
 {
+  workstation_CLM03_t src = (workstation_CLM03_t) workstation_src;
+  workstation_CLM03_t dst = (workstation_CLM03_t) workstation_dst;
   return surf_network_model->extension.
   return surf_network_model->extension.
-    network.communicate(((workstation_CLM03_t) workstation_src)->network_card,
-                        ((workstation_CLM03_t) workstation_dst)->network_card,
-                        size, rate);
+    network.communicate(surf_resource_name(src->cpu),surf_resource_name(dst->cpu),
+        src->id,dst->id,
+        size, rate);
 }
 
 static e_surf_cpu_state_t get_state(void *workstation)
 }
 
 static e_surf_cpu_state_t get_state(void *workstation)
@@ -231,10 +232,8 @@ static xbt_dynar_t get_route(void *src, void *dst)
 {
   workstation_CLM03_t workstation_src = (workstation_CLM03_t) src;
   workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst;
 {
   workstation_CLM03_t workstation_src = (workstation_CLM03_t) src;
   workstation_CLM03_t workstation_dst = (workstation_CLM03_t) dst;
-  return surf_network_model->extension.network.get_route(workstation_src->
-                                                         network_card,
-                                                         workstation_dst->
-                                                         network_card);
+  return surf_network_model->extension.network.get_route(workstation_src->id,
+                                                         workstation_dst->id);
 }
 
 static double get_link_bandwidth(const void *link)
 }
 
 static double get_link_bandwidth(const void *link)
@@ -292,9 +291,9 @@ static void surf_workstation_model_init_internal(void)
   surf_workstation_model->get_properties = get_properties;
 
   surf_workstation_model->extension.workstation.communicate = communicate;
   surf_workstation_model->get_properties = get_properties;
 
   surf_workstation_model->extension.workstation.communicate = communicate;
+  surf_workstation_model->extension.workstation.get_route = get_route;
   surf_workstation_model->extension.workstation.execute_parallel_task =
     execute_parallel_task;
   surf_workstation_model->extension.workstation.execute_parallel_task =
     execute_parallel_task;
-  surf_workstation_model->extension.workstation.get_route = get_route;
   surf_workstation_model->extension.workstation.get_link_bandwidth =
     get_link_bandwidth;
   surf_workstation_model->extension.workstation.get_link_latency =
   surf_workstation_model->extension.workstation.get_link_bandwidth =
     get_link_bandwidth;
   surf_workstation_model->extension.workstation.get_link_latency =
index 0eb1248..6aafb39 100644 (file)
@@ -13,7 +13,7 @@
 typedef struct workstation_CLM03 {
   s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */
   void *cpu;
 typedef struct workstation_CLM03 {
   s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */
   void *cpu;
-  void *network_card;
+  int id;
 } s_workstation_CLM03_t, *workstation_CLM03_t;
 
 typedef struct surf_action_parallel_task_CSL05 {
 } s_workstation_CLM03_t, *workstation_CLM03_t;
 
 typedef struct surf_action_parallel_task_CSL05 {
index e722a5e..214f033 100644 (file)
@@ -66,10 +66,7 @@ typedef struct surf_action_workstation_L07 {
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
 
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_workstation);
 
-static int nb_workstation = 0;
-static xbt_dynar_t *routing_table = NULL;
-#define ROUTE(i,j) routing_table[(i)+(j)*nb_workstation]
-static link_L07_t loopback = NULL;
+static int host_count = 0;
 static xbt_dict_t parallel_task_link_set = NULL;
 lmm_system_t ptask_maxmin_system = NULL;
 
 static xbt_dict_t parallel_task_link_set = NULL;
 lmm_system_t ptask_maxmin_system = NULL;
 
@@ -87,7 +84,7 @@ static void update_action_bound(surf_action_workstation_L07_t action)
     for (j = 0; j < workstation_nb; j++) {
       cpu_L07_t card_src = action->workstation_list[i];
       cpu_L07_t card_dst = action->workstation_list[j];
     for (j = 0; j < workstation_nb; j++) {
       cpu_L07_t card_src = action->workstation_list[i];
       cpu_L07_t card_dst = action->workstation_list[j];
-      xbt_dynar_t route = ROUTE(card_src->id, card_dst->id);
+      xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id);
       double lat = 0.0;
 
       if (action->communication_amount[i * workstation_nb + j] > 0) {
       double lat = 0.0;
 
       if (action->communication_amount[i * workstation_nb + j] > 0) {
@@ -386,8 +383,6 @@ static void update_resource_state(void *id,
 
 static void finalize(void)
 {
 
 static void finalize(void)
 {
-  int i, j;
-
   xbt_dict_free(&link_set);
   if (parallel_task_link_set != NULL) {
     xbt_dict_free(&parallel_task_link_set);
   xbt_dict_free(&link_set);
   if (parallel_task_link_set != NULL) {
     xbt_dict_free(&parallel_task_link_set);
@@ -395,13 +390,9 @@ static void finalize(void)
 
   surf_model_exit(surf_workstation_model);
   surf_workstation_model = NULL;
 
   surf_model_exit(surf_workstation_model);
   surf_workstation_model = NULL;
+  used_routing->finalize();
 
 
-  for (i = 0; i < nb_workstation; i++)
-    for (j = 0; j < nb_workstation; j++)
-      xbt_dynar_free(&ROUTE(i, j));
-  free(routing_table);
-  routing_table = NULL;
-  nb_workstation = 0;
+  host_count = 0; // FIXME: KILLME?
 
   if (ptask_maxmin_system) {
     lmm_system_free(ptask_maxmin_system);
 
   if (ptask_maxmin_system) {
     lmm_system_free(ptask_maxmin_system);
@@ -452,7 +443,7 @@ static surf_action_t execute_parallel_task(int workstation_nb,
       cpu_L07_t card_src = workstation_list[i];
       cpu_L07_t card_dst = workstation_list[j];
       link_L07_t link;
       cpu_L07_t card_src = workstation_list[i];
       cpu_L07_t card_dst = workstation_list[j];
       link_L07_t link;
-      xbt_dynar_t route = ROUTE(card_src->id, card_dst->id);
+      xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id);
       double lat = 0.0;
 
       if (communication_amount[i * workstation_nb + j] > 0)
       double lat = 0.0;
 
       if (communication_amount[i * workstation_nb + j] > 0)
@@ -513,7 +504,7 @@ static surf_action_t execute_parallel_task(int workstation_nb,
       cpu_L07_t card_src = workstation_list[i];
       cpu_L07_t card_dst = workstation_list[j];
       link_L07_t link;
       cpu_L07_t card_src = workstation_list[i];
       cpu_L07_t card_dst = workstation_list[j];
       link_L07_t link;
-      xbt_dynar_t route = ROUTE(card_src->id, card_dst->id);
+      xbt_dynar_t route = used_routing->get_route(card_src->id, card_dst->id);
 
       if (communication_amount[i * workstation_nb + j] == 0.0)
         continue;
 
       if (communication_amount[i * workstation_nb + j] == 0.0)
         continue;
@@ -581,13 +572,12 @@ static surf_action_t action_sleep(void *cpu, double duration)
   return (surf_action_t) action;
 }
 
   return (surf_action_t) action;
 }
 
-/* returns a dynar of link_L07_t */
 static xbt_dynar_t get_route(void *src, void *dst)
 {
 static xbt_dynar_t get_route(void *src, void *dst)
 {
-  cpu_L07_t card_src = src;
-  cpu_L07_t card_dst = dst;
+  cpu_L07_t host_src = src;
+  cpu_L07_t host_dst = dst;
 
 
-  return ROUTE(card_src->id, card_dst->id);
+  return used_routing->get_route(host_src->id, host_dst->id);
 }
 
 static double get_link_bandwidth(const void *link)
 }
 
 static double get_link_bandwidth(const void *link)
@@ -628,7 +618,7 @@ static cpu_L07_t cpu_new(const char *name, double power_scale,
   cpu->generic_resource.model = surf_workstation_model;
   cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
   cpu->generic_resource.name = xbt_strdup(name);
   cpu->generic_resource.model = surf_workstation_model;
   cpu->type = SURF_WORKSTATION_RESOURCE_CPU;
   cpu->generic_resource.name = xbt_strdup(name);
-  cpu->id = nb_workstation++;
+  cpu->id = host_count++;
 
   cpu->power_scale = power_scale;
   xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
 
   cpu->power_scale = power_scale;
   xbt_assert0(cpu->power_scale > 0, "Power has to be >0");
@@ -656,16 +646,6 @@ static cpu_L07_t cpu_new(const char *name, double power_scale,
   return cpu;
 }
 
   return cpu;
 }
 
-static void create_routing_table(void)
-{
-  int i,j;
-  routing_table = xbt_new0(xbt_dynar_t,       /*card_number * card_number */
-                           nb_workstation * nb_workstation);
-  for (i=0;i<nb_workstation;i++)
-    for (j=0;j<nb_workstation;j++)
-      ROUTE(i,j) = xbt_dynar_new(sizeof(link_L07_t),NULL);
-}
-
 static void parse_cpu_init(void)
 {
   double power_scale = 0.0;
 static void parse_cpu_init(void)
 {
   double power_scale = 0.0;
@@ -781,91 +761,6 @@ static void parse_link_init(void)
            current_property_set);
 }
 
            current_property_set);
 }
 
-static int src_id = -1;
-static int dst_id = -1;
-
-static void parse_route_set_endpoints(void)
-{
-  cpu_L07_t cpu_tmp = NULL;
-
-  cpu_tmp =
-    (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model,
-                                            A_surfxml_route_src);
-  xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_src);
-  if (cpu_tmp != NULL)
-    src_id = cpu_tmp->id;
-
-  cpu_tmp =
-    (cpu_L07_t) surf_model_resource_by_name(surf_workstation_model,
-                                            A_surfxml_route_dst);
-  xbt_assert1(cpu_tmp, "Invalid cpu %s", A_surfxml_route_dst);
-  if (cpu_tmp != NULL)
-    dst_id = cpu_tmp->id;
-
-  route_action = A_surfxml_route_action;
-}
-
-static void parse_route_set_route(void)
-{
-  char *name;
-  if (src_id != -1 && dst_id != -1) {
-    name = bprintf("%x#%x", src_id, dst_id);
-    manage_route(route_table, name, route_action, 0);
-    free(name);
-  }
-}
-
-static void add_loopback(void)
-{
-  int i;
-
-  /* Adding loopback if needed */
-  for (i = 0; i < nb_workstation; i++)
-    if (!xbt_dynar_length(ROUTE(i, i))) {
-      if (!loopback)
-        loopback = link_new(xbt_strdup("__MSG_loopback__"),
-                            498000000, NULL, 0.000015, NULL,
-                            SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL);
-
-      xbt_dynar_push(ROUTE(i,i),&loopback);
-    }
-}
-
-static void add_route(void)
-{
-  xbt_ex_t e;
-  int nb_link = 0;
-  unsigned int cpt = 0;
-  xbt_dict_cursor_t cursor = NULL;
-  char *key, *data, *end;
-  const char *sep = "#";
-  xbt_dynar_t links, keys;
-  char *link_name = NULL;
-
-  if (routing_table == NULL)
-    create_routing_table();
-
-  xbt_dict_foreach(route_table, cursor, key, data) {
-    nb_link = 0;
-    links = (xbt_dynar_t) data;
-    keys = xbt_str_split_str(key, sep);
-
-    src_id = strtol(xbt_dynar_get_as(keys, 0, char *), &end, 16);
-    dst_id = strtol(xbt_dynar_get_as(keys, 1, char *), &end, 16);
-    xbt_dynar_free(&keys);
-
-    xbt_dynar_foreach(links, cpt, link_name) {
-      TRY {
-        link_L07_t link = xbt_dict_get(link_set, link_name);
-        xbt_dynar_push(ROUTE(src_id,dst_id),&link);
-      }
-      CATCH(e) {
-        RETHROW1("Link %s not found (dict raised this exception: %s)", link_name);
-      }
-    }
-  }
-}
-
 static void add_traces(void)
 {
   xbt_dict_cursor_t cursor = NULL;
 static void add_traces(void)
 {
   xbt_dict_cursor_t cursor = NULL;
@@ -933,11 +828,6 @@ static void define_callbacks(const char *file)
   surf_parse_reset_parser();
   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
   surf_parse_reset_parser();
   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
-  surfxml_add_callback(STag_surfxml_route_cb_list,
-                       &parse_route_set_endpoints);
-  surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
-  surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
 }
 
   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_traces);
 }
 
@@ -976,9 +866,9 @@ static void model_init_internal(void)
   surf_workstation_model->extension.workstation.get_available_speed =
     get_available_speed;
   surf_workstation_model->extension.workstation.communicate = communicate;
   surf_workstation_model->extension.workstation.get_available_speed =
     get_available_speed;
   surf_workstation_model->extension.workstation.communicate = communicate;
+  surf_workstation_model->extension.workstation.get_route = get_route;
   surf_workstation_model->extension.workstation.execute_parallel_task =
     execute_parallel_task;
   surf_workstation_model->extension.workstation.execute_parallel_task =
     execute_parallel_task;
-  surf_workstation_model->extension.workstation.get_route = get_route;
   surf_workstation_model->extension.workstation.get_link_bandwidth =
     get_link_bandwidth;
   surf_workstation_model->extension.workstation.get_link_latency =
   surf_workstation_model->extension.workstation.get_link_bandwidth =
     get_link_bandwidth;
   surf_workstation_model->extension.workstation.get_link_latency =
@@ -991,6 +881,12 @@ static void model_init_internal(void)
 
   if (!ptask_maxmin_system)
     ptask_maxmin_system = lmm_system_new();
 
   if (!ptask_maxmin_system)
     ptask_maxmin_system = lmm_system_new();
+
+  routing_model_full_create(sizeof(link_L07_t),
+        link_new(xbt_strdup("__MSG_loopback__"),
+            498000000, NULL, 0.000015, NULL,
+            SURF_LINK_ON, NULL, SURF_LINK_FATPIPE, NULL));
+
 }
 
 /**************************************/
 }
 
 /**************************************/
@@ -1000,8 +896,8 @@ void surf_workstation_model_init_ptask_L07(const char *filename)
 {
   xbt_assert0(!surf_cpu_model, "CPU model type already defined");
   xbt_assert0(!surf_network_model, "network model type already defined");
 {
   xbt_assert0(!surf_cpu_model, "CPU model type already defined");
   xbt_assert0(!surf_network_model, "network model type already defined");
-  model_init_internal();
   define_callbacks(filename);
   define_callbacks(filename);
+  model_init_internal();
 
   update_model_description(surf_workstation_model_description,
                            "ptask_L07", surf_workstation_model);
 
   update_model_description(surf_workstation_model_description,
                            "ptask_L07", surf_workstation_model);