Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning "forced in submake" in parallel execution of make

When I run make -j3 to build in parallel, I get

warning: -jN forced in submake: disabling jobserver mode.

In the documentation I found the warning is emitted

if make detects error conditions related to parallel processing on systems where sub-makes can communicate.

What are these error conditions? What can I do to heal them or suppress the error message?

The makefile is generated from CMake, so I cannot (=I don't want to) edit the makefile.

like image 559
usr1234567 Avatar asked Jul 18 '14 05:07

usr1234567


3 Answers

You call make -j3 for you top-level Makefile, which means that up to 3 targets can be built simultaneously (make uses 3 threads to build). Your top-level Makefile (generated by CMake) run another make (which is called sub-make). And in this invocation another -jN option is used. So instead of using common jobserver for both makes, sub-make uses another N threads to build its targets. So up to 3 + N threads in total are used for building. So this is what this warning about.

To enable common jobserver for parent make and sub-make, there are 2 requirements:

  • Explicit -jN option mustn't be passed to sub-make. Call sub-make without this argument.
  • Sub-make must be called using $(MAKE) expression (not just plain make). Alternatively the + prefix can be added before make command. See this answer for details.

If both requirements are satisfied, then, when you run make -jN for you top-level Makefile, parent make and child make use N threads in common for building.

like image 125
anton_rh Avatar answered Nov 13 '22 22:11

anton_rh


Usually this message occurres if you call make from your Makefile not by the variable $(MAKE)

Example:

Change

foo:
     cd foo/ && make foo

to

foo:
     cd foo && $(MAKE) foo
like image 10
arved Avatar answered Nov 14 '22 00:11

arved


This is related to multi-threaded make feature. It happens when there is yet another multi-threaded make inside a make process that is already multi-threaded. As there is second level of multi-threaded make, the internal synchronization is not available.

It is possible to fix this by -j parameter.

make -j 1

The code above will avoid multiple thread and it will remove the warnings.

Again, we can use -j parameter in the makefile as well.

target:
    $(MAKE) -j 1 -C ${SUBDIR} $@

The above rule will not spawn threads for submake and it will avoid the warning.

like image 2
KRoy Avatar answered Nov 13 '22 22:11

KRoy