Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding a nice description mechanism for models + cleaning (many?) useless functions
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 2 Aug 2007 12:51:03 +0000 (12:51 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 2 Aug 2007 12:51:03 +0000 (12:51 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3937 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/include/surf/surf.h
src/surf/network.c
src/surf/network_gtnets.c
src/surf/surf.c
src/surf/workstation_KCCFLN05.c

index f068b0b..eb51ff6 100644 (file)
@@ -38,6 +38,23 @@ typedef struct surf_action *surf_action_t;
  */
 typedef struct surf_resource *surf_resource_t;
 
  */
 typedef struct surf_resource *surf_resource_t;
 
+/** \brief Resource model description
+ */
+typedef struct surf_resource_description {
+  const char *name;
+  surf_resource_t resource;
+  void (* resource_init) (const char *filename);
+} s_surf_resource_description_t, *surf_resource_description_t;
+
+XBT_PUBLIC(void) update_resource_description(s_surf_resource_description_t *table,
+                                            int table_size,
+                                            const char* name, 
+                                            surf_resource_t resource
+                                            );
+XBT_PUBLIC(int) find_resource_description(s_surf_resource_description_t *table,
+                                         int table_size,
+                                         const char* name);
+
 /** \brief Action structure
  * \ingroup SURF_actions
  *
 /** \brief Action structure
  * \ingroup SURF_actions
  *
@@ -224,6 +241,12 @@ XBT_PUBLIC_DATA(surf_cpu_resource_t) surf_cpu_resource;
  */
 XBT_PUBLIC(void) surf_cpu_resource_init_Cas01(const char *filename);
 
  */
 XBT_PUBLIC(void) surf_cpu_resource_init_Cas01(const char *filename);
 
+extern XBT_PUBLIC_DATA(int) surf_cpu_resource_description_size;
+/** \brief The list of all available cpu resource models
+ *  \ingroup SURF_resources
+ */
+extern XBT_PUBLIC_DATA(s_surf_resource_description_t) surf_cpu_resource_description[];
+
 /* Network resource */
 
 /** \brief Network resource extension public
 /* Network resource */
 
 /** \brief Network resource extension public
@@ -272,7 +295,7 @@ XBT_PUBLIC_DATA(surf_network_resource_t) surf_network_resource;
  */
 XBT_PUBLIC(void) surf_network_resource_init_CM02(const char *filename);
 
  */
 XBT_PUBLIC(void) surf_network_resource_init_CM02(const char *filename);
 
-#ifdef USE_GTNETS
+#ifdef HAVE_GTNETS
 /** \brief Initializes the platform with the network model GTNETS
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
 /** \brief Initializes the platform with the network model GTNETS
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
@@ -289,6 +312,12 @@ XBT_PUBLIC(void) surf_network_resource_init_GTNETS(const char *filename);
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
  *
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
  *
+ *  The problem is related to max( sum( arctan(C * Df * xi) ) ).
+ *
+ *  Reference:
+ *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
+ *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
+ *
  *  Call this function only if you plan using surf_workstation_resource_init_compound.
  *
  */
  *  Call this function only if you plan using surf_workstation_resource_init_compound.
  *
  */
@@ -298,6 +327,13 @@ XBT_PUBLIC(void) surf_network_resource_init_Reno(const char *filename);
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
  *
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
  *
+ *  This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent 
+ *  to the proportional fairness.
+ *
+ *  Reference:
+ *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
+ *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
+ *
  *  Call this function only if you plan using surf_workstation_resource_init_compound.
  *
  */
  *  Call this function only if you plan using surf_workstation_resource_init_compound.
  *
  */
@@ -308,11 +344,28 @@ XBT_PUBLIC(void) surf_network_resource_init_Vegas(const char *filename);
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
  *
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
  *
+ *  This function implements the proportional fairness known as the maximization
+ *  of x1*x2*...*xn .
+ *
+ *  Reference:
+ *
+ *  [TAG03]. Corinne Touati, Eitan Altman, and Jérôme Galtier.  
+ *  Semi-definite programming approach for bandwidth allocation and routing in networks.
+ *  Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
+ *
  *  Call this function only if you plan using surf_workstation_resource_init_compound.
  */
 XBT_PUBLIC(void) surf_network_resource_init_SDP(const char *filename);
 #endif
 
  *  Call this function only if you plan using surf_workstation_resource_init_compound.
  */
 XBT_PUBLIC(void) surf_network_resource_init_SDP(const char *filename);
 #endif
 
+
+
+extern XBT_PUBLIC_DATA(int) surf_network_resource_description_size;
+/** \brief The list of all available network resource models
+ *  \ingroup SURF_resources
+ */
+extern XBT_PUBLIC_DATA(s_surf_resource_description_t) surf_network_resource_description[];
+
 /** \brief Workstation resource extension public
  *  \ingroup SURF_resources
  *
 /** \brief Workstation resource extension public
  *  \ingroup SURF_resources
  *
@@ -390,76 +443,20 @@ XBT_PUBLIC(void) surf_workstation_resource_init_CLM03(const char *filename);
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
  *
  *  \ingroup SURF_resources
  *  \param filename XML platform file name
  *
- *  With this model, the workstations and the network are handled together.
- *  There is no network resource. This platform model is the default one for
- *  MSG and SimDag.
+ *  With this model, the workstations and the network are handled
+ *  together. The network model is roughly the same as in CM02 but
+ *  interference between computations and communications can be taken
+ *  into account. This platform model is the default one for MSG and
+ *  SimDag.
  *
  *
- *  \see surf_workstation_resource_init_CLM03()
  */
 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05(const char *filename);
 
  */
 XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05(const char *filename);
 
-/** \brief Initializes the platform with the model KCCFLN05 using the proportional
- *  approach as described in [TAG03]. 
- *  
+extern XBT_PUBLIC_DATA(int) surf_workstation_resource_description_size;
+/** \brief The list of all available workstation resource models
  *  \ingroup SURF_resources
  *  \ingroup SURF_resources
- *  \param filename XML platform file name
- *
- *  This function implements the proportional fairness known as the maximization
- *  of sum ( x1*x2*...*xn ).
- *
- *  Reference:
- *
- *  [TAG03]. Corinne Touati, Eitan Altman, and Jérôme Galtier.  
- *  Semi-definite programming approach for bandwidth allocation and routing in networks.
- *  Game Theory and Applications, 9:169-179, December 2003. Nova publisher.
- *  With this model, the workstations and the network are handled together.
- *  There is no network resource. This platform model is the default one for
- *  MSG and SimDag.
- *
- *  \see surf_workstation_resource_init_CLM03()
- */
-XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_proportional(const char *filename);
-
-/** \brief Initializes the platform with the model KCCFLN05 using a lagrange
- *  optimization approach to compute the effectivet bandwidth of each flow based
- *  on the Vegas TCP flavor fairness as shown in [LOW03]. 
- *  
- *  \ingroup SURF_resources
- *  \param filename XML platform file name
- *
- *  This problem is related to max( sum( a * Df * ln(xi) ) ) which is equivalent 
- *  to the proportional fairness.
- *
- *  Reference:
- *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
- *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
- *
- */
-XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_Vegas(const char *filename);
-
-/** \brief Initializes the platform with the model KCCFLN05 using a lagrange
- *  optimization approach to compute the effectivet bandwidth of each flow based
- *  on the Reno TCP flavor fairness as shown in [LOW03]. 
- *  
- *  \ingroup SURF_resources
- *  \param filename XML platform file name
- *
- *  The problem is related to max( sum( arctan(C * Df * xi) ) ).
- *
- *  Reference:
- *  [LOW03] S. H. Low. A duality model of TCP and queue management algorithms.
- *  IEEE/ACM Transaction on Networking, 11(4):525-536, 2003.
- *
- *  \see surf_workstation_resource_init_KCCFLN05_Vegas()
  */
  */
-XBT_PUBLIC(void) surf_workstation_resource_init_KCCFLN05_Reno(const char *filename);
-
-
-
-
-#ifdef USE_GTNETS
-XBT_PUBLIC(void) surf_workstation_resource_init_GTNETS(const char *filename);
-#endif
+extern XBT_PUBLIC_DATA(s_surf_resource_description_t) surf_workstation_resource_description[];
 
 /** \brief The network links
  *  \ingroup SURF_resources
 
 /** \brief The network links
  *  \ingroup SURF_resources
@@ -493,12 +490,14 @@ XBT_PUBLIC_DATA(xbt_dynar_t)  resource_list;
  *  \param argc argument number
  *  \param argv arguments
  *
  *  \param argc argument number
  *  \param argv arguments
  *
- *  This function has to be called to initialize the common structures.
- *  Then you will have to create the environment by calling surf_timer_resource_init()
- *  and surf_workstation_resource_init_CLM03() or surf_workstation_resource_init_KCCFLN05().
+ *  This function has to be called to initialize the common
+ *  structures.  Then you will have to create the environment by
+ *  calling surf_timer_resource_init() and
+ *  e.g. surf_workstation_resource_init_CLM03() or
+ *  surf_workstation_resource_init_KCCFLN05().
  *
  *  \see surf_timer_resource_init(), surf_workstation_resource_init_CLM03(),
  *
  *  \see surf_timer_resource_init(), surf_workstation_resource_init_CLM03(),
- *  surf_workstation_resource_init_KCCFLN05(), surf_exit()
+ *  surf_workstation_resource_init_KCCFLN05(), surf_workstation_resource_init_compound(), surf_exit()
  */
 XBT_PUBLIC(void) surf_init(int *argc, char **argv);    /* initialize common structures */
 
  */
 XBT_PUBLIC(void) surf_init(int *argc, char **argv);    /* initialize common structures */
 
index 5b877ba..a89e551 100644 (file)
@@ -624,12 +624,18 @@ static void surf_network_resource_init_internal(void)
 /* } */
 void surf_network_resource_init_CM02(const char *filename)
 {
 /* } */
 void surf_network_resource_init_CM02(const char *filename)
 {
+
   if (surf_network_resource)
     return;
   surf_network_resource_init_internal();
   parse_file(filename);
   xbt_dynar_push(resource_list, &surf_network_resource);
   network_solve = lmm_solve;
   if (surf_network_resource)
     return;
   surf_network_resource_init_internal();
   parse_file(filename);
   xbt_dynar_push(resource_list, &surf_network_resource);
   network_solve = lmm_solve;
+
+  update_resource_description(surf_network_resource_description,
+                             surf_network_resource_description_size,
+                             "CM02",
+                             (surf_resource_t) surf_network_resource);
 }
 
 void surf_network_resource_init_Reno(const char *filename)
 }
 
 void surf_network_resource_init_Reno(const char *filename)
@@ -639,10 +645,14 @@ void surf_network_resource_init_Reno(const char *filename)
   surf_network_resource_init_internal();
   parse_file(filename);
 
   surf_network_resource_init_internal();
   parse_file(filename);
 
+  xbt_dynar_push(resource_list, &surf_network_resource);
   lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
   network_solve = lagrange_solve;
 
   lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
   network_solve = lagrange_solve;
 
-  xbt_dynar_push(resource_list, &surf_network_resource);
+  update_resource_description(surf_network_resource_description,
+                             surf_network_resource_description_size,
+                             "Reno",
+                             (surf_resource_t) surf_network_resource);
 }
 
 void surf_network_resource_init_Vegas(const char *filename)
 }
 
 void surf_network_resource_init_Vegas(const char *filename)
