Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add option surf/parallel_threshold.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 15 Feb 2012 20:02:06 +0000 (21:02 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 8 Jan 2014 10:32:29 +0000 (11:32 +0100)
FIXME: update ChangeLog

src/include/surf/surf.h
src/simgrid/sg_config.c
src/surf/surf.c

index e59ba76..3d6a92a 100644 (file)
@@ -746,6 +746,9 @@ XBT_PUBLIC(xbt_dict_t) get_as_router_properties(const char* name);
 int surf_get_nthreads(void);
 void surf_set_nthreads(int nthreads);
 
+int surf_get_parallel_threshold(void);
+void surf_set_parallel_threshold(int threshold);
+
 /*
  * Returns the initial path. On Windows the initial path is
  * the current directory for the current process in the other
index 4203815..2e59389 100644 (file)
@@ -394,6 +394,11 @@ static void _sg_cfg_cb_surf_nthreads(const char *name, int pos)
   surf_set_nthreads(xbt_cfg_get_int(_sg_cfg_set, name));
 }
 
+static void _surf_cfg_cb_surf_parallel_threshold(const char *name, int pos)
+{
+  surf_set_parallel_threshold(xbt_cfg_get_int(_sg_cfg_set, name));
+}
+
 static void _sg_cfg_cb__surf_network_crosstraffic(const char *name,
                                                   int pos)
 {
@@ -670,6 +675,13 @@ void sg_config_init(int *argc, char **argv)
                      _sg_cfg_cb_surf_nthreads, NULL);
     xbt_cfg_setdefault_int(_sg_cfg_set, "surf/nthreads", surf_get_nthreads());
 
+    /* minimal number of pending actions to update Surf models in parallel */
+    xbt_cfg_register(&_sg_cfg_set, "surf/parallel_threshold",
+                     "Minimal number of pending actions to update Surf models in parallel",
+                     xbt_cfgelm_int, NULL, 1, 1,
+                     _surf_cfg_cb_surf_parallel_threshold, NULL);
+    xbt_cfg_setdefault_int(_sg_cfg_set, "surf/parallel_threshold", surf_get_parallel_threshold());
+
     xbt_cfg_register(&_sg_cfg_set, "network/coordinates",
                      "\"yes\" or \"no\", specifying whether we use a coordinate-based routing (as Vivaldi)",
                      xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb__surf_network_coordinates, NULL);
index 010f13b..72a7542 100644 (file)
@@ -207,6 +207,8 @@ static xbt_parmap_t surf_parmap = NULL; /* parallel map on models */
 #endif
 
 static int surf_nthreads = 1;    /* number of threads of the parmap (1 means no parallelism) */
+static int surf_parallel_threshold = 1; /* minimal number of pending actions to
+                                         * update Surf models in parallel */
 static double *surf_mins = NULL; /* return value of share_resources for each model */
 static int surf_min_index;       /* current index in surf_mins */
 static double min;               /* duration determined by surf_solve */
@@ -543,6 +545,26 @@ void surf_presolve(void)
       model->model_private->update_actions_state(NOW, 0.0);
 }
 
+/* Returns 1 if there is at least two models with more than
+ * surf/parallel_threshold actions */
+static int surf_do_par(void)
+{
+  const int thres = surf_get_parallel_threshold();
+  surf_model_t model;
+  unsigned int iter;
+  int res = 0;
+
+  xbt_dynar_foreach(model_list, iter, model) {
+    if (xbt_swag_size(model->states.ready_action_set)
+        + xbt_swag_size(model->states.running_action_set)
+        + xbt_swag_size(model->states.failed_action_set)
+        + xbt_swag_size(model->states.done_action_set) >= thres
+        && res++)
+      return 1;
+  }
+  return 0;
+}
+
 double surf_solve(double max_date)
 {
   min = -1.0; /* duration */
@@ -568,8 +590,7 @@ double surf_solve(double max_date)
   }
   surf_min_index = 0;
 
-
-  if (surf_get_nthreads() > 1) {
+  if (surf_get_nthreads() > 1 && surf_do_par()) {
     /* parallel version */
 #ifdef CONTEXT_THREADS
     xbt_parmap_apply(surf_parmap, (void_f_pvoid_t) surf_share_resources, model_list);
@@ -660,7 +681,7 @@ double surf_solve(double max_date)
 
   NOW = NOW + min;
 
-  if (surf_get_nthreads() > 1) {
+  if (surf_get_nthreads() > 1 && surf_do_par()) {
     /* parallel version */
 #ifdef CONTEXT_THREADS
     xbt_parmap_apply(surf_parmap, (void_f_pvoid_t) surf_update_actions_state, model_list);
@@ -740,3 +761,13 @@ void surf_set_nthreads(int nthreads) {
 
   surf_nthreads = nthreads;
 }
+
+int surf_get_parallel_threshold(void)
+{
+  return surf_parallel_threshold;
+}
+
+void surf_set_parallel_threshold(int threshold)
+{
+  surf_parallel_threshold = threshold;
+}