From fbae1c9ed5d3473dda6a8783c4c29be15fcaf24a Mon Sep 17 00:00:00 2001 From: Juan Gea Date: Tue, 21 May 2019 16:30:03 +0200 Subject: Particle: optimize threading for many particles and many cores MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- source/blender/blenkernel/intern/particle_system.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to '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; -- cgit v1.2.3