Skip to content

Add setConcurrency method#422

Merged
Grufoony merged 9 commits intomainfrom
nthreads
Mar 10, 2026
Merged

Add setConcurrency method#422
Grufoony merged 9 commits intomainfrom
nthreads

Conversation

@Grufoony
Copy link
Collaborator

@Grufoony Grufoony commented Mar 9, 2026

No description provided.

static_cast<int>(maxConcurrency));
m_taskArena.initialize(maxConcurrency);
return;
}

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
static_cast<int>(maxConcurrency));
m_taskArena.initialize(maxConcurrency);
return;
}

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 10.4 rule Note

MISRA 10.4 rule
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a public API to configure TBB parallelism for DSF simulations, and wires it through to mobility evolution so runtime parallel work scales to the configured task arena.

Changes:

  • Add Dynamics::setConcurrency(std::size_t) to reconfigure the underlying tbb::task_arena.
  • Update RoadDynamics::evolve() to derive its partitioning from the task arena’s configured concurrency (instead of std::thread::hardware_concurrency()).
  • Expose setConcurrency on the Python bindings for FirstOrderDynamics.

Reviewed changes

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

File Description
src/dsf/mobility/RoadDynamics.hpp Uses task-arena concurrency to size TBB work partitioning in evolve().
src/dsf/bindings.cpp Exposes setConcurrency to Python (FirstOrderDynamics).
src/dsf/base/Dynamics.hpp Implements task-arena initialization via TBB defaults and adds setConcurrency().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1919 to +1920
const auto grainSize = static_cast<std::size_t>(
std::max(1., std::floor(static_cast<double>(numNodes) / n_threads)));
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

grainSize is now computed via floating-point division + floor and then cast back to std::size_t. This adds unnecessary complexity and can produce incorrect results for large numNodes due to loss of integer precision in double. Prefer pure integer arithmetic here (e.g., std::max<std::size_t>(1, numNodes / n_threads)), which matches the intent and avoids rounding issues.

Suggested change
const auto grainSize = static_cast<std::size_t>(
std::max(1., std::floor(static_cast<double>(numNodes) / n_threads)));
const auto grainSize = std::max<std::size_t>(1, numNodes / n_threads);

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.78%. Comparing base (f503d0f) to head (429976a).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #422      +/-   ##
==========================================
- Coverage   87.80%   87.78%   -0.03%     
==========================================
  Files          52       52              
  Lines        6208     6319     +111     
  Branches      689      701      +12     
==========================================
+ Hits         5451     5547      +96     
- Misses        738      753      +15     
  Partials       19       19              
Flag Coverage Δ
unittests 87.78% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Grufoony Grufoony merged commit 32b2c65 into main Mar 10, 2026
43 of 45 checks passed
@Grufoony Grufoony deleted the nthreads branch March 10, 2026 10:51
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