Using make to execute independent tasks in parallel Using make to execute independent tasks in parallel shell shell

Using make to execute independent tasks in parallel


Here is more portable shell code that does not depend on brace expansion:

LOGS := $(shell seq 1 1024)

Note the use of := to define a more efficient variable: the simply expanded "flavor".


See pattern rules

Another way, if this is the single reason why you need make, is to use -n and -P options of xargs.


First the easy part. As Roman Cheplyaka points out, pattern rules are very useful:

LOGS = log.1 log.2 ... log.4096all: $(LOGS)log.%:    command -n $* > log.$*

The tricky part is creating that list, LOGS. Make isn't very good at handling numbers. The best way is probably to call on the shell. (You may have to adjust this script for your shell-- shell scripting isn't my strongest subject.)

NUM_LOGS = 4096LOGS = $(shell for ((i=1 ; i<=$(NUM_LOGS) ; ++i)) ;  do  echo log.$$i ; done)