如何加到cmake里
include(FindOpenMP)
if(OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
else(OPENMP_FOUND)
message("ERROR: OpenMP could not be found.")
endif(OPENMP_FOUND)
# NanoGICP
add_library(nano_gicp STATIC
)
target_link_libraries(nano_gicp ${PCL_LIBRARIES} ${OpenMP_LIBS} nanoflann)
target_include_directories(nano_gicp PUBLIC include ${PCL_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIR})
# Odometry Node
add_executable(dlo_odom_node src/dlo/odom_node.cc src/dlo/odom.cc)
add_dependencies(dlo_odom_node ${catkin_EXPORTED_TARGETS})
target_compile_options(dlo_odom_node PRIVATE ${OpenMP_FLAGS})
target_link_libraries(dlo_odom_node ${catkin_LIBRARIES} ${PCL_LIBRARIES} ${OpenMP_LIBS} Threads::Threads nano_gicp)
以下指令是啥意思
std::vector<int> k_indices(1);
std::vector<float> k_sq_dists(1);
#pragma omp parallel for num_threads(num_threads_) firstprivate(k_indices, k_sq_dists) schedule(guided, 8)
for (int i = 0; i < input_->size(); i++) {
PointTarget pt;
pt.getVector4fMap() = trans_f * input_->at(i).getVector4fMap();
target_kdtree_->nearestKSearch(pt, 1, k_indices, k_sq_dists);
double sum_errors = 0.0;
std::vector<Eigen::Matrix<double, 6, 6>, Eigen::aligned_allocator<Eigen::Matrix<double, 6, 6>>> Hs(num_threads_);
std::vector<Eigen::Matrix<double, 6, 1>, Eigen::aligned_allocator<Eigen::Matrix<double, 6, 1>>> bs(num_threads_);
for (int i = 0; i < num_threads_; i++) {
Hs[i].setZero();
bs[i].setZero();
}
#pragma omp parallel for num_threads(num_threads_) reduction(+ : sum_errors) schedule(guided, 8)
for (int i = 0; i < input_->size(); i++) {
int target_index = correspondences_[i];
if (target_index < 0) {
continue;
}
const Eigen::Vector4d mean_A = input_->at(i).getVector4fMap().template cast<double>();
const auto& cov_A = source_covs_[i];
const Eigen::Vector4d mean_B = target_->at(target_index).getVector4fMap().template cast<double>();
const auto& cov_B = target_covs_[target_index];
const Eigen::Vector4d transed_mean_A = trans * mean_A;
const Eigen::Vector4d error = mean_B - transed_mean_A;
sum_errors += error.transpose() * mahalanobis_[i] * error;
#pragma omp parallel for num_threads(num_threads_) schedule(guided, 8)
for (int i = 0; i < cloud->size(); i++) {
std::vector<int> k_indices;
std::vector<float> k_sq_distances;
kdtree.nearestKSearch(cloud->at(i), k_correspondences_, k_indices, k_sq_distances);
20230905更新:
报错cout’ not specified in enclosing ‘parallel’
#pragma omp parallel for \
default(none) \
shared(output) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_) \
schedule(dynamic, chunk_size_)
增加成
#pragma omp parallel for \
default(none) \
shared(output) \
shared(std::cout) \
firstprivate(nn_indices, nn_dists) \
num_threads(threads_) \
schedule(dynamic, chunk_size_)
OpenMP: ‘std::cout’ not specified in enclosing parallel_choubu1703的博客-CSDN博客