@@ -652,10 +662,14 @@ void surf_network_resource_init_Vegas(const char *filename)
   surf_network_resource_init_internal();
   parse_file(filename);
 
   surf_network_resource_init_internal();
   parse_file(filename);
 
+  xbt_dynar_push(resource_list, &surf_network_resource);
   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi);
   network_solve = lagrange_solve;
 
   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi);
   network_solve = lagrange_solve;
 
-  xbt_dynar_push(resource_list, &surf_network_resource);
+  update_resource_description(surf_network_resource_description,
+                             surf_network_resource_description_size,
+                             "Vegas",
+                             (surf_resource_t) surf_network_resource);
 }
 
 #ifdef HAVE_SDP
 }
 
 #ifdef HAVE_SDP
@@ -666,8 +680,12 @@ void surf_network_resource_init_SDP(const char *filename)
   surf_network_resource_init_internal();
   parse_file(filename);
 
   surf_network_resource_init_internal();
   parse_file(filename);
 
+  xbt_dynar_push(resource_list, &surf_network_resource);
   network_solve = sdp_solve;
 
   network_solve = sdp_solve;
 
-  xbt_dynar_push(resource_list, &surf_network_resource);
+  update_resource_description(surf_network_resource_description,
+                             surf_network_resource_description_size,
+                             "SDP",
+                             (surf_resource_t) surf_network_resource);
 }
 #endif
 }
 #endif
