Commit: 2409a9f0af42b999aed5ecb3118767551d8a04e0
Author: Bastien Montagne
Date:   Wed Sep 18 17:35:00 2019 +0200
Branches: master
https://developer.blender.org/rB2409a9f0af42b999aed5ecb3118767551d8a04e0

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.

===================================================================

M       source/blender/blenlib/intern/task.c

===================================================================

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;
     }
   }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to