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
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)
{
_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);
#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 */
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 */
}
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);
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);
surf_nthreads = nthreads;
}
+
+int surf_get_parallel_threshold(void)
+{
+ return surf_parallel_threshold;
+}
+
+void surf_set_parallel_threshold(int threshold)
+{
+ surf_parallel_threshold = threshold;
+}