[Bf-blender-cvs] [511e3c5] master: BLI_task: change BLI_task_parallel_range_ex() to just take a bool whether to use threading or not, instead of threshold.

Bastien Montagne noreply at git.blender.org
Wed Dec 30 20:44:13 CET 2015


Commit: 511e3c5d9d503b47cd5fb6fe48abeafde9fbff2d
Author: Bastien Montagne
Date:   Wed Dec 30 20:39:56 2015 +0100
Branches: master
https://developer.blender.org/rB511e3c5d9d503b47cd5fb6fe48abeafde9fbff2d

BLI_task: change BLI_task_parallel_range_ex() to just take a bool whether to use threading or not, instead of threshold.

>From recent experience, turns out we often do want to use something else than basic
range of parallelized forloop as control parameter over threads usage, so now BLI func
only takes a boolean, and caller defines best check for its own case.

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

M	source/blender/blenlib/BLI_task.h
M	source/blender/blenlib/intern/BLI_kdopbvh.c
M	source/blender/blenlib/intern/task.c
M	source/blender/modifiers/intern/MOD_uvwarp.c
M	source/blender/modifiers/intern/MOD_weightvgproximity.c

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

diff --git a/source/blender/blenlib/BLI_task.h b/source/blender/blenlib/BLI_task.h
index 45a6e0b..7b9a3c5 100644
--- a/source/blender/blenlib/BLI_task.h
+++ b/source/blender/blenlib/BLI_task.h
@@ -119,7 +119,7 @@ void BLI_task_parallel_range_ex(
         void *userdata_chunk,
         const size_t userdata_chunk_size,
         TaskParallelRangeFunc func,
-        const int range_threshold,
+        const bool use_threading,
         const bool use_dynamic_scheduling);
 void BLI_task_parallel_range(
         int start, int stop,
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index d2fc5c7..10e29e0 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -874,14 +874,9 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array,
 		cb_data.i = i;
 		cb_data.depth = depth;
 
-		if (num_leafs > KDOPBVH_THREAD_LEAF_THRESHOLD) {
-			BLI_task_parallel_range_ex(i, end_j, &cb_data, NULL, 0, non_recursive_bvh_div_nodes_task_cb, 0, false);
-		}
-		else {
-			for (j = i; j < end_j; j++) {
-				non_recursive_bvh_div_nodes_task_cb(&cb_data, NULL, j);
-			}
-		}
+		BLI_task_parallel_range_ex(
+		            i, end_j, &cb_data, NULL, 0, non_recursive_bvh_div_nodes_task_cb,
+		            num_leafs > KDOPBVH_THREAD_LEAF_THRESHOLD, false);
 	}
 }
 
@@ -1266,14 +1261,9 @@ BVHTreeOverlap *BLI_bvhtree_overlap(
 		data[j].thread = j;
 	}
 
-	if (tree1->totleaf > KDOPBVH_THREAD_LEAF_THRESHOLD) {
-		BLI_task_parallel_range_ex(0, thread_num, data, NULL, 0, bvhtree_overlap_task_cb, 0, false);
-	}
-	else {
-		for (j = 0; j < thread_num; j++) {
-			bvhtree_overlap_task_cb(data, NULL, j);
-		}
-	}
+	BLI_task_parallel_range_ex(
+	            0, thread_num, data, NULL, 0, bvhtree_overlap_task_cb,
+	            tree1->totleaf > KDOPBVH_THREAD_LEAF_THRESHOLD, false);
 	
 	for (j = 0; j < thread_num; j++)
 		total += BLI_stack_count(data[j].overlap);
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index 104ebce..d3b11d8 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -643,8 +643,8 @@ static void parallel_range_func(
  *                       (similar to OpenMP's firstprivate).
  * \param userdata_chunk_size Memory size of \a userdata_chunk.
  * \param func Callback function.
- * \param range_threshold Minimum size of processed range to start using tasks
- *                        (below this, loop is done in main thread only).
+ * \param use_threading If \a true, actually split-execute loop in threads, else just do a sequential forloop
+ *                      (allows caller to use any kind of test to switch on parallelization or not).
  * \param use_dynamic_scheduling If \a true, the whole range is divided in a lot of small chunks (of size 32 currently),
  *                               otherwise whole range is split in a few big chunks (num_threads * 2 chunks currently).
  */
@@ -654,7 +654,7 @@ void BLI_task_parallel_range_ex(
         void *userdata_chunk,
         const size_t userdata_chunk_size,
         TaskParallelRangeFunc func,
-        const int range_threshold,
+        const bool use_threading,
         const bool use_dynamic_scheduling)
 {
 	TaskScheduler *task_scheduler;
@@ -667,7 +667,7 @@ void BLI_task_parallel_range_ex(
 	/* If it's not enough data to be crunched, don't bother with tasks at all,
 	 * do everything from the main thread.
 	 */
-	if (stop - start < range_threshold) {
+	if (!use_threading) {
 		const bool use_userdata_chunk = (userdata_chunk_size != 0) && (userdata_chunk != NULL);
 		void *userdata_chunk_local = NULL;
 
@@ -733,7 +733,7 @@ void BLI_task_parallel_range(
         void *userdata,
         TaskParallelRangeFunc func)
 {
-	BLI_task_parallel_range_ex(start, stop, userdata, NULL, 0, func, 64, false);
+	BLI_task_parallel_range_ex(start, stop, userdata, NULL, 0, func, (stop - start) > 64, false);
 }
 
 #undef MALLOCA
diff --git a/source/blender/modifiers/intern/MOD_uvwarp.c b/source/blender/modifiers/intern/MOD_uvwarp.c
index 3434685..3b549ec 100644
--- a/source/blender/modifiers/intern/MOD_uvwarp.c
+++ b/source/blender/modifiers/intern/MOD_uvwarp.c
@@ -210,7 +210,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 	UVWarpData data = {.mpoly = mpoly, .mloop = mloop, .mloopuv = mloopuv,
 	                   .dvert = dvert, .defgrp_index = defgrp_index,
 	                   .warp_mat = warp_mat, .axis_u = axis_u, .axis_v = axis_v};
-	BLI_task_parallel_range_ex(0, numPolys, &data, NULL, 0, uv_warp_compute, 1000, false);
+	BLI_task_parallel_range_ex(0, numPolys, &data, NULL, 0, uv_warp_compute, numPolys > 1000, false);
 
 	dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
 
diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c
index 0a73a18..be86dfe 100644
--- a/source/blender/modifiers/intern/MOD_weightvgproximity.c
+++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c
@@ -176,7 +176,8 @@ static void get_vert2geom_distance(int numVerts, float (*v_cos)[3],
 	data.dist[1] = dist_e;
 	data.dist[2] = dist_f;
 
-	BLI_task_parallel_range_ex(0, numVerts, &data, &data_chunk, sizeof(data_chunk), vert2geom_task_cb, 10000, false);
+	BLI_task_parallel_range_ex(
+	            0, numVerts, &data, &data_chunk, sizeof(data_chunk), vert2geom_task_cb, numVerts > 10000, false);
 
 	if (dist_v)
 		free_bvhtree_from_mesh(&treeData_v);




More information about the Bf-blender-cvs mailing list