How to use parallel programming in catkin?
Hi,
I would like to use #pragma
to implement parallel programming in a ROS node. Adding the line add_compile_options(-fopenmp)
in CMakeLists.txt
is not working.
How to accomplish? Is there any other way to implement the same?
Thanks in advance.
Asked by SS6141 on 2018-10-22 01:30:44 UTC
Answers
Open mp you finde an exampel Code
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}")
endif()
Asked by duck-development on 2019-09-12 13:00:28 UTC
Comments
@duck-development's solution will most probably work.
However, it is recommended to not tinker around with CMAKE_C_FLAGS
and CMAKE_CXX_FLAGS
.
Another way to achieve this is (directly taken from the rosbuild to catkin migration guide:
# let cmake find OpenMP and set some variables
find_package(OpenMP REQUIRED)
if(OPENMP_FOUND)
message(STATUS "OPENMP FOUND")
set(OpenMP_FLAGS ${OpenMP_CXX_FLAGS}) # or if you use C: ${OpenMP_C_FLAGS}
set(OpenMP_LIBS gomp)
endif()
...
# the entry in catkin_package could be optional (I am not fully sure about this)
catkin_package(
DEPENDS
OpenMP
)
...
# exemplary executable foo using OpenMP
add_executable(foo
ros/src/foo_node.cpp
)
target_compile_options(foo PRIVATE ${OpenMP_FLAGS})
add_dependencies(foo ${catkin_EXPORTED_TARGETS})
target_link_libraries(foo
${catkin_LIBRARIES}
${OpenMP_LIBS}
)
Asked by mgruhler on 2019-09-13 01:35:51 UTC
Comments
If it is the right way i will use this +1
Asked by duck-development on 2019-09-14 05:59:28 UTC
Comments