DEFAULT INPUT SCALAR
Beginning with MCE 1.5, the input scalar $_ is localized prior to calling user_func for input_data and sequence of numbers. The following applies.
## use_slurpio => 1:
$_ is a reference to the buffer e.g. $_ = \$_buffer;
$_ is a ref irregardless of whether chunk_size is 1 or greater
user_func => sub {
# my ($self, $chunk_ref, $chunk_id) = @_;
print ${ $_ }; ## $_ is same as $chunk_ref
}
## chunk_size is greater than 1, use_slurpio => 0:
$_ is a reference to an array. $_ = \@_records; $_ = \@_seq_n;
$_ is same as $chunk_ref or $_[CHUNK]
user_func => sub {
# my ($self, $chunk_ref, $chunk_id) = @_;
for my $row ( @{ $_ } ) {
print $row, "\n";
}
}
use MCE CONST => 1;
user_func => sub {
# my ($self, $chunk_ref, $chunk_id) = @_;
for my $row ( @{ $_[CHUNK] } ) {
print $row, "\n";
}
}
## chunk_size equals 1, use_slurpio => 0:
$_ contains the actual value. $_ = $_buffer; $_ = $seq_n;
## Note that $_ and $chunk_ref are not the same below.
## $chunk_ref is a reference to an array.
user_func => sub {
# my ($self, $chunk_ref, $chunk_id) = @_;
print $_, "\n; ## Same as $chunk_ref->[0];
}
MCE->foreach("/path/to/file", sub {
# my ($self, $chunk_ref, $chunk_id) = @_;
print $_; ## Same as $chunk_ref->[0];
});
## However, that's not the case for the forseq method.
## Both $_ and $n_seq are the same when chunk_size => 1.
MCE->forseq([ 1, 9 ], sub {
# my ($self, $n_seq, $chunk_id) = @_;
print $_, "\n"; ## Same as $n_seq
});
In case you missed it, forseq will now apply the chunk_size option. Note that sequence can also be specified using an array reference. The below is the same as the example afterwards.
MCE->forseq( { begin => 10, end => 40, step => 2 }, ... );
The code block receives an array containing the next 5 sequences. Chunk 1 (chunk_id = 1) contains 10,12,14,16,18. $n_seq is a reference to an array, same as $_, due to chunk_size being greater than 1.
MCE->forseq( [ 10, 40000, 2 ], { chunk_size => 5 }, sub {
# my ($self, $n_seq, $chunk_id) = @_;
my @result;
for my $n ( @{ $_ } ) {
... do work, append to result for 5
}
... do something with result afterwards
});
############################################################################### # * # * # * # * # * # * # * # * # * # * # * # * # * # * # * # * # * # * # * # ###############################################################################
<> REQUIREMENTS
Perl 5.8.0 or later. The PDL::IO::Storable module is required in scripts parallelizing PDL with MCE.
-- SEE ALSO
MCE::Signal, MCE::Subs, MCE::Util
-- SOURCE
The source is hosted at http://code.google.com/p/many-core-engine-perl/
-- AUTHOR
Mario E. Roy, marioeroy AT gmail DOT com
-- COPYRIGHT AND LICENSE
Copyright (C) 2012-2013 by Mario E. Roy
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.