Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cfg=contexts/parallel:nb is now the number of threads instead of a boolean
authorthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 1 Feb 2011 09:03:59 +0000 (09:03 +0000)
committerthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Tue, 1 Feb 2011 09:03:59 +0000 (09:03 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9543 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/simix/context.h
src/simix/smx_context.c
src/simix/smx_context_raw.c
src/simix/smx_context_sysv.c
src/simix/smx_context_thread.c
src/simix/smx_smurf.c
src/surf/surf_config.c

index 6bf251e..0ba2a6c 100644 (file)
@@ -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 */
index 06f0cbb..c2bf12d 100644 (file)
@@ -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;
+}
+
index 37f61d6..ffd2bdf 100644 (file)
@@ -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;
   }
 }
index a168a7e..51410dd 100644 (file)
@@ -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;
index ddd4deb..9eae0fd 100644 (file)
@@ -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;
index 139d06b..f671b72 100644 (file)
@@ -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,
index 4473b6f..eceaaa7 100644 (file)
@@ -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;