Currently, the default number of threads for gnubg is 1, but considering today’s typical PCs, I believe this is a rather conservative setting.
In particular, users trying gnubg for the first time are likely to attempt an analysis without changing the thread count setting; in that case, even on a PC with a multi-core CPU, only one thread will be used. As a result, this may give the first impression that gnubg’s analysis is slower than it actually is. Since the number of threads explicitly set by a user is saved as "set threads", changing the default value will not overwrite existing users' saved settings. The change will primarily affect the initial value for new users or environments where the number of threads has not yet been set. Therefore, I propose determining the default number of evaluation threads based on the number of available CPUs. One proposal, for example, is to use MIN(g_get_num_processors(), 4) which utilizes the number of schedulable threads returned by GLib while capping the default at a maximum of 4 threads. This way, in environments where only one or two threads are available, the program will adapt accordingly, while in typical multi-core environments, it will run significantly faster than the current single-threaded version. On the other hand, even on machines with a large number of logical CPUs, this approach prevents gnubg from using up nearly all available CPU resources by default. Another option is to use g_get_num_processors() as-is and use all threads deemed available as the default. This approach is straightforward in terms of prioritizing analysis speed and allows us to more directly show first-time users the performance achievable on their machine. However, in environments capable of using 8, 16, 32, or more threads, gnubg will place a significantly high CPU load even if the user hasn’t configured anything. I believe that if we want to address the issue where the default setting of 1 thread gives the impression that "gnubg is slow", while also ensuring the default setting does not consume an excessive amount of CPU resources, MIN(g_get_num_processors(), 4) would be a reasonable choice. On the other hand, if the priority is for the analysis software to use the maximum number of available CPUs by default, using g_get_num_processors() as-is is also a viable option. Which approach do you think is better? Best regards, -- TAKAHASHI Kaoru
>From 75d685de1435ed5924cb7c3e823d7afc9cce6c5b Mon Sep 17 00:00:00 2001 From: TAKAHASHI Kaoru <[email protected]> Date: Sat, 5 Sep 2026 20:04:00 +0900 Subject: [PATCH] Use multiple evaluation threads by default Use g_get_num_processors() to select the default number of evaluation threads, capped at 4 to avoid excessive CPU use on systems with many processors. Keep the previous default of one thread when building with GLib older than 2.36. --- multithread.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/multithread.c b/multithread.c index bc3ff4ee..f96e6153 100644 --- a/multithread.c +++ b/multithread.c @@ -218,12 +218,15 @@ extern void MT_StartThreads(void) { if (td.numThreads == 0) { - /* We could set it to something else (the number of cores or some - * fraction of that ?) but it is probably not a good idea to hog - * a lot of resources by default. +#if GLIB_CHECK_VERSION(2,36,0) + /* Use multiple evaluation threads by default, but cap the number + * to avoid excessive CPU use on systems with many processors. */ + td.numThreads = MIN(g_get_num_processors(), 4); +#else + /* g_get_num_processors() requires GLib 2.36. */ td.numThreads = 1; - +#endif MT_CreateThreads(); } } -- 2.47.3