index 2fb0f04..0819e31 100644 (file)
@@ -606,4 +606,9 @@ void surf_network_resource_init_GTNETS(const char *filename)
   surf_network_resource_init_internal();
   parse_file(filename);
   xbt_dynar_push(resource_list, &surf_network_resource);
   surf_network_resource_init_internal();
   parse_file(filename);
   xbt_dynar_push(resource_list, &surf_network_resource);
+
+  update_resource_description(surf_network_resource_description,
+                             surf_network_resource_description_size,
+                             "GTNets",
+                             (surf_resource_t) surf_network_resource);
 }
 }
index 87ff13f..29daa32 100644 (file)
@@ -127,6 +127,71 @@ const char *surf_action_state_names[6] = {
   "SURF_ACTION_NOT_IN_THE_SYSTEM"
 };
 
   "SURF_ACTION_NOT_IN_THE_SYSTEM"
 };
 
+int surf_network_resource_description_size=3
+  #ifdef HAVE_GTNETS
+     +1
+  #endif
+  #ifdef HAVE_SDP
+     +1
+  #endif
+;
+s_surf_resource_description_t surf_network_resource_description[]=
+  {
+    {"CM02",NULL,surf_network_resource_init_CM02},
+#ifdef HAVE_GTNETS
+    {"GTNets",NULL,surf_network_resource_init_GTNETS},
+#endif
+#ifdef HAVE_SDP
+    {"SDP",NULL,surf_network_resource_init_SDP},
+#endif
+    {"Reno",NULL,surf_network_resource_init_Reno},
+    {"Vegas",NULL,surf_network_resource_init_Vegas}
+  };
+
+int surf_cpu_resource_description_size=1;
+s_surf_resource_description_t surf_cpu_resource_description[]=
+  {
+    {"Cas01",NULL,surf_cpu_resource_init_Cas01},
+  };
+
+int surf_workstation_resource_description_size=3;
+s_surf_resource_description_t surf_workstation_resource_description[]=
+  {
+    {"CLM03",NULL,surf_workstation_resource_init_CLM03},
+    {"KCCFLN05",NULL,surf_workstation_resource_init_KCCFLN05},
+    {"compound",NULL,surf_workstation_resource_init_compound}
+  };
+
+void update_resource_description(s_surf_resource_description_t *table,
+                                int table_size,
+                                const char* name, 
+                                surf_resource_t resource
+                                ) 
+{
+  int i = find_resource_description(table, table_size, name);
+  table[i].resource=resource;
+}
+
+int find_resource_description(s_surf_resource_description_t *table,
+                              int table_size,
+                              const char* name)
+{
+  int i;
+  char *name_list=NULL;
+
+  for(i=0;i<table_size;i++)
+    if(!strcmp(name,table[i].name)) {
+      return i;
+    }
+  name_list=strdup(table[0].name);
+  for(i=1;i<table_size;i++) {
+    name_list = xbt_realloc(name_list,strlen(name_list)+strlen(table[i].name)+2);
+    strcat(name_list,", ");
+    strcat(name_list,table[i].name);
+  }
+  xbt_assert2(0, "Model '%s' is invalid! Valid models are: %s.",name,name_list);
+}
+
 double generic_maxmin_share_resources(xbt_swag_t running_actions,
                                       size_t offset)
 {
 double generic_maxmin_share_resources(xbt_swag_t running_actions,
                                       size_t offset)
 {
index 9eb913b..a439c6c 100644 (file)
@@ -1147,46 +1147,3 @@ void surf_workstation_resource_init_KCCFLN05(const char *filename)
 
   xbt_dynar_push(resource_list, &surf_workstation_resource);
 }
 
   xbt_dynar_push(resource_list, &surf_workstation_resource);
 }
