in reply to Re: MCE -- how to know which function to use
in thread MCE -- how to know which function to use
The following provides a demonstration. Notice how workers populate a local array before sending to the manager process using one gather call. This is one way to minimize IPC overhead.
use strict; use warnings; use MCE::Loop; use MCE::Candy; my $count = 0; my $input = [ ]; my $output = [ ]; my $sample = { a => ++$count, b => ++$count, c => ++$count }; push @{ $input }, $sample for ( 1 .. 100000 ); MCE::Loop::init( max_workers => 3, chunk_size => 100, gather => MCE::Candy::out_iter_array( $output ) ); mce_loop { my ( $mce, $chunk_ref, $chunk_id ) = @_; my @ret; for my $h ( @{ $chunk_ref } ) { push @ret, { a => $h->{a} * 2, b => $h->{b} * 2, c => $h->{c} * 2, }; } MCE->gather($chunk_id, @ret); } $input; MCE::Loop::finish(); print scalar(@{ $output }), "\n";
Regards, Mario.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: MCE -- how to know which function to use
by 1nickt (Canon) on Sep 29, 2016 at 21:48 UTC | |
by BrowserUk (Patriarch) on Sep 30, 2016 at 04:18 UTC | |
by 1nickt (Canon) on Sep 30, 2016 at 13:46 UTC | |
by marioroy (Prior) on Sep 29, 2016 at 23:56 UTC |