Skip to content

Commit eee3fe8

Browse files
committed
Set num_threads_ to 1 if OMP is not available. Some classes use the num_threads_ as indices into arrays, which would fail with value of 0.
1 parent a8cb261 commit eee3fe8

33 files changed

Lines changed: 81 additions & 66 deletions

File tree

common/include/pcl/impl/pcl_base.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,12 @@ 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
170+
// Set the number of threads
171+
#ifdef _OPENMP
172+
num_threads_ = num_threads_ != 0 ? num_threads_ : omp_get_num_procs();
173+
#else
174+
num_threads_ = 1;
175+
#endif
178176

179177
return (true);
180178
}

common/src/pcl_base.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,12 @@ 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
133+
// Set the number of threads
134+
#ifdef _OPENMP
135+
num_threads_ = num_threads_ != 0 ? num_threads_ : omp_get_num_procs();
136+
#else
137+
num_threads_ = 1;
138+
#endif
141139

142140
return (true);
143141
}

features/include/pcl/features/impl/fpfh_omp.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ pcl::FPFHEstimationOMP<PointInT, PointNT, PointOutT>::setNumberOfThreads (unsign
5555
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
5656
#else
5757
if (num_threads_ != 1) {
58-
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
58+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
59+
num_threads_ = 1;
5960
}
6061
#endif
6162
}

features/include/pcl/features/impl/normal_3d_omp.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ pcl::NormalEstimationOMP<PointInT, PointOutT>::setNumberOfThreads (unsigned int
5151
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
5252
#else
5353
if (num_threads_ != 1) {
54-
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
54+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
55+
num_threads_ = 1;
5556
}
5657
#endif
5758
}

features/include/pcl/features/impl/principal_curvatures.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ pcl::PrincipalCurvaturesEstimation<PointInT, PointNT, PointOutT>::setNumberOfThr
5353
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
5454
#else
5555
if (num_threads_ != 1) {
56-
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
56+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
57+
num_threads_ = 1;
5758
}
5859
#endif
5960
}

features/include/pcl/features/impl/shot_lrf_omp.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ pcl::SHOTLocalReferenceFrameEstimationOMP<PointInT, PointOutT>::setNumberOfThrea
5151
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
5252
#else
5353
if (num_threads_ != 1) {
54-
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
54+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
55+
num_threads_ = 1;
5556
}
5657
#endif
5758
}

features/include/pcl/features/impl/shot_omp.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ pcl::SHOTEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::setNumberOfThrea
129129
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
130130
#else
131131
if (num_threads_ != 1) {
132-
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
132+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
133+
num_threads_ = 1;
133134
}
134135
#endif
135136
}
@@ -211,7 +212,8 @@ pcl::SHOTColorEstimationOMP<PointInT, PointNT, PointOutT, PointRFT>::setNumberOf
211212
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
212213
#else
213214
if (num_threads_ != 1) {
214-
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
215+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
216+
num_threads_ = 1;
215217
}
216218
#endif
217219
}

features/include/pcl/features/intensity_gradient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ namespace pcl
8484
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
8585
#else
8686
if (num_threads_ != 1) {
87-
PCL_WARN(
88-
"OpenMP is not available. Keeping number of threads unchanged at 1\n");
87+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
88+
num_threads_ = 1;
8989
}
9090
#endif
9191
}

filters/include/pcl/filters/convolution.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ namespace pcl
130130
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
131131
#else
132132
if (num_threads_ != 1) {
133-
PCL_WARN(
134-
"OpenMP is not available. Keeping number of threads unchanged at 1\n");
133+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
134+
num_threads_ = 1;
135135
}
136136
#endif
137137
}

filters/include/pcl/filters/convolution_3d.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ namespace pcl
220220
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
221221
#else
222222
if (num_threads_ != 1) {
223-
PCL_WARN(
224-
"OpenMP is not available. Keeping number of threads unchanged at 1\n");
223+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
224+
num_threads_ = 1;
225225
}
226226
#endif
227227
}

0 commit comments

Comments
 (0)