Skip to content

Commit 5a216b8

Browse files
committed
Move num_threads_ to pcl_base.
Set number of threads using omp_get_num_procs in initCompute.
1 parent afafe4f commit 5a216b8

File tree

33 files changed

+36
-85
lines changed

33 files changed

+36
-85
lines changed

benchmarks/filters/radius_outlier_removal.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ BM_RadiusOutlierRemoval(benchmark::State& state, const std::string& file)
1515
ror.setInputCloud(cloud);
1616
ror.setRadiusSearch(0.02);
1717
ror.setMinNeighborsInRadius(14);
18+
ror.setNumberOfThreads(1);
1819

1920
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_voxelized(
2021
new pcl::PointCloud<pcl::PointXYZ>);

common/include/pcl/impl/pcl_base.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ pcl::PCLBase<PointT>::initCompute ()
167167
for (auto i = indices_size; i < indices_->size (); ++i) { (*indices_)[i] = i; }
168168
}
169169

170+
// Set the number of threads
171+
#ifdef _OPENMP
172+
num_threads_ = num_threads_ != 0 ? num_threads_ : omp_get_num_procs();
173+
#else
174+
if (num_threads_ != 1) {
175+
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
176+
}
177+
#endif
178+
170179
return (true);
171180
}
172181

common/include/pcl/pcl_base.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ namespace pcl
155155
/** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
156156
bool fake_indices_;
157157

158+
/**
159+
* @brief Number of threads used if the algorithm supports parallelization
160+
*/
161+
unsigned int num_threads_{0};
162+
158163
/** \brief This method should get called before starting the actual computation.
159164
*
160165
* Internally, initCompute() does the following:
@@ -233,6 +238,11 @@ namespace pcl
233238
/** \brief If no set of indices are given, we construct a set of fake indices that mimic the input PointCloud. */
234239
bool fake_indices_;
235240

241+
/**
242+
* @brief Number of threads used during filtering
243+
*/
244+
unsigned int num_threads_{0};
245+
236246
/** \brief The size of each individual field. */
237247
std::vector<uindex_t> field_sizes_;
238248

common/src/pcl_base.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ pcl::PCLBase<pcl::PCLPointCloud2>::initCompute ()
130130
std::iota(indices_->begin () + indices_size, indices_->end (), indices_size);
131131
}
132132

133+
// Set the number of threads
134+
#ifdef _OPENMP
135+
num_threads_ = num_threads_ != 0 ? num_threads_ : omp_get_num_procs();
136+
#else
137+
if (num_threads_ != 1) {
138+
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
139+
}
140+
#endif
141+
133142
return (true);
134143
}
135144

features/include/pcl/features/fpfh_omp.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ namespace pcl
119119
public:
120120
/** \brief The number of subdivisions for each angular feature interval. */
121121
int nr_bins_f1_{11}, nr_bins_f2_{11}, nr_bins_f3_{11};
122-
private:
123-
/** \brief The number of threads the scheduler should use. */
124-
unsigned int num_threads_{1};
125122
};
126123
}
127124

features/include/pcl/features/intensity_gradient.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ namespace pcl
117117
protected:
118118
///intensity field accessor structure
119119
IntensitySelectorT intensity_;
120-
///number of threads to be used
121-
unsigned int num_threads_{1};
122120
};
123121
}
124122

features/include/pcl/features/normal_3d_omp.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ namespace pcl
8888
setNumberOfThreads (unsigned int num_threads = 0);
8989

9090
protected:
91-
/** \brief The number of threads the scheduler should use. */
92-
unsigned int num_threads_{1};
93-
9491
/** \brief Chunk size for (dynamic) scheduling. */
9592
int chunk_size_;
9693
private:

features/include/pcl/features/principal_curvatures.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ namespace pcl
111111
setNumberOfThreads (unsigned int num_threads = 0);
112112

113113
protected:
114-
/** \brief The number of threads the scheduler should use. */
115-
unsigned int num_threads_{1};
116-
117114
/** \brief Chunk size for (dynamic) scheduling. */
118115
int chunk_size_;
119116

features/include/pcl/features/shot_lrf_omp.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ namespace pcl
103103
*/
104104
void
105105
computeFeature (PointCloudOut &output) override;
106-
107-
/** \brief The number of threads the scheduler should use. */
108-
unsigned int num_threads_{1};
109-
110106
};
111107
}
112108

features/include/pcl/features/shot_omp.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ namespace pcl
119119
/** \brief This method should get called before starting the actual computation. */
120120
bool
121121
initCompute () override;
122-
123-
/** \brief The number of threads the scheduler should use. */
124-
unsigned int num_threads_{1};
125122
};
126123

127124
/** \brief SHOTColorEstimationOMP estimates the Signature of Histograms of OrienTations (SHOT) descriptor for a given point cloud dataset
@@ -204,9 +201,6 @@ namespace pcl
204201
/** \brief This method should get called before starting the actual computation. */
205202
bool
206203
initCompute () override;
207-
208-
/** \brief The number of threads the scheduler should use. */
209-
unsigned int num_threads_{1};
210204
};
211205

212206
}

0 commit comments

Comments
 (0)