Rename SetMaxThreads to InitialiseStaticMemory; add max_threads override#204
Conversation
There was a problem hiding this comment.
Pull request overview
This PR clarifies DDS initialization by renaming the legacy SetMaxThreads concept to InitialiseStaticMemory, and introduces *N batch C APIs that allow callers to optionally cap worker-thread usage while preserving existing auto-sizing behavior.
Changes:
- Add
InitialiseStaticMemory()and makeSetMaxThreads()a deprecated alias that only performs static initialization. - Introduce
resolve_worker_count(max_threads, count)and plumbmax_threadsthrough the legacy parallel batch paths (SolveAllBoards*,Calc*Tables*) via new*NC entry points. - Add system tests covering worker-count resolution and equivalence between auto vs explicit
maxThreadscaps.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| python/src/bindings.cpp | Updates Python docstring to reflect SetMaxThreads deprecation/aliasing. |
| library/tests/system/worker_count_test.cpp | Adds unit tests for resolve_worker_count behavior. |
| library/tests/system/max_threads_equivalence_test.cpp | Adds equivalence tests for *N APIs and init/alias behavior. |
| library/tests/system/context_tt_facade_test.cpp | Switches tests from SetMaxThreads to InitialiseStaticMemory. |
| library/tests/system/context_equivalence_test.cpp | Switches tests from SetMaxThreads to InitialiseStaticMemory. |
| library/tests/system/BUILD.bazel | Registers the two new system tests. |
| library/src/system/parallel_boards.hpp | Declares resolve_worker_count. |
| library/src/system/parallel_boards.cpp | Implements resolve_worker_count and uses it in parallel_all_boards_n. |
| library/src/solve_board.cpp | Adds SolveAllBoardsN/SolveAllBoardsBinN and threads maxThreads to batch solve path. |
| library/src/init.cpp | Adds InitialiseStaticMemory; makes SetMaxThreads a deprecated alias. |
| library/src/dds.cpp | Updates library-load init hooks to call InitialiseStaticMemory. |
| library/src/calc_tables.cpp | Threads max_threads through legacy parallel batch calc and adds Calc*N entry points. |
| library/src/api/dll.h | Exposes InitialiseStaticMemory and new *N C API declarations with docs. |
| examples/migration_example.cpp | Updates example to call InitialiseStaticMemory instead of SetMaxThreads. |
| examples/dd_table_for_deal.cpp | Updates example initialization call to InitialiseStaticMemory. |
| dotnet/DDS_Core/Native/DdsNative.cs | Clarifies in comments that SetMaxThreads is deprecated/aliased. |
| dotnet/DDS_Core/DDS.cs | Clarifies in comments that the .NET wrapper calls the deprecated alias symbol. |
Collapse the duplicated max(1, min(hardware_concurrency, count)) worker-count formula into a single resolve_worker_count helper in parallel_boards, and rewire parallel_all_boards_n to use it. Pure refactor, no behaviour change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The function initialises static library state (TT memory pools, scheduler / thread-manager, lookup tables) and no longer controls thread count. Add InitialiseStaticMemory() as the public name and keep SetMaxThreads as a thin deprecated alias for ABI/back-compat. Repoint internal callers (dds.cpp, examples); update .NET/Python binding comments only. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a trailing max_threads (default 0 = auto) to solve_all_boards_n and the legacy parallel calc_all_boards_n, forwarding it to parallel_all_boards_n and using resolve_worker_count to size the SolverContext pool. Default preserves the current hardware_concurrency auto-sizing, so no behaviour change. Deviation from task: the C++ calc_dd_table overloads use the sequential context-aware calc_all_boards_n, so threading max_threads there would be a no-op; left unchanged. The C API CalcDDtable/CalcAllTables use the legacy parallel overload, which now carries the parameter for Task 04. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add SolveAllBoardsN, SolveAllBoardsBinN, CalcDDtableN, CalcDDtablePBNN, CalcAllTablesN and CalcAllTablesPBNN, which forward an explicit maxThreads (<= 0 = auto) down to the internal batch solvers. The existing functions keep their signatures and now delegate to the *N variants with 0, preserving ABI and current auto-sizing behaviour. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add worker_count_test (resolve_worker_count edge cases) and max_threads_equivalence_test (CalcDDtableN / SolveAllBoardsBinN with an explicit cap match the auto path; InitialiseStaticMemory and the deprecated SetMaxThreads alias both leave the library usable). Migrate existing SetMaxThreads(1) call sites to InitialiseStaticMemory(), keeping one deliberate alias usage in the new test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ed4e1a9 to
f36dc17
Compare
|
Shall I wait to request another Copilot review until the build is fixed? |
|
Ready for another round of Copilot. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
tameware
left a comment
There was a problem hiding this comment.
I am not qualified to review the code for readability and functionality - I'm happy to delegate that to Copilot.
I did pull the branch and run it through my benchmarks. I see that dtest's -n flag - number of threads - still works, so the replacement threading limits are being respected.
Copilot is complaining about something that a previous iteration marked as resolved. I suggest either making Copilot happy or adding a comment noting why it's OK.
The spelling of Initialise is inconsistent with the internal variable spelling that uses the American Initialize. I suggest renaming to InitializeStaticMemory everywhere unless there's a reason not to. That's what most developers will expect.
|
LGTM |
|
@tameware, would you mind approving the pull request as well? |
|
I would if I knew how! I see no "Approve" button. |
|
Do you see a submit review button here https://github.com/dds-bridge/dds/pull/204/changes? Otherwise I need to look into permissions. |
Summary
SetMaxThreadstoInitialiseStaticMemory: the function initialisesstatic library state (TT memory pools, scheduler/thread-manager, lookup
tables) and no longer controls thread count, since internal batch threading
was removed.
SetMaxThreadsis kept as a thin deprecated alias so theexported C symbol, the .NET P/Invoke, and the Python binding keep working.
max(1, min(hardware_concurrency, n))worker-countformula into one
resolve_worker_count(max_threads, count)helper, and plumban optional
max_threads(0 = auto) throughsolve_all_boards_nand thelegacy parallel
calc_all_boards_n.*NC variants —SolveAllBoardsN,SolveAllBoardsBinN,CalcDDtableN,CalcDDtablePBNN,CalcAllTablesN,CalcAllTablesPBNN—that accept
maxThreads. The existing functions keep their signatures/ABIand delegate with
0, so current auto-sizing behaviour is unchanged.resolve_worker_countedge cases, and equivalence checks provingan explicit
maxThreadscap produces results identical to the auto path.Notes
calc_dd_tableoverloads use the sequential context-awarecalc_all_boards_n, where a thread cap would be a no-op, so they were leftunchanged. Only the legacy parallel path (used by the C API) carries the
parameter.
the current
hardware_concurrencyauto-sizing.Test plan
bazel build //library/... //examples/...bazel test //library/tests/...— 31 tests pass (29 existing + 2 new)CalcDDtableN(..., maxThreads=1)matchesCalcDDtable(...)SolveAllBoardsBinN(..., maxThreads=1)matchesSolveAllBoardsBin(...)InitialiseStaticMemory()and the deprecatedSetMaxThreadsalias bothleave the library usable for a subsequent solve
🤖 Generated with Claude Code
Closes #168
Closes #188