From b60b16779ef9bd4a09f1d7191aff386ce7798cfd Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sat, 4 Apr 2009 11:33:42 +0200 Subject: [PATCH] Bug fix: -j 1 ran 2 jobs. Should of course only run 1 job --- parallel | 38 ++++++++++++++++++++++++++++++++------ parallel.1 | 24 ++++++++++++++++++++++-- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/parallel b/parallel index 761489f7..1090c3fd 100755 --- a/parallel +++ b/parallel @@ -6,7 +6,7 @@ parallel - build and execute command lines from standard input in parallel =head1 SYNOPSIS -B [-0cfgqsuvx] [-j num] [command [arguments]] < list_of_arguments +B [-0cfgqsuvxX] [-j num] [command [arguments]] < list_of_arguments =head1 DESCRIPTION @@ -176,6 +176,7 @@ is a better solution: find . -name '*.jpg' | parallel -j +0 convert -geometry 120 {} {}_thumb.jpg find . -name '*_thumb.jpg' | ren 's:/([^/]+)_thumb.jpg$:/thumb_$1:' + =head1 EXAMPLE 4: Substitution and redirection This will compare all files in the dir to the file foo and save the @@ -200,6 +201,29 @@ To put the output in a file called .dir: B>B< {}.dir'> + +=head1 EXAMPLE 6: Context replace + +To remove the files I .. I you could do: + +B + +You could also do: + +B + +The first will run B 8999 times, while the last will only run +B as many times needed to keep the command line length short +enough. + +You could also run: + +B + +This will also only run B as many times needed to keep the command +line length short enough. + + =head1 QUOTING For more advanced use quoting may be an issue. The following will @@ -531,7 +555,9 @@ sub compute_number_of_processes { # Number of processes wanted and limited by system ressources my $opt_j = shift; my $wanted_processes = user_requested_processes($opt_j); + debug("Wanted procs: $wanted_processes\n"); my $system_limit = processes_available_by_system_limit($wanted_processes); + debug("Limited to procs: $system_limit\n"); return $system_limit; } @@ -594,21 +620,21 @@ sub processes_available_by_system_limit { $system_limit = int ($system_limit * 0.9)+1; $spawning_too_slow = 1; } - } while($system_limit <= $wanted_processes + } while($system_limit < $wanted_processes and defined $next_command_line and $more_filehandles and not $max_system_proc_reached and not $spawning_too_slow); - if($system_limit <= $wanted_processes and not $more_filehandles) { + if($system_limit < $wanted_processes and not $more_filehandles) { print STDERR ("Warning: Only enough filehandles to run ", $system_limit, " jobs in parallel. ", "Raising ulimit -n may help\n"); } - if($system_limit <= $wanted_processes and $max_system_proc_reached) { + if($system_limit < $wanted_processes and $max_system_proc_reached) { print STDERR ("Warning: Only enough available processes to run ", $system_limit, " jobs in parallel.\n"); } - if($system_limit <= $wanted_processes and $spawning_too_slow) { + if($system_limit < $wanted_processes and $spawning_too_slow) { print STDERR ("Warning: Starting 10 extra processes takes > 1 sec.\n", "Limiting to ", $system_limit, " jobs in parallel.\n"); } @@ -894,7 +920,7 @@ sub die_usage { sub usage { print "Usage:\n"; - print "parallel [-0cfgqsuvx] [command [arguments]] < list_of_arguments\n"; + print "parallel [-0cfgqsuvxX] [-j num] [command [arguments]] < list_of_arguments\n"; } # diff --git a/parallel.1 b/parallel.1 index 2744ffb8..0506d28d 100644 --- a/parallel.1 +++ b/parallel.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "PARALLEL 1" -.TH PARALLEL 1 "2009-03-16" "perl v5.10.0" "User Contributed Perl Documentation" +.TH PARALLEL 1 "2009-04-04" "perl v5.10.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -133,7 +133,7 @@ parallel \- build and execute command lines from standard input in parallel .SH "SYNOPSIS" .IX Header "SYNOPSIS" -\&\fBparallel\fR [\-0cfgqsuvx] [\-j num] [command [arguments]] < list_of_arguments +\&\fBparallel\fR [\-0cfgqsuvxX] [\-j num] [command [arguments]] < list_of_arguments .SH "DESCRIPTION" .IX Header "DESCRIPTION" For each line of input \fBparallel\fR will execute \fBcommand\fR with the @@ -306,6 +306,26 @@ files in each directory: To put the output in a file called .dir: .PP \&\fBls | parallel '(echo \-n {}\*(L" \*(R"; ls {}|wc \-l) \fR>\fB {}.dir'\fR +.SH "EXAMPLE 6: Context replace" +.IX Header "EXAMPLE 6: Context replace" +To remove the files \fIpict1000.jpg\fR .. \fIpict9999.jpg\fR you could do: +.PP +\&\fBseq 1000 9999 | parallel rm pict{}.jpg\fR +.PP +You could also do: +.PP +\&\fBseq 1000 9999 | perl \-pe 's/(.*)/pict$1.jpg/' | parallel \-x rm\fR +.PP +The first will run \fBrm\fR 8999 times, while the last will only run +\&\fBrm\fR as many times needed to keep the command line length short +enough. +.PP +You could also run: +.PP +\&\fBseq 1000 9999 | parallel \-X rm pict{}.jpg\fR +.PP +This will also only run \fBrm\fR as many times needed to keep the command +line length short enough. .SH "QUOTING" .IX Header "QUOTING" For more advanced use quoting may be an issue. The following will