Skip to content

Replace maybe_parallel_for with TBB APIs#214

Merged
zfergus merged 3 commits intomainfrom
remove-maybe-parallel
Feb 7, 2026
Merged

Replace maybe_parallel_for with TBB APIs#214
zfergus merged 3 commits intomainfrom
remove-maybe-parallel

Conversation

@zfergus
Copy link
Member

@zfergus zfergus commented Feb 7, 2026

Description

Remove the maybe_parallel_for wrapper and associated headers. Use tbb::parallel_for and tbb::enumerable_thread_specific directly, and update CMake and config to stop defining IPC_TOOLKIT_WITH_TBB

Remove the maybe_parallel_for wrapper and associated headers.
Use tbb::parallel_for and tbb::enumerable_thread_specific directly,
and update CMake and config to stop defining IPC_TOOLKIT_WITH_TBB
Copilot AI review requested due to automatic review settings February 7, 2026 18:28
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

This PR removes the maybe_parallel_for abstraction and the IPC_TOOLKIT_WITH_TBB macro, switching affected call sites to use OneTBB APIs (tbb::parallel_for, tbb::blocked_range, tbb::enumerable_thread_specific) directly.

Changes:

  • Deleted maybe_parallel_for headers/implementation and removed them from the utils CMake source list.
  • Updated smooth contact and potential implementations to use TBB primitives directly for parallel loops and thread-local storage.
  • Removed the IPC_TOOLKIT_WITH_TBB define from the generated config header template.

Reviewed changes

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

Show a summary per file
File Description
src/ipc/utils/maybe_parallel_for.tpp Removes the conditional TBB wrapper implementation.
src/ipc/utils/maybe_parallel_for.hpp Removes the public wrapper API and thread-storage helpers.
src/ipc/utils/matrix_cache.cpp Drops the now-unused maybe_parallel_for include.
src/ipc/utils/CMakeLists.txt Stops compiling/adding deleted maybe_parallel_for sources.
src/ipc/smooth_contact/smooth_contact_potential.cpp Replaces wrapper usage with tbb::parallel_for + enumerable_thread_specific.
src/ipc/smooth_contact/smooth_collisions_builder.hpp Switches merge signatures to take tbb::enumerable_thread_specific directly.
src/ipc/smooth_contact/smooth_collisions_builder.cpp Updates merge definitions to match new TBB-based signatures.
src/ipc/smooth_contact/smooth_collisions.cpp Replaces wrapper parallel loops with direct TBB parallel_for ranges.
src/ipc/potentials/potential.cpp Replaces wrapper usage with direct TBB parallel_for + enumerable_thread_specific.
src/ipc/config.hpp.in Removes the IPC_TOOLKIT_WITH_TBB macro definition.
Comments suppressed due to low confidence (2)

src/ipc/smooth_contact/smooth_contact_potential.cpp:7

  • #include <tbb/combinable.h> appears unused in this translation unit (no tbb::combinable usage). Consider removing it to avoid unused-include warnings in stricter builds.
#include <tbb/blocked_range.h>
#include <tbb/combinable.h>
#include <tbb/enumerable_thread_specific.h>

src/ipc/smooth_contact/smooth_contact_potential.cpp:187

  • tbb::parallel_for(size_t(0), storages.size(), ...) uses a lambda parameter of type int. This can cause signed/unsigned warnings and becomes incorrect if the range ever exceeds INT_MAX. Use size_t (or the same index type as the range) for the lambda parameter and downstream indexing.
        tbb::parallel_for(size_t(0), storages.size(), [&](int i) {
            const SparseMatrixCache& cache =
                dynamic_cast<const SparseMatrixCache&>(*storages[i]->cache);
            int offset = offsets[i];

            std::copy(
                cache.entries().begin(), cache.entries().end(),
                triplets.begin() + offset);
            offset += cache.entries().size();

            if (cache.mat().nonZeros() > 0) {
                int count = 0;
                for (int k = 0; k < cache.mat().outerSize(); ++k) {
                    for (Eigen::SparseMatrix<double>::InnerIterator it(
                             cache.mat(), k);
                         it; ++it) {
                        assert(count < cache.mat().nonZeros());
                        triplets[offset + count++] = Eigen::Triplet<double>(
                            it.row(), it.col(), it.value());
                    }
                }
            }
        });

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

Comment on lines +171 to +173
tbb::parallel_for(
tbb::blocked_range<int>(0, candidates.ev_candidates.size()),
[&](const tbb::blocked_range<int>& r) {
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

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

tbb::blocked_range<int>(0, candidates.ev_candidates.size()) converts a size_t size to int, which can overflow for large candidate sets and may trigger signed/unsigned warnings. Prefer tbb::blocked_range<size_t> (and adjust the lambda/range types accordingly).

Copilot uses AI. Check for mistakes.
zfergus and others added 2 commits February 7, 2026 13:34
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@zfergus zfergus merged commit 8377ff7 into main Feb 7, 2026
12 checks passed
@zfergus zfergus deleted the remove-maybe-parallel branch February 7, 2026 18:57
@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.95%. Comparing base (6051c39) to head (e80c167).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #214      +/-   ##
==========================================
- Coverage   96.96%   96.95%   -0.01%     
==========================================
  Files         159      158       -1     
  Lines       24666    24659       -7     
  Branches      883      882       -1     
==========================================
- Hits        23917    23908       -9     
- Misses        749      751       +2     
Flag Coverage Δ
unittests 96.95% <100.00%> (-0.01%) ⬇️

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.

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.

1 participant