2 use List
::Util
'shuffle'; # standard from Perl 5.8 and later
4 my $tempfile = "multigcc.out";
9 # parse command line arguments
21 my $command = join " ", @params;
23 # shuffle the file list to spread the load as evenly as we can
24 @files = shuffle
(@files);
26 # count number of cores
28 if (open CPUINFO
, "</proc/cpuinfo") {
29 $cores = scalar grep /^processor/i, <CPUINFO
>;
33 # don't run empty children
34 if (scalar @files <= $cores)
41 my $slice = int((scalar @files + $cores) / $cores);
42 for my $i (0 .. $cores-1)
52 # get my slice of the files
53 my @list = @files[$i * $slice .. $i * $slice + $slice - 1];
56 system("$command @list > $tempfile.$$");
62 for my $i (0 .. $cores - 1)
64 # wait for child to complete
68 if (open F
, "<$tempfile.$pids[$i]")
72 unlink "$tempfile.$pids[$i]";