I have a bunch of commands that I would like to execute in parallel. The teams are almost identical. They can be expected at about the same time, and they can work completely independently. They may look like this:
command -n 1 > log.1 command -n 2 > log.2 command -n 3 > log.3 ... command -n 4096 > log.4096
I could run them all in parallel in a shell script, but the system would try to load more than would be strictly necessary to keep the CPU busy (each task takes 100% of one core until it is complete). This can cause the disk to crash and make everything slower than the less greedy approach to execution.
The best approach is probably to complete n tasks, where n is the number of available cores.
I try not to reinvent the wheel. This problem has already been resolved in the Unix make program (when used with the -jn option). I was wondering if it is possible to write general Makefile rules for the above to avoid creating a linear sized Makefile that would look like this:
all: log.1 log.2 ... log.1: command -n 1 > log.1 log.2: command -n 2 > log.2 ...
If the best solution is not using make , but another program / utility, I am open to this if the dependencies are reasonable ( make was very good in this regard).
source share