Skip to content

Rename SetMaxThreads to InitialiseStaticMemory; add max_threads override#204

Merged
zzcgumn merged 16 commits into
developfrom
fix/pass_instead_of_set_max_thread
Jun 25, 2026
Merged

Rename SetMaxThreads to InitialiseStaticMemory; add max_threads override#204
zzcgumn merged 16 commits into
developfrom
fix/pass_instead_of_set_max_thread

Conversation

@zzcgumn

@zzcgumn zzcgumn commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Rename SetMaxThreads to InitialiseStaticMemory: the function initialises
    static library state (TT memory pools, scheduler/thread-manager, lookup
    tables) and no longer controls thread count, since internal batch threading
    was removed. SetMaxThreads is kept as a thin deprecated alias so the
    exported C symbol, the .NET P/Invoke, and the Python binding keep working.
  • Collapse the duplicated max(1, min(hardware_concurrency, n)) worker-count
    formula into one resolve_worker_count(max_threads, count) helper, and plumb
    an optional max_threads (0 = auto) through solve_all_boards_n and the
    legacy parallel calc_all_boards_n.
  • Add public *N C variants — SolveAllBoardsN, SolveAllBoardsBinN,
    CalcDDtableN, CalcDDtablePBNN, CalcAllTablesN, CalcAllTablesPBNN
    that accept maxThreads. The existing functions keep their signatures/ABI
    and delegate with 0, so current auto-sizing behaviour is unchanged.
  • Add tests: resolve_worker_count edge cases, and equivalence checks proving
    an explicit maxThreads cap produces results identical to the auto path.

Notes

  • The C++ calc_dd_table overloads use the sequential context-aware
    calc_all_boards_n, where a thread cap would be a no-op, so they were left
    unchanged. Only the legacy parallel path (used by the C API) carries the
    parameter.
  • No behaviour change for any existing caller: defaults and delegation preserve
    the current hardware_concurrency auto-sizing.

Test plan

  • bazel build //library/... //examples/...
  • bazel test //library/tests/... — 31 tests pass (29 existing + 2 new)
  • CalcDDtableN(..., maxThreads=1) matches CalcDDtable(...)
  • SolveAllBoardsBinN(..., maxThreads=1) matches SolveAllBoardsBin(...)
  • InitialiseStaticMemory() and the deprecated SetMaxThreads alias both
    leave the library usable for a subsequent solve

🤖 Generated with Claude Code

Closes #168
Closes #188

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 make SetMaxThreads() a deprecated alias that only performs static initialization.
  • Introduce resolve_worker_count(max_threads, count) and plumb max_threads through the legacy parallel batch paths (SolveAllBoards*, Calc*Tables*) via new *N C entry points.
  • Add system tests covering worker-count resolution and equivalence between auto vs explicit maxThreads caps.

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.

Comment thread library/src/system/parallel_boards.cpp
Comment thread library/src/system/parallel_boards.hpp
zzcgumn and others added 5 commits June 21, 2026 15:00
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>
@zzcgumn zzcgumn force-pushed the fix/pass_instead_of_set_max_thread branch from ed4e1a9 to f36dc17 Compare June 21, 2026 14:02
@tameware

Copy link
Copy Markdown
Collaborator

Shall I wait to request another Copilot review until the build is fixed?

@zzcgumn

zzcgumn commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator Author

Ready for another round of Copilot.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Comment thread library/src/solve_board.cpp Outdated
Comment thread library/src/api/dll.h Outdated
Comment thread python/src/bindings.cpp Outdated
Comment thread dotnet/DDS_Core/DDS.cs Outdated
zzcgumn and others added 2 commits June 21, 2026 22:59
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Comment thread library/src/calc_tables.cpp
Comment thread library/src/solve_board.cpp
Comment thread python/src/bindings.cpp
Comment thread python/src/bindings.cpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Comment thread python/src/bindings.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Comment thread python/src/bindings.cpp
Comment thread python/tests/test_analyse.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Comment thread python/src/bindings.cpp Outdated

@tameware tameware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread examples/dd_table_for_deal.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated no new comments.

@tameware

Copy link
Copy Markdown
Collaborator

LGTM

@zzcgumn

zzcgumn commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

@tameware, would you mind approving the pull request as well?

@tameware

Copy link
Copy Markdown
Collaborator

I would if I knew how! I see no "Approve" button.

@zzcgumn

zzcgumn commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

Do you see a submit review button here https://github.com/dds-bridge/dds/pull/204/changes?

Otherwise I need to look into permissions.

@zzcgumn zzcgumn merged commit 9c78c46 into develop Jun 25, 2026
5 checks passed
@zzcgumn zzcgumn deleted the fix/pass_instead_of_set_max_thread branch June 25, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an optional user_max_threads argument to calc_all_boards_n Confirm whether SetMaxThreads() call is necessary

3 participants