|
46 | 46 |
|
47 | 47 | namespace pcl { |
48 | 48 |
|
| 49 | +template <typename PointSource, typename PointTarget, typename FeatureT> |
| 50 | +void |
| 51 | +SampleConsensusInitialAlignment<PointSource, PointTarget, FeatureT>::setNumberOfThreads( |
| 52 | + unsigned int nr_threads) |
| 53 | +{ |
| 54 | +#ifdef _OPENMP |
| 55 | + if (nr_threads == 0) |
| 56 | + threads_ = omp_get_num_procs(); |
| 57 | + else |
| 58 | + threads_ = nr_threads; |
| 59 | + PCL_DEBUG("[pcl::%s::setNumberOfThreads] Setting number of threads to %u.\n", |
| 60 | + getClassName().c_str(), |
| 61 | + threads_); |
| 62 | +#else |
| 63 | + threads_ = 1; |
| 64 | + if (nr_threads != 1) |
| 65 | + PCL_WARN("[pcl::%s::setNumberOfThreads] Parallelization is requested, but OpenMP " |
| 66 | + "is not available! Continuing without parallelization.\n", |
| 67 | + getClassName().c_str()); |
| 68 | +#endif // _OPENMP |
| 69 | +} |
| 70 | + |
49 | 71 | template <typename PointSource, typename PointTarget, typename FeatureT> |
50 | 72 | void |
51 | 73 | SampleConsensusInitialAlignment<PointSource, PointTarget, FeatureT>::setSourceFeatures( |
@@ -172,11 +194,11 @@ SampleConsensusInitialAlignment<PointSource, PointTarget, FeatureT>::computeErro |
172 | 194 | std::vector<float> nn_distance(1); |
173 | 195 |
|
174 | 196 | const ErrorFunctor& compute_error = *error_functor_; |
175 | | - const auto tree = tree_; |
| 197 | + const auto& tree = tree_; |
176 | 198 | float error = 0; |
177 | 199 |
|
178 | 200 | #pragma omp parallel for default(none) shared(cloud, tree, compute_error) \ |
179 | | - firstprivate(nn_index, nn_distance) reduction(+ : error) |
| 201 | + firstprivate(nn_index, nn_distance) reduction(+ : error) num_threads(threads_) |
180 | 202 | for (std::ptrdiff_t i = 0; i < static_cast<std::ptrdiff_t>(cloud.size()); ++i) { |
181 | 203 | const auto& point = cloud[static_cast<std::size_t>(i)]; |
182 | 204 | // Find the distance between point and its nearest neighbor in the target point |
|
0 commit comments