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.