MCE - map with init
examples/forks/use_mce_map_init.pl
use strict; use warnings; use MCE::Map; main(); sub main { MCE::Map->init( max_workers => 3, # defaults to 4 chunk_size => 2, # defaults to 1 ); print "main PID: $$\n"; my @results = mce_map { work($_) } 1..10; print "Results: @results\n"; } sub work { my ($param) = @_; print "Param $param PID: $$\n"; #exit 23 if $param == 2; return $param * $param; }
main PID: 210966 Param 3 PID: 210969 Param 1 PID: 210967 Param 5 PID: 210968 Param 4 PID: 210969 Param 2 PID: 210967 Param 6 PID: 210968 Param 7 PID: 210968 Param 9 PID: 210969 Param 8 PID: 210968 Param 10 PID: 210969 Results: 1 4 9 16 25 36 49 64 81 100