Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
auto-set the amount of threads when the requested amount is negative
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 27 Jan 2012 21:15:09 +0000 (22:15 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 27 Jan 2012 21:15:09 +0000 (22:15 +0100)
src/simix/smx_context.c
src/surf/surf.c
src/surf/surf_config.c

index 6da9bff..39d77bd 100644 (file)
@@ -139,14 +139,17 @@ XBT_INLINE int SIMIX_context_get_nthreads(void) {
  */
 XBT_INLINE void SIMIX_context_set_nthreads(int nb_threads) {
 
-  xbt_assert(nb_threads > 0, "Invalid number of parallel threads: %d", nb_threads);
-
+  if (nb_threads<=0) { 
+     nb_threads = xbt_os_get_numcores();
+     XBT_INFO("Auto-setting contexts/nthreads to %d",nb_threads);
+  }   
+       
   if (nb_threads > 1) {
 #ifndef CONTEXT_THREADS
     THROWF(arg_error, 0, "The thread factory cannot be run in parallel");
 #endif
   }
-
   smx_parallel_contexts = nb_threads;
 }
 
index bacb60f..cf78bea 100644 (file)
@@ -10,6 +10,7 @@
 #include "xbt/module.h"
 #include "mc/mc.h"
 #include "surf/surf_resource.h"
+#include "xbt/xbt_os_thread.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf,
                                 "Logging specific to SURF (kernel)");
@@ -604,7 +605,10 @@ int surf_get_nthreads(void) {
  */
 void surf_set_nthreads(int nthreads) {
 
-  xbt_assert(nthreads > 0, "Invalid number of parallel threads: %d", nthreads);
+  if (nthreads<=0) {
+     nthreads = xbt_os_get_numcores();
+     XBT_INFO("Auto-setting surf/nthreads to %d",nthreads);
+  }
 
 #ifdef CONTEXT_THREADS
   xbt_parmap_destroy(surf_parmap);
index 7a39bc7..cef9716 100644 (file)
@@ -226,17 +226,7 @@ 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)
 {
-  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);
+  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)
@@ -471,10 +461,10 @@ void surf_config_init(int *argc, char **argv)
                      _surf_cfg_cb_context_stack_size, NULL);
 
     /* number of parallel threads for user processes */
-    default_value = xbt_strdup("1");
+    default_value_int = 1;
     xbt_cfg_register(&_surf_cfg_set, "contexts/nthreads",
                      "Number of parallel threads used to execute user contexts",
-                     xbt_cfgelm_string, &default_value, 1, 1,
+                     xbt_cfgelm_int, &default_value, 1, 1,
                      _surf_cfg_cb_contexts_nthreads, NULL);
 
     /* minimal number of user contexts to be run in parallel */