Multi-threaded bullet

Noehrgel
Posts: 10
Joined: Mon Aug 21, 2006 5:11 am

Multi-threaded bullet

Post by Noehrgel »

Well I think my thread got lost during breakdown. I'd like to bring back this topic as it is quite important for me.

I'd like to use multiple threads to do narrow-phase. The tips I got from Erwin where I'd have to change the processAllOverlappingPairs to run parallel. Someone (I think jmc) jumped in and said he managed to do this.

Well I couldn't get that running. Maybe I'm totally wrong, but I think this can't be done as processOverlap is not thread-safe. If I remember right the m_dispatchInfo variable contains a pointer to m_stackAllocator which is the same for all threads and pairs. Assuming stackAllocator does what its name implies (I check that: it does) than it is clear why everything keeps crashing.

Does anybody have any tips on how to get this going?

Thanks in advance, Noehrgel
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

For the parallel PS3 version of Bullet, running the collision detection on one or more SPUs, each SPU has its own Local Store memory, so no stack allocator is used. A new btParallelDispatcher was implemented to dispatch tasks in parallel and to pre-allocate storage for contact points (btPersistentManifolds).

Indeed, in a multi-threaded shared memory approach, each thread needs its own stackallocator. Also the memory allocator for contact points needs to be sorted properly. I plan to bring some of the parallel changes from PS3 back to open source, that should make it easier to develop a parallel PC version.

Do you have a recommendation for multiplatform threading library, or should we provide an abstraction in Bullet, and implement it for each platform ourselves?

Thanks,
Erwin
Noehrgel
Posts: 10
Joined: Mon Aug 21, 2006 5:11 am

Post by Noehrgel »

Erwin Coumans wrote:Do you have a recommendation for multiplatform threading library, or should we provide an abstraction in Bullet, and implement it for each platform ourselves?
I'm not quite sure if I understood what you mean with abstraction. The abstraction is there I think. Assuming everything internal is threadsafe you can push candidates into a list in the NearCallback and run over this list in parallel (this is what I'd do using ODE).

The only library for threading I've used till now is pthreads and I think this should work on most unix systems (don't know nothing about windows).
Last but not least I'd like to remember you off OpenMP. This problem is perfectly fit for this kind of parallelization! Using one pragma should do the trick.

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

Post by Erwin Coumans »

I was referring to a multiplatform abstraction for multithreading, like pthreads or OpenMP. It should run on all platforms, including Windows, Unix and Mac OS X. Preferably it should be a small library, so we can include it in the 'Extras' folder. Perhaps pthreads is a good startingpoint.

Thanks,
Erwin