Skip to content

Commit 8752f29

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 8752f29

11 files changed

Lines changed: 32 additions & 26 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
}

filters/include/pcl/filters/impl/fast_bilateral_omp.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ pcl::FastBilateralFilterOMP<PointT>::setNumberOfThreads (unsigned int num_thread
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
}

io/src/image_grabber.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,8 @@ pcl::ImageGrabberBase::setNumberOfThreads (unsigned int num_threads)
10211021
impl_->num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
10221022
#else
10231023
if (num_threads_ != 1) {
1024-
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
1024+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
1025+
num_threads_ = 1;
10251026
}
10261027
#endif
10271028
}

keypoints/include/pcl/keypoints/impl/iss_3d.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ pcl::ISSKeypoint3D<PointInT, PointOutT, NormalT>::setNumberOfThreads (unsigned i
109109
num_threads_ = num_threads != 0 ? num_threads : omp_get_num_procs();
110110
#else
111111
if (num_threads_ != 1) {
112-
PCL_WARN("OpenMP is not available. Keeping number of threads unchanged at 1\n");
112+
PCL_WARN("OpenMP is not available. Setting number of threads to 1\n");
113+
num_threads_ = 1;
113114
}
114115
#endif
115116
}

0 commit comments

Comments
 (0)