Skip to content
1 change: 1 addition & 0 deletions benchmarks/filters/radius_outlier_removal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ BM_RadiusOutlierRemoval(benchmark::State& state, const std::string& file)
ror.setInputCloud(cloud);
ror.setRadiusSearch(0.02);
ror.setMinNeighborsInRadius(14);
ror.setNumberOfThreads(1);

pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_voxelized(
new pcl::PointCloud<pcl::PointXYZ>);
Expand Down
7 changes: 7 additions & 0 deletions common/include/pcl/impl/pcl_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ pcl::PCLBase<PointT>::initCompute ()
for (auto i = indices_size; i < indices_->size (); ++i) { (*indices_)[i] = i; }
}

// Set the number of threads
#ifdef _OPENMP
num_threads_ = num_threads_ != 0 ? num_threads_ : omp_get_num_procs();
#else
num_threads_ = 1;
#endif

return (true);
}

Expand Down
11 changes: 11 additions & 0 deletions common/include/pcl/pcl_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ namespace pcl
/** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
bool fake_indices_;

/**
* @brief Number of threads used if the algorithm supports parallelization
*/
unsigned int num_threads_{0};

/** \brief This method should get called before starting the actual computation.
*
* Internally, initCompute() does the following:
Expand Down Expand Up @@ -233,6 +238,7 @@ namespace pcl
/** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
bool fake_indices_;


/** \brief The size of each individual field. */
std::vector<uindex_t> field_sizes_;

Expand All @@ -242,6 +248,11 @@ namespace pcl
/** \brief The desired x-y-z field names. */
std::string x_field_name_, y_field_name_, z_field_name_;

/**
* @brief Number of threads used during filtering
*/
unsigned int num_threads_{0};

bool initCompute ();
bool deinitCompute ();
public:
Expand Down
7 changes: 7 additions & 0 deletions common/src/pcl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ pcl::PCLBase<pcl::PCLPointCloud2>::initCompute ()
std::iota(indices_->begin () + indices_size, indices_->end (), indices_size);
}

// Set the number of threads
#ifdef _OPENMP
num_threads_ = num_threads_ != 0 ? num_threads_ : omp_get_num_procs();
#else
num_threads_ = 1;
#endif

return (true);
}

Expand Down
16 changes: 8 additions & 8 deletions features/include/pcl/features/fpfh_omp.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,23 @@ namespace pcl
using PointCloudOut = typename Feature<PointInT, PointOutT>::PointCloudOut;

/** \brief Initialize the scheduler and set the number of threads to use.
* \param[in] nr_threads the number of hardware threads to use (0 sets the value back to automatic)
* \param[in] num_threads the number of hardware threads to use (0 sets the value back to automatic)
*/
FPFHEstimationOMP (unsigned int nr_threads = 0)
FPFHEstimationOMP (unsigned int num_threads = 0)
{
feature_name_ = "FPFHEstimationOMP";

setNumberOfThreads(nr_threads);
setNumberOfThreads(num_threads);
}

/** \brief Initialize the scheduler and set the number of threads to use.
* \param[in] nr_threads the number of hardware threads to use (0 sets the value back to automatic)
* \param[in] num_threads the number of hardware threads to use (0 sets the value back to automatic)
*/
void
setNumberOfThreads (unsigned int nr_threads = 0);
setNumberOfThreads (unsigned int num_threads = 0);

protected:
using PCLBase<PointInT>::num_threads_;

private:
/** \brief Estimate the Fast Point Feature Histograms (FPFH) descriptors at a set of points given by
Expand All @@ -119,9 +122,6 @@ namespace pcl
public:
/** \brief The number of subdivisions for each angular feature interval. */
int nr_bins_f1_{11}, nr_bins_f2_{11}, nr_bins_f3_{11};
private:
/** \brief The number of threads the scheduler should use. */
unsigned int threads_;
};
}

Expand Down
16 changes: 8 additions & 8 deletions features/include/pcl/features/impl/fpfh_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointInT, typename PointNT, typename PointOutT> void
pcl::FPFHEstimationOMP<PointInT, PointNT, PointOutT>::setNumberOfThreads (unsigned int nr_threads)
pcl::FPFHEstimationOMP<PointInT, PointNT, PointOutT>::setNumberOfThreads (unsigned int num_threads)
{
if (nr_threads == 0)
#ifdef _OPENMP
threads_ = omp_get_num_procs();
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
#else
threads_ = 1;
if (num_threads_ != 1) {
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
num_threads_ = 1;
}
#endif
else
threads_ = nr_threads;
}

