diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d19d3229b1..e79775aaf2 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -472,6 +472,9 @@ changes (where available). results depending on the number of CPU threads, and occasionally wrong colors near the left or right image edge. +- Fixed darktable-cli crashing when `--threads` was set below the + number of CPUs. + ## Lua ### API Version diff --git a/src/common/darktable.c b/src/common/darktable.c index c31604f58f..1b07d6f24a 100644 --- a/src/common/darktable.c +++ b/src/common/darktable.c @@ -1660,6 +1660,8 @@ int dt_init(int argc, } #ifdef _OPENMP + // avoid allocating per-thread buffers for workers excluded by the hard limit + darktable.num_openmp_threads = MIN(darktable.num_openmp_threads, omp_get_thread_limit()); omp_set_num_threads(darktable.num_openmp_threads); omp_set_dynamic(FALSE); #endif @@ -2052,6 +2054,13 @@ int dt_init(int argc, MagickWandGenesis(); #endif +#ifdef _OPENMP + // GraphicsMagick's init resets the thread count to the number of CPUs, + // overriding --threads. dt_alloc_perthread() pools are sized by + // dt_get_num_threads(), so a larger team would write past their end. + omp_set_num_threads(darktable.num_openmp_threads); +#endif + #ifdef HAVE_LIBHEIF dt_splash_screen_set_progress(_("initializing libheif")); heif_init(NULL);