Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2019-09-18 18:35:00 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2019-09-18 18:38:08 +0300
commit2409a9f0af42b999aed5ecb3118767551d8a04e0 (patch)
treebc1ab0551ab04c916c2e82f534208cd46ed25ad5 /source/blender/blenlib/intern/task.c
parent84bd9e284e06d886c24701bcd2b78b3d24617cb3 (diff)
BLI_tasks: simplify/generalize heuristic computing default chunk size.
That code is simpler and more general (not limited to some specific values of thread numbers). It still gives similar default chunk size as what we had before, but handles smoother increase steps, and higher number of threads, by keeping increasing the chunk size. No functional change expected from that commit.
Diffstat (limited to 'source/blender/blenlib/intern/task.c')
-rw-r--r--source/blender/blenlib/intern/task.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index 2f6c88c128a..6cdaec97d9a 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -1064,22 +1064,28 @@ BLI_INLINE void task_parallel_range_calc_chunk_size(const TaskParallelSettings *
chunk_size = settings->min_iter_per_thread;
}
else {
- /* Basic heuristic to avoid threading on low amount of items. We could make that limit
- * configurable in settings too... */
- if (tot_items > 0 && tot_items < 256) {
- chunk_size = tot_items;
- }
- /* NOTE: The idea here is to compensate for rather measurable threading
+ /* Multiplier used in heuristics below to define "optimal" chunk size.
+ * The idea here is to increase the chunk size to compensate for a rather measurable threading
* overhead caused by fetching tasks. With too many CPU threads we are starting
- * to spend too much time in those overheads. */
- else if (num_tasks > 32) {
- chunk_size = 128;
- }
- else if (num_tasks > 16) {
- chunk_size = 64;
- }
- else {
- chunk_size = 32;
+ * to spend too much time in those overheads.
+ * First values are: 1 if num_tasks < 16;
+ * else 2 if num_tasks < 32;
+ * else 3 if num_tasks < 48;
+ * else 4 if num_tasks < 64;
+ * etc.
+ * Note: If we wanted to keep the 'power of two' multiplier, we'd need something like:
+ * 1 << max_ii(0, (int)(sizeof(int) * 8) - 1 - bitscan_reverse_i(num_tasks) - 3)
+ */
+ const int num_tasks_factor = max_ii(1, num_tasks >> 3);
+
+ /* We could make that 'base' 32 number configurable in TaskParallelSettings too, or maybe just
+ * always use that heuristic using TaskParallelSettings.min_iter_per_thread as basis? */
+ chunk_size = 32 * num_tasks_factor;
+
+ /* Basic heuristic to avoid threading on low amount of items.
+ * We could make that limit configurable in settings too. */
+ if (tot_items > 0 && tot_items < max_ii(256, chunk_size * 2)) {
+ chunk_size = tot_items;
}
}