-
-void surf_workstation_resource_init_KCCFLN05_proportional(const char *filename)
-{
-  xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
-  xbt_assert0(!surf_network_resource, "network resource type already defined");
-  resource_init_internal();
-  parse_file(filename);
-
-  surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (proportional)";
-  use_sdp_solver=1;
-  xbt_dynar_push(resource_list, &surf_workstation_resource);
-}
-
-void surf_workstation_resource_init_KCCFLN05_Vegas(const char *filename)
-{
-  xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
-  xbt_assert0(!surf_network_resource, "network resource type already defined");
-  resource_init_internal();
-  parse_file(filename);
-
-  lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp, func_vegas_fpi);
-
-  surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (Vegas)";
-  use_lagrange_solver=1;
-  xbt_dynar_push(resource_list, &surf_workstation_resource);
-}
-
-void surf_workstation_resource_init_KCCFLN05_Reno(const char *filename)
-{
-  xbt_assert0(!surf_cpu_resource, "CPU resource type already defined");
-  xbt_assert0(!surf_network_resource, "network resource type already defined");
-  resource_init_internal();
-  parse_file(filename);
-
-  lmm_set_default_protocol_function(func_reno_f, func_reno_fp, func_reno_fpi);
-
-  surf_workstation_resource->common_public->name = "Workstation KCCFLN05 (Reno)";
-  use_lagrange_solver=1;
-  xbt_dynar_push(resource_list, &surf_workstation_resource);
-}
-
-
-