3
$\begingroup$

Rosanswers logo

How Can I define the number of threads for a colcon building process in ROS2?

In previous ros building tools we used "-j {number_of_threads}", but that does not work anymore.


Originally posted by Pablo Iñigo Blasco on ROS Answers with karma: 2982 on 2020-12-22

Post score: 5

$\endgroup$

3 Answers 3

2
$\begingroup$

Rosanswers logo

There are two independent dimensions of parallelization:

  • The maximum number of packages processed in parallel when using the parallel executor. This dimension can be limited with the option --parallel-workers NUMBER. It can also be limited to 1 by selecting the sequential executor with --executor sequential.

  • The maximum number of threads used for a specific package using make. This can be controlled using the environment variable MAKEFLAGS. By setting e.g. export MAKEFLAGS="-j 4" only four threads are used to build a single package. By default colcon-cmake uses the number of available CPU cores (including hyper threading) to limit the number of threads (-j) as well as the system load (-l).

As a result the overall number of threads is the product of packages processed in parallel and maximum number of threads per package.


Originally posted by Dirk Thomas with karma: 16276 on 2020-12-31

This answer was ACCEPTED on the original site

Post score: 7


Original comments

Comment by brianlmerritt on 2021-11-10:
For anyone finding this, I found that colcon build on a Raspberry Pi 4 can crash, but adding --executor sequential sorted this out without a massive time penalty.

$\endgroup$
1
$\begingroup$

Rosanswers logo

--parallel-workers NUMBER is the syntax you're looking for. "-j N" is a make specific argument.

There's documentation of the parallel executor command line options here: https://colcon.readthedocs.io/en/released/reference/executor-arguments.html


Originally posted by tfoote with karma: 58457 on 2020-12-22

This answer was NOT ACCEPTED on the original site

Post score: 3

$\endgroup$
-1
$\begingroup$

yes, export MAKEFLAGS="-j 1" can fix this error:

c++: fatal error: Killed signal terminated program cc1plus
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.