parallel: Fixed bug #37325: Inefficiency of --pipe -L

This commit is contained in:
Ole Tange 2012-11-26 00:19:58 +01:00
parent cf8f1d924b
commit 6921d28f9a
7 changed files with 55 additions and 27 deletions

View file

@ -313,19 +313,25 @@ sub spreadstdin {
my $force_one_time_through = 0; my $force_one_time_through = 0;
for my $in (@fhlist) { for my $in (@fhlist) {
piperead: while(1) { piperead: while(1) {
if(!$force_one_time_through) { eof($in) and $force_one_time_through++ and last piperead;
$force_one_time_through++; if($Global::max_lines) {
} elsif($Global::max_lines) { # Read records of $Global::max_lines lines
# Read $Global::max_lines lines my @lines;
eof($in) and last piperead; my $blocksize = length $buf;
for(my $t = 0; !eof($in) and do {
substr($buf,length $buf,0) = <$in> and $t < $Global::max_lines; for(my $t = 0; !eof($in) and $t < $Global::max_lines; $t++) {
$t++) {} my $l = <$in>;
push @lines, $l;
$blocksize += length($l);
}
} while($blocksize < $opt::blocksize and !eof($in));
substr($buf,length $buf,0) = join("",@lines);
} else { } else {
# Read a block # Read a block
read($in,substr($buf,length $buf,0),$opt::blocksize) or last; read($in,substr($buf,length $buf,0),$opt::blocksize);
# substr above = append to $buf # substr above = append to $buf
} }
if($opt::r) { if($opt::r) {
# Remove empty lines # Remove empty lines
$buf=~s/^\s*\n//gm; $buf=~s/^\s*\n//gm;
@ -767,7 +773,10 @@ sub parse_options {
# Read more than one arg at a time (-L, -N) # Read more than one arg at a time (-L, -N)
if(defined $opt::L) { if(defined $opt::L) {
$Global::max_lines = $opt::L; $Global::max_lines = $opt::L;
$Global::max_number_of_args ||= $Global::max_lines; if(not $opt::pipe) {
# --pipe -L means length of record - not max_number_of_args
$Global::max_number_of_args ||= $Global::max_lines;
}
} }
if(defined $opt::N) { if(defined $opt::N) {
$Global::max_number_of_args = $opt::N; $Global::max_number_of_args = $opt::N;

View file

@ -1247,7 +1247,7 @@ job sequence number.
@item @strong{--hashbang} @item @strong{--hashbang}
@anchor{@strong{--hashbang}} @anchor{@strong{--hashbang}}
GNU @strong{Parallel} can be called as a shebang (#!) command as the first GNU @strong{parallel} can be called as a shebang (#!) command as the first
line of a script. The content of the file will be treated as line of a script. The content of the file will be treated as
inputsource. inputsource.
@ -1263,10 +1263,10 @@ Like this:
@strong{--shebang} must be set as the first option. @strong{--shebang} must be set as the first option.
@item @strong{--shebang-wrap} @item @strong{--shebang-wrap} (alpha testing)
@anchor{@strong{--shebang-wrap}} @anchor{@strong{--shebang-wrap} (alpha testing)}
GNU @strong{Parallel} can parallelize scripts by wrapping the shebang GNU @strong{parallel} can parallelize scripts by wrapping the shebang
line. If the program can be run like this: line. If the program can be run like this:
@verbatim @verbatim

View file

@ -44,6 +44,9 @@ echo "bug #36657: --load does not work with custom ssh";
echo "bug #34958: --pipe with record size measured in lines"; echo "bug #34958: --pipe with record size measured in lines";
seq 10 | parallel -k --pipe -L 4 cat\;echo FOO | uniq seq 10 | parallel -k --pipe -L 4 cat\;echo FOO | uniq
echo "bug #37325: Inefficiency of --pipe -L";
seq 2000 | parallel -k --pipe --block 1k -L 4 wc\;echo FOO | uniq
echo "bug #34958: --pipe with record size measured in lines"; echo "bug #34958: --pipe with record size measured in lines";
seq 10 | parallel -k --pipe -l 4 cat\;echo FOO | uniq seq 10 | parallel -k --pipe -l 4 cat\;echo FOO | uniq

View file

@ -35,9 +35,11 @@ seq 1 10 | parallel -j2 -k -N 3 --pipe 'cat;echo jjjjjjjjjj' | uniq
echo '### Test -l -N -L and -n with multiple jobslots and multiple args' echo '### Test -l -N -L and -n with multiple jobslots and multiple args'
seq 1 5 | parallel -kj2 -l 2 --pipe "cat; echo a" | uniq seq 1 5 | parallel -kj2 -l 2 --pipe "cat; echo a" | uniq
seq 1 5 | parallel -kj2 -N 2 --pipe "cat; echo b" | uniq seq 1 5 | parallel -kj2 -N 2 --pipe "cat; echo b" | uniq
seq 1 5 | parallel -kj2 -L 2 --pipe "cat; echo c" | uniq
seq 1 5 | parallel -kj2 -n 2 --pipe "cat; echo d" | uniq seq 1 5 | parallel -kj2 -n 2 --pipe "cat; echo d" | uniq
echo '### Test -L --pipe'
seq 1 5 | parallel -kj2 -L 2 --pipe "cat; echo c" | uniq
echo '### Test output is the same for different block size' echo '### Test output is the same for different block size'
echo -n 01a02a0a0a12a34a45a6a | echo -n 01a02a0a0a12a34a45a6a |
parallel -k -j1 --blocksize 100 --pipe --recend a -N 3 'echo -n "$PARALLEL_SEQ>"; cat; echo; sleep 0.1' parallel -k -j1 --blocksize 100 --pipe --recend a -N 3 'echo -n "$PARALLEL_SEQ>"; cat; echo; sleep 0.1'

View file

@ -93,15 +93,34 @@ bug #34958: --pipe with record size measured in lines
2 2
3 3
4 4
FOO
5 5
6 6
7 7
8 8
FOO
9 9
10 10
FOO FOO
bug #37325: Inefficiency of --pipe -L
280 280 1012
FOO
252 252 1008
FOO
252 252 1008
FOO
244 244 1005
FOO
200 200 1000
FOO
200 200 1000
FOO
200 200 1000
FOO
200 200 1000
FOO
172 172 860
FOO
0 0 0
FOO
bug #34958: --pipe with record size measured in lines bug #34958: --pipe with record size measured in lines
1 1
2 2

View file

@ -100,20 +100,19 @@ b
b b
1 1
2 2
c d
3 3
4 4
c d
5 5
c d
### Test -L --pipe
1 1
2 2
d
3 3
4 4
d
5 5
d c
### Test output is the same for different block size ### Test output is the same for different block size
1>01a02a0a 1>01a02a0a
2>0a12a34a 2>0a12a34a

View file

@ -31,10 +31,6 @@ h2
6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
7xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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