[Bf-blender-cvs] [20250659312] functions: simulate particles in parallel

Jacques Lucke noreply at git.blender.org
Thu Jan 2 16:38:14 CET 2020


Commit: 20250659312762a973f6aa8364c29695a79a55d6
Author: Jacques Lucke
Date:   Thu Jan 2 14:58:39 2020 +0100
Branches: functions
https://developer.blender.org/rB20250659312762a973f6aa8364c29695a79a55d6

simulate particles in parallel

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

M	source/blender/simulations/bparticles/simulate.cpp

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

diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 6330e841965..99ba9dcefb3 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -35,6 +35,21 @@ template<typename FuncT> void parallel_for(IndexRange range, const FuncT &func)
 #endif
 }
 
+template<typename FuncT>
+void blocked_parallel_for(IndexRange range, uint grain_size, const FuncT &func)
+{
+  if (range.size() == 0) {
+    return;
+  }
+#ifdef WITH_TBB
+  tbb::parallel_for(
+      tbb::blocked_range<uint>(range.first(), range.one_after_last(), grain_size),
+      [&](const tbb::blocked_range<uint> &sub_range) { func(IndexRange(sub_range)); });
+#else
+  func(range);
+#endif
+}
+
 template<typename FuncT1, typename FuncT2>
 void parallel_invoke(const FuncT1 &func1, const FuncT2 &func2)
 {
@@ -378,13 +393,15 @@ BLI_NOINLINE static void simulate_particles_for_time_span(SimulationState &simul
                                                           FloatInterval time_span,
                                                           MutableAttributesRef particle_attributes)
 {
-  Array<float> remaining_durations(particle_attributes.size(), time_span.size());
-  simulate_particle_chunk(simulation_state,
-                          particle_allocator,
-                          particle_attributes,
-                          system_info,
-                          remaining_durations,
-                          time_span.end());
+  blocked_parallel_for(IndexRange(particle_attributes.size()), 1000, [&](IndexRange range) {
+    Array<float> remaining_durations(range.size(), time_span.size());
+    simulate_particle_chunk(simulation_state,
+                            particle_allocator,
+                            particle_attributes.slice(range),
+                            system_info,
+                            remaining_durations,
+                            time_span.end());
+  });
 }
 
 BLI_NOINLINE static void simulate_particles_from_birth_to_end_of_step(



More information about the Bf-blender-cvs mailing list