I'm trying to undersand the true meaning of -j option in make command. According to manual, with this option the user can "specifie the number of jobs to run simultaneously". What I actually want to understand is the link between the numeric value specified in this option and the number of core/threads of the pc. So, if, for example I use:
make -j 8
it means that my pc has at least 8 cores (or threads)?
And, if this link exists, what happens if the value specified in -j option is greater than the number of cores/thread of the pc? Will that option be simply ignored?
Thanks to anyone so kind to answer to my (stupid) doubts.
This option specifies how many simultaneous threads will be used.
If you use too many of them, the option won't be ignored, but the compilation may run slower.
If you set too few threads, not all CPU cores will be loaded.
There are some recommendations to use + 1, or even *2. I am using twice # of CPU cores.
You can test which way gives a better result.
The -j option tells
make
how many jobs (commands) to run in parallel. This is limited by how many physical CPUs and RAM your system has.Many
make
jobs use as many CPUs as it finds in the system. On my computer, it has four CPU's, which is the equivalent to setting "-j 4". This will allow themake
to complete in the fastest time.However, if you use all, or too many CPUs, you lose some system control, as there are no free CPUs. So I've always been told to use the -j option with one LESS CPU than you really have, so if you have to control-c the
make
(for example), the remaining CPU can do it. In my case, I'd be using "-j 3".Try using -j CPUs, or CPUs+1, or CPUs*2, and see what works best for you. To time each run, prefix your command with the
time
command, and it'll give you specific compile/run times.