NAME
Parallel::SubArray - Execute forked subref array and join return values, timeouts and error captures.
SYNOPSIS
use Parallel::SubArray 'par';
my $sub_arrayref = [
sub{ sleep(1); [1] }, # simple structure
sub{ bless {}, 'a' }, # blessed structure
sub{ while(1){$_++} }, # runaway routine
sub{ die 'TEST' }, # bad code
sub{ [ 1, {2=>3} ] }, # complex structure
];
my($result_arrayref, $error_arrayref) = par(3)->($sub_arrayref);
## or you can ignore errors
# my $result_arrayref = par(3)->($sub_arrayref);
$result_arrayref == [
[ 1 ],
{}, # blessed into 'a'
undef,
undef,
[ 1, { 2 => 3 } ]
];
$error_arrayref == [
undef,
undef,
'TIMEOUT',
'TEST',
undef,
];
DESCRIPTION
I want fast, safe, and simple parallelism. Current offerings did not satisfy me. Most are not enough while remaining are too complex or tedious. Palallel::SubArray scratches my itch: forking, joining, timeouts, and return values done simply.
EXPORTS
Nothing automatically. I don't like magic.
par
Takes one argument that represents timeout in seconds and evaluates into a subref that will execute subarrayref in parallel returning resultarrayref in scalar context or resultarrayref and errorarrayref in list context.
Timeout can be undef or zero. In this case timeout is disabled and you might never join forks.
SEE ALSO
perlipc "fork" in perlfunc perlfork subs::parallel Parallel::Simple Parallel::Queue Parallel::Forker Parallel::Jobs Parallel::Workers Parallel::SubFork Parallel::Pvm Parallel::Performing Parallel::Fork::BossWorker Parallel::ForkControl Proc::Fork
BUGS
Expect lots if Windows or Object Orientation. Windows because of the lack of forking and OOP has a hard time finding a foot in the parallel world as it requires locking. If you have the itch to ignore the first warning, you will get slower performance (because Perl emulates forking on Windows) and hopefully no bugs. If you have the OO stones, let me know how you have solved the parallelism problem.
The joining mechanism of this module can be incompatible with other forking because it's waiting for child processes to finish. Nesting of par
works as expected.
Subroutines passed to par
that return anything other than references to simple Perl structures may behave unexpectedly.
AUTHOR
Eugene Grigoriev,
let a b c d e f g = concat [e,f,d,g,c,f,b] in
a "com" "gmail" "grigoriev" "eugene" "." "@"
LICENSE
BSD