//////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -112,7 +112,7 @@ pcl::FPFHEstimationOMP<PointInT, PointNT, PointOutT>::computeFeature (PointCloud
default(none) \
shared(spfh_hist_lookup, spfh_indices_vec) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_)
num_threads(num_threads_)
for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t> (spfh_indices_vec.size ()); ++i)
{
// Get the next point index
Expand Down Expand Up @@ -141,7 +141,7 @@ pcl::FPFHEstimationOMP<PointInT, PointNT, PointOutT>::computeFeature (PointCloud
default(none) \
shared(nr_bins, output, spfh_hist_lookup) \
firstprivate(nn_dists, nn_indices) \
num_threads(threads_)
num_threads(num_threads_)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
// Find the indices of point idx's neighbors...
Expand Down
11 changes: 2 additions & 9 deletions features/include/pcl/features/impl/intensity_gradient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,14 @@ pcl::IntensityGradientEstimation<PointInT, PointNT, PointOutT, IntensitySelector
std::vector<float> nn_dists (k_);
output.is_dense = true;

#ifdef _OPENMP
if (threads_ == 0) {
threads_ = omp_get_num_procs();
PCL_DEBUG ("[pcl::IntensityGradientEstimation::computeFeature] Setting number of threads to %u.\n", threads_);
}
#endif // _OPENMP

// If the data is dense, we don't need to check for NaN
if (surface_->is_dense)
{
#pragma omp parallel for \
default(none) \
shared(output) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_)
num_threads(num_threads_)
// Iterating over the entire index vector
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
Expand Down Expand Up @@ -203,7 +196,7 @@ pcl::IntensityGradientEstimation<PointInT, PointNT, PointOutT, IntensitySelector
default(none) \
shared(output) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_)
num_threads(num_threads_)
// Iterating over the entire index vector
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
Expand Down
21 changes: 9 additions & 12 deletions features/include/pcl/features/impl/normal_3d_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,16 @@

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointInT, typename PointOutT> void
pcl::NormalEstimationOMP<PointInT, PointOutT>::setNumberOfThreads (unsigned int nr_threads)
pcl::NormalEstimationOMP<PointInT, PointOutT>::setNumberOfThreads (unsigned int num_threads)
{
#ifdef _OPENMP
if (nr_threads == 0)
threads_ = omp_get_num_procs();
else
threads_ = nr_threads;
PCL_DEBUG ("[pcl::NormalEstimationOMP::setNumberOfThreads] Setting number of threads to %u.\n", threads_);
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
#else
threads_ = 1;
if (nr_threads != 1)
PCL_WARN ("[pcl::NormalEstimationOMP::setNumberOfThreads] Parallelization is requested, but OpenMP is not available! Continuing without parallelization.\n");
#endif // _OPENMP
if (num_threads_ != 1) {
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
num_threads_ = 1;
}
#endif
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -77,7 +74,7 @@ pcl::NormalEstimationOMP<PointInT, PointOutT>::computeFeature (PointCloudOut &ou
default(none) \
shared(output) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_) \
num_threads(num_threads_) \
schedule(dynamic, chunk_size_)
// Iterating over the entire index vector
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
Expand Down Expand Up @@ -107,7 +104,7 @@ pcl::NormalEstimationOMP<PointInT, PointOutT>::computeFeature (PointCloudOut &ou
default(none) \
shared(output) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_) \
num_threads(num_threads_) \
schedule(dynamic, chunk_size_)
// Iterating over the entire index vector
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
Expand Down
21 changes: 9 additions & 12 deletions features/include/pcl/features/impl/principal_curvatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,16 @@

///////////////////////////////////////////////////////////////////////////////////////////
template <typename PointInT, typename PointNT, typename PointOutT> void
pcl::PrincipalCurvaturesEstimation<PointInT, PointNT, PointOutT>::setNumberOfThreads (unsigned int nr_threads)
pcl::PrincipalCurvaturesEstimation<PointInT, PointNT, PointOutT>::setNumberOfThreads (unsigned int num_threads)
{
#ifdef _OPENMP
if (nr_threads == 0)
threads_ = omp_get_num_procs();
else
threads_ = nr_threads;
PCL_DEBUG ("[pcl::PrincipalCurvaturesEstimation::setNumberOfThreads] Setting number of threads to %u.\n", threads_);
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
#else
threads_ = 1;
if (nr_threads != 1)
PCL_WARN ("[pcl::PrincipalCurvaturesEstimation::setNumberOfThreads] Parallelization is requested, but OpenMP is not available! Continuing without parallelization.\n");
#endif // _OPENMP
if (num_threads_ != 1) {
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
num_threads_ = 1;
}
#endif
}

//////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -142,7 +139,7 @@ pcl::PrincipalCurvaturesEstimation<PointInT, PointNT, PointOutT>::computeFeature
default(none) \
shared(output) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_) \
num_threads(num_threads_) \
schedule(dynamic, chunk_size_)
// Iterating over the entire index vector
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
Expand All @@ -167,7 +164,7 @@ pcl::PrincipalCurvaturesEstimation<PointInT, PointNT, PointOutT>::computeFeature
default(none) \
shared(output) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_) \
num_threads(num_threads_) \
schedule(dynamic, chunk_size_)
// Iterating over the entire index vector
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
Expand Down
14 changes: 7 additions & 7 deletions features/include/pcl/features/impl/shot_lrf_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@

