diff --git a/CITATION b/CITATION new file mode 100644 index 00000000..60eb9e87 --- /dev/null +++ b/CITATION @@ -0,0 +1,23 @@ +When using programs that use GNU Parallel to process data for publication please cite: + +@article{Tange2011a, + title = {GNU Parallel - The Command-Line Power Tool}, + author = {O. Tange}, + address = {Frederiksberg, Denmark}, + journal = {;login: The USENIX Magazine}, + month = {Feb}, + number = {1}, + volume = {36}, + url = {http://www.gnu.org/s/parallel}, + year = {2011}, + pages = {42-47} +} + +(Feel free to use \nocite{Tange2011a}) + +Or: + + O. Tange (2011): GNU Parallel - The Command-Line Power Tool, + ;login: The USENIX Magazine, February 2011:42-47. + +This helps funding further development. diff --git a/Makefile.am b/Makefile.am index d1b2850e..fbaa0729 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,3 +2,5 @@ SUBDIRS = src test: cd testsuite; make 1 + +EXTRA_DIST = CITATION diff --git a/Makefile.in b/Makefile.in index 0a6b608c..a44c1666 100644 --- a/Makefile.in +++ b/Makefile.in @@ -197,6 +197,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = src +EXTRA_DIST = CITATION all: config.h $(MAKE) $(AM_MAKEFLAGS) all-recursive diff --git a/doc/release_new_version b/doc/release_new_version index ed4ed536..41b2c29f 100644 --- a/doc/release_new_version +++ b/doc/release_new_version @@ -164,6 +164,7 @@ YYYYMMDD=`yyyymmdd` git tag -s -m "Released as $YYYYMMDD ('$TAG')" $TAG git tag -s -m "Released as $YYYYMMDD ('$TAG')" $YYYYMMDD +git push == Update Savannah == diff --git a/src/Makefile.am b/src/Makefile.am index c91c2f3e..053a8de9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,35 +38,35 @@ niceload.1: niceload.pod || echo "Warning: pod2man not found. Using old niceload.1" parallel.html: parallel.pod - pod2html $(srcdir)/parallel.pod > $(srcdir)/parallel.htmln \ + pod2html --title "GNU Parallel" $(srcdir)/parallel.pod > $(srcdir)/parallel.htmln \ && mv $(srcdir)/parallel.htmln $(srcdir)/parallel.html \ || echo "Warning: pod2html not found. Using old parallel.html" rm -f $(srcdir)/pod2htm* # Depending on parallel.html to avoid stupid pod2html race condition parallel_tutorial.html: parallel_tutorial.pod parallel.html - pod2html $(srcdir)/parallel_tutorial.pod > $(srcdir)/parallel_tutorial.htmln \ + pod2html --title "GNU Parallel tutorial" $(srcdir)/parallel_tutorial.pod > $(srcdir)/parallel_tutorial.htmln \ && mv $(srcdir)/parallel_tutorial.htmln $(srcdir)/parallel_tutorial.html \ || echo "Warning: pod2html not found. Using old parallel_tutorial.html" rm -f $(srcdir)/pod2htm* # Depending on parallel_tutorial.html to avoid stupid pod2html race condition sem.html: sem.pod parallel_tutorial.html - pod2html $(srcdir)/sem.pod > $(srcdir)/sem.htmln \ + pod2html --title "sem (GNU Parallel)" $(srcdir)/sem.pod > $(srcdir)/sem.htmln \ && mv $(srcdir)/sem.htmln $(srcdir)/sem.html \ || echo "Warning: pod2html not found. Using old sem.html" rm -f $(srcdir)/pod2htm* # Depending on sem.html to avoid stupid pod2html race condition sql.html: sql sem.html - pod2html $(srcdir)/sql > $(srcdir)/sql.htmln \ + pod2html --title "GNU SQL" $(srcdir)/sql > $(srcdir)/sql.htmln \ && mv $(srcdir)/sql.htmln $(srcdir)/sql.html \ || echo "Warning: pod2html not found. Using old sql.html" rm -f $(srcdir)/pod2htm* # Depending on sql.html to avoid stupid pod2html race condition niceload.html: niceload.pod sql.html - pod2html $(srcdir)/niceload.pod > $(srcdir)/niceload.htmln \ + pod2html --title "GNU niceload" $(srcdir)/niceload.pod > $(srcdir)/niceload.htmln \ && mv $(srcdir)/niceload.htmln $(srcdir)/niceload.html \ || echo "Warning: pod2html not found. Using old niceload.html" rm -f $(srcdir)/pod2htm* diff --git a/src/parallel b/src/parallel index f8454537..404d4fcb 100755 --- a/src/parallel +++ b/src/parallel @@ -192,7 +192,7 @@ sub pipe_part_files { my @cmdlines; for(my $i=0; $i<$#pos; $i++) { my $cmd = $Global::JobQueue->{'commandlinequeue'}->get(); - $cmd->{'replaced'} = + $cmd->{'replaced'} = cat_partial($file, 0, length($header), $pos[$i], $pos[$i+1]) . "|" . "(".$cmd->{'replaced'}.")"; ::debug("init", "Unget ", $cmd->{'replaced'}, "\n"); @@ -210,7 +210,7 @@ sub find_header { $opt::header =~ s/^(\d+)$/"(.*\n)"x$1/e; while(read($fh,substr($$buf_ref,length $$buf_ref,0),$opt::blocksize)) { if($$buf_ref=~s/^($opt::header)//) { - $header = $1; + $header = $1; last; } } @@ -310,7 +310,7 @@ sub spreadstdin { } } if($Global::max_lines and not $Global::max_number_of_args) { - # Read n-line records + # Read n-line records my $n_lines = $buf=~tr/\n/\n/; my $last_newline_pos = rindex($buf,"\n"); while($n_lines % $Global::max_lines) { @@ -572,6 +572,7 @@ sub options_hash { # Replacement strings "parens=s" => \$opt::parens, "rpl=s" => \@opt::rpl, + "plus" => \$opt::plus, "I=s" => \$opt::I, "extensionreplace|er=s" => \$opt::U, "U=s" => \$opt::retired, @@ -739,6 +740,21 @@ sub parse_options { '{/.}' => 's:.*/::; s:\.[^/.]+$::;', '{.}' => 's:\.[^/.]+$::', ); + %Global::plus = + ( + # {} = {+/}/{/} + # = {.}.{+.} = {+/}/{/.}.{+.} + # = {..}.{+..} = {+/}/{/..}.{+..} + # = {...}.{+...} = {+/}/{/...}.{+...} + '{+/}' => 's:/[^/]*$::', + '{+.}' => 's:.*\.::', + '{+..}' => 's:.*\.([^.]*\.):$1:', + '{+...}' => 's:.*\.([^.]*\.[^.]*\.):$1:', + '{..}' => 's:\.[^/.]+$::; s:\.[^/.]+$::', + '{...}' => 's:\.[^/.]+$::; s:\.[^/.]+$::; s:\.[^/.]+$::', + '{/..}' => 's:.*/::; s:\.[^/.]+$::; s:\.[^/.]+$::', + '{/...}' => 's:.*/::; s:\.[^/.]+$::; s:\.[^/.]+$::; s:\.[^/.]+$::', + ); # Modifiable copy of %Global::replace %Global::rpl = %Global::replace; $Global::parens = "{==}"; @@ -784,6 +800,7 @@ sub parse_options { my $parenslen = 0.5*length $Global::parens; $Global::parensleft = substr($Global::parens,0,$parenslen); $Global::parensright = substr($Global::parens,$parenslen); + if(defined $opt::plus) { %Global::rpl = (%Global::plus,%Global::rpl); } if(defined $opt::I) { rpl('{}',$opt::I); } if(defined $opt::U) { rpl('{.}',$opt::U); } if(defined $opt::i and $opt::i) { rpl('{}',$opt::i); } @@ -828,6 +845,7 @@ sub parse_options { not defined $opt::recend) { $opt::recend = "\n"; } if(not defined $opt::blocksize) { $opt::blocksize = "1M"; } $opt::blocksize = multiply_binary_prefix($opt::blocksize); + if(defined $opt::controlmaster) { $opt::noctrlc = 1; } if(defined $opt::semaphore) { $Global::semaphore = 1; } if(defined $opt::semaphoretimeout) { $Global::semaphore = 1; } if(defined $opt::semaphorename) { $Global::semaphore = 1; } @@ -1057,8 +1075,8 @@ sub parse_env_var { # Create lines like: # echo $SHELL | grep "/t\\{0,1\\}csh" >/dev/null && setenv V1 val1 && setenv V2 val2 || export V1=val1 && export V2=val2 ; echo "$V1$V2" if(@vars) { - $Global::envvar .= - join"", + $Global::envvar .= + join"", (q{echo $SHELL | grep "/t\\{0,1\\}csh" > /dev/null && } . join(" && ", @qcsh) . q{ || } @@ -1148,7 +1166,7 @@ sub which { # Returns: # $full_path = full path to $program. undef if not found my $program = $_[0]; - + return (grep { -e $_."/".$program } split(":",$ENV{'PATH'}))[0]; } @@ -1358,8 +1376,10 @@ sub shell_quote_scalar { # $shell_quoted = string quoted with \ as needed by the shell my $a = $_[0]; if(defined $a) { - $a =~ s/([\002-\011\013-\032\\\#\?\`\(\)\{\}\[\]\*\>\<\~\|\; \"\!\$\&\'\202-\377])/\\$1/g; - $a =~ s/[\n]/'\n'/g; # filenames with '\n' is quoted using \' + # $a =~ s/([\002-\011\013-\032\\\#\?\`\(\)\{\}\[\]\*\>\<\~\|\; \"\!\$\&\'\202-\377])/\\$1/g; + # This is 1% faster than the above + $a =~ s/[\002-\011\013-\032\\\#\?\`\(\)\{\}\[\]\*\>\<\~\|\; \"\!\$\&\'\202-\377]/\\$&/go; + $a =~ s/[\n]/'\n'/go; # filenames with '\n' is quoted using \' } return $a; } @@ -1443,7 +1463,7 @@ sub save_stdin_stdout_stderr { # Returns: N/A # Find file descriptors that are already opened (by the shell) - for my $fdno (1..61) { + for my $fdno (1..61) { # /dev/fd/62 and above are used by bash for <(cmd) my $fh; if(open($fh,">&=",$fdno)) { @@ -1468,7 +1488,7 @@ sub enough_file_handles { my $enough_filehandles = 1; # perl uses 7 filehandles for something? # open3 uses 2 extra filehandles temporarily - # We need a filehandle for each redirected file descriptor + # We need a filehandle for each redirected file descriptor # (normally just STDOUT and STDERR) for my $i (1..(7+2+keys %Global::fd)) { $enough_filehandles &&= open($fh{$i}, "<", "/dev/null"); @@ -1569,7 +1589,7 @@ sub start_more_jobs { next; } if($sshlogin->too_fast_remote_login()) { - # It has been too short since + # It has been too short since next; } if($opt::delay and $opt::delay > ::now() - $Global::newest_starttime) { @@ -1795,9 +1815,9 @@ sub progress { } $eta = sprintf("ETA: %ds Left: %d AVG: %.2fs ", $this_eta, $left, $avgtime); if($opt::bar) { - my $arg = $Global::newest_job ? + my $arg = $Global::newest_job ? $Global::newest_job->{'commandline'}->replace_placeholders(["\257<\257>"],0,0) : ""; - my $bar_text = sprintf("%d%% %d:%d=%ds %s", + my $bar_text = sprintf("%d%% %d:%d=%ds %s", $pctcomplete*100, $completed, $left, $this_eta, $arg); my $rev = ''; my $reset = ''; @@ -1807,7 +1827,7 @@ sub progress { my $width = int($terminal_width * $pctcomplete); $s =~ s/^(.{$width})/$1$reset/; $s = "\r# ".int($this_eta)." sec $arg" . "\r". $pctcomplete*100 # Prefix with zenity header - . "\r" . $rev . $s . $reset; + . "\r" . $rev . $s . $reset; $status = $s; } } @@ -2064,7 +2084,7 @@ sub parse_sshlogin { } - debug("start", "sshlogin: ", my_dump(%Global::host),"\n"); + # debug("start", "sshlogin: ", my_dump(%Global::host),"\n"); if($opt::transfer or @opt::return or $opt::cleanup or @opt::basefile) { if(not remote_hosts()) { # There are no remote hosts @@ -2262,7 +2282,7 @@ sub onall { return $tmpfile; } my @command = @_; - if($Global::quoting) { + if($Global::quoting) { @command = shell_quote_empty(@command); } @@ -2353,9 +2373,9 @@ sub save_original_signal_handler { # Remember the original signal handler # Returns: N/A $SIG{TERM} ||= sub { exit 0; }; # $SIG{TERM} is not set on Mac OS X - $SIG{INT} = sub { if($opt::tmux) { qx { tmux kill-session -t p$$ }; } + $SIG{INT} = sub { if($opt::tmux) { qx { tmux kill-session -t p$$ }; } unlink keys %Global::unlink; exit -1 }; - $SIG{TERM} = sub { if($opt::tmux) { qx { tmux kill-session -t p$$ }; } + $SIG{TERM} = sub { if($opt::tmux) { qx { tmux kill-session -t p$$ }; } unlink keys %Global::unlink; exit -1 }; %Global::original_sig = %SIG; $SIG{TERM} = sub {}; # Dummy until jobs really start @@ -2426,11 +2446,11 @@ sub reaper { $Private::job_end_sequence++, $j = $Private::print_later{$Private::job_end_sequence}) { debug("run", "Found job end $Private::job_end_sequence"); - if($j) { + if($j) { $j->print(); delete $Private::print_later{$Private::job_end_sequence}; } - } + } } else { $job->print(); } @@ -2441,7 +2461,7 @@ sub reaper { if($opt::halt_on_error) { if($opt::halt_on_error == 1 or - ($opt::halt_on_error < 1 and $Global::total_failed > 3 + ($opt::halt_on_error < 1 and $Global::total_failed > 3 and $Global::total_failed / $Global::total_started > $opt::halt_on_error)) { # If halt on error == 1 or --halt 10% @@ -2507,26 +2527,29 @@ sub usage { print join ("\n", "Usage:", + "", "$Global::progname [options] [command [arguments]] < list_of_arguments", "$Global::progname [options] [command [arguments]] (::: arguments|:::: argfile(s))...", "cat ... | $Global::progname --pipe [options] [command [arguments]]", "", - "-j n Run n jobs in parallel", - "-k Keep same order", - "-X Multiple arguments with context replace", - "--colsep regexp Split input on regexp for positional replacements", - "{} {.} {/} {/.} {#} {%} Replacement strings", - "{3} {3.} {3/} {3/.} Positional replacement strings", + "-j n Run n jobs in parallel", + "-k Keep same order", + "-X Multiple arguments with context replace", + "--colsep regexp Split input on regexp for positional replacements", + "{} {.} {/} {/.} {#} {%} {= perl code =} Replacement strings", + "{3} {3.} {3/} {3/.} {=3 perl code =} Positional replacement strings", + "With --plus: {} = {+/}/{/} = {.}.{+.} = {+/}/{/.}.{+.} = {..}.{+..} =", + " {+/}/{/..}.{+..} = {...}.{+...} = {+/}/{/...}.{+...}", "", - "-S sshlogin Example: foo\@server.example.com", - "--slf .. Use ~/.parallel/sshloginfile as the list of sshlogins", - "--trc {}.bar Shorthand for --transfer --return {}.bar --cleanup", - "--onall Run the given command with argument on all sshlogins", - "--nonall Run the given command with no arguments on all sshlogins", + "-S sshlogin Example: foo\@server.example.com", + "--slf .. Use ~/.parallel/sshloginfile as the list of sshlogins", + "--trc {}.bar Shorthand for --transfer --return {}.bar --cleanup", + "--onall Run the given command with argument on all sshlogins", + "--nonall Run the given command with no arguments on all sshlogins", "", - "--pipe Split stdin (standard input) to multiple jobs.", - "--recend str Record end separator for --pipe.", - "--recstart str Record start separator for --pipe.", + "--pipe Split stdin (standard input) to multiple jobs.", + "--recend str Record end separator for --pipe.", + "--recstart str Record start separator for --pipe.", "", "See 'man $Global::progname' for details", "", @@ -2552,7 +2575,7 @@ sub citation_notice { -e $ENV{'HOME'}."/.parallel/will-cite") { # skip } else { - print $Global::original_stderr + print $Global::original_stderr ("When using programs that use GNU Parallel to process data for publication please cite:\n", "\n", " O. Tange (2011): GNU Parallel - The Command-Line Power Tool,\n", @@ -2647,7 +2670,7 @@ sub bibtex { my $input = ; if($input =~ /will cite/i) { mkdir $ENV{'HOME'}."/.parallel"; - open (my $fh, ">", $ENV{'HOME'}."/.parallel/will-cite") + open (my $fh, ">", $ENV{'HOME'}."/.parallel/will-cite") || ::die_bug("Cannot write: ".$ENV{'HOME'}."/.parallel/will-cite"); close $fh; print "\nThank you for your support. It is much appreciated. The citation\n", @@ -3104,14 +3127,14 @@ sub swap_activity { # $ vm_stat -c 2 1 # Mach Virtual Memory Statistics: (page size of 4096 bytes) # free active specul inactive throttle wired prgable faults copy 0fill reactive purged file-backed anonymous cmprssed cmprssor dcomprs comprs pageins pageout swapins swapouts - # 346306 829050 74871 606027 0 240231 90367 544858K 62343596 270837K 14178 415070 570102 939846 356 370 116 922 4019813 4 0 0 - # 345740 830383 74875 606031 0 239234 90369 2696 359 553 0 0 570110 941179 356 370 0 0 0 0 0 0 + # 346306 829050 74871 606027 0 240231 90367 544858K 62343596 270837K 14178 415070 570102 939846 356 370 116 922 4019813 4 0 0 + # 345740 830383 74875 606031 0 239234 90369 2696 359 553 0 0 570110 941179 356 370 0 0 0 0 0 0 'darwin' => ['vm_stat -c 2 1 | tail -n1', '$21*$22'], # ultrix: $12*$13 # $ vmstat -S 1 2 - # procs faults cpu memory page disk - # r b w in sy cs us sy id avm fre si so pi po fr de sr s0 + # procs faults cpu memory page disk + # r b w in sy cs us sy id avm fre si so pi po fr de sr s0 # 1 0 0 4 23 2 3 0 97 7743 217k 0 0 0 0 0 0 0 0 # 1 0 0 6 40 8 0 1 99 7743 217k 0 0 3 0 0 0 0 0 'ultrix' => ['vmstat -S 1 2 | tail -1', '$12*$13'], @@ -3119,8 +3142,8 @@ sub swap_activity { # aix: $6*$7 # $ vmstat 1 2 # System configuration: lcpu=1 mem=2048MB - # - # kthr memory page faults cpu + # + # kthr memory page faults cpu # ----- ----------- ------------------------ ------------ ----------- # r b avm fre re pi po fr sr cy in sy cs us sy id wa # 0 0 333933 241803 0 0 0 0 0 0 10 143 90 0 0 99 0 @@ -3193,7 +3216,7 @@ sub swap_activity { #q[ { vmstat 1 2 2> /dev/null || vmstat -c 1 2; } | ]. # q[ awk 'NR!=4{next} NF==17||NF==16{print $7*$8} NF==22{print $21*$22} {exit}' ]; $vmstat{$os}[1] =~ s/\$/\\\\\\\$/g; # $ => \\\$ - $perlscript .= 'if($^O eq "'.$os.'") { print `'.$vmstat{$os}[0].' | awk "{print ' . + $perlscript .= 'if($^O eq "'.$os.'") { print `'.$vmstat{$os}[0].' | awk "{print ' . $vmstat{$os}[1] . '}"` }'; } $perlscript = "perl -e " . ::shell_quote_scalar($perlscript); @@ -3822,7 +3845,7 @@ sub nproc { # Number of cores using `nproc` my $no_of_cores = `nproc 2>/dev/null`; return $no_of_cores; -} +} sub no_of_cpus_gnu_linux { # Returns: @@ -4098,8 +4121,7 @@ sub no_of_cpus_irix { # Returns: # Number of physical CPUs on IRIX # undef if not IRIX - my $no_of_cpus = - (`hinv | grep HZ | grep Processor | awk '{print \$1}'`); + my $no_of_cpus = `hinv | grep HZ | grep Processor | awk '{print \$1}'`; return $no_of_cpus; } @@ -4107,8 +4129,7 @@ sub no_of_cores_irix { # Returns: # Number of CPU cores on IRIX # undef if not IRIX - my $no_of_cores = - (`hinv | grep HZ | grep Processor | awk '{print \$1}'`); + my $no_of_cores = `hinv | grep HZ | grep Processor | awk '{print \$1}'`; return $no_of_cores; } @@ -4116,8 +4137,7 @@ sub no_of_cpus_tru64 { # Returns: # Number of physical CPUs on Tru64 # undef if not Tru64 - my $no_of_cpus = - (`sizer -pr`); + my $no_of_cpus = `sizer -pr`; return $no_of_cpus; } @@ -4125,8 +4145,7 @@ sub no_of_cores_tru64 { # Returns: # Number of CPU cores on Tru64 # undef if not Tru64 - my $no_of_cores = - (`sizer -pr`); + my $no_of_cores = `sizer -pr`; return $no_of_cores; } @@ -4544,7 +4563,7 @@ sub openoutputfiles { $self->fh($fdno,'name')) || die $?; $self->set_fh($fdno,'w',$fdw); $self->set_fh($fdno,'wpid',$wpid); - my $rpid = open(my $fdr, "-|", "perl", "-e", $cattail, + my $rpid = open(my $fdr, "-|", "perl", "-e", $cattail, $opt::decompress_program, $wpid, $self->fh($fdno,'name'),$self->fh($fdno,'unlink')) || die $?; $self->set_fh($fdno,'r',$fdr); @@ -4556,7 +4575,7 @@ sub openoutputfiles { # Re-open the file for reading # so fdw can be closed seperately # and fdr can be seeked seperately (for --line-buffer) - open(my $fdr,"<", $self->fh($fdno,'name')) || + open(my $fdr,"<", $self->fh($fdno,'name')) || ::die_bug("fdr: Cannot open ".$self->fh($fdno,'name')); $self->set_fh($fdno,'r',$fdr); # Unlink if required @@ -4788,7 +4807,7 @@ sub kill { my $self = shift; my $pid = $self->pid(); - %pid_parentpid_cmd or %pid_parentpid_cmd = + %pid_parentpid_cmd or %pid_parentpid_cmd = ( 'aix' => q( ps -ef | awk '{print $2" "$3}' ), 'cygwin' => q( ps -ef | awk '{print $2" "$3}' ), @@ -4960,7 +4979,7 @@ sub sshlogin_wrap { if($opt::workdir) { my $wd = ::shell_quote_file($self->workdir()); $remote_pre .= ::shell_quote_scalar("mkdir -p ") . $wd . - ::shell_quote_scalar("; cd ") . $wd . + ::shell_quote_scalar("; cd ") . $wd . # exit 255 (instead of exec false) would be the correct thing, # but that fails on tcsh ::shell_quote_scalar(qq{ || exec false;}); @@ -4971,14 +4990,14 @@ sub sshlogin_wrap { # It works on Linux but not Solaris my $signal_script = "perl -e '". q{ - use IO::Poll; - $SIG{CHLD} = sub {exit ($?&127 ? 128+($?&127) : 1+$?>>8)}; - $p = IO::Poll->new; - $p->mask(STDOUT, POLLHUP); - $pid=fork; unless($pid) {setpgrp; exec $ENV{SHELL}, "-c", @ARGV; die "exec: $!\n"} - $p->poll; - kill SIGHUP, -${pid} unless $done; - wait; exit ($?&127 ? 128+($?&127) : 1+$?>>8) + use IO::Poll; + $SIG{CHLD} = sub {exit ($?&127 ? 128+($?&127) : 1+$?>>8)}; + $p = IO::Poll->new; + $p->mask(STDOUT, POLLHUP); + $pid=fork; unless($pid) {setpgrp; exec $ENV{SHELL}, "-c", @ARGV; die "exec: $!\n"} + $p->poll; + kill SIGHUP, -${pid} unless $done; + wait; exit ($?&127 ? 128+($?&127) : 1+$?>>8) } . "' "; $signal_script =~ s/\s+/ /g; @@ -4988,7 +5007,7 @@ sub sshlogin_wrap { . $remote_pre # . ::shell_quote_scalar($signal_script . ::shell_quote_scalar($next_command_line)) . ::shell_quote_scalar($next_command_line) - . ";" + . ";" . $post); } } @@ -5080,7 +5099,7 @@ sub sshreturn { } # Only load File::Basename if actually needed $Global::use{"File::Basename"} ||= eval "use File::Basename; 1;"; - # dir/./file means relative to dir, so remove dir on remote + # dir/./file means relative to dir, so remove dir on remote $file =~ m:(.*)/\./:; my $basedir = $1 ? ::shell_quote_file($1."/") : ""; my $nobasedir = $file; @@ -5089,8 +5108,8 @@ sub sshreturn { my $rsync_cd = '--rsync-path='.::shell_quote_scalar("cd $wd$cd; rsync"); my $basename = ::shell_quote_scalar(::shell_quote_file(basename($file))); # --return - # mkdir -p /home/tange/dir/subdir/; - # rsync -rlDzR --rsync-path="cd /home/tange/dir/subdir/; rsync" + # mkdir -p /home/tange/dir/subdir/; + # rsync -rlDzR --rsync-path="cd /home/tange/dir/subdir/; rsync" # server:file.gz /home/tange/dir/subdir/ $pre .= "mkdir -p $basedir$cd; rsync $rsync_cd $rsync_opt $serverlogin:". $basename . " ".$basedir.$cd.";"; @@ -5246,7 +5265,7 @@ sub start { $job->seq(), "): $command\n"); if($opt::pipe) { my ($stdin_fh); - # Wrap command with end-of-file detector, + # Wrap command with end-of-file detector, # so we do not spawn a program if there is no input. # Exit value: # empty input = true @@ -5586,7 +5605,7 @@ sub print { print $out_fd $buf; } } - close $in_fh; + close $in_fh; } flush $out_fd; } @@ -5731,7 +5750,7 @@ sub populate { my $self = shift; my $next_arg; my $max_len = $Global::minimal_command_line_length || Limits::Command::max_length(); - + if($opt::cat or $opt::fifo) { # Get a tempfile name my($outfh,$name) = ::tempfile(SUFFIX => ".pip"); @@ -5758,7 +5777,7 @@ sub populate { last; } else { my $args = join(" ", map { $_->orig() } @$next_arg); - ::error("Command line too long (", + ::error("Command line too long (", $self->len(), " >= ", Limits::Command::max_length(), ") at number ", @@ -5800,18 +5819,18 @@ sub push { my $self = shift; my $record = shift; push @{$self->{'arg_list'}}, $record; - my $arg_no = ($self->number_of_args()-1) * ($#$record+1); my $quote_arg = $Global::noquote ? 0 : not $Global::quoting; my $rep; for my $arg (@$record) { - $arg_no++; if(defined $arg) { for my $perlexpr (keys %{$self->{'replacecount'}}) { - $rep = $arg->replace($perlexpr,$quote_arg,$self); - $self->{'len'}{$perlexpr} += length $rep; - ::debug("length", "Length: ", length $rep, - "(", $perlexpr, "=>", $rep, ")\n"); + # 50% faster than below + $self->{'len'}{$perlexpr} += length $arg->replace($perlexpr,$quote_arg,$self); + # $rep = $arg->replace($perlexpr,$quote_arg,$self); + # $self->{'len'}{$perlexpr} += length $rep; + # ::debug("length", "Length: ", length $rep, + # "(", $perlexpr, "=>", $rep, ")\n"); } } } @@ -5857,12 +5876,12 @@ sub number_of_args { # Mdzrvadp Nvmdymeaz az 2011-04-10. Ftue oaawuq dqxqmeqp az # 2013-08-18 ue m nuf tmdpqd me kag tmhq fa geq daf14. Bxqmeq # qymux oaawuq@fmzsq.pw itqz kag dqmp ftue. - # + # # U my ftq ymuzfmuzqd ar m buqoq ar rdqq earfimdq omxxqp SZG # Bmdmxxqx. Rdqq earfimdq sgmdmzfqqe kag mooqee fa ftq eagdoq # oapq, ngf U tmhq nqqz iazpqduzs tai ymzk mofgmxxk _dqmp_ ftq # eagdoq oapq. - # + # # Fa fqef ftue U bgf uz m oayyqzf fqxxuzs bqabxq fa qymux yq itqz # ftqk dqmp ftue. Ftq oayyqzf ime bgf uz m eqofuaz ar ftq oapq # ftmf za azq iagxp xaaw fa ruj ad uybdahq ftq earfimdq - ea ftq @@ -5870,11 +5889,11 @@ sub number_of_args { # oayyqzf iagxp zaf etai gb ur eayq azq vgef sdqbbqp ftdagst ftq # eagdoq oapq U daf13'qp ftq eagdoq oapq # tffb://qz.iuwubqpum.ads/iuwu/DAF13 - # + # # 2.5 yazfte xmfqd U dqoquhqp mz qymux rday eayqazq ita zaf azxk # ymzmsqp fa ruzp ftq oayyqzf, ngf mxea ymzmsqp fa sgqee ftq oapq # tmp fa nq daf13'qp. - # + # # Ftue nduzse yq fa ftq oazoxgeuaz ftmf ftqdq _mdq_ bqabxq, ita # mdq zaf mrruxumfqp iuft ftq bdavqof, ftmf iuxx dqmp ftq eagdoq # oapq - ftagst uf ymk zaf tmbbqz hqdk arfqz. @@ -5943,7 +5962,7 @@ sub header_indexes_sorted { # Returns: # Indexes of %Global::input_source_header sorted my $max_col = shift; - + no warnings 'numeric'; for my $col (1 .. $max_col) { # Make sure the header is defined. If it is not: use column number @@ -6033,17 +6052,17 @@ sub replaced { if($opt::cat) { # Prepend 'cat > {};' # Append '_EXIT=$?;(rm {};exit $_EXIT)' - $self->{'replaced'} = - $self->replace_placeholders(["cat > \257<\257>; ", $cmdstring, + $self->{'replaced'} = + $self->replace_placeholders(["cat > \257<\257>; ", $cmdstring, "; _EXIT=\$?; rm \257<\257>; exit \$_EXIT"], 0,0); } elsif($opt::fifo) { # Prepend 'mkfifo {}; (' # Append ') & _PID=$!; cat > {}; wait $_PID; _EXIT=$?;(rm {};exit $_EXIT)' - $self->{'replaced'} = + $self->{'replaced'} = $self->replace_placeholders(["mkfifo \257<\257>; (", $cmdstring, - ") & _PID=\$!; cat > \257<\257>; ", + ") & _PID=\$!; cat > \257<\257>; ", "wait \$_PID; _EXIT=\$?; ", "rm \257<\257>; exit \$_EXIT"], 0,0); @@ -6077,7 +6096,7 @@ sub replaced { } sub replace_placeholders { - # Replace foo{}bar with fooargbar + # Replace foo{}bar with fooargbar # Input: # target = foo{}bar # quote = should this be quoted? @@ -6163,7 +6182,7 @@ sub replace_placeholders { if($w !~ /\257/) { # No more replacement strings in $w: No need to do more - CORE::push(@{$replace{$word}}, $w); + CORE::push(@{$replace{$word}}, $w); next; } # for each arg: @@ -6200,14 +6219,14 @@ sub replace_placeholders { if($quote) { $val = ::shell_quote_scalar($val); } - CORE::push(@{$replace{$ww}}, $val); + CORE::push(@{$replace{$ww}}, $val); } } if($quote) { @target = ::shell_quote(@target); } - ::debug("replace", "%replace=".(::my_dump(%replace))."\n"); + # ::debug("replace", "%replace=",::my_dump(%replace),"\n"); if(%replace) { # Substitute the replace strings with the replacement values # Must be sorted by length if a short word is a substring of a long word @@ -6295,7 +6314,7 @@ sub new { $contextgroups++; } # All {= perl expr =} have been removed: The rest is non-context - $noncontextlen += length $c; + $noncontextlen += length $c; } if($opt::tagstring) { my $t = $opt::tagstring; @@ -6437,7 +6456,7 @@ sub max_length { # Returns: # number of chars on the longest command line allowed if(not $Limits::Command::line_max_len) { - # Disk cache of max command line length + # Disk cache of max command line length my $len_cache = $ENV{'HOME'} . "/.parallel/tmp/linelen-" . ::hostname(); my $cached_limit; if(-e $len_cache) { @@ -6795,22 +6814,22 @@ sub read_arg_from_fh { my $prepend = undef; my $arg; do {{ - if(eof($fh)) { + # This makes 10% faster + if(not ($arg = <$fh>)) { if(defined $prepend) { return Arg->new($prepend); } else { return undef; } } - $arg = <$fh>; - ::debug("run", "read $arg\n"); +# ::debug("run", "read $arg\n"); # Remove delimiter $arg =~ s:$/$::; if($Global::end_of_file_string and $arg eq $Global::end_of_file_string) { # Ignore the rest of input file while (<$fh>) {} - ::debug("run", "EOF-string $arg\n"); +# ::debug("run", "EOF-string $arg\n"); if(defined $prepend) { return Arg->new($prepend); } else { @@ -6878,7 +6897,7 @@ sub new { sub replace { # Calculates the corresponding value for a given perl expression # Returns: - # The calculated string unquoted + # The calculated string (quoted if asked for) my $self = shift; my $perlexpr = shift; # E.g. $_=$_ or s/.gz// my $quote = (shift) ? 1 : 0; # should the string be quoted? @@ -6887,15 +6906,26 @@ sub replace { my $job = shift; $perlexpr =~ s/^-?\d+ //; # Positional replace treated as normal replace if(not defined $self->{"rpl",0,$perlexpr}) { - my $s; + local $_; if($Global::trim eq "n") { - $s = $self->{'orig'}; + $_ = $self->{'orig'}; } else { - $s = trim_of($self->{'orig'}); + $_ = trim_of($self->{'orig'}); } - local $_ = $s; ::debug("replace", "eval ", $perlexpr, " ", $_, "\n"); - eval $perlexpr; + if(not $Global::perleval{$perlexpr}) { + # Make an anonymous function of the $perlexpr + # And more importantly: Compile it only once + if($Global::perleval{$perlexpr} = eval('sub { my $job = shift; '.$perlexpr.' }')) { + # All is good + } else { + # The eval failed. Maybe $perlexpr is invalid perl? + ::error("Cannot use $perlexpr\n"); + ::wait_and_exit(255); + } + } + # Execute the function + $Global::perleval{$perlexpr}->($job); $self->{"rpl",0,$perlexpr} = $_; } if(not defined $self->{"rpl",$quote,$perlexpr}) { @@ -6972,7 +7002,7 @@ sub remedian { } sub set_remedian { - # Set median of the last 999^3 (=997002999) values using Remedian + # Set median of the last 999^3 (=997002999) values using Remedian # # Rousseeuw, Peter J., and Gilbert W. Bassett Jr. "The remedian: A # robust averaging method for large data sets." Journal of the diff --git a/src/parallel.pod b/src/parallel.pod index dcc1d7b1..07baca15 100644 --- a/src/parallel.pod +++ b/src/parallel.pod @@ -1,5 +1,7 @@ #!/usr/bin/perl -w +=encoding utf8 + =head1 NAME parallel - build and execute shell command lines from standard input in parallel diff --git a/src/parallel.texi b/src/parallel.texi index c54586ef..2c224f66 100644 --- a/src/parallel.texi +++ b/src/parallel.texi @@ -172,7 +172,7 @@ If it is a zsh function you will need to use this helper function SHELL=/bin/bash parallel "my_func {}" ::: 1 2 @end verbatim -The command cannot contain the character \257 (¯). +The command cannot contain the character \257 (¯). @item @strong{@{@}} (alpha testing) @anchor{@strong{@{@}} (alpha testing)} diff --git a/src/parallel_tutorial.1 b/src/parallel_tutorial.1 index 189c7948..65a7c955 100644 --- a/src/parallel_tutorial.1 +++ b/src/parallel_tutorial.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) +.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== @@ -38,6 +38,8 @@ . ds PI \(*p . ds L" `` . ds R" '' +. ds C` +. ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. @@ -48,17 +50,24 @@ .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. -.ie \nF \{\ -. de IX -. tm Index:\\$1\t\\n%\t"\\$2" +.\" +.\" Avoid warning from groff about undefined register 'F'. +.de IX .. -. nr % 0 -. rr F -.\} -.el \{\ -. de IX +.nr rF 0 +.if \n(.g .if rF .nr rF 1 +.if (\n(rF:(\n(.g==0)) \{ +. if \nF \{ +. de IX +. tm Index:\\$1\t\\n%\t"\\$2" .. +. if !\nF==2 \{ +. nr % 0 +. nr F 2 +. \} +. \} .\} +.rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. @@ -124,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "PARALLEL_TUTORIAL 1" -.TH PARALLEL_TUTORIAL 1 "2014-07-20" "20140711" "parallel" +.TH PARALLEL_TUTORIAL 1 "2014-07-26" "20140722" "parallel" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -257,7 +266,7 @@ The input source can be a file: .PP Output: Same as above. .PP -\&\s-1STDIN\s0 (standard input) can be the input source: +\&\s-1STDIN \s0(standard input) can be the input source: .PP .Vb 1 \& cat abc\-file | parallel echo @@ -296,7 +305,7 @@ The input sources can be files: .PP Output: Same as above. .PP -\&\s-1STDIN\s0 (standard input) can be one of the input sources using '\-': +\&\s-1STDIN \s0(standard input) can be one of the input sources using '\-': .PP .Vb 1 \& cat abc\-file | parallel \-a \- \-a def\-file echo @@ -721,7 +730,7 @@ replacement string, too: .PP Output: Same as above. .PP -\&\s-1GNU\s0 \fBparallel\fR's 7 replacement strings are implemented as: +\&\s-1GNU \s0\fBparallel\fR's 7 replacement strings are implemented as: .PP .Vb 7 \& \-\-rpl \*(Aq{} \*(Aq @@ -814,7 +823,7 @@ Output: Same as above. .IX Subsection "Input from columns" .PP The columns in a file can be bound to positional replacement strings -using \-\-colsep. Here the columns are separated with \s-1TAB\s0 (\et): +using \-\-colsep. Here the columns are separated with \s-1TAB \s0(\et): .PP .Vb 1 \& parallel \-\-colsep \*(Aq\et\*(Aq echo 1={1} 2={2} :::: tsv\-file.tsv @@ -2127,7 +2136,7 @@ where command_B is slow, and you want to speed up command_B. .SS "Chunk size" .IX Subsection "Chunk size" By default \s-1GNU\s0 Parallel will start an instance of command_B, read a -chunk of 1 \s-1MB\s0, and pass that to the instance. Then start another +chunk of 1 \s-1MB,\s0 and pass that to the instance. Then start another instance, read another chunk, and pass that to the second instance. .PP .Vb 1 @@ -2148,7 +2157,7 @@ Output (the order may be different): .PP The size of the chunk is not exactly 1 \s-1MB\s0 because \s-1GNU\s0 Parallel only passes full lines \- never half a line, thus the blocksize is only -average 1 \s-1MB\s0. You can change the block size to 2 \s-1MB\s0 with \-\-block: +average 1 \s-1MB.\s0 You can change the block size to 2 \s-1MB\s0 with \-\-block: .PP .Vb 1 \& cat num1000000 | parallel \-\-pipe \-\-block 2M wc diff --git a/src/parallel_tutorial.html b/src/parallel_tutorial.html index 56a9862d..206bed23 100644 --- a/src/parallel_tutorial.html +++ b/src/parallel_tutorial.html @@ -2,7 +2,7 @@ -GNU Parallel Tutorial + @@ -10,245 +10,237 @@ - -
-

-
- +

GNU Parallel Tutorial

+ +

This tutorial shows off much of GNU Parallel's functionality. The tutorial is meant to learn the options in GNU Parallel. The tutorial is not to show realistic examples from the real world.

+ +

Spend an hour walking through the tutorial. Your command line will love you for it.

+ +

Prerequisites

-

-

-

GNU Parallel Tutorial

-

This tutorial shows off much of GNU Parallel's functionality. The -tutorial is meant to learn the options in GNU Parallel. The tutorial -is not to show realistic examples from the real world.

-

Spend an hour walking through the tutorial. Your command line will -love you for it.

-

-

-
-

Prerequisites

To run this tutorial you must have the following:

+
-
parallel >= version 20140622
+
parallel >= version 20140622
+

Install the newest version with:

-
-  (wget -O - pi.dk/3 || curl pi.dk/3/) | bash
+ +
  (wget -O - pi.dk/3 || curl pi.dk/3/) | bash
+

This will also install the newest version of the tutorial:

-
-  man parallel_tutorial
+ +
  man parallel_tutorial
+

Most of the tutorial will work on older versions, too.

-
-
abc-file:
+ +
abc-file:
+

The file can be generated by:

-
-  parallel -k echo ::: A B C > abc-file
-
-
def-file:
+
  parallel -k echo ::: A B C > abc-file
+ + +
def-file:
+

The file can be generated by:

-
-  parallel -k echo ::: D E F > def-file
-
-
abc0-file:
+
  parallel -k echo ::: D E F > def-file
+ + +
abc0-file:
+

The file can be generated by:

-
-  perl -e 'printf "A\0B\0C\0"' > abc0-file
-
-
abc_-file:
+
  perl -e 'printf "A\0B\0C\0"' > abc0-file
+ + +
abc_-file:
+

The file can be generated by:

-
-  perl -e 'printf "A_B_C_"' > abc_-file
-
-
tsv-file.tsv
+
  perl -e 'printf "A_B_C_"' > abc_-file
+ + +
tsv-file.tsv
+

The file can be generated by:

-
-  perl -e 'printf "f1\tf2\nA\tB\nC\tD\n"' > tsv-file.tsv
-
-
num30000
+
  perl -e 'printf "f1\tf2\nA\tB\nC\tD\n"' > tsv-file.tsv
+ + +
num30000
+

The file can be generated by:

-
-  perl -e 'for(1..30000){print "$_\n"}' > num30000
-
-
num1000000
+
  perl -e 'for(1..30000){print "$_\n"}' > num30000
+ + +
num1000000
+

The file can be generated by:

-
-  perl -e 'for(1..1000000){print "$_\n"}' > num1000000
-
-
num_%header
+
  perl -e 'for(1..1000000){print "$_\n"}' > num1000000
+ + +
num_%header
+

The file can be generated by:

-
-  (echo %head1; echo %head2; perl -e 'for(1..10){print "$_\n"}') > num_%header
-
-
For remote running: ssh login on 2 servers with no password in -$SERVER1 and $SERVER2
+
  (echo %head1; echo %head2; perl -e 'for(1..10){print "$_\n"}') > num_%header
+ + +
For remote running: ssh login on 2 servers with no password in $SERVER1 and $SERVER2
-
-  SERVER1=server.example.com
-  SERVER2=server2.example.net
+ +
  SERVER1=server.example.com
+  SERVER2=server2.example.net
+

You must be able to:

-
-  ssh $SERVER1 echo works
-  ssh $SERVER2 echo works
-

It can be setup by running 'ssh-keygen -t dsa; ssh-copy-id $SERVER1' -and using an empty pass phrase.

+ +
  ssh $SERVER1 echo works
+  ssh $SERVER2 echo works
+ +

It can be setup by running 'ssh-keygen -t dsa; ssh-copy-id $SERVER1' and using an empty pass phrase.

+
-

-

-
-

Input sources

-

GNU Parallel reads input from input sources. These can be files, the -command line, and stdin (standard input or a pipe).

-

-

-

A single input source

+ +

Input sources

+ +

GNU Parallel reads input from input sources. These can be files, the command line, and stdin (standard input or a pipe).

+ +

A single input source

+

Input can be read from the command line:

-
-  parallel echo ::: A B C
-

Output (the order may be different because the jobs are run in -parallel):

-
-  A
+
+
  parallel echo ::: A B C
+ +

Output (the order may be different because the jobs are run in parallel):

+ +
  A
   B
-  C
+ C
+

The input source can be a file:

-
-  parallel -a abc-file echo
+ +
  parallel -a abc-file echo
+

Output: Same as above.

+

STDIN (standard input) can be the input source:

-
-  cat abc-file | parallel echo
+ +
  cat abc-file | parallel echo
+

Output: Same as above.

-

-

-

Multiple input sources

-

GNU Parallel can take multiple input sources given on the command -line. GNU Parallel then generates all combinations of the input -sources:

-
-  parallel echo ::: A B C ::: D E F
+ +

Multiple input sources

+ +

GNU Parallel can take multiple input sources given on the command line. GNU Parallel then generates all combinations of the input sources:

+ +
  parallel echo ::: A B C ::: D E F
+

Output (the order may be different):

-
-  A D
+
+
  A D
   A E
   A F
   B D
@@ -256,54 +248,65 @@ sources:

B F C D C E - C F
+ C F
+

The input sources can be files:

-
-  parallel -a abc-file -a def-file echo
+ +
  parallel -a abc-file -a def-file echo
+

Output: Same as above.

-

STDIN (standard input) can be one of the input sources using '-':

-
-  cat abc-file | parallel -a - -a def-file echo
+ +

STDIN (standard input) can be one of the input sources using '-':

+ +
  cat abc-file | parallel -a - -a def-file echo 
+

Output: Same as above.

-

Instead of -a files can be given after '::::':

-
-  cat abc-file | parallel echo :::: - def-file
+ +

Instead of -a files can be given after '::::':

+ +
  cat abc-file | parallel echo :::: - def-file
+

Output: Same as above.

+

::: and :::: can be mixed:

-
-  parallel echo ::: A B C :::: def-file
+ +
  parallel echo ::: A B C :::: def-file
+

Output: Same as above.

-

-

-

Matching arguments from all input sources

+ +

Matching arguments from all input sources

+

With --xapply you can get one argument from each input source:

-
-  parallel --xapply echo ::: A B C ::: D E F
+ +
  parallel --xapply echo ::: A B C ::: D E F
+

Output (the order may be different):

-
-  A D
+
+
  A D
   B E
-  C F
+ C F
+

If one of the input sources is too short, its values will wrap:

-
-  parallel --xapply echo ::: A B C D E ::: F G
+ +
  parallel --xapply echo ::: A B C D E ::: F G
+

Output (the order may be different):

-
-  A F
+
+
  A F
   B G
   C F
   D G
-  E F
-

-

-

Changing the argument separator.

-

GNU Parallel can use other separators than ::: or ::::. This is -typically useful if ::: or :::: is used in the command to run:

-
-  parallel --arg-sep ,, echo ,, A B C :::: def-file
+ E F
+ +

Changing the argument separator.

+ +

GNU Parallel can use other separators than ::: or ::::. This is typically useful if ::: or :::: is used in the command to run:

+ +
  parallel --arg-sep ,, echo ,, A B C :::: def-file
+

Output (the order may be different):

-
-  A D
+
+
  A D
   A E
   A F
   B D
@@ -311,504 +314,581 @@ typically useful if ::: or :::: is used in the command to run:

B F C D C E - C F
+ C F
+

Changing the argument file separator:

-
-  parallel --arg-file-sep // echo ::: A B C // def-file
+ +
  parallel --arg-file-sep // echo ::: A B C // def-file
+

Output: Same as above.

-

-

-

Changing the argument delimiter

-

GNU Parallel will normally treat a full line as a single argument: It -uses \n as argument delimiter. This can be changed with -d:

-
-  parallel -d _ echo :::: abc_-file
+ +

Changing the argument delimiter

+ +

GNU Parallel will normally treat a full line as a single argument: It uses \n as argument delimiter. This can be changed with -d:

+ +
  parallel -d _ echo :::: abc_-file
+

Output (the order may be different):

-
-  A
+
+
  A
   B
-  C
+ C
+

NULL can be given as \0:

-
-  parallel -d '\0' echo :::: abc0-file
+ +
  parallel -d '\0' echo :::: abc0-file
+

Output: Same as above.

-

A shorthand for -d '\0' is -0 (this will often be used to read files -from find ... -print0):

-
-  parallel -0 echo :::: abc0-file
+ +

A shorthand for -d '\0' is -0 (this will often be used to read files from find ... -print0):

+ +
  parallel -0 echo :::: abc0-file
+

Output: Same as above.

-

-

-

End-of-file value for input source

+ +

End-of-file value for input source

+

GNU Parallel can stop reading when it encounters a certain value:

-
-  parallel -E stop echo ::: A B stop C D
+ +
  parallel -E stop echo ::: A B stop C D
+

Output:

-
-  A
-  B
-

-

-

Skipping empty lines

+ +
  A
+  B
+ +

Skipping empty lines

+

Using --no-run-if-empty GNU Parallel will skip empty lines.

-
-  (echo 1; echo; echo 2) | parallel --no-run-if-empty echo
+ +
  (echo 1; echo; echo 2) | parallel --no-run-if-empty echo
+

Output:

-
-  1
-  2
-

-

-
-

Building the command line

-

-

-

No command means arguments are commands

-

If no command is given after parallel the arguments themselves are -treated as commands:

-
-  parallel ::: ls 'echo foo' pwd
+ +
  1
+  2
+ +

Building the command line

+ +

No command means arguments are commands

+ +

If no command is given after parallel the arguments themselves are treated as commands:

+ +
  parallel ::: ls 'echo foo' pwd
+

Output (the order may be different):

-
-  [list of files in current dir]
+
+
  [list of files in current dir]
   foo
-  [/path/to/current/working/dir]
-

The command can be a script, a binary or a Bash function if the function is -exported using 'export -f':

-
-  # Only works in Bash and only if $SHELL=.../bash
+  [/path/to/current/working/dir]
+ +

The command can be a script, a binary or a Bash function if the function is exported using 'export -f':

+ +
  # Only works in Bash and only if $SHELL=.../bash
   my_func() {
     echo in my_func $1
   }
   export -f my_func
-  parallel my_func ::: 1 2 3
+ parallel my_func ::: 1 2 3
+

Output (the order may be different):

-
-  in my_func 1
+
+
  in my_func 1
   in my_func 2
-  in my_func 3
-

-

-

Replacement strings

-

-

-

The 7 predefined replacement strings

-

GNU Parallel has several replacement strings. If no replacement -strings are used the default is to append {}:

-
-  parallel echo ::: A/B.C
+ in my_func 3
+ +

Replacement strings

+ +

The 7 predefined replacement strings

+ +

GNU Parallel has several replacement strings. If no replacement strings are used the default is to append {}:

+ +
  parallel echo ::: A/B.C
+

Output:

-
-  A/B.C
+ +
  A/B.C
+

The default replacement string is {}:

-
-  parallel echo {} ::: A/B.C
+ +
  parallel echo {} ::: A/B.C
+

Output:

-
-  A/B.C
+ +
  A/B.C
+

The replacement string {.} removes the extension:

-
-  parallel echo {.} ::: A/B.C
+ +
  parallel echo {.} ::: A/B.C
+

Output:

-
-  A/B
+ +
  A/B
+

The replacement string {/} removes the path:

-
-  parallel echo {/} ::: A/B.C
+ +
  parallel echo {/} ::: A/B.C
+

Output:

-
-  B.C
+ +
  B.C
+

The replacement string {//} keeps only the path:

-
-  parallel echo {//} ::: A/B.C
+ +
  parallel echo {//} ::: A/B.C
+

Output:

-
-  A
+ +
  A
+

The replacement string {/.} removes the path and the extension:

-
-  parallel echo {/.} ::: A/B.C
+ +
  parallel echo {/.} ::: A/B.C
+

Output:

-
-  B
+ +
  B
+

The replacement string {#} gives the job number:

-
-  parallel echo {#} ::: A B C
+ +
  parallel echo {#} ::: A B C
+

Output (the order may be different):

-
-  1
+
+
  1
   2
-  3
-

The replacement string {%} gives the job slot number (between 1 and -number of jobs to run in parallel):

-
-  parallel -j 2 echo {%} ::: A B C
+ 3
+ +

The replacement string {%} gives the job slot number (between 1 and number of jobs to run in parallel):

+ +
  parallel -j 2 echo {%} ::: A B C
+

Output (the order may be different):

-
-  1
+
+
  1
   2
-  1
-

-

-

Changing the replacement strings

+ 1
+ +

Changing the replacement strings

+

The replacement string {} can be changed with -I:

-
-  parallel -I ,, echo ,, ::: A/B.C
+ +
  parallel -I ,, echo ,, ::: A/B.C
+

Output:

-
-  A/B.C
+ +
  A/B.C
+

The replacement string {.} can be changed with --extensionreplace:

-
-  parallel --extensionreplace ,, echo ,, ::: A/B.C
+ +
  parallel --extensionreplace ,, echo ,, ::: A/B.C
+

Output:

-
-  A/B
+ +
  A/B
+

The replacement string {/} can be replaced with --basenamereplace:

-
-  parallel --basenamereplace ,, echo ,, ::: A/B.C
+ +
  parallel --basenamereplace ,, echo ,, ::: A/B.C
+

Output:

-
-  B.C
+ +
  B.C
+

The replacement string {//} can be changed with --dirnamereplace:

-
-  parallel --dirnamereplace ,, echo ,, ::: A/B.C
+ +
  parallel --dirnamereplace ,, echo ,, ::: A/B.C
+

Output:

-
-  A
+ +
  A
+

The replacement string {/.} can be changed with --basenameextensionreplace:

-
-  parallel --basenameextensionreplace ,, echo ,, ::: A/B.C
+ +
  parallel --basenameextensionreplace ,, echo ,, ::: A/B.C
+

Output:

-
-  B
+ +
  B
+

The replacement string {#} can be changed with --seqreplace:

-
-  parallel --seqreplace ,, echo ,, ::: A B C
+ +
  parallel --seqreplace ,, echo ,, ::: A B C
+

Output (the order may be different):

-
-  1
+
+
  1
   2
-  3
+ 3
+

The replacement string {%} can be changed with --slotreplace:

-
-  parallel -j2 --slotreplace ,, echo ,, ::: A B C
+ +
  parallel -j2 --slotreplace ,, echo ,, ::: A B C
+

Output (the order may be different):

-
-  1
+
+
  1
   2
-  1
-

-

-

Perl expression replacement string

-

When predefined replacement strings are not flexible enough a perl -expression can be used instead. One example is to remove two -extensions: foo.tar.gz -> foo

-
-   parallel echo '{= s:\.[^.]+$::;s:\.[^.]+$::; =}' ::: foo.tar.gz
+ 1
+ +

Perl expression replacement string

+ +

When predefined replacement strings are not flexible enough a perl expression can be used instead. One example is to remove two extensions: foo.tar.gz -> foo

+ +
   parallel echo '{= s:\.[^.]+$::;s:\.[^.]+$::; =}' ::: foo.tar.gz
+

Output:

-
-   foo
-

If the strings {= and =} cause problems they can be replaced with --parens:

-
-   parallel --parens ,,,, echo ',, s:\.[^.]+$::;s:\.[^.]+$::; ,,' ::: foo.tar.gz
+ +
   foo
+ +

If the strings {= and =} cause problems they can be replaced with --parens:

+ +
   parallel --parens ,,,, echo ',, s:\.[^.]+$::;s:\.[^.]+$::; ,,' ::: foo.tar.gz
+

Output: Same as above.

-

To define a short hand replacement string use --rpl:

-
-   parallel --rpl '.. s:\.[^.]+$::;s:\.[^.]+$::;' echo '..' ::: foo.tar.gz
+ +

To define a short hand replacement string use --rpl:

+ +
   parallel --rpl '.. s:\.[^.]+$::;s:\.[^.]+$::;' echo '..' ::: foo.tar.gz
+

Output: Same as above.

-

If the short hand starts with '{' it can be used as a positional -replacement string, too:

-
-   parallel --rpl '{..} s:\.[^.]+$::;s:\.[^.]+$::;' echo '{..}' ::: foo.tar.gz
+ +

If the short hand starts with '{' it can be used as a positional replacement string, too:

+ +
   parallel --rpl '{..} s:\.[^.]+$::;s:\.[^.]+$::;' echo '{..}' ::: foo.tar.gz
+

Output: Same as above.

-

GNU parallel's 7 replacement strings are implemented as:

-
-  --rpl '{} '
-  --rpl '{#} $_=$job->seq()'
-  --rpl '{%} $_=$job->slot()'
-  --rpl '{/} s:.*/::'
-  --rpl '{//} $Global::use{"File::Basename"} ||= eval "use File::Basename; 1;"; $_ = dirname($_);'
-  --rpl '{/.} s:.*/::; s:\.[^/.]+$::;'
-  --rpl '{.} s:\.[^/.]+$::'
-

-

-

Positional replacement strings

-

With multiple input sources the argument from the individual input -sources can be access with {number}:

-
-  parallel echo {1} and {2} ::: A B ::: C D
+ +

GNU parallel's 7 replacement strings are implemented as:

+ +
  --rpl '{} '
+  --rpl '{#} $_=$job->seq()'
+  --rpl '{%} $_=$job->slot()'
+  --rpl '{/} s:.*/::'
+  --rpl '{//} $Global::use{"File::Basename"} ||= eval "use File::Basename; 1;"; $_ = dirname($_);'
+  --rpl '{/.} s:.*/::; s:\.[^/.]+$::;'
+  --rpl '{.} s:\.[^/.]+$::'
+ +

Positional replacement strings

+ +

With multiple input sources the argument from the individual input sources can be access with {number}:

+ +
  parallel echo {1} and {2} ::: A B ::: C D
+

Output (the order may be different):

-
-  A and C
+
+
  A and C
   A and D
   B and C
-  B and D
-

The positional replacement strings can also be modified using / // /. and .:

-
-  parallel echo /={1/} //={1//} /.={1/.} .={1.} ::: A/B.C D/E.F
+ B and D
+ +

The positional replacement strings can also be modified using / // /. and .:

+ +
  parallel echo /={1/} //={1//} /.={1/.} .={1.} ::: A/B.C D/E.F
+

Output (the order may be different):

-
-  /=B.C //=A /.=B .=A/B
-  /=E.F //=D /.=E .=D/E
-

If a position is negative, it will refer to the input source counted -from behind:

-
-  parallel echo 1={1} 2={2} 3={3} -1={-1} -2={-2} -3={-3} ::: A B ::: C D ::: E F
+ +
  /=B.C //=A /.=B .=A/B
+  /=E.F //=D /.=E .=D/E
+ +

If a position is negative, it will refer to the input source counted from behind:

+ +
  parallel echo 1={1} 2={2} 3={3} -1={-1} -2={-2} -3={-3} ::: A B ::: C D ::: E F
+

Output (the order may be different):

-
-  1=A 2=C 3=E -1=E -2=C -3=A
+
+
  1=A 2=C 3=E -1=E -2=C -3=A
   1=A 2=C 3=F -1=F -2=C -3=A
   1=A 2=D 3=E -1=E -2=D -3=A
   1=A 2=D 3=F -1=F -2=D -3=A
   1=B 2=C 3=E -1=E -2=C -3=B
   1=B 2=C 3=F -1=F -2=C -3=B
   1=B 2=D 3=E -1=E -2=D -3=B
-  1=B 2=D 3=F -1=F -2=D -3=B
-

-

-

Positional perl expression replacement string

-

To use a perl expression as a positional replacement string simply -prepend the perl expression with number and space:

-
-   parallel echo '{=2 s:\.[^.]+$::;s:\.[^.]+$::; =} {1}' ::: bar ::: foo.tar.gz
+ 1=B 2=D 3=F -1=F -2=D -3=B
+ +

Positional perl expression replacement string

+ +

To use a perl expression as a positional replacement string simply prepend the perl expression with number and space:

+ +
   parallel echo '{=2 s:\.[^.]+$::;s:\.[^.]+$::; =} {1}' ::: bar ::: foo.tar.gz
+

Output:

-
-   foo bar
-

If a defined short hand starts with '{' it can be used as a positional -replacement string, too:

-
-   parallel --rpl '{..} s:\.[^.]+$::;s:\.[^.]+$::;' echo '{2..} {1}' ::: bar ::: foo.tar.gz
+ +
   foo bar
+ +

If a defined short hand starts with '{' it can be used as a positional replacement string, too:

+ +
   parallel --rpl '{..} s:\.[^.]+$::;s:\.[^.]+$::;' echo '{2..} {1}' ::: bar ::: foo.tar.gz
+

Output: Same as above.

-

-

-

Input from columns

-

The columns in a file can be bound to positional replacement strings -using --colsep. Here the columns are separated with TAB (\t):

-
-  parallel --colsep '\t' echo 1={1} 2={2} :::: tsv-file.tsv
+ +

Input from columns

+ +

The columns in a file can be bound to positional replacement strings using --colsep. Here the columns are separated with TAB (\t):

+ +
  parallel --colsep '\t' echo 1={1} 2={2} :::: tsv-file.tsv
+

Output (the order may be different):

-
-  1=f1 2=f2
+
+
  1=f1 2=f2
   1=A 2=B
-  1=C 2=D
-

-

-

Header defined replacement strings

-

With --header GNU Parallel will use the first value of the input -source as the name of the replacement string. Only the non-modified -version {} is supported:

-
-  parallel --header : echo f1={f1} f2={f2} ::: f1 A B ::: f2 C D
+ 1=C 2=D
+ +

Header defined replacement strings

+ +

With --header GNU Parallel will use the first value of the input source as the name of the replacement string. Only the non-modified version {} is supported:

+ +
  parallel --header : echo f1={f1} f2={f2} ::: f1 A B ::: f2 C D
+

Output (the order may be different):

-
-  f1=A f2=C
+
+
  f1=A f2=C
   f1=A f2=D
   f1=B f2=C
-  f1=B f2=D
+ f1=B f2=D
+

It is useful with --colsep for processing files with TAB separated values:

-
-  parallel --header : --colsep '\t' echo f1={f1} f2={f2} :::: tsv-file.tsv
+ +
  parallel --header : --colsep '\t' echo f1={f1} f2={f2} :::: tsv-file.tsv
+

Output (the order may be different):

-
-  f1=A f2=B
-  f1=C f2=D
-

-

-

More than one argument

-

With --xargs will GNU Parallel fit as many arguments as possible on a -single line:

-
-  cat num30000 | parallel --xargs echo | wc -l
+ +
  f1=A f2=B
+  f1=C f2=D
+ +

More than one argument

+ +

With --xargs will GNU Parallel fit as many arguments as possible on a single line:

+ +
  cat num30000 | parallel --xargs echo | wc -l
+

Output:

-
-  2
+ +
  2
+

The 30000 arguments fitted on 2 lines.

-

The maximal length of a single line can be set with -s. With a maximal -line length of 10000 chars 17 commands will be run:

-
-  cat num30000 | parallel --xargs -s 10000 echo | wc -l
+ +

The maximal length of a single line can be set with -s. With a maximal line length of 10000 chars 17 commands will be run:

+ +
  cat num30000 | parallel --xargs -s 10000 echo | wc -l
+

Output:

-
-  17
-

For better parallelism GNU Parallel can distribute the arguments -between all the parallel jobs when end of file is met.

-

Below GNU Parallel reads the last argument when generating the second -job. When GNU Parallel reads the last argument, it spreads all the -arguments for the second job over 4 jobs instead, as 4 parallel jobs -are requested.

-

The first job will be the same as the --xargs example above, but the -second job will be split into 4 evenly sized jobs, resulting in a -total of 5 jobs:

-
-  cat num30000 | parallel --jobs 4 -m echo | wc -l
+ +
  17
+ +

For better parallelism GNU Parallel can distribute the arguments between all the parallel jobs when end of file is met.

+ +

Below GNU Parallel reads the last argument when generating the second job. When GNU Parallel reads the last argument, it spreads all the arguments for the second job over 4 jobs instead, as 4 parallel jobs are requested.

+ +

The first job will be the same as the --xargs example above, but the second job will be split into 4 evenly sized jobs, resulting in a total of 5 jobs:

+ +
  cat num30000 | parallel --jobs 4 -m echo | wc -l
+

Output:

-
-  5
-

This is even more visible when running 4 jobs with 10 arguments. The -10 arguments are being spread over 4 jobs:

-
-  parallel --jobs 4 -m echo ::: {1..10}
+ +
  5
+ +

This is even more visible when running 4 jobs with 10 arguments. The 10 arguments are being spread over 4 jobs:

+ +
  parallel --jobs 4 -m echo ::: {1..10}
+

Output:

-
-  1 2 3
+
+
  1 2 3
   4 5 6
   7 8 9
-  10
+ 10
+

A replacement string can be part of a word. -m will not repeat the context:

-
-  parallel --jobs 4 -m echo pre-{}-post ::: A B C D E F G
+ +
  parallel --jobs 4 -m echo pre-{}-post ::: A B C D E F G
+

Output (the order may be different):

-
-  pre-A B-post
+
+
  pre-A B-post
   pre-C D-post
   pre-E F-post
-  pre-G-post
+ pre-G-post
+

To repeat the context use -X which otherwise works like -m:

-
-  parallel --jobs 4 -X echo pre-{}-post ::: A B C D E F G
+ +
  parallel --jobs 4 -X echo pre-{}-post ::: A B C D E F G
+

Output (the order may be different):

-
-  pre-A-post pre-B-post
+
+
  pre-A-post pre-B-post
   pre-C-post pre-D-post
   pre-E-post pre-F-post
-  pre-G-post
+ pre-G-post
+

To limit the number of arguments use -N:

-
-  parallel -N3 echo ::: A B C D E F G H
+ +
  parallel -N3 echo ::: A B C D E F G H
+

Output (the order may be different):

-
-  A B C
+
+
  A B C
   D E F
-  G H
+ G H
+

-N also sets the positional replacement strings:

-
-  parallel -N3 echo 1={1} 2={2} 3={3} ::: A B C D E F G H
+ +
  parallel -N3 echo 1={1} 2={2} 3={3} ::: A B C D E F G H
+

Output (the order may be different):

-
-  1=A 2=B 3=C
+
+
  1=A 2=B 3=C
   1=D 2=E 3=F
-  1=G 2=H 3=
+ 1=G 2=H 3=
+

-N0 reads 1 argument but inserts none:

-
-  parallel -N0 echo foo ::: 1 2 3
+ +
  parallel -N0 echo foo ::: 1 2 3
+

Output:

-
+
+
  foo
   foo
-  foo
-  foo
-

-

-

Quoting

+ foo
+ +

Quoting

+

Command lines that contain special characters may need to be protected from the shell.

-

The perl program 'print "@ARGV\n"' basically works like echo.

-
-  perl -e 'print "@ARGV\n"' A
+ +

The perl program 'print "@ARGV\n"' basically works like echo.

+ +
  perl -e 'print "@ARGV\n"' A
+

Output:

-
-  A
+ +
  A
+

To run that in parallel the command needs to be quoted:

-
-  parallel perl -e 'print "@ARGV\n"' ::: This wont work
+ +
  parallel perl -e 'print "@ARGV\n"' ::: This wont work
+

Output:

-
-  [Nothing]
+ +
  [Nothing]
+

To quote the command use -q:

-
-  parallel -q perl -e 'print "@ARGV\n"' ::: This works
+ +
  parallel -q perl -e 'print "@ARGV\n"' ::: This works
+

Output (the order may be different):

-
-  This
-  works
-

Or you can quote the critical part using \':

-
-  parallel perl -e \''print "@ARGV\n"'\' ::: This works, too
+ +
  This
+  works
+ +

Or you can quote the critical part using \':

+ +
  parallel perl -e \''print "@ARGV\n"'\' ::: This works, too
+

Output (the order may be different):

-
-  This
+
+
  This
   works,
-  too
+ too
+

GNU Parallel can also \-quote full lines. Simply run:

-
-  parallel --shellquote
+
+
  parallel --shellquote
   parallel: Warning: Input is read from the terminal. Only experts do this on purpose. Press CTRL-D to exit.
-  perl -e 'print "@ARGV\n"'
-  [CTRL-D]
+ perl -e 'print "@ARGV\n"' + [CTRL-D]
+

Output:

-
-  perl\ -e\ \'print\ \"@ARGV\\n\"\'
+ +
  perl\ -e\ \'print\ \"@ARGV\\n\"\'
+

This can then be used as the command:

-
-  parallel perl\ -e\ \'print\ \"@ARGV\\n\"\' ::: This also works
+ +
  parallel perl\ -e\ \'print\ \"@ARGV\\n\"\' ::: This also works
+

Output (the order may be different):

-
-  This
+
+
  This
   also
-  works
-

-

-

Trimming space

+ works
+ +

Trimming space

+

Space can be trimmed on the arguments using --trim:

-
-  parallel --trim r echo pre-{}-post ::: ' A '
+ +
  parallel --trim r echo pre-{}-post ::: ' A '
+

Output:

-
-  pre- A-post
+ +
  pre- A-post
+

To trim on the left side:

-
-  parallel --trim l echo pre-{}-post ::: ' A '
+ +
  parallel --trim l echo pre-{}-post ::: ' A '
+

Output:

-
-  pre-A -post
+ +
  pre-A -post
+

To trim on the both sides:

-
-  parallel --trim lr echo pre-{}-post ::: ' A '
+ +
  parallel --trim lr echo pre-{}-post ::: ' A '
+

Output:

-
-  pre-A-post
-

-

-
-

Controling the output

+ +
  pre-A-post
+ +

Controling the output

+

The output can prefixed with the argument:

-
-  parallel --tag echo foo-{} ::: A B C
+ +
  parallel --tag echo foo-{} ::: A B C
+

Output (the order may be different):

-
-  A       foo-A
+
+
  A       foo-A
   B       foo-B
-  C       foo-C
+ C foo-C
+

To prefix it with another string use --tagstring:

-
-  parallel --tagstring {}-bar echo foo-{} ::: A B C
+ +
  parallel --tagstring {}-bar echo foo-{} ::: A B C
+

Output (the order may be different):

-
-  A-bar   foo-A
+
+
  A-bar   foo-A
   B-bar   foo-B
-  C-bar   foo-C
+ C-bar foo-C
+

To see what commands will be run without running them:

-
-  parallel --dryrun echo {} ::: A B C
+ +
  parallel --dryrun echo {} ::: A B C
+

Output (the order may be different):

-
-  echo A
+
+
  echo A
   echo B
-  echo C
+ echo C
+

To print the command before running them use --verbose:

-
-  parallel --verbose echo {} ::: A B C
+ +
  parallel --verbose echo {} ::: A B C
+

Output (the order may be different):

-
-  echo A
+
+
  echo A
   echo B
   A
   echo C
   B
-  C
+ C
+

GNU Parallel will postpone the output until the command completes:

-
-  parallel -j2 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
+ +
  parallel -j2 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
+

Output:

-
-  2-start
+
+
  2-start
   2-middle
   2-end
   1-start
@@ -816,14 +896,15 @@ total of 5 jobs:

1-end 4-start 4-middle - 4-end
-

To get the output immediately use --ungroup:

-
-  parallel -j2 --ungroup 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
-

Output:

-
+  4-end
- 4-start +

To get the output immediately use --ungroup:

+ +
  parallel -j2 --ungroup 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1      
+ +

Output:

+ +
  4-start
   42-start
   2-middle
   2-end
@@ -831,16 +912,17 @@ total of 5 jobs:

1-middle 1-end -middle - 4-end
-

--ungroup is fast, but can cause half a line from one job to be mixed -with half a line of another job. That has happend in the second line, -where the line '4-middle' is mixed with '2-start'.

+ 4-end
+ +

--ungroup is fast, but can cause half a line from one job to be mixed with half a line of another job. That has happend in the second line, where the line '4-middle' is mixed with '2-start'.

+

To avoid this use --linebuffer:

-
-  parallel -j2 --linebuffer 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
+ +
  parallel -j2 --linebuffer 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
+

Output:

-
-  4-start
+
+
  4-start
   2-start
   2-middle
   2-end
@@ -848,13 +930,15 @@ where the line '4-middle' is mixed with '2-start'.

1-middle 1-end 4-middle - 4-end
+ 4-end
+

To force the output in the same order as the arguments use --keep-order/-k:

-
-  parallel -j2 -k 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
+ +
  parallel -j2 -k 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
+

Output:

-
-  4-start
+
+
  4-start
   4-middle
   4-end
   2-start
@@ -862,222 +946,241 @@ where the line '4-middle' is mixed with '2-start'.

2-end 1-start 1-middle - 1-end
-

-

-

Saving output into files

+ 1-end
+ +

Saving output into files

+

GNU Parallel can save the output of each job into files:

-
-  parallel --files ::: A B C
+ +
  parallel --files ::: A B C
+

Output will be similar to:

-
-  /tmp/pAh6uWuQCg.par
+
+
  /tmp/pAh6uWuQCg.par
   /tmp/opjhZCzAX4.par
-  /tmp/W0AT_Rph2o.par
-

By default GNU Parallel will cache the output in files in /tmp. This -can be changed by setting $TMPDIR or --tmpdir:

-
-  parallel --tmpdir /var/tmp --files ::: A B C
+ /tmp/W0AT_Rph2o.par
+ +

By default GNU Parallel will cache the output in files in /tmp. This can be changed by setting $TMPDIR or --tmpdir:

+ +
  parallel --tmpdir /var/tmp --files ::: A B C
+

Output will be similar to:

-
-  /var/tmp/N_vk7phQRc.par
+
+
  /var/tmp/N_vk7phQRc.par
   /var/tmp/7zA4Ccf3wZ.par
-  /var/tmp/LIuKgF_2LP.par
+ /var/tmp/LIuKgF_2LP.par
+

Or:

-
-  TMPDIR=/var/tmp parallel --files ::: A B C
+ +
  TMPDIR=/var/tmp parallel --files ::: A B C
+

Output: Same as above.

+

The output files can be saved in a structured way using --results:

-
-  parallel --results outdir echo ::: A B C
+ +
  parallel --results outdir echo ::: A B C
+

Output:

-
-  A
+
+
  A
   B
-  C
-

but also these files were generated containing the standard output -(stdout) and standard error (stderr):

-
-  outdir/1/A/stderr
+  C
+ +

but also these files were generated containing the standard output (stdout) and standard error (stderr):

+ +
  outdir/1/A/stderr
   outdir/1/A/stdout
   outdir/1/B/stderr
   outdir/1/B/stdout
   outdir/1/C/stderr
-  outdir/1/C/stdout
+ outdir/1/C/stdout
+

This is useful if you are running multiple variables:

-
-  parallel --header : --results outdir echo ::: f1 A B ::: f2 C D
+ +
  parallel --header : --results outdir echo ::: f1 A B ::: f2 C D
+

Generated files:

-
-  outdir/f1/A/f2/C/stderr
+
+
  outdir/f1/A/f2/C/stderr
   outdir/f1/A/f2/C/stdout
   outdir/f1/A/f2/D/stderr
   outdir/f1/A/f2/D/stdout
   outdir/f1/B/f2/C/stderr
   outdir/f1/B/f2/C/stdout
   outdir/f1/B/f2/D/stderr
-  outdir/f1/B/f2/D/stdout
+ outdir/f1/B/f2/D/stdout
+

The directories are named after the variables and their values.

-

-

-
-

Control the execution

-

-

-

Number of simultaneous jobs

+ +

Control the execution

+ +

Number of simultaneous jobs

+

The number of concurrent jobs is given with --jobs/-j:

-
-  /usr/bin/time parallel -N0 -j64 sleep 1 ::: {1..128}
-

With 64 jobs in parallel the 128 sleeps will take 2-8 seconds to run - -depending on how fast your machine is.

+ +
  /usr/bin/time parallel -N0 -j64 sleep 1 ::: {1..128}
+ +

With 64 jobs in parallel the 128 sleeps will take 2-8 seconds to run - depending on how fast your machine is.

+

By default --jobs is the same as the number of CPU cores. So this:

-
-  /usr/bin/time parallel -N0 sleep 1 ::: {1..128}
+ +
  /usr/bin/time parallel -N0 sleep 1 ::: {1..128}
+

should take twice the time of running 2 jobs per CPU core:

-
-  /usr/bin/time parallel -N0 --jobs 200% sleep 1 ::: {1..128}
+ +
  /usr/bin/time parallel -N0 --jobs 200% sleep 1 ::: {1..128}
+

--jobs 0 will run as many jobs in parallel as possible:

-
-  /usr/bin/time parallel -N0 --jobs 0 sleep 1 ::: {1..128}
+ +
  /usr/bin/time parallel -N0 --jobs 0 sleep 1 ::: {1..128}
+

which should take 1-7 seconds depending on how fast your machine is.

+

--jobs can read from a file which is re-read when a job finishes:

-
-  echo 50% > my_jobs
+
+
  echo 50% > my_jobs
   /usr/bin/time parallel -N0 --jobs my_jobs sleep 1 ::: {1..128} &
   sleep 1
   echo 0 > my_jobs
-  wait
-

The first second only 50% of the CPU cores will run a job. The '0' is -put into my_jobs and then the rest of the jobs will be started in -parallel.

-

Instead of basing the percentage on the number of CPU cores -GNU Parallel can base it on the number of CPUs:

-
-  parallel --use-cpus-instead-of-cores -N0 sleep 1 ::: {1..128}
-

-

-

Interactivity

+ wait
+ +

The first second only 50% of the CPU cores will run a job. The '0' is put into my_jobs and then the rest of the jobs will be started in parallel.

+ +

Instead of basing the percentage on the number of CPU cores GNU Parallel can base it on the number of CPUs:

+ +
  parallel --use-cpus-instead-of-cores -N0 sleep 1 ::: {1..128}
+ +

Interactivity

+

GNU Parallel can ask the user if a command should be run using --interactive:

-
-  parallel --interactive echo ::: 1 2 3
+ +
  parallel --interactive echo ::: 1 2 3
+

Output:

-
-  echo 1 ?...y
+
+
  echo 1 ?...y
   echo 2 ?...n
   1
   echo 3 ?...y
-  3
-

GNU Parallel can be used to put arguments on the command line for an -interactive command such as emacs to edit one file at a time:

-
-  parallel --tty emacs ::: 1 2 3
+ 3
+ +

GNU Parallel can be used to put arguments on the command line for an interactive command such as emacs to edit one file at a time:

+ +
  parallel --tty emacs ::: 1 2 3
+

Or give multiple argument in one go to open multiple files:

-
-  parallel -X --tty vi ::: 1 2 3
-

-

-

Timing

-

Some jobs do heavy I/O when they start. To avoid a thundering herd GNU -Parallel can delay starting new jobs. --delay X will make sure there is -at least X seconds between each start:

-
-  parallel --delay 2.5 echo Starting {}\;date ::: 1 2 3
+ +
  parallel -X --tty vi ::: 1 2 3
+ +

Timing

+ +

Some jobs do heavy I/O when they start. To avoid a thundering herd GNU Parallel can delay starting new jobs. --delay X will make sure there is at least X seconds between each start:

+ +
  parallel --delay 2.5 echo Starting {}\;date ::: 1 2 3
+

Output:

-
-  Starting 1
+
+
  Starting 1
   Thu Aug 15 16:24:33 CEST 2013
   Starting 2
   Thu Aug 15 16:24:35 CEST 2013
   Starting 3
-  Thu Aug 15 16:24:38 CEST 2013
-

If jobs taking more than a certain amount of time are known to fail, -they can be stopped with --timeout:

-
-  parallel --timeout 2.1 sleep {}\; echo {} ::: 1 2 3 4
+ Thu Aug 15 16:24:38 CEST 2013
+ +

If jobs taking more than a certain amount of time are known to fail, they can be stopped with --timeout:

+ +
  parallel --timeout 2.1 sleep {}\; echo {} ::: 1 2 3 4
+

Output:

-
-  1
-  2
-

GNU Parallel can compute the median runtime for jobs and kill those -that take more than 200% of the median runtime:

-
-  parallel --timeout 200% sleep {}\; echo {} ::: 2.1 2.2 3 7 2.3
+ +
  1
+  2
+ +

GNU Parallel can compute the median runtime for jobs and kill those that take more than 200% of the median runtime:

+ +
  parallel --timeout 200% sleep {}\; echo {} ::: 2.1 2.2 3 7 2.3
+

Output:

-
-  2.1
+
+
  2.1
   2.2
   3
-  2.3
-

Based on the runtime of completed jobs GNU Parallel can estimate the -total runtime:

-
-  parallel --eta sleep ::: 1 3 2 2 1 3 3 2 1
+ 2.3
+ +

Based on the runtime of completed jobs GNU Parallel can estimate the total runtime:

+ +
  parallel --eta sleep ::: 1 3 2 2 1 3 3 2 1
+

Output:

-
-  Computers / CPU cores / Max jobs to run
-  1:local / 2 / 2
-
+
+
  Computers / CPU cores / Max jobs to run
+  1:local / 2 / 2
+
   Computer:jobs running/jobs completed/%of started jobs/Average seconds to complete
-  ETA: 2s 0left 1.11avg  local:0/9/100%/1.1s
-

-

-

Progress

+ ETA: 2s 0left 1.11avg local:0/9/100%/1.1s
+ +

Progress

+

GNU Parallel can give progress information with --progress:

-
-  parallel --progress sleep ::: 1 3 2 2 1 3 3 2 1
+ +
  parallel --progress sleep ::: 1 3 2 2 1 3 3 2 1
+

Output:

-
-  Computers / CPU cores / Max jobs to run
-  1:local / 2 / 2
-
+
+
  Computers / CPU cores / Max jobs to run
+  1:local / 2 / 2
+
   Computer:jobs running/jobs completed/%of started jobs/Average seconds to complete
-  local:0/9/100%/1.1s
+ local:0/9/100%/1.1s
+

A logfile of the jobs completed so far can be generated with --joblog:

-
-  parallel --joblog /tmp/log exit  ::: 1 2 3 0 
-  cat /tmp/log
+ +
  parallel --joblog /tmp/log exit  ::: 1 2 3 0 
+  cat /tmp/log
+

Output:

-
-  Seq     Host    Starttime       Runtime Send    Receive Exitval Signal  Command
+
+
  Seq     Host    Starttime       Runtime Send    Receive Exitval Signal  Command
   1       :       1376577364.974  0.008   0       0       1       0       exit 1
   2       :       1376577364.982  0.013   0       0       2       0       exit 2
   3       :       1376577364.990  0.013   0       0       3       0       exit 3
-  4       :       1376577365.003  0.003   0       0       0       0       exit 0
-

The log contains the job sequence, which host the job was run on, the -start time and run time, how much data was transferred if the job was -run on a remote host, the exit value, the signal that killed the job, -and finally the command being run.

-

With a joblog GNU Parallel can be stopped and later pickup where it -left off. It it important that the input of the completed jobs is -unchanged.

-
-  parallel --joblog /tmp/log exit  ::: 1 2 3 0 
+  4       :       1376577365.003  0.003   0       0       0       0       exit 0
+ +

The log contains the job sequence, which host the job was run on, the start time and run time, how much data was transferred if the job was run on a remote host, the exit value, the signal that killed the job, and finally the command being run.

+ +

With a joblog GNU Parallel can be stopped and later pickup where it left off. It it important that the input of the completed jobs is unchanged.

+ +
  parallel --joblog /tmp/log exit  ::: 1 2 3 0 
   cat /tmp/log
   parallel --resume --joblog /tmp/log exit  ::: 1 2 3 0 0 0
-  cat /tmp/log
+ cat /tmp/log
+

Output:

-
-  Seq     Host    Starttime       Runtime Send    Receive Exitval Signal  Command
+
+
  Seq     Host    Starttime       Runtime Send    Receive Exitval Signal  Command
   1       :       1376580069.544  0.008   0       0       1       0       exit 1
   2       :       1376580069.552  0.009   0       0       2       0       exit 2
   3       :       1376580069.560  0.012   0       0       3       0       exit 3
-  4       :       1376580069.571  0.005   0       0       0       0       exit 0
-
+  4       :       1376580069.571  0.005   0       0       0       0       exit 0
+
   Seq     Host    Starttime       Runtime Send    Receive Exitval Signal  Command
   1       :       1376580069.544  0.008   0       0       1       0       exit 1
   2       :       1376580069.552  0.009   0       0       2       0       exit 2
   3       :       1376580069.560  0.012   0       0       3       0       exit 3
   4       :       1376580069.571  0.005   0       0       0       0       exit 0
   5       :       1376580070.028  0.009   0       0       0       0       exit 0
-  6       :       1376580070.038  0.007   0       0       0       0       exit 0
+ 6 : 1376580070.038 0.007 0 0 0 0 exit 0
+

Note how the start time of the last 2 jobs is clearly from the second run.

+

With --resume-failed GNU Parallel will re-run the jobs that failed:

-
-  parallel --resume-failed --joblog /tmp/log exit  ::: 1 2 3 0 0 0
-  cat /tmp/log
+ +
  parallel --resume-failed --joblog /tmp/log exit  ::: 1 2 3 0 0 0
+  cat /tmp/log
+

Output:

-
-  Seq     Host    Starttime       Runtime Send    Receive Exitval Signal  Command
+
+
  Seq     Host    Starttime       Runtime Send    Receive Exitval Signal  Command
   1       :       1376580069.544  0.008   0       0       1       0       exit 1
   2       :       1376580069.552  0.009   0       0       2       0       exit 2
   3       :       1376580069.560  0.012   0       0       3       0       exit 3
@@ -1086,43 +1189,46 @@ unchanged.

6 : 1376580070.038 0.007 0 0 0 0 exit 0 1 : 1376580154.433 0.010 0 0 1 0 exit 1 2 : 1376580154.444 0.022 0 0 2 0 exit 2 - 3 : 1376580154.466 0.005 0 0 3 0 exit 3
+ 3 : 1376580154.466 0.005 0 0 3 0 exit 3
+

Note how seq 1 2 3 have been repeated because they had exit value != 0.

-

-

-

Termination

-

For certain jobs there is no need to continue if one of the jobs fails -and has an exit code != 0. GNU Parallel will stop spawning new jobs -with --halt 1:

-
-  parallel -j2 --halt 1 echo {}\; exit {} ::: 0 0 1 2 3
+ +

Termination

+ +

For certain jobs there is no need to continue if one of the jobs fails and has an exit code != 0. GNU Parallel will stop spawning new jobs with --halt 1:

+ +
  parallel -j2 --halt 1 echo {}\; exit {} ::: 0 0 1 2 3
+

Output:

-
-  0
+
+
  0
   0
   1
   parallel: Starting no more jobs. Waiting for 2 jobs to finish. This job failed:
   echo 1; exit 1
   2
   parallel: Starting no more jobs. Waiting for 1 jobs to finish. This job failed:
-  echo 2; exit 2
+ echo 2; exit 2
+

With --halt 2 the running jobs will be killed immediately:

-
-  parallel -j2 --halt 2 echo {}\; exit {} ::: 0 0 1 2 3
+ +
  parallel -j2 --halt 2 echo {}\; exit {} ::: 0 0 1 2 3
+

Output:

-
-  0
+
+
  0
   0
   1
   parallel: This job failed:
-  echo 1; exit 1
-

If --halt is given a percentage this percentage of the jobs must fail -(though minimum 3) before GNU Parallel stops spawning more jobs:

-
-  parallel -j2 --halt 20% echo {}\; exit {} ::: 0 0 1 2 3 4 5 6 7
+ echo 1; exit 1
+ +

If --halt is given a percentage this percentage of the jobs must fail (though minimum 3) before GNU Parallel stops spawning more jobs:

+ +
  parallel -j2 --halt 20% echo {}\; exit {} ::: 0 0 1 2 3 4 5 6 7
+

Output:

-
-  0
+
+
  0
   0
   1
   2
@@ -1132,420 +1238,441 @@ with --halt 1:

echo 4; exit 4 5 parallel: Starting no more jobs. Waiting for 1 jobs to finish. This job failed: - echo 5; exit 5
-

GNU Parallel can retry the command with --retries. This is useful if a -command fails for unkown reasons now and then.

-
-  parallel -k --retries 3 'echo tried {} >>/tmp/runs; echo completed {}; exit {}' ::: 1 2 0
-  cat /tmp/runs
+ echo 5; exit 5
+ +

GNU Parallel can retry the command with --retries. This is useful if a command fails for unkown reasons now and then.

+ +
  parallel -k --retries 3 'echo tried {} >>/tmp/runs; echo completed {}; exit {}' ::: 1 2 0
+  cat /tmp/runs
+

Output:

-
-  completed 1
+
+
  completed 1
   completed 2
-  completed 0
-
+  completed 0
+
   tried 1
   tried 2
   tried 1
   tried 2
   tried 1
   tried 2
-  tried 0
+ tried 0
+

Note how job 1 and 2 were tried 3 times, but 0 was not retried because it had exit code 0.

-

-

-

Limiting the ressources

-

To avoid overloading systems GNU Parallel can look at the system load -before starting another job:

-
-  parallel --load 100% echo load is less than {} job per cpu ::: 1
+ +

Limiting the ressources

+ +

To avoid overloading systems GNU Parallel can look at the system load before starting another job:

+ +
  parallel --load 100% echo load is less than {} job per cpu ::: 1 
+

Output:

-
-  [when then load is less than the number of cpu cores]
-  load is less than 1 job per cpu
+ +
  [when then load is less than the number of cpu cores]
+  load is less than 1 job per cpu
+

GNU Parallel can also check if the system is swapping.

-
-  parallel --noswap echo the system is not swapping ::: now
+ +
  parallel --noswap echo the system is not swapping ::: now
+

Output:

-
-  [when then system is not swapping]
-  the system is not swapping now
-

GNU Parallel can run the jobs with a nice value. This will work both -locally and remotely.

-
-  parallel --nice 17 echo this is being run with nice -n ::: 17
+ +
  [when then system is not swapping]
+  the system is not swapping now
+ +

GNU Parallel can run the jobs with a nice value. This will work both locally and remotely.

+ +
  parallel --nice 17 echo this is being run with nice -n ::: 17
+

Output:

-
-  this is being run with nice -n 17
-

-

-
-

Remote execution

-

GNU Parallel can run jobs on remote servers. It uses ssh to -communicate with the remote machines.

-

-

-

Sshlogin

+ +
  this is being run with nice -n 17
+ +

Remote execution

+ +

GNU Parallel can run jobs on remote servers. It uses ssh to communicate with the remote machines.

+ +

Sshlogin

+

The most basic sshlogin is -S host:

-
-  parallel -S $SERVER1 echo running on ::: $SERVER1
+ +
  parallel -S $SERVER1 echo running on ::: $SERVER1
+

Output:

-
-  running on [$SERVER1]
+ +
  running on [$SERVER1]
+

To use a different username prepend the server with username@

-
-  parallel -S username@$SERVER1 echo running on ::: username@$SERVER1
+ +
  parallel -S username@$SERVER1 echo running on ::: username@$SERVER1
+

Output:

-
-  running on [username@$SERVER1]
-

The special sshlogin ':' is the local machine:

-
-  parallel -S : echo running on ::: the_local_machine
+ +
  running on [username@$SERVER1]
+ +

The special sshlogin ':' is the local machine:

+ +
  parallel -S : echo running on ::: the_local_machine
+

Output:

-
-  running on the_local_machine
+ +
  running on the_local_machine
+

If ssh is not in $PATH it can be prepended to $SERVER1:

-
-  parallel -S '/usr/bin/ssh '$SERVER1 echo custom ::: ssh
+ +
  parallel -S '/usr/bin/ssh '$SERVER1 echo custom ::: ssh
+

Output:

-
-  custom ssh
+ +
  custom ssh
+

Several servers can be given using multiple -S:

-
-  parallel -S $SERVER1 -S $SERVER2 echo ::: running on more hosts
+ +
  parallel -S $SERVER1 -S $SERVER2 echo ::: running on more hosts
+

Output (the order may be different):

-
-  running
+
+
  running
   on
   more
-  hosts
+ hosts
+

Or they can be separated by ,:

-
-  parallel -S $SERVER1,$SERVER2 echo ::: running on more hosts
+ +
  parallel -S $SERVER1,$SERVER2 echo ::: running on more hosts
+

Output: Same as above.

+

The can also be read from a file (replace user@ with the user on $SERVER2):

-
-  echo $SERVER1 > nodefile
+
+
  echo $SERVER1 > nodefile
   # Force 4 cores, special ssh-command, username
   echo 4//usr/bin/ssh user@$SERVER2 >> nodefile
-  parallel --sshloginfile nodefile echo ::: running on more hosts
+ parallel --sshloginfile nodefile echo ::: running on more hosts
+

Output: Same as above.

-

The special --sshloginfile '..' reads from ~/.parallel/sshloginfile.

-

To force GNU Parallel to treat a server having a given number of CPU -cores prepend #/ to the sshlogin:

-
-  parallel -S 4/$SERVER1 echo force {} cpus on server ::: 4
+ +

The special --sshloginfile '..' reads from ~/.parallel/sshloginfile.

+ +

To force GNU Parallel to treat a server having a given number of CPU cores prepend #/ to the sshlogin:

+ +
  parallel -S 4/$SERVER1 echo force {} cpus on server ::: 4
+

Output:

-
-  force 4 cpus on server
-

-

-

Transferring files

-

GNU Parallel can transfer the files to be processed to the remote -host. It does that using rsync.

-
-  echo This is input_file > input_file
-  parallel -S $SERVER1 --transfer cat ::: input_file
+ +
  force 4 cpus on server
+ +

Transferring files

+ +

GNU Parallel can transfer the files to be processed to the remote host. It does that using rsync.

+ +
  echo This is input_file > input_file
+  parallel -S $SERVER1 --transfer cat ::: input_file 
+

Output:

-
-  This is input_file
-

If the files is processed into another file, the resulting file can be -transferred back:

-
-  echo This is input_file > input_file
+
+
  This is input_file
+ +

If the files is processed into another file, the resulting file can be transferred back:

+ +
  echo This is input_file > input_file
   parallel -S $SERVER1 --transfer --return {}.out cat {} ">"{}.out ::: input_file 
-  cat input_file.out
+ cat input_file.out
+

Output: Same as above.

+

To remove the input and output file on the remote server use --cleanup:

-
-  echo This is input_file > input_file
+
+
  echo This is input_file > input_file
   parallel -S $SERVER1 --transfer --return {}.out --cleanup cat {} ">"{}.out ::: input_file 
-  cat input_file.out
+ cat input_file.out
+

Output: Same as above.

+

There is a short hand for --transfer --return --cleanup called --trc:

-
-  echo This is input_file > input_file
+
+
  echo This is input_file > input_file
   parallel -S $SERVER1 --trc {}.out cat {} ">"{}.out ::: input_file 
-  cat input_file.out
+ cat input_file.out
+

Output: Same as above.

-

Some jobs need a common database for all jobs. GNU Parallel can -transfer that using --basefile which will transfer the file before the -first job:

-
-  echo common data > common_file
+
+

Some jobs need a common database for all jobs. GNU Parallel can transfer that using --basefile which will transfer the file before the first job:

+ +
  echo common data > common_file
   parallel --basefile common_file -S $SERVER1 cat common_file\; echo {} ::: foo
-  
-Output:
-
-  common data
-  foo
+
+ +

Output:

+ +
  common data
+  foo
+

To remove it from the remote host after the last job use --cleanup.

-

-

-

Working dir

-

The default working dir on the remote machines is the login dir. This -can be changed with --workdir mydir.

-

Files transferred using --transfer and --return will be relative -to mydir on remote computers, and the command will be executed in -the dir mydir.

-

The special mydir value ... will create working dirs under -~/.parallel/tmp/ on the remote computers. If --cleanup is given -these dirs will be removed.

-

The special mydir value . uses the current working dir. If the -current working dir is beneath your home dir, the value . is -treated as the relative path to your home dir. This means that if your -home dir is different on remote computers (e.g. if your login is -different) the relative path will still be relative to your home dir.

-
-  parallel -S $SERVER1 pwd ::: ""
+
+

Working dir

+ +

The default working dir on the remote machines is the login dir. This can be changed with --workdir mydir.

+ +

Files transferred using --transfer and --return will be relative to mydir on remote computers, and the command will be executed in the dir mydir.

+ +

The special mydir value ... will create working dirs under ~/.parallel/tmp/ on the remote computers. If --cleanup is given these dirs will be removed.

+ +

The special mydir value . uses the current working dir. If the current working dir is beneath your home dir, the value . is treated as the relative path to your home dir. This means that if your home dir is different on remote computers (e.g. if your login is different) the relative path will still be relative to your home dir.

+ +
  parallel -S $SERVER1 pwd ::: ""
   parallel --workdir . -S $SERVER1 pwd ::: ""
-  parallel --workdir ... -S $SERVER1 pwd ::: ""
+ parallel --workdir ... -S $SERVER1 pwd ::: ""
+

Output:

-
-  [the login dir on $SERVER1]
+
+
  [the login dir on $SERVER1]
   [current dir relative on $SERVER1]
-  [a dir in ~/.parallel/tmp/...]
-

-

-

Avoid overloading sshd

-

If many jobs are started on the same server, sshd can be -overloaded. GNU Parallel can insert a delay between each job run on -the same server:

-
-  parallel -S $SERVER1 --sshdelay 0.2 echo ::: 1 2 3
+ [a dir in ~/.parallel/tmp/...]
+ +

Avoid overloading sshd

+ +

If many jobs are started on the same server, sshd can be overloaded. GNU Parallel can insert a delay between each job run on the same server:

+ +
  parallel -S $SERVER1 --sshdelay 0.2 echo ::: 1 2 3
+

Output (the order may be different):

-
-  1
+
+
  1
   2
-  3
-

Sshd will be less overloaded if using --controlmaster, which will -multiplex ssh connections:

-
-  parallel --controlmaster -S $SERVER1 echo ::: 1 2 3
+ 3
+ +

Sshd will be less overloaded if using --controlmaster, which will multiplex ssh connections:

+ +
  parallel --controlmaster -S $SERVER1 echo ::: 1 2 3
+

Output: Same as above.

-

-

-

Ignore hosts that are down

-

In clusters with many hosts a few of the are often down. GNU Parallel -can ignore those hosts. In this case the host 173.194.32.46 is down:

-
-  parallel --filter-hosts -S 173.194.32.46,$SERVER1 echo ::: bar
+ +

Ignore hosts that are down

+ +

In clusters with many hosts a few of the are often down. GNU Parallel can ignore those hosts. In this case the host 173.194.32.46 is down:

+ +
  parallel --filter-hosts -S 173.194.32.46,$SERVER1 echo ::: bar 
+

Output:

-
-  bar
-

-

-

Running the same commands on all hosts

+ +
  bar
+ +

Running the same commands on all hosts

+

GNU Parallel can run the same command on all the hosts:

-
-  parallel --onall -S $SERVER1,$SERVER2 echo ::: foo bar
+ +
  parallel --onall -S $SERVER1,$SERVER2 echo ::: foo bar
+

Output (the order may be different):

-
-  foo
+
+
  foo
   bar
   foo
-  bar
-

Often you will just want to run a single command on all hosts with out -arguments. --nonall is a no argument --onall:

-
-  parallel --nonall -S $SERVER1,$SERVER2 echo foo bar
-

Output:

-
+  bar
+ +

Often you will just want to run a single command on all hosts with out arguments. --nonall is a no argument --onall:

+ +
  parallel --nonall -S $SERVER1,$SERVER2 echo foo bar
- foo bar - foo bar
-

When --tag is used with --nonall and --onall the --tagstring is the host:

-
-  parallel --nonall --tag -S $SERVER1,$SERVER2 echo foo bar
-

Output (the order may be different):

-
-  $SERVER1 foo bar
-  $SERVER2 foo bar
-

--jobs sets the number of servers to log in to in parallel.

-

-

-

Transfer environment variables and functions

-

Using --env GNU Parallel can transfer an environment variable to the -remote system.

-
-  MYVAR='foo bar'
-  export MYVAR
-  parallel --env MYVAR -S $SERVER1 echo '$MYVAR' ::: baz

Output:

-
-  foo bar baz
+ +
  foo bar
+  foo bar
+ +

When --tag is used with --nonall and --onall the --tagstring is the host:

+ +
  parallel --nonall --tag -S $SERVER1,$SERVER2 echo foo bar
+ +

Output (the order may be different):

+ +
  $SERVER1 foo bar
+  $SERVER2 foo bar
+ +

--jobs sets the number of servers to log in to in parallel.

+ +

Transfer environment variables and functions

+ +

Using --env GNU Parallel can transfer an environment variable to the remote system.

+ +
  MYVAR='foo bar'
+  export MYVAR
+  parallel --env MYVAR -S $SERVER1 echo '$MYVAR' ::: baz
+ +

Output:

+ +
  foo bar baz
+

This works for functions too if your shell is Bash:

-
-  # This only works in Bash
+
+
  # This only works in Bash
   my_func() {
     echo in my_func $1
   }
   export -f my_func
-  parallel --env my_func -S $SERVER1 my_func ::: baz
+ parallel --env my_func -S $SERVER1 my_func ::: baz
+

Output:

-
-  in my_func baz
-

GNU Parallel can copy all defined variables and functions to the -remote system. It just needs to record which ones to ignore in -~/.parallel/ignored_vars. Do that by running this once:

-
-  parallel --record-env
-  cat ~/.parallel/ignored_vars
+ +
  in my_func baz
+ +

GNU Parallel can copy all defined variables and functions to the remote system. It just needs to record which ones to ignore in ~/.parallel/ignored_vars. Do that by running this once:

+ +
  parallel --record-env
+  cat ~/.parallel/ignored_vars
+

Output:

-
-  [list of variables to ignore - including $PATH and $HOME]
-

Now all new variables and functions defined will be copied when using ---env _:

-
-  # The function is only copied if using Bash
+
+
  [list of variables to ignore - including $PATH and $HOME]
+ +

Now all new variables and functions defined will be copied when using --env _:

+ +
  # The function is only copied if using Bash
   my_func2() {
     echo in my_func2 $VAR $1
   }
   export -f my_func2
   VAR=foo
-  export VAR
-
-  parallel --env _ -S $SERVER1 'echo $VAR; my_func2' ::: bar
+ export VAR + + parallel --env _ -S $SERVER1 'echo $VAR; my_func2' ::: bar
+

Output:

-
-  foo
-  in my_func2 foo bar
-

-

-

Showing what is actually run

-

--verbose will show the command that would be run on the local -machine. When a job is run on a remote machine this is wrapped with -ssh and possibly transferring files and environment variables, setting -the workdir, and setting --nice value. -vv shows all of this.

-
-  parallel -vv -S $SERVER1 echo ::: bar
+ +
  foo
+  in my_func2 foo bar
+ +

Showing what is actually run

+ +

--verbose will show the command that would be run on the local machine. When a job is run on a remote machine this is wrapped with ssh and possibly transferring files and environment variables, setting the workdir, and setting --nice value. -vv shows all of this.

+ +
  parallel -vv -S $SERVER1 echo ::: bar
+

Output:

-
-  ssh -tt -oLogLevel=quiet lo  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ bar;
-  bar
+ +
  ssh -tt -oLogLevel=quiet lo  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ bar;
+  bar
+

When the command gets more complex, the output is so hard to read, that it is only useful for debugging:

-
-  my_func3() {
+
+
  my_func3() {
     echo in my_func $1 > $1.out
   }
   export -f my_func3
-  parallel -vv --workdir ... --nice 17 --env _ --trc {}.out -S $SERVER1 my_func3 {} ::: abc-file
+ parallel -vv --workdir ... --nice 17 --env _ --trc {}.out -S $SERVER1 my_func3 {} ::: abc-file
+

Output will be similar to:

-
-  ssh server mkdir -p .parallel/tmp/hk-31483-1; rsync -rlDzR -essh ./abc-file server:.parallel/tmp/hk-31483-1;ssh -tt -oLogLevel=quiet server  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;mkdir\ -p\ .parallel/tmp/hk-31483-1\;\ cd\ .parallel/tmp/hk-31483-1\ \&\&\ echo\ \$SHELL\ \|\ grep\ \"/t\\\{0,1\\\}csh\"\ \>\ /dev/null\ \&\&\ setenv\ my_func3\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\\\ \\\>\\\ \\\$1.out\"'
-  '\"\\\}\ \&\&\ setenv\ VAR\ foo\ \&\&\ setenv\ my_func2\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
-  '\"\\\}\ \|\|\ export\ my_func3=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\\\ \\\>\\\ \\\$1.out\"'
-  '\"\\\}\ \&\&\ export\ VAR=foo\ \&\&\ export\ my_func2=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ eval\ my_func3\"\$my_func3\"\ \&\&\ eval\ my_func2\"\$my_func2\"\;\\nice\ -n17\ /bin/bash\ -c\ my_func3\\\ abc-file;_EXIT_status=$?; mkdir -p .; rsync --rsync-path=cd\ .parallel/tmp/hk-31483-1/.\;\ rsync -rlDzR -essh server:abc-file.out .;ssh server rm\ -f\ .parallel/tmp/hk-31483-1/abc-file\;rm\ -f\ .parallel/tmp/hk-31483-1/abc-file.out\;rm -rf .parallel/tmp/hk-31483-1\;; exit $_EXIT_status;
-

-

-
-

--pipe

-

The --pipe functionality puts GNU Parallel in a different mode: -Instead of treating the data on stdin (standard input) as arguments -for a command to run, the data will be sent to stdin (standard input) -of the command.

+ +
  ssh server mkdir -p .parallel/tmp/hk-31483-1; rsync -rlDzR -essh ./abc-file server:.parallel/tmp/hk-31483-1;ssh -tt -oLogLevel=quiet server  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;mkdir\ -p\ .parallel/tmp/hk-31483-1\;\ cd\ .parallel/tmp/hk-31483-1\ \&\&\ echo\ \$SHELL\ \|\ grep\ \"/t\\\{0,1\\\}csh\"\ \>\ /dev/null\ \&\&\ setenv\ my_func3\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\\\ \\\>\\\ \\\$1.out\"'
+  '\"\\\}\ \&\&\ setenv\ VAR\ foo\ \&\&\ setenv\ my_func2\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
+  '\"\\\}\ \|\|\ export\ my_func3=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\\\ \\\>\\\ \\\$1.out\"'
+  '\"\\\}\ \&\&\ export\ VAR=foo\ \&\&\ export\ my_func2=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ eval\ my_func3\"\$my_func3\"\ \&\&\ eval\ my_func2\"\$my_func2\"\;\\nice\ -n17\ /bin/bash\ -c\ my_func3\\\ abc-file;_EXIT_status=$?; mkdir -p .; rsync --rsync-path=cd\ .parallel/tmp/hk-31483-1/.\;\ rsync -rlDzR -essh server:abc-file.out .;ssh server rm\ -f\ .parallel/tmp/hk-31483-1/abc-file\;rm\ -f\ .parallel/tmp/hk-31483-1/abc-file.out\;rm -rf .parallel/tmp/hk-31483-1\;; exit $_EXIT_status;
+ +

--pipe

+ +

The --pipe functionality puts GNU Parallel in a different mode: Instead of treating the data on stdin (standard input) as arguments for a command to run, the data will be sent to stdin (standard input) of the command.

+

The typical situation is:

-
-  command_A | command_B | command_C
+ +
  command_A | command_B | command_C
+

where command_B is slow, and you want to speed up command_B.

-

-

-

Chunk size

-

By default GNU Parallel will start an instance of command_B, read a -chunk of 1 MB, and pass that to the instance. Then start another -instance, read another chunk, and pass that to the second instance.

-
-  cat num1000000 | parallel --pipe wc
+ +

Chunk size

+ +

By default GNU Parallel will start an instance of command_B, read a chunk of 1 MB, and pass that to the instance. Then start another instance, read another chunk, and pass that to the second instance.

+ +
  cat num1000000 | parallel --pipe wc
+

Output (the order may be different):

-
-  165668  165668 1048571
+
+
  165668  165668 1048571
   149797  149797 1048579
   149796  149796 1048572
   149797  149797 1048579
   149797  149797 1048579
   149796  149796 1048572
-   85349   85349  597444
-

The size of the chunk is not exactly 1 MB because GNU Parallel only -passes full lines - never half a line, thus the blocksize is only -average 1 MB. You can change the block size to 2 MB with --block:

-
-  cat num1000000 | parallel --pipe --block 2M wc
+ 85349 85349 597444
+ +

The size of the chunk is not exactly 1 MB because GNU Parallel only passes full lines - never half a line, thus the blocksize is only average 1 MB. You can change the block size to 2 MB with --block:

+ +
  cat num1000000 | parallel --pipe --block 2M wc
+

Output (the order may be different):

-
-  315465  315465 2097150
+
+
  315465  315465 2097150
   299593  299593 2097151
   299593  299593 2097151
-   85349   85349  597444
-

GNU Parallel treats each line as a record. If the order of record is -unimportant (e.g. you need all lines processed, but you do not care -which is processed first), then you can use --round-robin. Without ---round-robin GNU Parallel will start a command per block; with ---round-robin only the requested number of jobs will be started -(--jobs). The records will then be distributed between the running -jobs:

-
-  cat num1000000 | parallel --pipe -j4 --round-robin wc
+ 85349 85349 597444
+ +

GNU Parallel treats each line as a record. If the order of record is unimportant (e.g. you need all lines processed, but you do not care which is processed first), then you can use --round-robin. Without --round-robin GNU Parallel will start a command per block; with --round-robin only the requested number of jobs will be started (--jobs). The records will then be distributed between the running jobs:

+ +
  cat num1000000 | parallel --pipe -j4 --round-robin wc
+

Output will be similar to:

-
-  149797  149797 1048579
+
+
  149797  149797 1048579
   299593  299593 2097151
   315465  315465 2097150
-  235145  235145 1646016
-

One of the 4 instances got a single record, 2 instances got 2 full -records each, and one instance got 1 full and 1 partial record.

-

-

-

Records

-

GNU Parallel sees the input as records. The default record is a single -line.

+ 235145 235145 1646016
+ +

One of the 4 instances got a single record, 2 instances got 2 full records each, and one instance got 1 full and 1 partial record.

+ +

Records

+ +

GNU Parallel sees the input as records. The default record is a single line.

+

Using -N140000 GNU Parallel will read 140000 records at a time:

-
-  cat num1000000 | parallel --pipe -N140000 wc
+ +
  cat num1000000 | parallel --pipe -N140000 wc
+

Output (the order may be different):

-
-  140000  140000  868895
+
+
  140000  140000  868895
   140000  140000  980000
   140000  140000  980000
   140000  140000  980000
   140000  140000  980000
   140000  140000  980000
   140000  140000  980000
-   20000   20000  140001
-

Notice that the last job could not get the full 140000 lines, but only -20000 lines.

+ 20000 20000 140001
+ +

Notice that the last job could not get the full 140000 lines, but only 20000 lines.

+

If a record is 75 lines -L can be used:

-
-  cat num1000000 | parallel --pipe -L75 wc
+ +
  cat num1000000 | parallel --pipe -L75 wc
+

Output (the order may be different):

-
-  165600  165600 1048095
+
+
  165600  165600 1048095
   149850  149850 1048950
   149775  149775 1048425
   149775  149775 1048425
   149850  149850 1048950
   149775  149775 1048425
    85350   85350  597450
-      25      25     176
-

Notice GNU Parallel still reads a block of around 1 MB; but instead of -passing full lines to 'wc' it passes full 75 lines at a time. This -of course does not hold for the last job (which in this case got 25 -lines).

-

-

-

Record separators

+ 25 25 176
+ +

Notice GNU Parallel still reads a block of around 1 MB; but instead of passing full lines to 'wc' it passes full 75 lines at a time. This of course does not hold for the last job (which in this case got 25 lines).

+ +

Record separators

+

GNU Parallel uses separators to determine where two record split.

-

--recstart gives the string that starts a record; --recend gives the -string that ends a record. The default is --recend '\n' (newline).

-

If both --recend and --recstart are given, then the record will only -split if the recend string is immediately followed by the recstart -string.

-

Here the --recend is set to ', ':

-
-  echo /foo, bar/, /baz, qux/, | parallel -kN1 --recend ', ' --pipe echo JOB{#}\;cat\;echo END
+ +

--recstart gives the string that starts a record; --recend gives the string that ends a record. The default is --recend '\n' (newline).

+ +

If both --recend and --recstart are given, then the record will only split if the recend string is immediately followed by the recstart string.

+ +

Here the --recend is set to ', ':

+ +
  echo /foo, bar/, /baz, qux/, | parallel -kN1 --recend ', ' --pipe echo JOB{#}\;cat\;echo END
+

Output:

-
-  JOB1
+
+
  JOB1
   /foo, END
   JOB2
   bar/, END
@@ -1553,13 +1680,15 @@ string.

/baz, END JOB4 qux/, - END
-

Here the --recstart is set to '/':

-
-  echo /foo, bar/, /baz, qux/, | parallel -kN1 --recstart '/' --pipe echo JOB{#}\;cat\;echo END
+ END
+ +

Here the --recstart is set to '/':

+ +
  echo /foo, bar/, /baz, qux/, | parallel -kN1 --recstart '/' --pipe echo JOB{#}\;cat\;echo END
+

Output:

-
-  JOB1
+
+
  JOB1
   /foo, barEND
   JOB2
   /, END
@@ -1567,52 +1696,59 @@ string.

/baz, quxEND JOB4 /, - END
+ END
+

Here both --recend and --recstart are set:

-
-  echo /foo, bar/, /baz, qux/, | parallel -kN1 --recend ', ' --recstart '/' --pipe echo JOB{#}\;cat\;echo END
+ +
  echo /foo, bar/, /baz, qux/, | parallel -kN1 --recend ', ' --recstart '/' --pipe echo JOB{#}\;cat\;echo END
+

Output:

-
-  JOB1
+
+
  JOB1
   /foo, bar/, END
   JOB2
   /baz, qux/,
-  END
+ END
+

Note the difference between setting one string and setting both strings.

+

With --regexp the --recend and --recstart will be treated as a regular expression:

-
-  echo foo,bar,_baz,__qux, | parallel -kN1 --regexp --recend ',_+' --pipe echo JOB{#}\;cat\;echo END
+ +
  echo foo,bar,_baz,__qux, | parallel -kN1 --regexp --recend ',_+' --pipe echo JOB{#}\;cat\;echo END
+

Output:

-
-  JOB1
+
+
  JOB1
   foo,bar,_END
   JOB2
   baz,__END
   JOB3
   qux,
-  END
+ END
+

GNU Parallel can remove the record separators with --remove-rec-sep/--rrs:

-
-  echo foo,bar,_baz,__qux, | parallel -kN1 --rrs --regexp --recend ',_+' --pipe echo JOB{#}\;cat\;echo END
+ +
  echo foo,bar,_baz,__qux, | parallel -kN1 --rrs --regexp --recend ',_+' --pipe echo JOB{#}\;cat\;echo END
+

Output:

-
-  JOB1
+
+
  JOB1
   foo,barEND
   JOB2
   bazEND
   JOB3
   qux,
-  END
-

-

-

Header

-

If the input data has a header, the header can be repeated for each -job by matching the header with --header. If headers start with %:

-
-  cat num_%header | parallel --header '(%.*\n)*' --pipe -N3 echo JOB{#}\;cat
+ END
+ + + +

If the input data has a header, the header can be repeated for each job by matching the header with --header. If headers start with %:

+ +
  cat num_%header | parallel --header '(%.*\n)*' --pipe -N3 echo JOB{#}\;cat
+

Output (the order may be different):

-
-  JOB1
+
+
  JOB1
   %head1
   %head2
   1
@@ -1633,181 +1769,196 @@ job by matching the header with --header. If headers start with %:

JOB4 %head1 %head2 - 10
+ 10
+

If the header is 2 lines, --header 2 will work:

-
-  cat num_%header | parallel --header 2 --pipe -N3 echo JOB{#}\;cat
+ +
  cat num_%header | parallel --header 2 --pipe -N3 echo JOB{#}\;cat
+

Output: Same as above.

-

-

-
-

Shebang

-

-

-

Input data and parallel command in the same file

+ +

Shebang

+ +

Input data and parallel command in the same file

+

GNU Parallel is often called as:

-
-  cat input_file | parallel command
+ +
  cat input_file | parallel command
+

With --shebang the input_file and parallel can be combined into the same script.

+

UNIX-scripts start with a shebang line like:

-
-  #!/bin/bash
-

GNU Parallel can do that, too. With --shebang the arguments can be -listed in the file. The parallel command is the first line of the -script:

-
-  #!/usr/bin/parallel --shebang -r echo
-
+
+
  #!/bin/bash
+ +

GNU Parallel can do that, too. With --shebang the arguments can be listed in the file. The parallel command is the first line of the script:

+ +
  #!/usr/bin/parallel --shebang -r echo
+
   foo
   bar
-  baz
+ baz
+

Output (the order may be different):

-
-  foo
+
+
  foo
   bar
-  baz
-

-

-

Parallelizing existing scripts

+ baz
+ +

Parallelizing existing scripts

+

GNU Parallel is often called as:

-
-  cat input_file | parallel command
-  parallel command ::: foo bar
+ +
  cat input_file | parallel command
+  parallel command ::: foo bar
+

If command is a script parallel can be combined into a single file so:

-
-  cat input_file | command
-  command foo bar
+ +
  cat input_file | command
+  command foo bar
+

will run the script in parallel.

+

This perl script perl_echo works like echo:

-
-  #!/usr/bin/perl
-
-  print "@ARGV\n"
+ +
  #!/usr/bin/perl
+
+  print "@ARGV\n"
+

It can be called as:

-
-  parallel perl_echo ::: foo bar
+ +
  parallel perl_echo ::: foo bar
+

By changing the #!-line it can be run in parallel

-
-  #!/usr/bin/parallel --shebang-wrap /usr/bin/perl
-
-  print "@ARGV\n"
+ +
  #!/usr/bin/parallel --shebang-wrap /usr/bin/perl
+
+  print "@ARGV\n"
+

Thus this will work:

-
-  perl_echo foo bar
+ +
  perl_echo foo bar
+

Output (the order may be different):

-
-  foo
-  bar
+ +
  foo
+  bar
+

This technique can be used for:

+
-
Perl:
+
Perl:
+

#!/usr/bin/parallel --shebang-wrap /usr/bin/perl

-
-
Python:
+ +
Python:
+

#!/usr/bin/parallel --shebang-wrap /usr/bin/python

-
-
Bash:
+ +
Bash:
+

#!/usr/bin/parallel --shebang-wrap /bin/bash

-
-
R:
+ +
R:
+

#!/usr/bin/parallel --shebang-wrap /usr/bin/Rscript --vanilla --slave

-
-
GNUplot:
+ +
GNUplot:
+

#!/usr/bin/parallel --shebang-wrap ARG={} /usr/bin/gnuplot

-
-
Ruby:
+ +
Ruby:
+

#!/usr/bin/parallel --shebang-wrap /usr/bin/ruby

+
-

-

-
-

Semaphore

-

GNU Parallel can work as a counting semaphore. This is slower and less -efficient than its normal mode.

-

An alias for 'parallel --semaphore' is 'sem'. The default is to allow -only one program to run at a time (technically called a mutex). The -program is started in the background. Use --wait for all 'sem's to -finish:

-
-  sem 'sleep 1; echo The first finished' &&
+
+

Semaphore

+ +

GNU Parallel can work as a counting semaphore. This is slower and less efficient than its normal mode.

+ +

An alias for 'parallel --semaphore' is 'sem'. The default is to allow only one program to run at a time (technically called a mutex). The program is started in the background. Use --wait for all 'sem's to finish:

+ +
  sem 'sleep 1; echo The first finished' &&
     echo The first is now running in the background &&
-    sem 'sleep 1; echo The second finished' &&
+    sem 'sleep 1; echo The second finished' &&
     echo The second is now running in the background
-  sem --wait
+ sem --wait
+

Output:

-
-  The first is now running in the background
+
+
  The first is now running in the background
   The first finished
   The second is now running in the background
-  The second finished
+ The second finished
+

The command can be run in the foreground with --fg:

-
-  sem --fg 'sleep 1; echo The first finished' &&
+
+
  sem --fg 'sleep 1; echo The first finished' &&
     echo The first finished running in the foreground &&
-    sem --fg 'sleep 1; echo The second finished' &&
+    sem --fg 'sleep 1; echo The second finished' &&
     echo The second finished running in the foreground
-  sem --wait
-

The difference between this and just running the command, is that a -mutex is set, so if other sems were running in the background only one -would run at the same time.

-

To tell the difference between which semaphore is used, use ---semaphorename/--id. Run this in one terminal:

-
-  sem --id my_id -u 'echo First started; sleep 10; echo The first finished'
+ sem --wait
+ +

The difference between this and just running the command, is that a mutex is set, so if other sems were running in the background only one would run at the same time.

+ +

To tell the difference between which semaphore is used, use --semaphorename/--id. Run this in one terminal:

+ +
  sem --id my_id -u 'echo First started; sleep 10; echo The first finished'
+

and simultaneously this in another terminal:

-
-  sem --id my_id -u 'echo Second started; sleep 10; echo The second finished'
+ +
  sem --id my_id -u 'echo Second started; sleep 10; echo The second finished'
+

Note how the second will only be started when the first has finished.

-

-

-

Counting semaphore

-

A mutex is like having a single toilet: When it is in use everyone -else will have to wait. A counting semaphore is like having multiple -toilets: Several people can use the toilets, but when they all are in -use, everyone else will have to wait.

-

sem can emulate a counting semaphore. Use --jobs to set the number of -toilets:

-
-  sem --jobs 3 --id my_id -u 'echo First started; sleep 5; echo The first finished' &&
-  sem --jobs 3 --id my_id -u 'echo Second started; sleep 6; echo The second finished' &&
-  sem --jobs 3 --id my_id -u 'echo Third started; sleep 7; echo The third finished' &&
-  sem --jobs 3 --id my_id -u 'echo Fourth started; sleep 8; echo The fourth finished' &&
-  sem --wait --id my_id
+ +

Counting semaphore

+ +

A mutex is like having a single toilet: When it is in use everyone else will have to wait. A counting semaphore is like having multiple toilets: Several people can use the toilets, but when they all are in use, everyone else will have to wait.

+ +

sem can emulate a counting semaphore. Use --jobs to set the number of toilets:

+ +
  sem --jobs 3 --id my_id -u 'echo First started; sleep 5; echo The first finished' &&
+  sem --jobs 3 --id my_id -u 'echo Second started; sleep 6; echo The second finished' &&
+  sem --jobs 3 --id my_id -u 'echo Third started; sleep 7; echo The third finished' &&
+  sem --jobs 3 --id my_id -u 'echo Fourth started; sleep 8; echo The fourth finished' &&
+  sem --wait --id my_id
+

Output:

-
-  First started
+
+
  First started
   Second started
   Third started
   The first finished
   Fourth started
   The second finished
   The third finished
-  The fourth finished
-

-

-
-

Informational

-

GNU Parallel has some options to give short information about the -configuration.

+ The fourth finished
+ +

Informational

+ +

GNU Parallel has some options to give short information about the configuration.

+

--help will print a summary of the most important options:

-
-  parallel --help
+ +
  parallel --help
+

Output:

-
-  Usage:
+
+
  Usage:
   parallel [options] [command [arguments]] < list_of_arguments
   parallel [options] [command [arguments]] (::: arguments|:::: argfile(s))...
   cat ... | parallel --pipe [options] [command [arguments]]
@@ -1829,44 +1980,48 @@ configuration.

--recend str Record end separator for --pipe. --recstart str Record start separator for --pipe. - See 'man parallel' for details + See 'man parallel' for details When using GNU Parallel for a publication please cite: O. Tange (2011): GNU Parallel - The Command-Line Power Tool, - ;login: The USENIX Magazine, February 2011:42-47.
+ ;login: The USENIX Magazine, February 2011:42-47.
+

When asking for help, always report the full output of:

-
-  parallel --version
+ +
  parallel --version
+

Output:

-
-  GNU parallel 20130822
+
+
  GNU parallel 20130822
   Copyright (C) 2007,2008,2009,2010,2011,2012,2013 Ole Tange and Free Software Foundation, Inc.
-  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>;
+  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
   This is free software: you are free to change and redistribute it.
   GNU parallel comes with no warranty.
   
-  Web site: http://www.gnu.org/software/parallel
+  Web site: http://www.gnu.org/software/parallel
   
   When using GNU Parallel for a publication please cite:
   
   O. Tange (2011): GNU Parallel - The Command-Line Power Tool, 
-  ;login: The USENIX Magazine, February 2011:42-47.
-

In scripts --minversion can be used to ensure the user has at least -this version:

-
-  parallel --minversion 20130722 && echo Your version is at least 20130722.
+ ;login: The USENIX Magazine, February 2011:42-47.
+ +

In scripts --minversion can be used to ensure the user has at least this version:

+ +
  parallel --minversion 20130722 && echo Your version is at least 20130722.
+

Output:

-
-  20130722
-  Your version is at least 20130722.
-

If using GNU Parallel for research the BibTeX citation can be -generated using --bibtex.

-
-  parallel --bibtex
+ +
  20130722
+  Your version is at least 20130722.
+ +

If using GNU Parallel for research the BibTeX citation can be generated using --bibtex.

+ +
  parallel --bibtex
+

Output:

-
-  @article{Tange2011a,
+
+
  @article{Tange2011a,
    title = {GNU Parallel - The Command-Line Power Tool},
    author = {O. Tange},
    address = {Frederiksberg, Denmark},
@@ -1874,104 +2029,116 @@ generated using --bibtex.

month = {Feb}, number = {1}, volume = {36}, - url = {http://www.gnu.org/s/parallel}, + url = {http://www.gnu.org/s/parallel}, year = {2011}, pages = {42-47} - }
-

With --max-line-length-allowed GNU Parallel will report the maximal -size of the command line:

-
-  parallel --max-line-length-allowed
+ }
+ +

With --max-line-length-allowed GNU Parallel will report the maximal size of the command line:

+ +
  parallel --max-line-length-allowed
+

Output (may vary on different systems):

-
-  131071
-

--number-of-cpus and --number-of-cores run system specific code to -determine the number of CPUs and CPU cores on the system. On -unsupported platforms they will return 1:

-
-  parallel --number-of-cpus 
-  parallel --number-of-cores
+ +
  131071
+ +

--number-of-cpus and --number-of-cores run system specific code to determine the number of CPUs and CPU cores on the system. On unsupported platforms they will return 1:

+ +
  parallel --number-of-cpus 
+  parallel --number-of-cores
+

Output (may vary on different systems):

-
-  4
-  64
-

-

-
-

Profiles

-

The defaults for GNU Parallel can be changed systemwise by putting the -command line options in /etc/parallel/config. They can be changed for -a user by putting them in ~/.parallel/config.

+ +
  4
+  64
+ +

Profiles

+ +

The defaults for GNU Parallel can be changed systemwise by putting the command line options in /etc/parallel/config. They can be changed for a user by putting them in ~/.parallel/config.

+

Profiles work the same way, but have to be referred to with --profile:

-
-  echo '-S :,'$SERVER1 > ~/.parallel/cluster
-  echo '--nice 17' >> ~/.parallel/cluster
-  echo '--filter-hosts' >> ~/.parallel/cluster
-  echo '--timeout 300%' >> ~/.parallel/cluster
-  echo '--env _' >> ~/.parallel/cluster
-  parallel --profile cluster echo ::: A B C
+ +
  echo '-S :,'$SERVER1 > ~/.parallel/cluster
+  echo '--nice 17' >> ~/.parallel/cluster
+  echo '--filter-hosts' >> ~/.parallel/cluster
+  echo '--timeout 300%' >> ~/.parallel/cluster
+  echo '--env _' >> ~/.parallel/cluster
+  parallel --profile cluster echo ::: A B C
+

Output:

-
-  A
+
+
  A
   B
-  C
+ C
+

Profiles can be combined:

-
-  echo '-vv --dry-run' > ~/.parallel/dryverbose
-  parallel --profile dryverbose --profile cluster echo ::: A B C
+ +
  echo '-vv --dry-run' > ~/.parallel/dryverbose
+  parallel --profile dryverbose --profile cluster echo ::: A B C
+

Output:

-
-  ssh -tt -oLogLevel=quiet lo  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ \$SHELL\ \|\ grep\ \"/t\\\{0,1\\\}csh\"\ \>\ /dev/null\ \&\&\ setenv\ SERVER1\ lo\ \&\&\ setenv\ MYVAR\ foo\\\ bar\ \&\&\ setenv\ VAR\ foo\ \&\&\ setenv\ my_func\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ setenv\ my_func2\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
-  '\"\\\}\ \|\|\ export\ SERVER1=lo\ \&\&\ export\ MYVAR=foo\\\ bar\ \&\&\ export\ VAR=foo\ \&\&\ export\ my_func=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ export\ my_func2=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ eval\ my_func\"\$my_func\"\ \&\&\ eval\ my_func2\"\$my_func2\"\;\\nice\ -n17\ /bin/bash\ -c\ echo\\\ A;
-  ssh -tt -oLogLevel=quiet lo  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ \$SHELL\ \|\ grep\ \"/t\\\{0,1\\\}csh\"\ \>\ /dev/null\ \&\&\ setenv\ SERVER1\ lo\ \&\&\ setenv\ MYVAR\ foo\\\ bar\ \&\&\ setenv\ VAR\ foo\ \&\&\ setenv\ my_func\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ setenv\ my_func2\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
-  '\"\\\}\ \|\|\ export\ SERVER1=lo\ \&\&\ export\ MYVAR=foo\\\ bar\ \&\&\ export\ VAR=foo\ \&\&\ export\ my_func=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ export\ my_func2=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ eval\ my_func\"\$my_func\"\ \&\&\ eval\ my_func2\"\$my_func2\"\;\\nice\ -n17\ /bin/bash\ -c\ echo\\\ B;
-  ssh -tt -oLogLevel=quiet lo  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ \$SHELL\ \|\ grep\ \"/t\\\{0,1\\\}csh\"\ \>\ /dev/null\ \&\&\ setenv\ SERVER1\ lo\ \&\&\ setenv\ MYVAR\ foo\\\ bar\ \&\&\ setenv\ VAR\ foo\ \&\&\ setenv\ my_func\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ setenv\ my_func2\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
-  '\"\\\}\ \|\|\ export\ SERVER1=lo\ \&\&\ export\ MYVAR=foo\\\ bar\ \&\&\ export\ VAR=foo\ \&\&\ export\ my_func=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ export\ my_func2=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
-  '\"\\\}\ \&\&\ eval\ my_func\"\$my_func\"\ \&\&\ eval\ my_func2\"\$my_func2\"\;\\nice\ -n17\ /bin/bash\ -c\ echo\\\ C;
-

-

-
-

Spread the word

+ +
  ssh -tt -oLogLevel=quiet lo  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ \$SHELL\ \|\ grep\ \"/t\\\{0,1\\\}csh\"\ \>\ /dev/null\ \&\&\ setenv\ SERVER1\ lo\ \&\&\ setenv\ MYVAR\ foo\\\ bar\ \&\&\ setenv\ VAR\ foo\ \&\&\ setenv\ my_func\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ setenv\ my_func2\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
+  '\"\\\}\ \|\|\ export\ SERVER1=lo\ \&\&\ export\ MYVAR=foo\\\ bar\ \&\&\ export\ VAR=foo\ \&\&\ export\ my_func=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ export\ my_func2=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ eval\ my_func\"\$my_func\"\ \&\&\ eval\ my_func2\"\$my_func2\"\;\\nice\ -n17\ /bin/bash\ -c\ echo\\\ A;
+  ssh -tt -oLogLevel=quiet lo  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ \$SHELL\ \|\ grep\ \"/t\\\{0,1\\\}csh\"\ \>\ /dev/null\ \&\&\ setenv\ SERVER1\ lo\ \&\&\ setenv\ MYVAR\ foo\\\ bar\ \&\&\ setenv\ VAR\ foo\ \&\&\ setenv\ my_func\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ setenv\ my_func2\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
+  '\"\\\}\ \|\|\ export\ SERVER1=lo\ \&\&\ export\ MYVAR=foo\\\ bar\ \&\&\ export\ VAR=foo\ \&\&\ export\ my_func=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ export\ my_func2=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ eval\ my_func\"\$my_func\"\ \&\&\ eval\ my_func2\"\$my_func2\"\;\\nice\ -n17\ /bin/bash\ -c\ echo\\\ B;
+  ssh -tt -oLogLevel=quiet lo  'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null  && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\;  setenv PARALLEL_PID '$PARALLEL_PID'  || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\;  PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;'  tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ \$SHELL\ \|\ grep\ \"/t\\\{0,1\\\}csh\"\ \>\ /dev/null\ \&\&\ setenv\ SERVER1\ lo\ \&\&\ setenv\ MYVAR\ foo\\\ bar\ \&\&\ setenv\ VAR\ foo\ \&\&\ setenv\ my_func\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ setenv\ my_func2\ \\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
+  '\"\\\}\ \|\|\ export\ SERVER1=lo\ \&\&\ export\ MYVAR=foo\\\ bar\ \&\&\ export\ VAR=foo\ \&\&\ export\ my_func=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ export\ my_func2=\\\(\\\)\\\ \\\{\\\ \\\ echo\\\ in\\\ my_func2\\\ \\\$VAR\\\ \\\$1\"'
+  '\"\\\}\ \&\&\ eval\ my_func\"\$my_func\"\ \&\&\ eval\ my_func2\"\$my_func2\"\;\\nice\ -n17\ /bin/bash\ -c\ echo\\\ C;
+ +

Spread the word

+

I hope you have learned something from this tutorial.

+

If you like GNU Parallel:

+ +

If you use GNU Parallel for research:

+ +

If GNU Parallel saves you money:

+ +

(C) 20140622 Ole Tange GPLv3

+ + + diff --git a/src/sem.pdf b/src/sem.pdf index 3c6555e5..464dd3b5 100644 Binary files a/src/sem.pdf and b/src/sem.pdf differ diff --git a/testsuite/Makefile b/testsuite/Makefile index ac4ee65a..c228d66e 100644 --- a/testsuite/Makefile +++ b/testsuite/Makefile @@ -58,7 +58,7 @@ installparallel: ../src/parallel startdb: #echo shutdown abort | sudo su - oracle -c "sqlplus / as sysdba" - sudo parallel /etc/init.d/{} restart ::: postgresql mysql # oracle-xe + sudo parallel /etc/init.d/{} status '||' /etc/init.d/{} restart ::: postgresql mysql # oracle-xe VBoxManage startvm OracleXE || true clean: diff --git a/testsuite/tests-to-run/parallel-install.sh b/testsuite/tests-to-run/parallel-install.sh index 24569067..4c0c0f21 100644 --- a/testsuite/tests-to-run/parallel-install.sh +++ b/testsuite/tests-to-run/parallel-install.sh @@ -5,12 +5,15 @@ echo '### Test installation missing pod2*' parallel which ::: pod2html pod2man pod2texi pod2pdf | sudo parallel mv {} {}.hidden cd ~/privat/parallel +# Make a .tar.gz file stdout make dist | perl -pe 's/make\[\d\]/make[0]/g;s/\d{8}/00000000/g' LAST=$(ls *tar.gz | tail -n1) + cd /tmp rm -rf parallel-20??????/ tar xf ~/privat/parallel/$LAST cd parallel-20??????/ +# Make sure files depending on *.pod have to be rebuilt touch src/*pod src/sql ./configure && sudo stdout make install | perl -pe 's/make\[\d\]/make[0]/g;s/\d{8}/00000000/g' diff --git a/testsuite/tests-to-run/parallel-local22.sh b/testsuite/tests-to-run/parallel-local22.sh index f424f3f0..b27ac92b 100755 --- a/testsuite/tests-to-run/parallel-local22.sh +++ b/testsuite/tests-to-run/parallel-local22.sh @@ -58,6 +58,7 @@ echo '### bug #42055: --pipe -a bigfile should not require sequential reading of parallel --pipepart -a /etc/passwd -l 1 should not be run echo '### --tmux test - check termination' - perl -e 'map {printf "$_%o%c\n",$_,$_}1..255' | parallel --tmux echo {} :::: - ::: a b + perl -e 'map {printf "$_%o%c\n",$_,$_}1..255' | stdout parallel --tmux echo {} :::: - ::: a b | perl -pe 's/\d/0/g' + EOF diff --git a/testsuite/tests-to-run/test13.sh b/testsuite/tests-to-run/test13.sh index 22ab3ee3..6ef1fd6c 100755 --- a/testsuite/tests-to-run/test13.sh +++ b/testsuite/tests-to-run/test13.sh @@ -12,7 +12,7 @@ echo '### Test --keeporder' (seq 0 2) | parallel --keeporder -j100% -S 1/:,2/parallel@parallel-server2 -q perl -e 'sleep 1;print "job{}\n";exit({})' echo '### Test SIGTERM' -parallel -k -j9 sleep 3';' echo ::: {1..99} >/tmp/$$ 2>&1 & +parallel -k -j20 sleep 3';' echo ::: {1..99} >/tmp/$$ 2>&1 & A=$! sleep 5; kill -TERM $A wait diff --git a/testsuite/tests-to-run/test18.sh b/testsuite/tests-to-run/test18.sh index 07a0646e..699faad0 100644 --- a/testsuite/tests-to-run/test18.sh +++ b/testsuite/tests-to-run/test18.sh @@ -43,7 +43,7 @@ echo "#2/ssh -l tange nothing" >>/tmp/parallel-sshlogin seq 1 10 | parallel -k --sshloginfile /tmp/parallel-sshlogin echo echo '### Check forced number of CPUs being respected' -stdout seq 1 20 | parallel -k -j+0 -S 1/:,7/$SSHLOGIN1 "hostname; echo {} >/dev/null" +seq 1 20 | stdout parallel -k -j+0 -S 1/:,7/$SSHLOGIN1 "hostname; echo {} >/dev/null" | sort echo '### Check more than 9 simultaneous sshlogins' seq 1 11 | parallel -k -j0 -S "ssh $SSHLOGIN1" echo diff --git a/testsuite/tests-to-run/test21.sh b/testsuite/tests-to-run/test21.sh index 464b08f2..b745f0a0 100644 --- a/testsuite/tests-to-run/test21.sh +++ b/testsuite/tests-to-run/test21.sh @@ -5,20 +5,20 @@ SERVER2=parallel-server2 echo '### Test $PARALLEL - single line' echo | PARALLEL=--number-of-cpus parallel -seq 1 2 | PARALLEL="-Sparallel\@$SERVER1 -Sssh\ -l\ parallel\ $SERVER2 -j1" parallel -kvv echo +(echo 1; echo 1) | PARALLEL="-Sparallel\@$SERVER1 -Sssh\ -l\ parallel\ $SERVER2 -j1" parallel -kv hostname\; echo | sort echo '### Test $PARALLEL - multi line' -seq 1 2 | PARALLEL="-Sparallel\@$SERVER1 +(echo 1; echo 1) | PARALLEL="-Sparallel\@$SERVER1 -Sssh\ -l\ parallel\ $SERVER2 --j1" parallel -kvv echo +-j1" parallel -kv hostname\; echo | sort echo '### Test ~/.parallel/config - single line' echo "-Sparallel\@$SERVER1 -Sssh\ -l\ parallel\ $SERVER2 -j1" > ~/.parallel/config -seq 1 2 | parallel -kvv echo +(echo 1; echo 1) | parallel -kv hostname\; echo | sort echo '### Test ~/.parallel/config - multi line' echo "-Sparallel\@$SERVER1 -Sssh\ -l\ parallel\ $SERVER2 -j1" > ~/.parallel/config -seq 1 2 | parallel -kvv echo +(echo 1; echo 1) | parallel -kv hostname\; echo | sort rm ~/.parallel/config diff --git a/testsuite/wanted-results/parallel-install b/testsuite/wanted-results/parallel-install index d67a34e0..33c8875c 100644 --- a/testsuite/wanted-results/parallel-install +++ b/testsuite/wanted-results/parallel-install @@ -5,26 +5,6 @@ test -d "parallel-00000000" || mkdir "parallel-00000000" (cd src && make top_distdir=../parallel-00000000 distdir=../parallel-00000000/src \ am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir) make[0]: Entering directory `/home/tange/privat/parallel/src' -pod2man --release='00000000' --center='parallel' \ - --section=1 ./parallel.pod > ./parallel.1n \ - && mv ./parallel.1n ./parallel.1 \ - || echo "Warning: pod2man not found. Using old parallel.1" -/bin/bash: pod2man: command not found -Warning: pod2man not found. Using old parallel.1 -pod2html ./parallel.pod > ./parallel.htmln \ - && mv ./parallel.htmln ./parallel.html \ - || echo "Warning: pod2html not found. Using old parallel.html" -/bin/bash: pod2html: command not found -Warning: pod2html not found. Using old parallel.html -rm -f ./pod2htm* -pod2texi --output=./parallel.texi ./parallel.pod \ - || echo "Warning: pod2texi not found. Using old parallel.texi" -/bin/bash: pod2texi: command not found -Warning: pod2texi not found. Using old parallel.texi -pod2pdf --output-file ./parallel.pdf ./parallel.pod --title "GNU Parallel" \ - || echo "Warning: pod2pdf not found. Using old parallel.pdf" -/bin/bash: pod2pdf: command not found -Warning: pod2pdf not found. Using old parallel.pdf make[0]: Leaving directory `/home/tange/privat/parallel/src' test -n "" \ || find "parallel-00000000" -type d ! -perm -755 \ diff --git a/testsuite/wanted-results/parallel-local22 b/testsuite/wanted-results/parallel-local22 index 7b244484..97053448 100644 --- a/testsuite/wanted-results/parallel-local22 +++ b/testsuite/wanted-results/parallel-local22 @@ -75,5 +75,5 @@ parallel: Error: --pipepart is incompatible with --max-replace-args, --max-lines parallel: Error: --pipepart is incompatible with --max-replace-args, --max-lines, and -L. echo '### --tmux test - check termination' ### --tmux test - check termination - perl -e 'map {printf "$_%o%c\n",$_,$_}1..255' | parallel --tmux echo {} :::: - ::: a b -See output with: tmux attach -t p6522 + perl -e 'map {printf "$_%o%c\n",$_,$_}1..255' | stdout parallel --tmux echo {} :::: - ::: a b | perl -pe 's/\d/0/g' +See output with: tmux attach -t p00000 diff --git a/testsuite/wanted-results/parallel-local9 b/testsuite/wanted-results/parallel-local9 index 33f16d92..095d004b 100644 --- a/testsuite/wanted-results/parallel-local9 +++ b/testsuite/wanted-results/parallel-local9 @@ -180,26 +180,29 @@ echo "# --recend '' --files --halt-on-error" echo '### Test of -j filename - non-existent file'; nice stdout parallel -j no_such_file echo ::: 1 ### Test of -j filename - non-existent file Usage: + parallel [options] [command [arguments]] < list_of_arguments parallel [options] [command [arguments]] (::: arguments|:::: argfile(s))... cat ... | parallel --pipe [options] [command [arguments]] --j n Run n jobs in parallel --k Keep same order --X Multiple arguments with context replace ---colsep regexp Split input on regexp for positional replacements -{} {.} {/} {/.} {#} {%} Replacement strings -{3} {3.} {3/} {3/.} Positional replacement strings +-j n Run n jobs in parallel +-k Keep same order +-X Multiple arguments with context replace +--colsep regexp Split input on regexp for positional replacements +{} {.} {/} {/.} {#} {%} {= perl code =} Replacement strings +{3} {3.} {3/} {3/.} {=3 perl code =} Positional replacement strings +With --plus: {} = {+/}/{/} = {.}.{+.} = {+/}/{/.}.{+.} = {..}.{+..} = + {+/}/{/..}.{+..} = {...}.{+...} = {+/}/{/...}.{+...} --S sshlogin Example: foo@server.example.com ---slf .. Use ~/.parallel/sshloginfile as the list of sshlogins ---trc {}.bar Shorthand for --transfer --return {}.bar --cleanup ---onall Run the given command with argument on all sshlogins ---nonall Run the given command with no arguments on all sshlogins +-S sshlogin Example: foo@server.example.com +--slf .. Use ~/.parallel/sshloginfile as the list of sshlogins +--trc {}.bar Shorthand for --transfer --return {}.bar --cleanup +--onall Run the given command with argument on all sshlogins +--nonall Run the given command with no arguments on all sshlogins ---pipe Split stdin (standard input) to multiple jobs. ---recend str Record end separator for --pipe. ---recstart str Record start separator for --pipe. +--pipe Split stdin (standard input) to multiple jobs. +--recend str Record end separator for --pipe. +--recstart str Record start separator for --pipe. See 'man parallel' for details diff --git a/testsuite/wanted-results/test13 b/testsuite/wanted-results/test13 index f3a98e86..6a33f707 100644 --- a/testsuite/wanted-results/test13 +++ b/testsuite/wanted-results/test13 @@ -1,5 +1,5 @@ ### Test -k -parallel: Warning: Only enough file handles to run 8 jobs in parallel. +parallel: Warning: Only enough file handles to run 9 jobs in parallel. Raising ulimit -n or /etc/security/limits.conf may help. begin 1 @@ -9,8 +9,8 @@ begin 5 6 7 -parallel: Warning: No more file handles. Raising ulimit -n or /etc/security/limits.conf may help. 8 +parallel: Warning: No more file handles. Raising ulimit -n or /etc/security/limits.conf may help. 9 10 11 @@ -51,6 +51,8 @@ job2 14 15 16 +17 +18 2 3 4 @@ -61,8 +63,8 @@ job2 9 Raising ulimit -n or /etc/security/limits.conf may help. parallel: SIGTERM received. No new jobs will be started. -parallel: Waiting for these 8 jobs to finish. Send SIGTERM again to stop now. -parallel: Warning: Only enough file handles to run 8 jobs in parallel. +parallel: Waiting for these 9 jobs to finish. Send SIGTERM again to stop now. +parallel: Warning: Only enough file handles to run 9 jobs in parallel. parallel: sleep 3; echo 10 parallel: sleep 3; echo 11 parallel: sleep 3; echo 12 @@ -70,7 +72,8 @@ parallel: sleep 3; echo 13 parallel: sleep 3; echo 14 parallel: sleep 3; echo 15 parallel: sleep 3; echo 16 -parallel: sleep 3; echo 9 +parallel: sleep 3; echo 17 +parallel: sleep 3; echo 18 ### Test bug: empty line for | sh with -k a b diff --git a/testsuite/wanted-results/test15 b/testsuite/wanted-results/test15 index 4e12aa16..ac32fc75 100644 --- a/testsuite/wanted-results/test15 +++ b/testsuite/wanted-results/test15 @@ -383,8 +383,8 @@ line 2 ### Test --no-run-if-empty and -r: This should give no output ### Test --help and -h: Help output (just check we get the same amount of lines) Output from -h and --help -28 -28 +31 +31 ### Test --version: Version output (just check we get the same amount of lines) 12 ### Test --verbose and -t diff --git a/testsuite/wanted-results/test18 b/testsuite/wanted-results/test18 index 25e25f02..934f2bf8 100644 --- a/testsuite/wanted-results/test18 +++ b/testsuite/wanted-results/test18 @@ -79,6 +79,18 @@ parallel: Warning: --cleanup ignored as there are no remote --sshlogin. 10 ### Check forced number of CPUs being respected aspire +aspire +aspire +aspire +aspire +aspire +aspire +aspire +aspire +aspire +aspire +aspire +aspire redhat9.tange.dk redhat9.tange.dk redhat9.tange.dk @@ -86,18 +98,6 @@ redhat9.tange.dk redhat9.tange.dk redhat9.tange.dk redhat9.tange.dk -aspire -aspire -aspire -aspire -aspire -aspire -aspire -aspire -aspire -aspire -aspire -aspire ### Check more than 9 simultaneous sshlogins 1 2 diff --git a/testsuite/wanted-results/test19 b/testsuite/wanted-results/test19 index 8ab86674..4ed19c49 100644 --- a/testsuite/wanted-results/test19 +++ b/testsuite/wanted-results/test19 @@ -76,15 +76,15 @@ ls: tmp/parallel.file*: No such file or directory OK Input for ssh parallel@parallel-server1 mkdir -p ./. --l parallel parallel-server1 rsync --server -lDrRze.iLsf . ./. +-l parallel parallel-server1 rsync --server -lDrRze.iLs . ./. -tt -oLogLevel=quiet parallel@parallel-server1 eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ 2\; setenv PARALLEL_PID 00000 || echo PARALLEL_SEQ=2\;export PARALLEL_SEQ\; PARALLEL_PID=00000\;export PARALLEL_PID` ; tty >/dev/null && stty isig -onlcr -echo;cat tmp/parallel.file.' 'newline2 > tmp/parallel.file.' 'newline2.out;cat tmp/parallel.file.' 'newline2 > tmp/parallel.file.' 'newline2.out2 --l parallel parallel-server1 cd ././tmp; rsync --server --sender -lDrRze.iLsf . ./parallel.file.' +-l parallel parallel-server1 cd ././tmp; rsync --server --sender -lDrRze.iLs . ./parallel.file.' 'newline2.out --l parallel parallel-server1 cd ././tmp; rsync --server --sender -lDrRze.iLsf . ./parallel.file.' +-l parallel parallel-server1 cd ././tmp; rsync --server --sender -lDrRze.iLs . ./parallel.file.' 'newline2.out2 parallel@parallel-server1 (rm -f ./tmp/parallel.file.' 'newline2; rmdir ./tmp/ ./ 2>/dev/null;) @@ -93,15 +93,15 @@ parallel@parallel-server1 (rm -f ./tmp/parallel.file.' parallel@parallel-server1 (rm -f ./tmp/parallel.file.' 'newline2.out2; rmdir ./tmp/ ./ 2>/dev/null;) parallel@parallel-server2 mkdir -p ./. --l parallel parallel-server2 rsync --server -lDrRze.iLsf . ./. +-l parallel parallel-server2 rsync --server -lDrRze.iLs . ./. -tt -oLogLevel=quiet parallel@parallel-server2 eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ 1\; setenv PARALLEL_PID 00000 || echo PARALLEL_SEQ=1\;export PARALLEL_SEQ\; PARALLEL_PID=00000\;export PARALLEL_PID` ; tty >/dev/null && stty isig -onlcr -echo;cat tmp/parallel.file.' 'newline1 > tmp/parallel.file.' 'newline1.out;cat tmp/parallel.file.' 'newline1 > tmp/parallel.file.' 'newline1.out2 --l parallel parallel-server2 cd ././tmp; rsync --server --sender -lDrRze.iLsf . ./parallel.file.' +-l parallel parallel-server2 cd ././tmp; rsync --server --sender -lDrRze.iLs . ./parallel.file.' 'newline1.out --l parallel parallel-server2 cd ././tmp; rsync --server --sender -lDrRze.iLsf . ./parallel.file.' +-l parallel parallel-server2 cd ././tmp; rsync --server --sender -lDrRze.iLs . ./parallel.file.' 'newline1.out2 parallel@parallel-server2 (rm -f ./tmp/parallel.file.' 'newline1; rmdir ./tmp/ ./ 2>/dev/null;) diff --git a/testsuite/wanted-results/test21 b/testsuite/wanted-results/test21 index e2c91c25..2f7a2873 100644 --- a/testsuite/wanted-results/test21 +++ b/testsuite/wanted-results/test21 @@ -1,21 +1,29 @@ ### Test $PARALLEL - single line 1 -ssh -l parallel -tt -oLogLevel=quiet parallel-server2 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ 1; 1 -ssh -tt -oLogLevel=quiet parallel\@parallel-server3 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ 2; -2 +1 +centos3.tange.dk +hostname; echo 1 +hostname; echo 1 +nlv ### Test $PARALLEL - multi line -ssh -l parallel -tt -oLogLevel=quiet parallel-server2 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ 1; 1 -ssh -tt -oLogLevel=quiet parallel\@parallel-server3 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ 2; -2 +1 +centos3.tange.dk +hostname; echo 1 +hostname; echo 1 +nlv ### Test ~/.parallel/config - single line -ssh -l parallel -tt -oLogLevel=quiet parallel-server2 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ 1; 1 -ssh -tt -oLogLevel=quiet parallel\@parallel-server3 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ 2; -2 +1 +centos3.tange.dk +hostname; echo 1 +hostname; echo 1 +nlv ### Test ~/.parallel/config - multi line -ssh -l parallel -tt -oLogLevel=quiet parallel-server2 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ 1; 1 -ssh -tt -oLogLevel=quiet parallel\@parallel-server3 'eval `echo $SHELL | grep "/t\{0,1\}csh" > /dev/null && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; setenv PARALLEL_PID '$PARALLEL_PID' || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; PARALLEL_PID='$PARALLEL_PID'\;export PARALLEL_PID` ;' tty\ \>/dev/null\ \&\&\ stty\ isig\ -onlcr\ -echo\;echo\ 2; -2 +1 +centos3.tange.dk +hostname; echo 1 +hostname; echo 1 +nlv