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()
#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.
*
* \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;
* 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;
}
* 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;
+}
+
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;
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)
{
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)",