From 7631e98c4699e3d1f9fa92a21594294f119f95ac Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christophe=20Thi=C3=A9ry?= Date: Wed, 25 Jan 2012 14:27:27 +0100 Subject: [PATCH] Keep an int parameter to SIMIX_context_get_nthreads --- include/simix/context.h | 2 +- src/simix/smx_context.c | 13 ++----------- src/surf/surf_config.c | 12 +++++++++++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/simix/context.h b/include/simix/context.h index ce4def0ef6..137e374519 100644 --- a/include/simix/context.h +++ b/include/simix/context.h @@ -101,7 +101,7 @@ XBT_PUBLIC(smx_process_t) SIMIX_process_from_PID(int PID); /* parallelism */ XBT_INLINE int SIMIX_context_is_parallel(void); XBT_INLINE int SIMIX_context_get_nthreads(void); -XBT_INLINE void SIMIX_context_set_nthreads(char* str_nb_threads); +XBT_INLINE void SIMIX_context_set_nthreads(int nb_threads); XBT_INLINE int SIMIX_context_get_parallel_threshold(void); XBT_INLINE void SIMIX_context_set_parallel_threshold(int threshold); XBT_INLINE e_xbt_parmap_mode_t SIMIX_context_get_parallel_mode(void); diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 01de34bd8f..9faef0ed17 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -132,21 +132,12 @@ XBT_INLINE int SIMIX_context_get_nthreads(void) { * for the user contexts. * * This function should be called before initializing SIMIX. - * A value of 1 means no parallelism. + * A value of 1 means no parallelism (1 thread only). * If the value is greater than 1, the thread support must be enabled. * * \param nb_threads the number of threads to use */ -XBT_INLINE void SIMIX_context_set_nthreads(char* str_nb_threads) { - - int nb_threads; - - if(!strcmp(str_nb_threads,"auto")){ - nb_threads = PROCESSOR_COUNT; - XBT_DEBUG("Auto-setting threads to %d",nb_threads); - } - else - nb_threads = atoi(str_nb_threads); +XBT_INLINE void SIMIX_context_set_nthreads(int nb_threads) { xbt_assert(nb_threads > 0, "Invalid number of parallel threads: %d", nb_threads); diff --git a/src/surf/surf_config.c b/src/surf/surf_config.c index 6cd40b291d..7a39bc71f8 100644 --- a/src/surf/surf_config.c +++ b/src/surf/surf_config.c @@ -226,7 +226,17 @@ static void _surf_cfg_cb_context_stack_size(const char *name, int pos) static void _surf_cfg_cb_contexts_nthreads(const char *name, int pos) { - SIMIX_context_set_nthreads(xbt_cfg_get_string(_surf_cfg_set, name)); + unsigned int nthreads; + const char* value = xbt_cfg_get_string(_surf_cfg_set, name); + if (!strcmp(value, "auto")) { + XBT_DEBUG("Auto setting contexts/nthreads to %d", PROCESSOR_COUNT); + nthreads = PROCESSOR_COUNT; + } + else { + nthreads = atoi(value); + xbt_assert(nthreads > 0, "context/threads should be a positive number or 'auto'"); + } + SIMIX_context_set_nthreads(nthreads); } static void _surf_cfg_cb_contexts_parallel_threshold(const char *name, int pos) -- 2.20.1