3

I am trying to install LLVM on my CentOS machine. In the installation tutorial of LLVM, a flag -jn is specified along with make.

It says to perform make -jn and also says "Choose n such that make doesn’t run in to swap space issue."

What is the use of the -j flag and how can I choose the value of n?

5

The -j make flag denotes how many threads you want to allot for compiling.

n is, in this case, a place-holder for the number of processes.

The classic rule of thumb is that it's safe to make n = the number of cores your CPU has. So if you are on a dual core machine, you might use -j2, while on an 8-core machine -j8

In practise, I have found that to be a good starting place, but you should probably feel free to experiment a bit and see what works best for you.

  • 2
    I like cores + 1 – WorBlux Jan 24 '16 at 23:32
  • 1
    Won't it be processes not threads in a strict sense? – heemayl Jan 25 '16 at 1:27
  • yes good point @heemayl – Klaatu von Schlacker Jan 25 '16 at 2:58
  • 1
    Cores+1 is usually a better option: it lets you have one process stalled on disk I/O while still fully utilizing your CPU. – Mark Jan 25 '16 at 4:53
2

Whether it's safe to use n = number of cores also depends on whether you have enough memory for all the parallel compile/link jobs. It could also cause issues for disk I/O. If this is a make job you only expect to need to run once it's probably better to choose a lower n and just let it take its time.

1

The -j flag tells make(1) how many processes to run in parallel. Best value depends on the tasks run, dependencies, ... a rule of thumb is the number of processors. If you give just -j (no n), make starts as many processes in parallel as possible.

0

Just as a concrete example of how the -j flag affects a build operation and a reason to be careful with it:

I forgot I had MAKEFLAGS=-j5 and tried to build LLVM; once it reached 97% percent it spawned 5 ld processes at the same time, each consuming 1.5GB+ RAM. The first one crashed within 20 minutes, and the rest kept consuming more and more memory until my computer was unusable and I finally decided to Ctrl+C it and try again with a smaller -j. With -j3 my computer is still struggling with three ld processes but at least I can still type this with only a few hiccups.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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