NAME

Proc::Forkmap - map with forking

SYNOPSIS

EXAMPLE:

use Proc::Forkmap;

$Proc::Forkmap::MAX_PROCS = 4;

sub foo {
  my $n = shift;
  sleep $n;
  print "slept for $n seconds\n";
}

my @x = (1, 4, 2);

forkmap { foo($_) } @x;

DESCRIPTION

Mapping with built-in forking.

INTERFACE

forkmap

forkmap { foo($_) } @x;

Run code blocks in parallel.

IPC

IPC is off by default. Set to 1 for results to get returned to the parent. IPC is handled by creating a pipe, with reader and writer file handles. Currently, only scalar values are supported for the function return values. Pipes operate as simple byte streams, so any data sent through the pipe must be serialized into a scalar (e.g., a string or a number) before being transmitted.

$Proc::Forkmap::IPC = 1;  # (default: 0)
my @results = forkmap { foo($_) } @x;

MAX_PROCS

Max parallelism.

$Proc::Forkmap::MAX_PROCS = 4;  # (default: 4)

TIMEOUT

Max time in seconds any single child process can run.

$Proc::Forkmap::TIMEOUT = 2;  # (default: 0)

SEE ALSO

Proc::Fork

AUTHOR

Andrew Shapiro, <trski@cpan.org>

BUGS

Please report any bugs or feature requests to bug-proc-forkmap at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Proc-Forkmap. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

LICENSE AND COPYRIGHT

Copyright 2024 Andrew Shapiro.

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.