help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Building some targets serially, others in parallel


From: dan soucy
Subject: Building some targets serially, others in parallel
Date: Sat, 22 Aug 2020 16:46:06 -0400

Hi list.

I find myself in a situation where I want the makefile to know not to build
certain targets in parallel, even though they do not actually depend on each
other. To explain:
Suppose we have three executables to build: `server`, `client`, `demo`. Each
of these has an associated source file.

There are many other source files -- maybe a dozen. They will be compiled to
object files which are depended on by all three executable files.

Normally, the quick solution is to add one target for each object file and tell `make` to invoke the compiler on each in a separate process, using as many processors as are available.

But -- in this case, the design of the compiler is such that telling the
compiler to build all required object files in parallel is much faster than
invoking the compiler many times. This is due to a (relatively) slow start-up and also the re-use of data between source files (such as types).

So instead, we have something like this:

```
server client demo: $(OBJECTS)
$(COMPILER) -j 4 $@ -o $< ```

Running `make -j 4 server client demo` with the object files not built will result in the compiler being invoked thrice, and each will begin by compiling the same object files. The result is that this actually takes longer than running `make` serially.

However, if the object files are already built, then `server`, `client`, and
`demo` can be built faster in parallel.

For the curious, the compiler is GHC and the code is Haskell.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]