Task scheduler and ForestTraversal#2342
Conversation
Choose numThreads to not saturate Time big chain
There was a problem hiding this comment.
Pull request overview
This PR introduces a priority-based task scheduler and a forest traversal system that can utilize either the new scheduler or TBB (when available), aimed at improving parallel performance even in non-TBB builds.
- Adds
PriorityScheduler<Y>- a thread pool with priority queue scheduling and work stealing - Adds
ForestTraversal- a CRTP mixin providing top-down and bottom-up tree traversal with automatic TBB/scheduler selection - Includes basic test coverage for both new components
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
| gtsam/base/PriorityScheduler.h | New priority-based task scheduler with per-worker queues and work stealing |
| gtsam/base/ForestTraversal.h | New forest traversal mixin with TBB and scheduler backends |
| gtsam/base/tests/testPriorityScheduler.cpp | Basic test for scheduler return value composition |
| gtsam/base/tests/testForestTraversal.cpp | Basic tests for bottom-up and top-down traversal |
| gtsam/base/FastSet.h | Removes IsTestable concept assertion (unexplained) |
| .github/copilot-instructions.md | Adds guideline about public struct field naming |
|
@copilot open a new pull request to apply changes based on the comments in this thread |
Co-authored-by: dellaert <10515273+dellaert@users.noreply.github.com>
…EXPORT from templates Co-authored-by: dellaert <10515273+dellaert@users.noreply.github.com>
|
Hmm I need a bit of time looking at this code but why do we need priority scheduling here? It seems to me that the work is deterministic and cooperative scheduling is enough. Might be that just the name is misleading? |
Co-authored-by: dellaert <10515273+dellaert@users.noreply.github.com>
Address code review feedback for PriorityScheduler and ForestTraversal
It’s true, priority is not needed. Even hurts a bit in perf, maybe a %. But I have a PR after these two PRs that fixes that. |
Two Schedulers - One very fast Solver
Scheduled MultifrontalSolver
|
@ProfFan uncanny, that’s the next PR :-) it gives another nice improvement, especially for BAL. But can we land this first? |
|
PS, having 30k children update the same parent sbm_ needed creating per-thread SBM temporaries. If we have to lock parallelism does not help :-) |
|
That's why you need deterministic work distribution so threads don't race ;) |
|
So, are we good to go on this one? |
|
I’ll fix test in next PR |

With some help, created one "core" scheduler, specialized using a Policy class to either task traversal or priority (which I need in other places). Some refactoring of the core scheduler to make it faster. One particular change, to drastically decrease the use of
condition_.notify_all();made a 5-fold difference on LinuxNow, on Linux, the new MixIn implementation alone delivers large speedups over classic GTSAM (up to ~26× on large chain problems). While TBB still achieves the lowest absolute MultifrontalSolver times, both backends now show strong performance improvements on the largest BAL and chain benchmarks.
That means that even in the absence of TBB, users should see a big jump in performance - once integrated in NonlinearOptimizer (next next PR :-))