Skip to content

Commit

Permalink
Default to number of usable CPUs if possible (#1180)
Browse files Browse the repository at this point in the history
* Default to number of usable CPUs if possible

* Comment improvement
  • Loading branch information
wico-silva authored Sep 19, 2022
1 parent 2612c4c commit ff31d45
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion python/catkin/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,14 @@ def handle_make_arguments(input_make_args, append_default_jobs_flags=True):
elif append_default_jobs_flags:
# Else Use the number of CPU cores
try:
jobs = multiprocessing.cpu_count()
if "sched_getaffinity" in dir(os):
# Using sched_getaffinity we get the number of usable CPUs but
# it's not available on all platforms
jobs = len(os.sched_getaffinity(0))
else:
# cpu_count returns the number of CPUs (usable or not)
jobs = multiprocessing.cpu_count()

make_args.append('-j{0}'.format(jobs))
make_args.append('-l{0}'.format(jobs))
except NotImplementedError:
Expand Down

0 comments on commit ff31d45

Please sign in to comment.