Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Multi-core loops



On Sun, Jun 28, 2009 at 01:31:29PM +0300, Nadav Har'El wrote:
> Instead, you'll want to keep all CPUs busy all the time, running M
> (=number of CPUs) processes at the same time.

Perl has a nice module for this.  Perhaps we can steal ideas from this:

use Parallel::ForkManager;
my $pm = new Parallel::ForkManager(5); # limit to 5 parallel processes
foreach my $var (@array) {
  # can do non-parallel-ized work here, as needed
  ...
  $pm->start and next; # do the fork, parent skips to next loop
  # use any perl commands you like here.
  ...
  $pm->finish; # do the exit in the child process
}
pm->wait_all_children;

If we had something similar for zsh (perhaps using a loadable module),
it would make it easy to parallelize a sequence of shell commands
without having to use '&'.

..wayne..



Messages sorted by: Reverse Date, Date, Thread, Author