kzampog / cilantro

A lean C++ library for working with point cloud data
MIT License
1.02k stars 207 forks source link

compiling errors regarding to omp #12

Closed etudemin closed 5 years ago

etudemin commented 5 years ago

Hi kzampog,

I am trying to compile the latest version of the project.

It works well when I compile the branch released before 373cf70 (Various improvements and additions).

But unfortunately when I compile the branch 373cf70, there are some errors.

It seems like the codes added in include/cilantro/rigid_registration_utilities.hpp would trigger some error:

#pragma omp declare reduction (+: Eigen::Matrix<ScalarT,6,6>: omp_out = omp_out + omp_in) initializer(omp_priv = Eigen::Matrix<ScalarT,6,6>::Zero())
#pragma omp declare reduction (+: Eigen::Matrix<ScalarT,6,1>: omp_out = omp_out + omp_in) initializer(omp_priv = Eigen::Matrix<ScalarT,6,1>::Zero())

The errors are shown as follows:

In file included from /home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/icp_rigid_point_to_point.hpp:4:0,
                 from /home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/icp_common_instances.hpp:6,
                 from /home/yogurtsea/all_libs/cilantro_0372204/examples/non_rigid_icp.cpp:1:
/home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/rigid_registration_utilities.hpp: In function ‘bool cilantro::estimateRigidTransformCombinedMetric3(cilantro::ConstVectorSetMatrixMap<PointT, 3l>&, cilantro::ConstVectorSetMatrixMap<PointT, 3l>&, cilantro::ConstVectorSetMatrixMap<PointT, 3l>&, cilantro::CorrespondenceSet<typename PointCorrWeightEvaluatorT::InputScalar>&, ScalarT, cilantro::CorrespondenceSet<typename PlaneCorrWeightEvaluatorT::InputScalar>&, ScalarT, cilantro::RigidTransformation<PointT, 3l>&, std::size_t, ScalarT, const PointCorrWeightEvaluatorT&, const PlaneCorrWeightEvaluatorT&)’:
/home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/rigid_registration_utilities.hpp:80:61: error: default argument for template parameter for class enclosing ‘void cilantro::omp declare reduction operator+(Eigen::Matrix<ScalarT, 6, 6>&)’
 #pragma omp declare reduction (+: Eigen::Matrix<ScalarT,6,6>: omp_out = omp_out + omp_in) initializer(omp_priv = Eigen::Matrix<ScalarT,6,6>::Zero())
                                                             ^
In file included from /home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/ransac_rigid_transformation_estimator.hpp:4:0,
                 from /home/yogurtsea/all_libs/cilantro_0372204/examples/ransac_rigid_transformation_estimator.cpp:2:
/home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/rigid_registration_utilities.hpp: In function ‘bool cilantro::estimateRigidTransformCombinedMetric3(cilantro::ConstVectorSetMatrixMap<PointT, 3l>&, cilantro::ConstVectorSetMatrixMap<PointT, 3l>&, cilantro::ConstVectorSetMatrixMap<PointT, 3l>&, cilantro::CorrespondenceSet<typename PointCorrWeightEvaluatorT::InputScalar>&, ScalarT, cilantro::CorrespondenceSet<typename PlaneCorrWeightEvaluatorT::InputScalar>&, ScalarT, cilantro::RigidTransformation<PointT, 3l>&, std::size_t, ScalarT, const PointCorrWeightEvaluatorT&, const PlaneCorrWeightEvaluatorT&)’:
/home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/rigid_registration_utilities.hpp:80:61: error: default argument for template parameter for class enclosing ‘void cilantro::omp declare reduction operator+(Eigen::Matrix<ScalarT, 6, 6>&)’
 #pragma omp declare reduction (+: Eigen::Matrix<ScalarT,6,6>: omp_out = omp_out + omp_in) initializer(omp_priv = Eigen::Matrix<ScalarT,6,6>::Zero())
                                                             ^
In file included from /home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/icp_rigid_point_to_point.hpp:4:0,
                 from /home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/icp_common_instances.hpp:6,
                 from /home/yogurtsea/all_libs/cilantro_0372204/examples/fusion.cpp:5:
