I have a script - a linear list of commands - that takes a long time to run sequentially. I would like to create a utility script (Perl, Bash or other available on Cygwin) that can read commands from any linear script and farm them out to a configurable number of parallel workers.
So if myscript
is
command1
command2
command3
I can run:
threadpool -n 2 myscript
Two threads would be created, one commencing with command1
and the other command2
. Whichever thread finishes its first job first would then run command3
.
Before diving into Perl (it's been a long time) I thought I should ask the experts if something like this already exists. I'm sure there should be something like this because it would be incredibly useful both for exploiting multi-CPU machines and for parallel network transfers (wget
or scp
). I guess I don't know the right search terms. Thanks!