[Bf-blender-cvs] [6289393f7b9] functions: initial c++ api for parallel processing on top of BLI_task

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


Commit: 6289393f7b95dccc5d02cc270003afb157bca6cb
Author: Jacques Lucke
Date:   Mon Jul 1 09:57:34 2019 +0200
Branches: functions
https://developer.blender.org/rB6289393f7b95dccc5d02cc270003afb157bca6cb

initial c++ api for parallel processing on top of BLI_task

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

A	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
new file mode 100644
index 00000000000..f5bfb60e953
--- /dev/null
+++ b/source/blender/blenlib/BLI_task.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "BLI_task.h"
+#include "BLI_array_ref.hpp"
+
+namespace BLI {
+namespace Task {
+
+template<typename T, typename Func>
+static void parallel_array(ArrayRef<T> array, Func function, ParallelRangeSettings &settings)
+{
+  struct ParallelData {
+    ArrayRef<T> array;
+    Func &function;
+  } data = {array, function};
+
+  BLI_task_parallel_range(0,
+                          array.size(),
+                          (void *)&data,
+                          [](void *__restrict userdata,
+                             const int index,
+                             const ParallelRangeTLS *__restrict UNUSED(tls)) {
+                            ParallelData &data = *(ParallelData *)userdata;
+                            T &element = data.array[index];
+                            data.function(element);
+                          },
+                          &settings);
+}
+
+}  // namespace Task
+}  // namespace BLI
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 0f65614f6e4..4e19160d98a 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -2,7 +2,7 @@
 #include "time_span.hpp"
 
 #include "BLI_lazy_init.hpp"
-#include "BLI_task.h"
+#include "BLI_task.hpp"
 #include "BLI_timeit.hpp"
 
 #include "xmmintrin.h"
@@ -689,18 +689,6 @@ BLI_NOINLINE static void delete_tagged_particles_and_reorder(ParticlesBlock &blo
   }
 }
 
-struct DeleteTaggedParticlesData {
-  ArrayRef<ParticlesBlock *> blocks;
-};
-
-BLI_NOINLINE static void delete_tagged_particles_in_block_cb(
-    void *__restrict userdata, const int index, const ParallelRangeTLS *__restrict UNUSED(tls))
-{
-  DeleteTaggedParticlesData *data = (DeleteTaggedParticlesData *)userdata;
-  ParticlesBlock &block = *data->blocks[index];
-  delete_tagged_particles_and_reorder(block);
-}
-
 BLI_NOINLINE static void delete_tagged_particles(ParticlesState &state)
 {
   SmallVector<ParticlesBlock *> blocks = get_all_blocks(state);
@@ -709,9 +697,10 @@ BLI_NOINLINE static void delete_tagged_particles(ParticlesState &state)
   BLI_parallel_range_settings_defaults(&settings);
   settings.use_threading = USE_THREADING;
 
-  DeleteTaggedParticlesData data = {blocks};
-  BLI_task_parallel_range(
-      0, blocks.size(), (void *)&data, delete_tagged_particles_in_block_cb, &settings);
+  BLI::Task::parallel_array(
+      ArrayRef<ParticlesBlock *>(blocks),
+      [](ParticlesBlock *block) { delete_tagged_particles_and_reorder(*block); },
+      settings);
 }
 
 /* Compress particle blocks.



More information about the Bf-blender-cvs mailing list