Skip to content

Restore scheduler-based calc threading with persistent worker contexts.#229

Draft
tameware wants to merge 1 commit into
dds-bridge:developfrom
tameware:calc-run-threads
Draft

Restore scheduler-based calc threading with persistent worker contexts.#229
tameware wants to merge 1 commit into
dds-bridge:developfrom
tameware:calc-run-threads

Conversation

@tameware

@tameware tameware commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Honor SetResources thread limits again so batch calc uses strain-aware scheduling and reuses per-slot SolverContexts instead of fresh std::thread workers on every CalcAllTables call.

Honor SetResources thread limits again so batch calc uses strain-aware
scheduling and reuses per-slot SolverContexts instead of fresh std::thread
workers on every CalcAllTables call.

Co-authored-by: Cursor <cursoragent@cursor.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

This PR restores scheduler-driven parallelism for the legacy batch/table calculation path, aiming to respect SetResources() thread limits while reusing per-worker SolverContext instances across calls to reduce repeated setup overhead.

Changes:

  • Re-enable SetResources()-controlled thread count selection (bounded by cores and memory budget).
  • Introduce a persistent per-thread SolverContext pool for calc-table workers and a cleanup hook.
  • Switch legacy calc-all-boards execution back to scheduler-based work distribution with worker threads.

Reviewed changes

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

File Description
library/src/init.cpp Restores thread-count selection in SetResources() and clears persistent calc contexts in FreeMemory().
library/src/calc_tables.hpp Adds clear_calc_thread_contexts() declaration for lifecycle management of persistent worker contexts.
library/src/calc_tables.cpp Implements persistent worker SolverContext pool and scheduler-based calc threading.

Comment on lines 259 to 263
START_BLOCK_TIMER;

const int nthreads = resolve_worker_count(max_threads, n);

int err = RETURN_NO_FAULT;
if (nthreads <= 1)
{
SolverContext ctx;
for (int bno = 0; bno < n; ++bno)
{
err = calc_single_common_internal(ctx, *bop, *solvedp, bno);
if (err != RETURN_NO_FAULT)
break;
}
}
else
{
std::vector<SolverContext> contexts(static_cast<unsigned>(nthreads));
err = parallel_all_boards_n(n, nthreads,
[&](const int worker_id, const int bno) -> int {
return calc_single_common_internal(
contexts[static_cast<unsigned>(worker_id)], *bop, *solvedp, bno);
});
}
(void)max_threads;
const int ret_run = run_calc_threads(param);

Comment on lines +80 to +85
while (true)
{
const schedType st = scheduler.GetNumber(thr_id);
const int index = st.number;
if (index == -1)
break;
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.

2 participants