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;
/* *********************** */
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 */
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.
}
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;
+}
+
(*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;
#else
THROW0(arg_error, 0, "No thread support for parallel context execution");
#endif
- }else{
+ } else {
(*factory)->runall = smx_ctx_raw_runall;
}
}
(*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;
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) */
(*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;
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,
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,
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;