diff options
author | Iliay Katueshenock <Moder> | 2022-07-26 12:06:49 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2022-07-26 12:10:16 +0300 |
commit | c94ca54cdafdba15d5a7be55e81d6f7a0da7ed7e (patch) | |
tree | fe6644d41f65b4e1d5861c33b465b6371b49306c /source/blender/blenlib/BLI_task.hh | |
parent | 203e7ba3320e7ed978ec094efa0c1b22137fb12a (diff) |
BLI: add use_threading parameter to parallel_invoke
`parallel_invoke` allows executing functions on separate threads.
However, creating tasks in tbb has a measurable amount of overhead.
Therefore, it can be benefitial to disable parallelization when
the amount of work done per function is small.
See D15539 for some benchmark results.
Differential Revision: https://developer.blender.org/D15539
Diffstat (limited to 'source/blender/blenlib/BLI_task.hh')
-rw-r--r-- | source/blender/blenlib/BLI_task.hh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_task.hh b/source/blender/blenlib/BLI_task.hh index 904dea66f7a..33a781d3749 100644 --- a/source/blender/blenlib/BLI_task.hh +++ b/source/blender/blenlib/BLI_task.hh @@ -105,6 +105,22 @@ template<typename... Functions> void parallel_invoke(Functions &&...functions) #endif } +/** + * Same #parallel_invoke, but allows disabling threading dynamically. This is useful because when + * the individual functions do very little work, there is a lot of overhead from starting parallel + * tasks. + */ +template<typename... Functions> +void parallel_invoke(const bool use_threading, Functions &&...functions) +{ + if (use_threading) { + parallel_invoke(std::forward<Functions>(functions)...); + } + else { + (functions(), ...); + } +} + /** See #BLI_task_isolate for a description of what isolating a task means. */ template<typename Function> void isolate_task(const Function &function) { |