CPU multithreading is working!

lunkhound
Posts: 97
Joined: Thu Nov 21, 2013 8:57 pm

Re: CPU multithreading is working!

Post by lunkhound » Sat Mar 03, 2018 1:36 am

To show how the new parallel solver can improve on and integrate with the existing multithreading, consider the demo from the example browser found under "Benchmarks/1000 stack". In this scene we have a large island, a medium island and 3 small islands. This graphic shows a comparison of using the existing multithreading (which doesn't handle single large islands well) with a new approach which augments the existing method with a parallel solver (which does handle large islands well -- but not small ones).

In each case we are using 4 threads to solve all 5 islands:

demo1kstack-batching-threshold-comparison.png
demo1kstack-batching-threshold-comparison.png (472.62 KiB) Viewed 426 times

rebirth
Posts: 24
Joined: Thu Jul 24, 2014 2:48 am

Re: CPU multithreading is working!

Post by rebirth » Wed Mar 07, 2018 5:26 pm

I've tried getting this working, but VS is throwing an assert:

Code: Select all

btAssert( gBtTaskScheduler != NULL );  // call btSetTaskScheduler() with a valid task scheduler first! - line 444 of btThreads.cpp
I chose PPL in cmake and I'm creating the world like so:

Code: Select all

broadPhase = new btDbvtBroadphase();
collisionConfig = new btDefaultCollisionConfiguration();
collisionDispatcher = new btCollisionDispatcherMt(collisionConfig, 40);
solver = new btConstraintSolverPoolMt(BT_MAX_THREAD_COUNT);
dynamicsWorld = new btDiscreteDynamicsWorldMt(collisionDispatcher, broadPhase, solver, collisionConfig);
Am I missing something?

lunkhound
Posts: 97
Joined: Thu Nov 21, 2013 8:57 pm

Re: CPU multithreading is working!

Post by lunkhound » Thu Mar 08, 2018 6:51 pm

rebirth wrote:
Wed Mar 07, 2018 5:26 pm
I've tried getting this working, but VS is throwing an assert:

Code: Select all

btAssert( gBtTaskScheduler != NULL );  // call btSetTaskScheduler() with a valid task scheduler first! - line 444 of btThreads.cpp
I chose PPL in cmake and I'm creating the world like so:

Code: Select all

broadPhase = new btDbvtBroadphase();
collisionConfig = new btDefaultCollisionConfiguration();
collisionDispatcher = new btCollisionDispatcherMt(collisionConfig, 40);
solver = new btConstraintSolverPoolMt(BT_MAX_THREAD_COUNT);
dynamicsWorld = new btDiscreteDynamicsWorldMt(collisionDispatcher, broadPhase, solver, collisionConfig);
Am I missing something?
It looks like you are not setting up a task scheduler. To use PPL you would add something like:

Code: Select all

btSetTaskScheduler( btGetPPLTaskScheduler() );
Note that the version of bullet multithreading I just recently posted about, is still only a Pull Request -- it is not (yet) present in the main Bullet repo.
However you can get it here:
https://github.com/lunkhound/bullet3

Note the world setup is changed slightly to allow for the new parallel solver:

Code: Select all

broadPhase = new btDbvtBroadphase();
collisionConfig = new btDefaultCollisionConfiguration();
collisionDispatcher = new btCollisionDispatcherMt(collisionConfig, 40);
solverPool = new btConstraintSolverPoolMt(BT_MAX_THREAD_COUNT);
parallelSolver = new btSequentialImpulseConstraintSolverMt();  // create parallel solver
dynamicsWorld = new btDiscreteDynamicsWorldMt(collisionDispatcher, broadPhase, solverPool, parallelSolver, collisionConfig);
btSetTaskScheduler( btCreateDefaultTaskScheduler() );  // use built-in task scheduler

rebirth
Posts: 24
Joined: Thu Jul 24, 2014 2:48 am

Re: CPU multithreading is working!

Post by rebirth » Thu Mar 08, 2018 7:16 pm

Thanks. I was using the wrong master, which doesn't have the btSequentialImpulseConstraintSolverMt source files. I'll build it now and let you know what I think after a couple of days of testing.

lunkhound
Posts: 97
Joined: Thu Nov 21, 2013 8:57 pm

Re: CPU multithreading is working!

Post by lunkhound » Thu Mar 08, 2018 7:58 pm

rebirth wrote:
Thu Mar 08, 2018 7:16 pm
Thanks. I was using the wrong master, which doesn't have the btSequentialImpulseConstraintSolverMt source files. I'll build it now and let you know what I think after a couple of days of testing.
Sorry, that was my bad -- I had the wrong default branch on my repo. I fixed that now.

If you should run into any trouble, just post it here and I'll try to help. Also, for best results I recommend using the built-in task scheduler rather than the others. I haven't been testing the others much.

lunkhound
Posts: 97
Joined: Thu Nov 21, 2013 8:57 pm

Re: CPU multithreading is working!

Post by lunkhound » Sun Apr 15, 2018 8:40 pm

Note that my pull-request for the multithreaded constraint solver has been accepted and merged (a couple of weeks ago). So this is now available in the main Bullet repo.
Thanks Erwin!

With this latest PR, the task scheduler is now included in the core libs, which should make it easier than ever to get multithreading working in a standalone project. Feel free to post in this thread if you run into any trouble getting it set up.

Post Reply