in reply to Re: No Performance gain with Parallel::ForkManager
in thread No Performance gain with Parallel::ForkManager
Hi,
probably something like that:
#!/usr/bin/perl use strict; use warnings; use strict; use 5.010; use local::lib './lib'; use File::Find::Rule; use Parallel::ForkManager; use utf8; my $dir = './'; my @mp3s = File::Find::Rule->file() ->name( '*.mp3' ) ->in($dir); say "INFO: Number of mp3 files found " . scalar @mp3s; my $num_of_cores = 2; my $pm = Parallel::ForkManager->new($num_of_cores); for my $proc_id (0..$num_of_cores - 1) { my $pid = $pm->start and next; for(my $i = $proc_id; $i < scalar @mp3s; $i += $num_of_cores) { my $file = $mp3s[$i]; say "Proc: $proc_id: Working on '$file'"; } $pm->finish; } $pm->wait_all_children; say "END";
I'm pretty sure you see the building blocks.
Regards
McA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: No Performance gain with Parallel::ForkManager
by RichardK (Parson) on Feb 23, 2014 at 17:59 UTC | |
by McA (Priest) on Feb 23, 2014 at 18:29 UTC | |
|
Re^3: No Performance gain with Parallel::ForkManager
by walto (Pilgrim) on Feb 23, 2014 at 19:06 UTC |