Skip to content

Commit 86ffe54

Browse files
jenshannoschwalmTurboGit
authored andcommitted
Make sure about a valid dt_get_num_procs()
The OpenMP omp_get_num_procs() does not gaurantee the returned value is > 0 so et's make sure. dt_iop_image_div_const() is a) not used at all and b) had a bad check for available openmp procs so let's get rid of it.
1 parent f47f5fb commit 86ffe54

File tree

3 files changed

+3
-39
lines changed

3 files changed

+3
-39
lines changed

src/common/darktable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,7 @@ static inline size_t dt_get_num_threads()
706706
static inline size_t dt_get_num_procs()
707707
{
708708
#ifdef _OPENMP
709-
// we can safely assume omp_get_num_procs is > 0
710-
return (size_t)omp_get_num_procs();
709+
return (size_t)MAX(1, omp_get_num_procs());
711710
#else
712711
return 1;
713712
#endif

src/common/imagebuf.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of darktable,
3-
Copyright (C) 2016-2024 darktable developers.
3+
Copyright (C) 2016-2025 darktable developers.
44
55
darktable is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -448,34 +448,6 @@ void dt_iop_image_mul_const(float *const buf,
448448
buf[k] *= mul_value;
449449
}
450450

451-
void dt_iop_image_div_const(float *const buf,
452-
const float div_value,
453-
const size_t width,
454-
const size_t height,
455-
const size_t ch)
456-
{
457-
const size_t nfloats = width * height * ch;
458-
#ifdef _OPENMP
459-
if(nfloats > parallel_imgop_minimum) // is the copy big enough to outweigh threading overhead?
460-
{
461-
// we can gain a little by using a small number of threads in
462-
// parallel, but not much since the memory bus quickly saturates
463-
// (basically, each core can saturate a memory channel, so a
464-
// system with quad-channel memory won't be able to take advantage
465-
// of more than four cores).
466-
const int nthreads = MIN(darktable.num_openmp_threads,parallel_imgop_maxthreads);
467-
DT_OMP_FOR_SIMD(num_threads(nthreads) aligned(buf:16))
468-
for(size_t k = 0; k < nfloats; k++)
469-
buf[k] /= div_value;
470-
return;
471-
}
472-
#endif // _OPENMP
473-
// no OpenMP, or image too small to bother parallelizing
474-
DT_OMP_SIMD(aligned(buf:16))
475-
for(size_t k = 0; k < nfloats; k++)
476-
buf[k] /= div_value;
477-
}
478-
479451
// elementwise: buf = lammda*buf + (1-lambda)*other
480452
void dt_iop_image_linear_blend(float *const restrict buf,
481453
const float lambda,

src/common/imagebuf.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
This file is part of darktable,
3-
Copyright (C) 2016-2023 darktable developers.
3+
Copyright (C) 2016-2025 darktable developers.
44
55
darktable is free software: you can redistribute it and/or modify
66
it under the terms of the GNU General Public License as published by
@@ -157,13 +157,6 @@ void dt_iop_image_mul_const(float *const buf,
157157
const size_t height,
158158
const size_t ch);
159159

160-
// Divide every element of the image buffer by a specified constant value
161-
void dt_iop_image_div_const(float *const buf,
162-
const float div_value,
163-
const size_t width,
164-
const size_t height,
165-
const size_t ch);
166-
167160
// elementwise: buf = lammda*buf + (1-lambda)*other
168161
void dt_iop_image_linear_blend(float *const __restrict__ buf,
169162
const float lambda,

0 commit comments

Comments
 (0)