From: thiery Date: Tue, 1 Feb 2011 09:03:59 +0000 (+0000) Subject: cfg=contexts/parallel:nb is now the number of threads instead of a boolean X-Git-Tag: v3.6_beta2~386 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/29202b3071fe6d3b7146dcd47218ab699ece7a62 cfg=contexts/parallel:nb is now the number of threads instead of a boolean git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9543 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/include/simix/context.h b/include/simix/context.h index 6bf251e2a7..0ba2a6c1d5 100644 --- a/include/simix/context.h +++ b/include/simix/context.h @@ -56,7 +56,6 @@ typedef void (*smx_ctx_factory_initializer_t)(smx_context_factory_t*); extern smx_ctx_factory_initializer_t smx_factory_initializer_to_use; extern char* smx_context_factory_name; extern int smx_context_stack_size; -extern int smx_parallel_contexts; extern smx_context_t smx_current_context; /* *********************** */ @@ -91,6 +90,11 @@ void smx_ctx_base_stop(smx_context_t context); smx_context_t smx_ctx_base_self(void); void *smx_ctx_base_get_data(smx_context_t context); +/* parallelism */ +void SIMIX_context_set_parallel_threads(int nb_threads); +int SIMIX_context_get_parallel_threads(void); +int SIMIX_context_is_parallel(void); + SG_END_DECL() #endif /* !_XBT_CONTEXT_H */ diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 06f0cbbd4e..c2bf12d475 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -19,6 +19,7 @@ char* smx_context_factory_name = NULL; /* factory name specified by --cfg=contex smx_ctx_factory_initializer_t smx_factory_initializer_to_use = NULL; int smx_context_stack_size = 128 * 1024; smx_context_t smx_current_context; +static int smx_parallel_contexts; /** * This function is called by SIMIX_global_init() to initialize the context module. @@ -64,3 +65,38 @@ void SIMIX_context_mod_exit(void) } xbt_dict_remove((xbt_dict_t) _surf_cfg_set,"contexts/factory"); } + +/** + * \brief Sets the number of parallel threads to use + * for the user contexts. + * + * This function should be called before initializing SIMIX. + * A value of 1 means no parallelism. + * If the value is greater than 1, the thread support must be enabled. + * + * \param nb_threads the number of threads to use + */ +void SIMIX_context_set_parallel_threads(int nb_threads) { + + xbt_assert1(nb_threads > 0, "Invalid number of parallel threads: %d", nb_threads); + smx_parallel_contexts = nb_threads; +} + +/** + * \brief Returns the number of parallel threads used + * for the user contexts. + * \return the number of threads (1 means no parallelism) + */ +int SIMIX_context_get_parallel_threads() { + return smx_parallel_contexts; +} + +/** + * \brief Returns whether some parallel threads are used + * for the user contexts. + * \return 1 if parallelism is used + */ +int SIMIX_context_is_parallel() { + return smx_parallel_contexts > 1; +} + diff --git a/src/simix/smx_context_raw.c b/src/simix/smx_context_raw.c index 37f61d6081..ffd2bdfbbb 100644 --- a/src/simix/smx_context_raw.c +++ b/src/simix/smx_context_raw.c @@ -300,7 +300,7 @@ void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory) (*factory)->suspend = smx_ctx_raw_suspend; (*factory)->name = "smx_raw_context_factory"; - if (smx_parallel_contexts) { + if (SIMIX_context_is_parallel()) { #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */ parmap = xbt_parmap_new(2); (*factory)->runall = smx_ctx_raw_runall_parallel; @@ -308,7 +308,7 @@ void SIMIX_ctx_raw_factory_init(smx_context_factory_t *factory) #else THROW0(arg_error, 0, "No thread support for parallel context execution"); #endif - }else{ + } else { (*factory)->runall = smx_ctx_raw_runall; } } diff --git a/src/simix/smx_context_sysv.c b/src/simix/smx_context_sysv.c index a168a7eb2b..51410dd434 100644 --- a/src/simix/smx_context_sysv.c +++ b/src/simix/smx_context_sysv.c @@ -62,7 +62,7 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) (*factory)->suspend = smx_ctx_sysv_suspend; (*factory)->name = "smx_sysv_context_factory"; - if (smx_parallel_contexts) { + if (SIMIX_context_is_parallel()) { #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */ parmap = xbt_parmap_new(2); (*factory)->runall = smx_ctx_sysv_runall_parallel; diff --git a/src/simix/smx_context_thread.c b/src/simix/smx_context_thread.c index ddd4deb48d..9eae0fd9ec 100644 --- a/src/simix/smx_context_thread.c +++ b/src/simix/smx_context_thread.c @@ -16,8 +16,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context); -int smx_parallel_contexts = 0; - typedef struct s_smx_ctx_thread { s_smx_ctx_base_t super; /* Fields of super implementation */ xbt_os_thread_t thread; /* a plain dumb thread (portable to posix or windows) */ @@ -52,7 +50,7 @@ void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory) (*factory)->stop = smx_ctx_thread_stop; (*factory)->suspend = smx_ctx_thread_suspend; - if (smx_parallel_contexts) + if (SIMIX_context_is_parallel()) (*factory)->runall = smx_ctx_thread_runall_parallel; else (*factory)->runall = smx_ctx_thread_runall_serial; diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index 139d06bd97..f671b723a9 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -34,13 +34,13 @@ void SIMIX_request_push() if (issuer != simix_global->maestro_process){ issuer->request.issuer = issuer; - if (smx_parallel_contexts) + if (SIMIX_context_is_parallel()) xbt_os_mutex_acquire(sync_req_positions); xbt_heap_push(req_todo,&issuer->request,issuer->pid); DEBUG4("Pushed request %s (%d) of %s; now %d requests waiting", SIMIX_request_name(issuer->request.call), issuer->request.call, issuer->name,xbt_heap_size(req_todo)); - if (smx_parallel_contexts) + if (SIMIX_context_is_parallel()) xbt_os_mutex_release(sync_req_positions); DEBUG3("Yield process '%s' on request of type %s (%d)", issuer->name, diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index 4473b6f723..eceaaa7fb0 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -201,7 +201,7 @@ static void _surf_cfg_cb_context_stack_size(const char *name, int pos) static void _surf_cfg_cb_parallel_contexts(const char *name, int pos) { - smx_parallel_contexts = 1; + SIMIX_context_set_parallel_threads(xbt_cfg_get_int(_surf_cfg_set, name)); } static void _surf_cfg_cb__surf_network_fullduplex(const char *name, @@ -358,11 +358,11 @@ void surf_config_init(int *argc, char **argv) xbt_cfgelm_int, &default_value_int, 1, 1, _surf_cfg_cb_context_stack_size, NULL); - /* parallel contexts */ - default_value_int = 0; + /* number of parallel threads for user processes */ + default_value_int = 1; xbt_cfg_register(&_surf_cfg_set, "contexts/parallel", - "Activate the parallel execution of user contexts (EXPERIMENTAL -- pthreads only)", - xbt_cfgelm_int, &default_value_int, 0, 1, + "Number of parallel threads for user contexts (EXPERIMENTAL)", + xbt_cfgelm_int, &default_value_int, 1, 1, _surf_cfg_cb_parallel_contexts, NULL); default_value_int = 0;