Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <mail@jlucke.com>2020-01-02 16:39:52 +0300
committerJacques Lucke <mail@jlucke.com>2020-01-02 16:39:52 +0300
commitecfed4d70fe654337f384095ea547636f669fc26 (patch)
tree43584fadc4fb37f36d894c8c818c29d74f7fe64c /source/blender/simulations
parent8a8223c193f765ed4ecdd3f99bbd111608d6e520 (diff)
cleanup parallel for/invoke
Diffstat (limited to 'source/blender/simulations')
-rw-r--r--source/blender/simulations/bparticles/simulate.cpp61
1 files changed, 39 insertions, 22 deletions
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index b79bc80fe6b..cf8b2136701 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -35,6 +35,17 @@ template<typename FuncT> void parallel_for(IndexRange range, const FuncT &func)
#endif
}
+template<typename FuncT1, typename FuncT2>
+void parallel_invoke(const FuncT1 &func1, const FuncT2 &func2)
+{
+#ifdef WITH_TBB
+ tbb::parallel_invoke(func1, func2);
+#else
+ func1();
+ func2();
+#endif
+}
+
BLI_NOINLINE static void find_next_event_per_particle(
BlockStepData &step_data,
IndexMask mask,
@@ -423,30 +434,36 @@ void simulate_particles(SimulationState &simulation_state,
MultiMap<std::string, ParticleSet *> newly_created_particles;
{
ParticleAllocator particle_allocator(particles_state);
- Vector<std::string> name_vector;
- Vector<ParticleSet *> particles_vector;
- particles_state.particle_containers().foreach_key_value_pair(
- [&](StringRef name, ParticleSet *particles) {
- name_vector.append(name);
- particles_vector.append(particles);
- });
- parallel_for(name_vector.index_iterator(), [&](uint index) {
- ParticleSystemInfo *system_info = systems_to_simulate.lookup_ptr(name_vector[index]);
- ParticleSet *particles = particles_vector[index];
- if (system_info == nullptr) {
- return;
- }
-
- simulate_particles_for_time_span(simulation_state,
- particle_allocator,
- *system_info,
- simulation_time_span,
- particles->attributes());
- });
+ parallel_invoke(
+ [&]() {
+ Vector<std::string> name_vector;
+ Vector<ParticleSet *> particles_vector;
+ particles_state.particle_containers().foreach_key_value_pair(
+ [&](StringRef name, ParticleSet *particles) {
+ name_vector.append(name);
+ particles_vector.append(particles);
+ });
+
+ parallel_for(name_vector.index_iterator(), [&](uint index) {
+ ParticleSystemInfo *system_info = systems_to_simulate.lookup_ptr(name_vector[index]);
+ ParticleSet *particles = particles_vector[index];
+ if (system_info == nullptr) {
+ return;
+ }
+
+ simulate_particles_for_time_span(simulation_state,
+ particle_allocator,
+ *system_info,
+ simulation_time_span,
+ particles->attributes());
+ });
+ },
+ [&]() {
+ create_particles_from_emitters(
+ simulation_state, particle_allocator, emitters, simulation_time_span);
+ });
- create_particles_from_emitters(
- simulation_state, particle_allocator, emitters, simulation_time_span);
newly_created_particles = particle_allocator.allocated_particles();
all_newly_created_particles = newly_created_particles;
}