Cleanup --cpu-threads/-t logic Currently it gets negated which means the default printed is wrong. Use an explicit flag to tell if the user has overridden it; if they haven't, and they turn off the GPUs, reset it to num_processors.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
diff --git a/main.c b/main.c
index 56a191c..cdd854d 100644
--- a/main.c
+++ b/main.c
@@ -136,7 +136,8 @@ static enum sha256_algos opt_algo = ALGO_C;
static int nDevs;
static int opt_g_threads = 2;
static int gpu_threads;
-static int opt_n_threads = 1;
+static bool forced_n_threads;
+static int opt_n_threads;
static int num_processors;
static int scan_intensity = 4;
static char *rpc_url;
@@ -206,6 +207,12 @@ static char *set_int_0_to_14(const char *arg, int *i)
return set_int_range(arg, i, 0, 14);
}
+static char *force_nthreads_int(const char *arg, int *i)
+{
+ forced_n_threads = true;
+ return set_int_range(arg, i, 0, 9999);
+}
+
static char *set_int_0_to_10(const char *arg, int *i)
{
return set_int_range(arg, i, 0, 10);
@@ -262,7 +269,7 @@ static struct opt_table opt_config_table[] = {
#endif
),
OPT_WITH_ARG("--cpu-threads|-t",
- set_int_0_to_9999, opt_show_intval, &opt_n_threads,
+ force_nthreads_int, opt_show_intval, &opt_n_threads,
"Number of miner CPU threads"),
OPT_WITHOUT_ARG("--debug|-D",
enable_debug, &opt_debug,
@@ -1444,10 +1451,8 @@ int main (int argc, char *argv[])
#ifdef HAVE_OPENCL
nDevs = clDevicesNum();
#endif
- /* Invert the value to determine if we manually set it in cmdline
- * or disable gpu threads */
if (nDevs)
- opt_n_threads = - opt_n_threads;
+ opt_n_threads = 0;
rpc_url = strdup(DEF_RPC_URL);
@@ -1471,11 +1476,9 @@ int main (int argc, char *argv[])
#endif
gpu_threads = nDevs * opt_g_threads;
- if (opt_n_threads < 0) {
- if (gpu_threads)
- opt_n_threads = 0;
- else
- opt_n_threads = -opt_n_threads;
+ if (!gpu_threads && !forced_n_threads) {
+ /* Maybe they turned GPU off; restore default CPU threads. */
+ opt_n_threads = num_processors;
}
if (!rpc_userpass) {