0
$\begingroup$

Rosanswers logo

Hi all,

I'm running Ubuntu on a 12-core machine. I was wondering whether there's any sort of automatic multi-threading support built into ROS. For instance, if I'm running two packages at the same time, will they be executed on different threads? If it's not automatic, is there a parameter I can set to enable it?

Thanks


Originally posted by Robin on ROS Answers with karma: 87 on 2011-10-28

Post score: 2

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Each node or nodelet executes on a separate thread, and hence can run on a separate core. There are also internal ROS threads for handling incoming messages or service requests. A large ROS system with many nodes can easily use 12 cores effectively.

Note that nodes and nodelets belong to packages, but some packages provide C++ libraries or Python packages, which are only multi-threaded if programmed appropriately.


Originally posted by joq with karma: 25443 on 2011-10-28

This answer was ACCEPTED on the original site

Post score: 10


Original comments

Comment by Mac on 2011-11-01:
Note that each node is actually a separate process (except in the case of nodelets), which is good for parallelism.

$\endgroup$
0
$\begingroup$

Rosanswers logo

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)
rosbuild_add_openmp_flags(binary_name)

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)


Originally posted by Daniel Canelhas with karma: 465 on 2011-10-31

This answer was NOT ACCEPTED on the original site

Post score: 9

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.