/home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/rigid_registration_utilities.hpp: In function ‘bool cilantro::estimateRigidTransformCombinedMetric3(cilantro::ConstVectorSetMatrixMap<PointT, 3l>&, cilantro::ConstVectorSetMatrixMap<PointT, 3l>&, cilantro::ConstVectorSetMatrixMap<PointT, 3l>&, cilantro::CorrespondenceSet<typename PointCorrWeightEvaluatorT::InputScalar>&, ScalarT, cilantro::CorrespondenceSet<typename PlaneCorrWeightEvaluatorT::InputScalar>&, ScalarT, cilantro::RigidTransformation<PointT, 3l>&, std::size_t, ScalarT, const PointCorrWeightEvaluatorT&, const PlaneCorrWeightEvaluatorT&)’:
/home/yogurtsea/all_libs/cilantro_0372204/include/cilantro/rigid_registration_utilities.hpp:80:61: error: default argument for template parameter for class enclosing ‘void cilantro::omp declare reduction operator+(Eigen::Matrix<ScalarT, 6, 6>&)’
 #pragma omp declare reduction (+: Eigen::Matrix<ScalarT,6,6>: omp_out = omp_out + omp_in) initializer(omp_priv = Eigen::Matrix<ScalarT,6,6>::Zero())

Is there any hint of how to solve this issue?

Thanks for your help and kind reply!

kzampog commented 5 years ago

Hi!

Interesting -- this does not seem to happen with gcc-6, gcc-7 or clang-6. It does happen with gcc-5 though!

If upgrading to gcc-6 or newer is not an option, simply separating function definitions from declarations (with no default template arguments in the former) seems to fix it. In the commit you mentioned (https://github.com/kzampog/cilantro/commit/373cf7048f493e8dfeda6449b39350efc29d838d), the culprit is estimateRigidTransformCombinedMetric3. Writing the declaration separately:

template <typename ScalarT, class PointCorrWeightEvaluatorT = UnityWeightEvaluator<ScalarT,ScalarT>, class PlaneCorrWeightEvaluatorT = UnityWeightEvaluator<ScalarT,ScalarT>>
bool estimateRigidTransformCombinedMetric3(const ConstVectorSetMatrixMap<ScalarT,3> &dst_p,
                                           const ConstVectorSetMatrixMap<ScalarT,3> &dst_n,
                                           const ConstVectorSetMatrixMap<ScalarT,3> &src_p,
                                           const CorrespondenceSet<typename PointCorrWeightEvaluatorT::InputScalar> &point_to_point_correspondences,
                                           ScalarT point_to_point_weight,
                                           const CorrespondenceSet<typename PlaneCorrWeightEvaluatorT::InputScalar> &point_to_plane_correspondences,
                                           ScalarT point_to_plane_weight,
                                           RigidTransformation<ScalarT,3> &tform,
                                           size_t max_iter = 1,
                                           ScalarT convergence_tol = (ScalarT)1e-5,
                                           const PointCorrWeightEvaluatorT &point_corr_evaluator = PointCorrWeightEvaluatorT(),
                                           const PlaneCorrWeightEvaluatorT &plane_corr_evaluator = PlaneCorrWeightEvaluatorT());

followed by the definition:

template <typename ScalarT, class PointCorrWeightEvaluatorT, class PlaneCorrWeightEvaluatorT>
bool estimateRigidTransformCombinedMetric3(const ConstVectorSetMatrixMap<ScalarT,3> &dst_p,
                                           const ConstVectorSetMatrixMap<ScalarT,3> &dst_n,
                                           const ConstVectorSetMatrixMap<ScalarT,3> &src_p,
                                           const CorrespondenceSet<typename PointCorrWeightEvaluatorT::InputScalar> &point_to_point_correspondences,
                                           ScalarT point_to_point_weight,
                                           const CorrespondenceSet<typename PlaneCorrWeightEvaluatorT::InputScalar> &point_to_plane_correspondences,
                                           ScalarT point_to_plane_weight,
                                           RigidTransformation<ScalarT,3> &tform,
                                           size_t max_iter,
                                           ScalarT convergence_tol,
                                           const PointCorrWeightEvaluatorT &point_corr_evaluator,
                                           const PlaneCorrWeightEvaluatorT &plane_corr_evaluator)
{
// ...
// rest of the body here

should fix the error with gcc-5. Simply commenting out all OpenMP #pragmas should also solve the compilation issue, but you would lose some performance in that case.

Since there are more custom reductions in more recent commits, I will try to investigate more and push a proper solution for gcc-5 soon!

etudemin commented 5 years ago

Hi kzampog,

I have followed your suggestions (separating function definitions from declarations / upgrading to gcc-6).

Both of the options can work, thank you very much!

kzampog commented 5 years ago

I applied a fix in the latest commit (https://github.com/kzampog/cilantro/commit/36d99293a91502399c068b9cdf9b8fa12766edab) -- it seems to do the trick with gcc-5.

Again, thank you for reporting this!

etudemin commented 5 years ago

Thank you very much. It can work on my computer (with gcc-5) now.