[Bf-blender-cvs] [6335c3dee8d] functions: change threading api

Jacques Lucke noreply at git.blender.org
Mon Jul 1 11:11:57 CEST 2019


Commit: 6335c3dee8d31ce8fa7b665b01c634808a115ab5
Author: Jacques Lucke
Date:   Mon Jul 1 10:16:29 2019 +0200
Branches: functions
https://developer.blender.org/rB6335c3dee8d31ce8fa7b665b01c634808a115ab5

change threading api

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

M	source/blender/blenlib/BLI_task.hpp
M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/blenlib/BLI_task.hpp b/source/blender/blenlib/BLI_task.hpp
index f5bfb60e953..87e2bb7abc4 100644
--- a/source/blender/blenlib/BLI_task.hpp
+++ b/source/blender/blenlib/BLI_task.hpp
@@ -6,9 +6,26 @@
 namespace BLI {
 namespace Task {
 
+/**
+ * Use this when the processing of individual array elements is relatively expensive.
+ * The function has to be a callable that takes an element of type T& as input.
+ *
+ * For debugging/profiling purposes the threading can be disabled.
+ */
 template<typename T, typename Func>
-static void parallel_array(ArrayRef<T> array, Func function, ParallelRangeSettings &settings)
+static void parallel_array_elements(ArrayRef<T> array, Func function, bool use_threading = false)
 {
+  if (!use_threading) {
+    for (T &element : array) {
+      function(element);
+    }
+    return;
+  }
+
+  ParallelRangeSettings settings = {0};
+  BLI_parallel_range_settings_defaults(&settings);
+  settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC;
+
   struct ParallelData {
     ArrayRef<T> array;
     Func &function;
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 4e19160d98a..f00b79a7cdb 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -7,7 +7,7 @@
 
 #include "xmmintrin.h"
 
-#define USE_THREADING false
+#define USE_THREADING true
 #define BLOCK_SIZE 1000
 
 namespace BParticles {
@@ -693,14 +693,10 @@ BLI_NOINLINE static void delete_tagged_particles(ParticlesState &state)
 {
   SmallVector<ParticlesBlock *> blocks = get_all_blocks(state);
 
-  ParallelRangeSettings settings;
-  BLI_parallel_range_settings_defaults(&settings);
-  settings.use_threading = USE_THREADING;
-
-  BLI::Task::parallel_array(
+  BLI::Task::parallel_array_elements(
       ArrayRef<ParticlesBlock *>(blocks),
       [](ParticlesBlock *block) { delete_tagged_particles_and_reorder(*block); },
-      settings);
+      USE_THREADING);
 }
 
 /* Compress particle blocks.



More information about the Bf-blender-cvs mailing list