Skip to content

registration: parallelize SAC-IA error metric with OpenMP#6431

Open
zeel2104 wants to merge 2 commits intoPointCloudLibrary:masterfrom
zeel2104:sac-ia-openmp-6429
Open

registration: parallelize SAC-IA error metric with OpenMP#6431
zeel2104 wants to merge 2 commits intoPointCloudLibrary:masterfrom
zeel2104:sac-ia-openmp-6429

Conversation

@zeel2104
Copy link
Copy Markdown

Summary

This PR parallelizes the error accumulation loop in SampleConsensusInitialAlignment::computeErrorMetric() using OpenMP.

The change uses an OpenMP parallel for with a reduction(+ : error) and thread-local nearest-neighbor buffers via firstprivate(...), so the accumulated registration error can be computed in parallel while preserving the original behavior.

Changes

  • parallelized the per-point loop in registration/include/pcl/registration/impl/ia_ransac.hpp
  • added OpenMP reduction for the error accumulator
  • kept nearest-neighbor index/distance buffers thread-local inside the parallel region

Validation

Built and ran the existing SAC-IA registration test locally on Windows/MSVC:

cmake --build D:\pcl\build --config Release --target test_sac_ia
ctest --test-dir D:\pcl\build\test -C Release -R sac_ia --output-on-failure

@mvieth mvieth added changelog: new feature Meta-information for changelog generation module: registration labels Apr 22, 2026
Copy link
Copy Markdown
Member

@mvieth mvieth left a comment

Choose a reason for hiding this comment

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

Thank you for the pull request, I have two small comments.

std::vector<float> nn_distance(1);

const ErrorFunctor& compute_error = *error_functor_;
const auto tree = tree_;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const auto tree = tree_;
const auto& tree = tree_;

I believe a reference would be a good choice here.


for (const auto& point : cloud) {
#pragma omp parallel for default(none) shared(cloud, tree, compute_error) \
firstprivate(nn_index, nn_distance) reduction(+ : error)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
firstprivate(nn_index, nn_distance) reduction(+ : error)
firstprivate(nn_index, nn_distance) reduction(+ : error) num_threads(threads_)

Please add the option to easily adapt the number of threads via setNumberOfThreads, see https://github.com/PointCloudLibrary/pcl/blob/master/features/include/pcl/features/impl/normal_3d_omp.hpp#L48 and https://github.com/PointCloudLibrary/pcl/blob/master/features/include/pcl/features/normal_3d_omp.h (but no need to also add chunk_size -- the default schedule is fine for now).

@zeel2104
Copy link
Copy Markdown
Author

@mvieth
Addressed both comments:

  • changed const auto tree = tree_; to const auto& tree = tree_;
  • added setNumberOfThreads() / threads_ and wired num_threads(threads_) into the SAC-IA OpenMP loop

Validation:

  • cmake --build build --config Release --target test_sac_ia
  • ctest --test-dir build/test -C Release -R sac_ia --output-on-failure
  • cmake --build build --config Release --target pcl_registration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: new feature Meta-information for changelog generation module: registration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[registration] Parallelize SampleConsensusInitialAlignment with OpenMP

2 participants