I have read several posts to ensure how to force targets NOT to run in parallel. But assume that I want two targets to actually start at the same time and run in parallel. Can this be done?
For example lets say I have a target as follows:
myParallelTarget:
$(MAKE) target1;
$(MAKE) target2;
And then I call it with for example:
make -j16 myParallelTarget
I have a project which is more complicated than this ofcourse but this is the general form. Even though I call my Makefile with -j16, it still builds target1 before resuming to target2.
When I look at the build output I get the feeling that the build would probably execute faster if target2 was started immediately, i.e. it seems that some threads are waiting for target1 to complete. Is it possible to force a start of targets at the same time?
make parallelism parallelizes targets found as prerequisites. It doesn't parallelize lines within a target recipe. Those are always executed one at a time in sequence.
If you want to parallelize those two make commands then you need to use something more like
myParallelTarget: target1 target2
But those will run parallel if myParallelTarget
is ever encountered when make is run with a -j
argument (whether on the command line or as a prerequisite of another target).
Conversely, preventing targets from running in parallel means either running them manually or explicitly sequencing them via prerequisite chains.