# Revision history [back]

For some basic parallelism in ROS, you can use OpenMP (assuming parts of your code can be executed in parallel, that is).

In CMakeLists.txt add the following for your project (replacing the binary_name and source_code by their actual names)

rosbuild_add_executable(binary_name src/source_code.cpp)


in your source code you can then use

#pragama omp parallel for


to execute for-loops in parallel. See this page for further reference, including restrictions on usage. Be careful with with shared variables such as counters that might be reset while another loop might still be using it.

For some basic parallelism in ROS, you can use OpenMP (assuming parts of your code can be executed in parallel, that is).

In CMakeLists.txt add the following for your project (replacing the binary_name and source_code by their actual names)

rosbuild_add_executable(binary_name src/source_code.cpp)


in your source code you can then use

#pragama omp parallel for


to execute for-loops in parallel. See this page for further reference, including restrictions on usage. Be careful with with shared variables such as counters that might be reset while another loop might still be using it.

Also, check out the tutorial on multi-threaded callback processing under ros_tutorials for another example

opt/ros/electric/stacks/ros_tutorials/roscpp_tutorials/listener_threaded_spin


(default path in electric)