My function is sorting a point cloud of 17000 points (approximately, it can fluctuate) to extract the relevant points in this one and store them in a vector. Everything works fine, but it's very slow. So I am trying to use openMp to parallelize the task but I'm getting a crash.
Here is the multi-threaded version which doesn't work:
void IntervalMapEstimator::extract_relevant_points_multithread(std::vector<Point3D>& relevant_points, std::vector<Point3D>& pointcloud, doubleIE cell_min_angle_sensor_rot, doubleIE cell_max_angle_sensor_rot)
{
#pragma omp parallel for shared( pointcloud, cell_min_angle_sensor_rot, cell_max_angle_sensor_rot)
for(int i = 0; i < pointcloud.size(); i++) {
//int numThread = omp_get_thread_num();
//std::cout << "numThread = " << numThread << std::endl;
// Check whether the cell is between the 2nd and 3rd quadrant (--> e.g. -170 to 170°)
if ( cell_min_angle_sensor_rot < 0 && cell_max_angle_sensor_rot >= 0 && abs(cell_min_angle_sensor_rot) > M_PI/2 && abs(cell_max_angle_sensor_rot) > M_PI/2) {
// Point must be smaller than the minimum angle and bigger than the max angle (e.g. min-angle: -1.5 max-angle: 1.5 point angle bigger than 1.5 or smaller than -1.5)
if ( pointcloud[i].pol_sensor_rot.phi <= cell_min_angle_sensor_rot || pointcloud[i].pol_sensor_rot.phi >= cell_max_angle_sensor_rot ) {
relevant_points.push_back(pointcloud[i]);
}
} else {
if (pointcloud[i].pol_sensor_rot.phi >= cell_min_angle_sensor_rot && pointcloud[i].pol_sensor_rot.phi <= cell_max_angle_sensor_rot ) {
relevant_points.push_back(pointcloud[i]);
}
}
}
}
And here the response i get on the output :
7fcc93737000-7fcc9374b000 r-xp 00012000 103:05 7078283 /lib/x86_64-linux-gnu/ld-2.23.so
7fcc938a3000-7fcc938f7000 rw-p 00000000 00:00 0
7fcc9391e000-7fcc9392c000 rw-p 00000000 00:00 0
7fcc93937000-7fcc93939000 rw-p 00000000 00:00 0
7fcc93947000-7fcc9394a000 rw-p 00000000 00:00 0
7fcc9394a000-7fcc9394b000 r--p 00025000 103:05 7078283 /lib/x86_64-linux-gnu/ld-2.23.so
7fcc9394b000-7fcc9394c000 rw-p 00026000 103:05 7078283 /lib/x86_64-linux-gnu/ld-2.23.so
7fcc9394c000-7fcc9394d000 rw-p 00000000 00:00 0
7fff20b58000-7fff20b7a000 rw-p 00000000 00:00 0 [stack]
7fff20bb8000-7fff20bbb000 r--p 00000000 00:00 0 [vvar]
7fff20bbb000-7fff20bbd000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
[interval_map-1] process has died [pid 12700, exit code -6, cmd /home/catkin_ws/SWC_INTERVAL_MAP/devel/lib/interval_map_test/interval_map_test __name:=interval_map __log:=/home/.ros/log/615acdf0-3714-11e8-bc07-9cebe84f847e/interval_map-1.log].
log file: /home/.ros/log/615acdf0-3714-11e8-bc07-9cebe84f847e/interval_map-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done
For now, my best guess is that there is a waiting list for looking at the value inside the vector of the point cloud or the push_back on the relevant_points vector, whose getting bigger and bigger and eventually exploding the stack. Does someone have any idea on the problem?