-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix vector initialization in NormalEstimationOMP
#3614
Fix vector initialization in NormalEstimationOMP
#3614
Conversation
The vectors nn_indices and nn_dists in NormalEstimationOMP::computeFeatures must be initialized to the correct size. They are initialized at the beginning of the function but the OpenMP parallel for loop basically generates a new pair of vectors for each thread. These vectors are initialized with the default constructor which means that they have zero size. To fix this I used 'firstprivate' for the vectors instead of 'private' this causes that the copy constructor is called instead of the default constructor.
👍 for As before, it'd be great if you can create a test which fails on OpenMP. I don't know if these issues are tested on the CI, but a test will be a good reason to look into enabling OpenMP on CI in some form |
I added the test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few minor aesthetic changes. LGTM otherwise
I also fixed the build for Ubuntu 16.04 where there was an error because of some unused variables. Why is the unused parameters warning only treated as an error in Ubuntu 16.04 but not in other builds? |
16.04 has Though I fear windows will be tough to enable the similar flag since the CI spews so much warnings. We might be missing some crucial flag there, due to MSVC's idiosyncrasies. |
All tests pass. Please reorganize the commits (squash, rebase as needed) and it's merge time 🚀 |
2107629
to
5e0d70c
Compare
NormalEstimationOMP
I created a custom pcl::Search class which I then used to do a normal estimation using NormalEstimationOMP. In the implementation of nearestKSearch in my custom class I assumed that k_indices and k_sqr_distances are initialized to the correct size because it says so in the documentation. When I then did the normal estimation the application would crash because I tried to index into an empty vector.
The problem was that the vectors nn_indices and nn_dists in NormalEstimationOMP::computeFeatures must be initialized to the correct size. They are initialized at the beginning of the function but the OpenMP parallel for loop basically generates a new pair of vectors for each thread. These vectors are initialized with the default constructor which means that they have zero size.
To fix this I used 'firstprivate' for the vectors instead of 'private' this causes that the copy constructor to be called instead of the default constructor.