Restore scheduler-based calc threading with persistent worker contexts.#229
Draft
tameware wants to merge 1 commit into
Draft
Restore scheduler-based calc threading with persistent worker contexts.#229tameware wants to merge 1 commit into
tameware wants to merge 1 commit into
Conversation
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>
Contributor
There was a problem hiding this comment.
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
SolverContextpool 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.