3 use List
::Util
'shuffle'; # standard from Perl 5.8 and later
5 my $tempfile = "multigcc.out";
10 # parse command line arguments
22 my $command = join " ", @params;
24 # shuffle the file list to spread the load as evenly as we can
25 @files = shuffle
(@files);
27 # count number of cores
31 chomp($cores = `sysctl -n hw.ncpu`);
35 $cores = scalar grep /on-line/i, `psrinfo`;
39 if (open CPUINFO
, "</proc/cpuinfo") {
40 $cores = scalar grep /^processor/i, <CPUINFO
>;
49 # don't run empty children
50 if (scalar @files <= $cores)
57 my $slice = int((scalar @files + $cores) / $cores);
58 for my $i (0 .. $cores-1)
68 # get my slice of the files
69 my @list = @files[$i * $slice .. $i * $slice + $slice - 1];
72 system("$command @list > $tempfile.$$");
78 for my $i (0 .. $cores - 1)
80 # wait for child to complete
84 if (open F
, "<$tempfile.$pids[$i]")
88 unlink "$tempfile.$pids[$i]";