ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to use parallel programming in catkin?

asked 2018-10-22 01:30:44 -0500

SS6141 gravatar image

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.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2019-09-13 01:35:51 -0500

mgruhler gravatar image

@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}
)
edit flag offensive delete link more

Comments

If it is the right way i will use this +1

duck-development gravatar image duck-development  ( 2019-09-14 05:59:28 -0500 )edit
0

answered 2019-09-12 13:00:28 -0500

duck-development gravatar image

updated 2019-09-12 13:01:09 -0500

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()
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-10-22 01:30:44 -0500

Seen: 1,717 times

Last updated: Sep 13 '19