Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Keep an int parameter to SIMIX_context_get_nthreads
[simgrid.git] / src / surf / surf_config.c
index ad2b55e..7a39bc7 100644 (file)
@@ -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_int(_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)
@@ -247,7 +257,7 @@ static void _surf_cfg_cb_contexts_parallel_mode(const char *name, int pos)
     SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
   }
   else {
-    XBT_WARN("Command line setting of the parallel synchronization mode should "
+    xbt_die("Command line setting of the parallel synchronization mode should "
         "be one of \"posix\", \"futex\" or \"busy_wait\"");
   }
 }
@@ -461,10 +471,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_int = 1;
+    default_value = xbt_strdup("1");
     xbt_cfg_register(&_surf_cfg_set, "contexts/nthreads",
                      "Number of parallel threads used to execute user contexts",
-                     xbt_cfgelm_int, &default_value_int, 1, 1,
+                     xbt_cfgelm_string, &default_value, 1, 1,
                      _surf_cfg_cb_contexts_nthreads, NULL);
 
     /* minimal number of user contexts to be run in parallel */