//////////////////////////////////////////////////////////////////////////////////////////////
template<typename PointInT, typename PointOutT> void
pcl::SHOTLocalReferenceFrameEstimationOMP<PointInT, PointOutT>::setNumberOfThreads (unsigned int nr_threads)
pcl::SHOTLocalReferenceFrameEstimationOMP<PointInT, PointOutT>::setNumberOfThreads (unsigned int num_threads)
{
if (nr_threads == 0)
#ifdef _OPENMP
threads_ = omp_get_num_procs();
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
#else
threads_ = 1;
if (num_threads_ != 1) {
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
num_threads_ = 1;
}
#endif
else
threads_ = nr_threads;
}

//////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -74,7 +74,7 @@ pcl::SHOTLocalReferenceFrameEstimationOMP<PointInT, PointOutT>::computeFeature (
#pragma omp parallel for \
default(none) \
shared(output) \
num_threads(threads_) \
num_threads(num_threads_) \
schedule(dynamic, 64)
for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t> (indices_->size ()); ++i)
{
Expand Down
32 changes: 16 additions & 16 deletions features/include/pcl/features/impl/shot_omp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pcl::SHOTEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::initCompute ()
lrf_estimator->setRadiusSearch ((lrf_radius_ > 0 ? lrf_radius_ : search_radius_));
lrf_estimator->setInputCloud (input_);
lrf_estimator->setIndices (indices_);
lrf_estimator->setNumberOfThreads(threads_);
lrf_estimator->setNumberOfThreads(num_threads_);

if (!fake_surface_)
lrf_estimator->setSearchSurface(surface_);
Expand Down Expand Up @@ -107,7 +107,7 @@ pcl::SHOTColorEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::initCompute
lrf_estimator->setRadiusSearch ((lrf_radius_ > 0 ? lrf_radius_ : search_radius_));
lrf_estimator->setInputCloud (input_);
lrf_estimator->setIndices (indices_);
lrf_estimator->setNumberOfThreads(threads_);
lrf_estimator->setNumberOfThreads(num_threads_);

if (!fake_surface_)
lrf_estimator->setSearchSurface(surface_);
Expand All @@ -123,16 +123,16 @@ pcl::SHOTColorEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::initCompute

//////////////////////////////////////////////////////////////////////////////////////////////
template<typename PointInT, typename PointNT, typename PointOutT, typename PointRFT> void
pcl::SHOTEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::setNumberOfThreads (unsigned int nr_threads)
pcl::SHOTEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::setNumberOfThreads (unsigned int num_threads)
{
if (nr_threads == 0)
#ifdef _OPENMP
threads_ = omp_get_num_procs();
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
#else
threads_ = 1;
if (num_threads_ != 1) {
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
num_threads_ = 1;
}
#endif
else
threads_ = nr_threads;
}

//////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -153,7 +153,7 @@ pcl::SHOTEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::computeFeature (
#pragma omp parallel for \
default(none) \
shared(output) \
num_threads(threads_)
num_threads(num_threads_)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{

Expand Down Expand Up @@ -206,16 +206,16 @@ pcl::SHOTEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::computeFeature (

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointInT, typename PointNT, typename PointOutT, typename PointRFT> void
pcl::SHOTColorEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::setNumberOfThreads (unsigned int nr_threads)
pcl::SHOTColorEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::setNumberOfThreads (unsigned int num_threads)
{
if (nr_threads == 0)
#ifdef _OPENMP
threads_ = omp_get_num_procs();
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
#else
threads_ = 1;
if (num_threads_ != 1) {
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
num_threads_ = 1;
}
#endif
else
threads_ = nr_threads;
}

//////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -240,7 +240,7 @@ pcl::SHOTColorEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::computeFeat
#pragma omp parallel for \
default(none) \
shared(output) \
num_threads(threads_)
num_threads(num_threads_)
for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
{
Eigen::VectorXf shot;
Expand Down
Loading