Skip to content

Make omp naming and functionality consistent. #6293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

larshg
Copy link
Contributor

@larshg larshg commented Jun 13, 2025

No description provided.

@larshg larshg requested a review from Copilot June 13, 2025 20:26
Copilot

This comment was marked as outdated.

///number of threads to be used, default 0 (auto)
unsigned int threads_{0};
///number of threads to be used
unsigned int num_threads_{1};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This defaulted to 0, ie. automatic number of threads, but now it defaults to 1 (as majority of the algorithms did) - but I guess we don't have any rule here, whether or not to include it?

@larshg larshg requested a review from Copilot June 13, 2025 20:44
Copilot

This comment was marked as outdated.

Copy link

@Copilot 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 standardizes the OpenMP thread‐count parameter name to num_threads, updates default values to 1, adds auto‐detection of hardware threads when requests are zero, and replaces all threads_ references in pragmas with num_threads_.

  • Renamed threads_ to num_threads_ and updated constructors/signatures.
  • Changed setNumberOfThreads logic to use num_threads and omp_get_num_procs().
  • Updated all OpenMP pragmas to use num_threads(num_threads_).

Reviewed Changes

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

Show a summary per file
File Description
filters/include/pcl/filters/pyramid.h Renamed and rewrote setNumberOfThreads, member renaming
filters/include/pcl/filters/impl/pyramid.hpp Updated OMP pragmas to use num_threads_
filters/include/pcl/filters/impl/fast_bilateral_omp.hpp Renamed parameter, updated logic and pragmas
filters/include/pcl/filters/impl/convolution_3d.hpp Updated OMP pragmas
filters/include/pcl/filters/impl/convolution.hpp Updated OMP pragmas
filters/include/pcl/filters/fast_bilateral_omp.h Renamed constructor and parameter
filters/include/pcl/filters/convolution_3d.h Renamed and rewrote setNumberOfThreads, member renaming
filters/include/pcl/filters/convolution.h Renamed and rewrote setNumberOfThreads, member renaming
features/include/pcl/features/shot_omp.h Renamed constructor and parameter, member renaming
features/include/pcl/features/shot_lrf_omp.h Renamed parameter and member
features/include/pcl/features/principal_curvatures.h Renamed constructor and parameter, member renaming
features/include/pcl/features/normal_3d_omp.h Renamed constructor and parameter, member renaming
features/include/pcl/features/intensity_gradient.h Renamed and rewrote setNumberOfThreads, member renaming
features/include/pcl/features/impl/shot_omp.hpp Updated calls and pragmas to use num_threads_
features/include/pcl/features/impl/shot_lrf_omp.hpp Updated parameter logic and pragmas
features/include/pcl/features/impl/principal_curvatures.hpp Updated setNumberOfThreads logic and pragmas
features/include/pcl/features/impl/normal_3d_omp.hpp Updated setNumberOfThreads logic and pragmas
features/include/pcl/features/impl/intensity_gradient.hpp Removed old detection logic, updated pragmas
features/include/pcl/features/impl/fpfh_omp.hpp Updated setNumberOfThreads logic and pragmas
features/include/pcl/features/fpfh_omp.h Renamed constructor and parameter, member renaming

