[Bf-blender-cvs] [fbae1c9ed5d] master: Particle: optimize threading for many particles and many cores

Juan Gea noreply at git.blender.org
Tue May 21 16:57:42 CEST 2019


Commit: fbae1c9ed5d3473dda6a8783c4c29be15fcaf24a
Author: Juan Gea
Date:   Tue May 21 16:30:03 2019 +0200
Branches: master
https://developer.blender.org/rBfbae1c9ed5d3473dda6a8783c4c29be15fcaf24a

Particle: optimize threading for many particles and many cores

The maximum particles per task of 256 was outdated and lead to too much thread
contention. Instead define a low fixed number of tasks per thread.

On a i7-7700HQ, creating 4 million particles went down from 31s to 4s.

Thanks to Oscar Abad, Sav Martin, Zebus3d, Sebastián Barschkis and Martin Felke
for testing and advice.

Differential Revision: https://developer.blender.org/D4910

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

M	source/blender/blenkernel/intern/particle_system.c

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

diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index cba15aed55f..568b0d3531e 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -471,8 +471,6 @@ void psys_thread_context_init(ParticleThreadContext *ctx, ParticleSimulationData
   ctx->ma = give_current_material(sim->ob, sim->psys->part->omat);
 }
 
-#define MAX_PARTICLES_PER_TASK \
-  256 /* XXX arbitrary - maybe use at least number of points instead for better balancing? */
 
 BLI_INLINE int ceil_ii(int a, int b)
 {
@@ -486,7 +484,7 @@ void psys_tasks_create(ParticleThreadContext *ctx,
                        int *r_numtasks)
 {
   ParticleTask *tasks;
-  int numtasks = ceil_ii((endpart - startpart), MAX_PARTICLES_PER_TASK);
+  int numtasks = min_ii(BLI_system_thread_count() * 4, endpart - startpart);
   float particles_per_task = (float)(endpart - startpart) / (float)numtasks, p, pnext;
   int i;



More information about the Bf-blender-cvs mailing list