Ask Your Question
2

Multi-threading

asked 2011-10-28 09:40:27 -0600

Robin gravatar image

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

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
10

answered 2011-10-28 15:01:14 -0600

joq gravatar image

updated 2011-10-28 15:03:31 -0600

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.

edit flag offensive delete link more

Comments

Note that each node is actually a separate process (except in the case of nodelets), which is good for parallelism.
Mac gravatar imageMac ( 2011-11-01 11:34:50 -0600 )edit
9

answered 2011-10-31 13:32:34 -0600

Daniel Canelhas gravatar image

updated 2011-10-31 13:37:47 -0600

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)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2011-10-28 09:40:27 -0600

Seen: 4,632 times

Last updated: Oct 31 '11