Multithread & parrallel dynamics world

mandor
Posts: 6
Joined: Sat Jan 17, 2009 6:46 pm

Multithread & parrallel dynamics world

Post by mandor »

Hi,

I'm trying to run many physics simulation in parallel. Each one has its own set of objects (broadphase, solver, dynamicsWorld, etc).
I'm using Intel Tbb to run each simulation in a parralell_for.

When I run some set of simulations in parralell with Tbb, the memory used by my software increases infinitely (and quite fast, it doubles in a few minutes). The strange thing is that if I run the exact same code without the parrarel_for, the memory used is constant. Valgrind does not see any leak in my code.

I'm quite sure there's no bug in tbb but should I know something about running dynamics_world in parallel ? Maybe there's a lock somewhere that prevents some memory to be freed ? A global cache ?

I've compiled bullet with --enable-multithreaded and the problem is still there.

Thank you for any help.

--
Mandor
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Multithread & parrallel dynamics world

Post by Erwin Coumans »

You can only run multiple dynamics world sequentially, not in parallel. This is because the memory allocator is not thread safe. You could try to register your custom thread-safe memory allocator.

BulletMultiThreaded is a thread-safe way of performing collision detection in parallel. We will provide a prototype CUDA constraint solver very soon.
Thanks,
Erwin
ravrat
Posts: 1
Joined: Tue Apr 27, 2010 2:03 pm

Re: Multithread & parrallel dynamics world

Post by ravrat »

Hello,

i have a similar question. I have 2 btDyanamicWorlds(X and Y) running on two different threads, but run stepSimulation only on X. The results of the simulation are then sent to Y(using motionstates). Y then updates the positions of the objects in its world, and performs raytraces in the world. Currently, this system works, but uses up a lot of memory, because the collisionShapes are loaded twice. My question is , is it safe to use the same collisionShape*, across multiple threads? I know it is safe to use the same collisionShape for different rigid bodies in the same thread, but does it work for rigid bodies across multiple threads?