From 125ba3dea38f9b31330b322f9bc59fdd428821ae Mon Sep 17 00:00:00 2001 From: thiery Date: Tue, 1 Feb 2011 17:34:19 +0000 Subject: [PATCH] Add a flag --cfg=contexts/parallel_threshold:n At each scheduling rounding, the user contexts are run in parallel if their number is greater than this threshold. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9560 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/simix/context.h | 8 +++++--- src/simix/smx_context.c | 33 ++++++++++++++++++++++++++++++--- src/simix/smx_context_raw.c | 4 ++-- src/surf/surf_config.c | 12 ++++++++++++ 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/include/simix/context.h b/include/simix/context.h index 9d8ea2e8b6..a82e6077a4 100644 --- a/include/simix/context.h +++ b/include/simix/context.h @@ -100,9 +100,11 @@ void *smx_ctx_base_get_data(smx_context_t context); int smx_ctx_base_get_thread_id(void); /* parallelism */ -void SIMIX_context_set_nthreads(int nb_threads); -int SIMIX_context_get_nthreads(void); -int SIMIX_context_is_parallel(void); +XBT_INLINE void SIMIX_context_set_nthreads(int nb_threads); +XBT_INLINE int SIMIX_context_get_nthreads(void); +XBT_INLINE int SIMIX_context_is_parallel(void); +XBT_INLINE void SIMIX_context_set_parallel_threshold(int threshold); +XBT_INLINE int SIMIX_context_get_parallel_threshold(void); SG_END_DECL() diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 2da152b007..fd93d1604f 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -27,6 +27,7 @@ smx_context_t smx_current_context; #endif static int smx_parallel_contexts = 1; +static int smx_parallel_threshold = 20; /** * This function is called by SIMIX_global_init() to initialize the context module. @@ -83,7 +84,7 @@ void SIMIX_context_mod_exit(void) * * \param nb_threads the number of threads to use */ -void SIMIX_context_set_nthreads(int nb_threads) { +XBT_INLINE void SIMIX_context_set_nthreads(int nb_threads) { xbt_assert1(nb_threads > 0, "Invalid number of parallel threads: %d", nb_threads); smx_parallel_contexts = nb_threads; @@ -94,7 +95,7 @@ void SIMIX_context_set_nthreads(int nb_threads) { * for the user contexts. * \return the number of threads (1 means no parallelism) */ -int SIMIX_context_get_nthreads(void) { +XBT_INLINE int SIMIX_context_get_nthreads(void) { return smx_parallel_contexts; } @@ -103,7 +104,33 @@ int SIMIX_context_get_nthreads(void) { * for the user contexts. * \return 1 if parallelism is used */ -int SIMIX_context_is_parallel(void) { +XBT_INLINE int SIMIX_context_is_parallel(void) { return smx_parallel_contexts > 1; } +/** + * \brief Sets the threshold above which user processes are run in parallel. + * + * If the number of threads is set to 1, there is no parallelism and this + * threshold has no effect. + * + * \param threshold when the number of user processes ready to run is above + * this threshold, they are run in parallel + */ +XBT_INLINE void SIMIX_context_set_parallel_threshold(int threshold) { + smx_parallel_threshold = threshold; +} + +/** + * \brief Returns the threshold above which user processes are run in parallel. + * + * If the number of threads is set to 1, there is no parallelism and this + * threshold has no effect. + * + * \return when the number of user processes ready to run is above + * this threshold, they are run in parallel + */ +XBT_INLINE int SIMIX_context_get_parallel_threshold(void) { + return smx_parallel_threshold; +} + diff --git a/src/simix/smx_context_raw.c b/src/simix/smx_context_raw.c index 9b2ac2b68f..f4a22c8817 100644 --- a/src/simix/smx_context_raw.c +++ b/src/simix/smx_context_raw.c @@ -280,12 +280,12 @@ static int smx_ctx_raw_get_thread_id(){ static void smx_ctx_raw_runall(xbt_dynar_t processes) { - if(xbt_dynar_length(processes) > 10){ + if (xbt_dynar_length(processes) > SIMIX_context_get_parallel_threshold()) { DEBUG1("Runall // %lu", xbt_dynar_length(processes)); raw_factory->self = smx_ctx_raw_self_parallel; raw_factory->get_thread_id = smx_ctx_raw_get_thread_id; smx_ctx_raw_runall_parallel(processes); - }else{ + } else { DEBUG1("Runall serial %lu", xbt_dynar_length(processes)); raw_factory->self = smx_ctx_base_self; raw_factory->get_thread_id = smx_ctx_base_get_thread_id; diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index 5227d675f2..e98f304966 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -204,6 +204,11 @@ static void _surf_cfg_cb_contexts_nthreads(const char *name, int pos) SIMIX_context_set_nthreads(xbt_cfg_get_int(_surf_cfg_set, name)); } +static void _surf_cfg_cb_contexts_parallel_threshold(const char *name, int pos) +{ + SIMIX_context_set_parallel_threshold(xbt_cfg_get_int(_surf_cfg_set, name)); +} + static void _surf_cfg_cb__surf_network_fullduplex(const char *name, int pos) { @@ -365,6 +370,13 @@ void surf_config_init(int *argc, char **argv) xbt_cfgelm_int, &default_value_int, 1, 1, _surf_cfg_cb_contexts_nthreads, NULL); + /* minimal number of user contexts to be run in parallel */ + default_value_int = 20; + xbt_cfg_register(&_surf_cfg_set, "contexts/parallel_threshold", + "Minimal number of user contexts to be run in parallel", + xbt_cfgelm_int, &default_value_int, 1, 1, + _surf_cfg_cb_contexts_parallel_threshold, NULL); + default_value_int = 0; xbt_cfg_register(&_surf_cfg_set, "fullduplex", "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM03)", -- 2.20.1