diff options
author | Tom Tromey <tom@tromey.com> | 2021-05-23 09:04:27 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-04-12 09:31:16 -0600 |
commit | 82d734f7a3b6f08813a9ad6272aa026779c88975 (patch) | |
tree | 26aea3dcb439f9c8a884535c60eb452ffcebc423 /gdbsupport | |
parent | c0892a1d5dc29eb849e9aed0fb7c7dade6dffb23 (diff) | |
download | binutils-82d734f7a3b6f08813a9ad6272aa026779c88975.zip binutils-82d734f7a3b6f08813a9ad6272aa026779c88975.tar.gz binutils-82d734f7a3b6f08813a9ad6272aa026779c88975.tar.bz2 |
Add batching parameter to parallel_for_each
parallel_for_each currently requires each thread to process at least
10 elements. However, when indexing, it's fine for a thread to handle
just a single CU. This patch parameterizes this, and updates the one
user.
Diffstat (limited to 'gdbsupport')
-rw-r--r-- | gdbsupport/parallel-for.h | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/gdbsupport/parallel-for.h b/gdbsupport/parallel-for.h index 915814e..811ffd6 100644 --- a/gdbsupport/parallel-for.h +++ b/gdbsupport/parallel-for.h @@ -32,11 +32,16 @@ namespace gdb This approach was chosen over having the callback work on single items because it makes it simple for the caller to do - once-per-subrange initialization and destruction. */ + once-per-subrange initialization and destruction. + + The parameter N says how batching ought to be done -- there will be + at least N elements processed per thread. Setting N to 0 is not + allowed. */ template<class RandomIt, class RangeFunction> void -parallel_for_each (RandomIt first, RandomIt last, RangeFunction callback) +parallel_for_each (unsigned n, RandomIt first, RandomIt last, + RangeFunction callback) { /* So we can use a local array below. */ const size_t local_max = 16; @@ -48,10 +53,11 @@ parallel_for_each (RandomIt first, RandomIt last, RangeFunction callback) size_t n_elements = last - first; if (n_threads > 1) { - /* Arbitrarily require that there should be at least 10 elements - in a thread. */ - if (n_elements / n_threads < 10) - n_threads = std::max (n_elements / 10, (size_t) 1); + /* Require that there should be at least N elements in a + thread. */ + gdb_assert (n > 0); + if (n_elements / n_threads < n) + n_threads = std::max (n_elements / n, (size_t) 1); size_t elts_per_thread = n_elements / n_threads; n_actual_threads = n_threads - 1; for (int i = 0; i < n_actual_threads; ++i) |