Skip to content

Commit f1adb4a

Browse files
committed
common: restore OpenMP thread limit after GraphicsMagick init
GraphicsMagick resets the main thread's OpenMP limit to the CPU count. With --threads set lower, darktable-cli can then run more threads than its per-thread buffers hold. Reapply the requested limit after Magick initialization. Fixes #22436
1 parent 8c64bf7 commit f1adb4a

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎RELEASE_NOTES.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ changes (where available).
513513
one, which slightly changed the colors along the right edge of the
514514
image.
515515

516+
- Fixed darktable-cli crashing when `--threads` was set below the
517+
number of CPUs.
518+
516519
## Lua
517520

518521
### API Version

‎src/common/darktable.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,13 @@ int dt_init(int argc,
20622062
MagickWandGenesis();
20632063
#endif
20642064

2065+
#ifdef _OPENMP
2066+
// GraphicsMagick's init resets the thread count to the number of CPUs,
2067+
// overriding --threads. dt_alloc_perthread() pools are sized by
2068+
// dt_get_num_threads(), so a larger team would write past their end.
2069+
omp_set_num_threads(darktable.num_openmp_threads);
2070+
#endif
2071+
20652072
#ifdef HAVE_LIBHEIF
20662073
dt_splash_screen_set_progress(_("initializing libheif"));
20672074
heif_init(NULL);

0 commit comments

Comments
 (0)