#ifdef _OPENMP
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
#else
if (num_threads_ != 1) {
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

The warning condition checks num_threads_ (the member) rather than the requested num_threads parameter. It should warn when the user-requested num_threads is not 1.

Suggested change
if (num_threads_ != 1) {
if (num_threads != 1) {

Copilot uses AI. Check for mistakes.

@@ -155,7 +165,7 @@ namespace pcl
/// Threshold distance between adjacent points
float threshold_{0.01f};
/// \brief number of threads
unsigned int threads_{0};
unsigned int num_threads_{1};
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

Defaulting num_threads_ to 1 changes the previous auto-detection behavior when setNumberOfThreads(0) was never called. Consider initializing to 0 or calling setNumberOfThreads(0) in the constructor to preserve auto-detect.

Suggested change
unsigned int num_threads_{1};
unsigned int num_threads_{0};

Copilot uses AI. Check for mistakes.

*/
inline void
setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
setNumberOfThreads(unsigned int num_threads = 0)
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

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

[nitpick] The setNumberOfThreads logic is duplicated across many classes. Consider extracting it into a shared helper or macro to reduce code repetition and ease future updates.

Copilot uses AI. Check for mistakes.

@larshg larshg added the changelog: behavior change Meta-information for changelog generation label Jun 13, 2025
@larshg larshg requested a review from mvieth June 13, 2025 21:33
@larshg larshg force-pushed the fixomp branch 4 times, most recently from b054dd8 to 808f253 Compare June 14, 2025 09:19
@mvieth
Copy link
Member

mvieth commented Jun 14, 2025

An idea: how about, instead of having unsigned int num_threads_{1}; in so many classes, we move that to PCLBase? That would have the additional benefit that there is no ABI break every time parallelization is added to a class (like in the two recent PRs).

As a second step, we could then discuss also moving setNumberOfThreads to PCLBase (to reduce code duplication), however that would make it less clear which classes actually use this setting.

@larshg
Copy link
Contributor Author

larshg commented Jun 16, 2025

An idea: how about, instead of having unsigned int num_threads_{1}; in so many classes, we move that to PCLBase? That would have the additional benefit that there is no ABI break every time parallelization is added to a class (like in the two recent PRs).

As a second step, we could then discuss also moving setNumberOfThreads to PCLBase (to reduce code duplication), however that would make it less clear which classes actually use this setting.

Yeah, It seems PCLBase is used for all algorithms, so could make sense. I'm not sure how we should do it with setNumberOfThreads. Not sure if it its enough, just documenting, that not all classes make use of the set value.

@larshg
Copy link
Contributor Author

larshg commented Jun 16, 2025

Should we default to using omp_get_num_procs() threads instead of 1 - I would expect code to be multithreaded by default 😄

@mvieth
Copy link
Member

mvieth commented Jun 17, 2025

I'm not sure how we should do it with setNumberOfThreads. Not sure if it its enough, just documenting, that not all classes make use of the set value.

I am also fine with setNumberOfThreads staying in each parallelized class.

Should we default to using omp_get_num_procs() threads instead of 1 - I would expect code to be multithreaded by default 😄

Sounds good to me. How are you planning to do that? Calling setNumberOfThreads(0) in each constructor?

@larshg
Copy link
Contributor Author

larshg commented Jun 17, 2025

Should SampleConsensus inherit from PCLBase as well?

The I/O Imagegrabber also has parallelizing, but should they also inherit from PCLBase?
The Brieft from PCLBase:
PCL base class. Implements methods that are used by most PCL algorithms.

So I guess I/O shouldn't, but SampleConsesus could(Should)?

@larshg larshg force-pushed the fixomp branch 4 times, most recently from 5a216b8 to 9679064 Compare June 17, 2025 14:58
@mvieth
Copy link
Member

mvieth commented Jun 17, 2025

Should SampleConsensus inherit from PCLBase as well?

The I/O Imagegrabber also has parallelizing, but should they also inherit from PCLBase? The Brieft from PCLBase: PCL base class. Implements methods that are used by most PCL algorithms.

So I guess I/O shouldn't, but SampleConsesus could(Should)?

I think I would not change any inheritance. SampleConsensus and the image grabber can then simply keep their own num_threads_ member.

@larshg larshg force-pushed the fixomp branch 4 times, most recently from c072a2f to fb4af32 Compare June 19, 2025 07:30
@larshg larshg added this to the pcl-1.16.0 milestone Jun 19, 2025
@larshg larshg force-pushed the fixomp branch 2 times, most recently from b225008 to 656b4eb Compare June 19, 2025 10:38
larshg added 2 commits June 19, 2025 16:29
Set number of threads using omp_get_num_procs in initCompute.
@larshg larshg force-pushed the fixomp branch 2 times, most recently from ad60cbf to d1f3bcf Compare June 19, 2025 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: behavior change Meta-information for changelog generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants