parallel: --(n)onall and --sshdelay fixed.
[parallel.git] / src / parallel.pod
blob2c6a203721e2f93c8231dc27df88f3c786ca7a3e
1 #!/usr/bin/perl -w
3 =encoding utf8
5 =head1 NAME
7 parallel - build and execute shell command lines from standard input
8 in parallel
11 =head1 SYNOPSIS
13 B<parallel> [options] [I<command> [arguments]] < list_of_arguments
15 B<parallel> [options] [I<command> [arguments]] ( B<:::> arguments |
16 B<:::+> arguments | B<::::> argfile(s) | B<::::+> argfile(s) ) ...
18 B<parallel> --semaphore [options] I<command>
20 B<#!/usr/bin/parallel> --shebang [options] [I<command> [arguments]]
22 B<#!/usr/bin/parallel> --shebang-wrap [options] [I<command>
23 [arguments]]
26 =head1 DESCRIPTION
28 STOP!
30 Read the B<Reader's guide> below if you are new to GNU B<parallel>.
32 GNU B<parallel> is a shell tool for executing jobs in parallel using
33 one or more computers. A job can be a single command or a small script
34 that has to be run for each of the lines in the input. The typical
35 input is a list of files, a list of hosts, a list of users, a list of
36 URLs, or a list of tables. A job can also be a command that reads from
37 a pipe. GNU B<parallel> can then split the input into blocks and pipe
38 a block into each command in parallel.
40 If you use xargs and tee today you will find GNU B<parallel> very easy
41 to use as GNU B<parallel> is written to have the same options as
42 xargs. If you write loops in shell, you will find GNU B<parallel> may
43 be able to replace most of the loops and make them run faster by
44 running several jobs in parallel.
46 GNU B<parallel> makes sure output from the commands is the same output
47 as you would get had you run the commands sequentially. This makes it
48 possible to use output from GNU B<parallel> as input for other
49 programs.
51 For each line of input GNU B<parallel> will execute I<command> with
52 the line as arguments. If no I<command> is given, the line of input is
53 executed. Several lines will be run in parallel. GNU B<parallel> can
54 often be used as a substitute for B<xargs> or B<cat | bash>.
57 =head2 Reader's guide
59 GNU B<parallel> includes the 4 types of documentation: Tutorial,
60 how-to, reference and explanation.
63 =head3 Tutorial
65 If you prefer reading a book buy B<GNU Parallel 2018> at
66 http://www.lulu.com/shop/ole-tange/gnu-parallel-2018/paperback/product-23558902.html
67 or download it at: https://doi.org/10.5281/zenodo.1146014 Read at
68 least chapter 1+2. It should take you less than 20 minutes.
70 Otherwise start by watching the intro videos for a quick introduction:
71 http://www.youtube.com/playlist?list=PL284C9FF2488BC6D1
73 If you want to dive deeper: spend a couple of hours walking through
74 the tutorial (B<man parallel_tutorial>). Your command line will love
75 you for it.
78 =head3 How-to
80 You can find a lot of B<EXAMPLE>s of use after the list of B<OPTIONS>
81 in B<man parallel> (Use B<LESS=+/EXAMPLE: man parallel>). That will
82 give you an idea of what GNU B<parallel> is capable of, and you may
83 find a solution you can simply adapt to your situation.
86 =head3 Reference
88 If you need a one page printable cheat sheet you can find it on:
89 https://www.gnu.org/software/parallel/parallel_cheat.pdf
91 The man page is the reference for all options.
94 =head3 Design discussion
96 If you want to know the design decisions behind GNU B<parallel>, try:
97 B<man parallel_design>. This is also a good intro if you intend to
98 change GNU B<parallel>.
102 =head1 OPTIONS
104 =over 4
106 =item I<command>
108 Command to execute. If I<command> or the following arguments contain
109 replacement strings (such as B<{}>) every instance will be substituted
110 with the input.
112 If I<command> is given, GNU B<parallel> solve the same tasks as
113 B<xargs>. If I<command> is not given GNU B<parallel> will behave
114 similar to B<cat | sh>.
116 The I<command> must be an executable, a script, a composed command, an
117 alias, or a function.
119 B<Bash functions>: B<export -f> the function first or use B<env_parallel>.
121 B<Bash, Csh, or Tcsh aliases>: Use B<env_parallel>.
123 B<Zsh, Fish, Ksh, and Pdksh functions and aliases>: Use B<env_parallel>.
125 =item B<{}>
127 Input line. This replacement string will be replaced by a full line
128 read from the input source. The input source is normally stdin
129 (standard input), but can also be given with B<-a>, B<:::>, or
130 B<::::>.
132 The replacement string B<{}> can be changed with B<-I>.
134 If the command line contains no replacement strings then B<{}> will be
135 appended to the command line.
137 Replacement strings are normally quoted, so special characters are not
138 parsed by the shell. The exception is if the command starts with a
139 replacement string; then the string is not quoted.
142 =item B<{.}>
144 Input line without extension. This replacement string will be replaced
145 by the input with the extension removed. If the input line contains
146 B<.> after the last B</>, the last B<.> until the end of the string
147 will be removed and B<{.}> will be replaced with the
148 remaining. E.g. I<foo.jpg> becomes I<foo>, I<subdir/foo.jpg> becomes
149 I<subdir/foo>, I<sub.dir/foo.jpg> becomes I<sub.dir/foo>,
150 I<sub.dir/bar> remains I<sub.dir/bar>. If the input line does not
151 contain B<.> it will remain unchanged.
153 The replacement string B<{.}> can be changed with B<--er>.
155 To understand replacement strings see B<{}>.
158 =item B<{/}>
160 Basename of input line. This replacement string will be replaced by
161 the input with the directory part removed.
163 The replacement string B<{/}> can be changed with
164 B<--basenamereplace>.
166 To understand replacement strings see B<{}>.
169 =item B<{//}>
171 Dirname of input line. This replacement string will be replaced by the
172 dir of the input line. See B<dirname>(1).
174 The replacement string B<{//}> can be changed with
175 B<--dirnamereplace>.
177 To understand replacement strings see B<{}>.
180 =item B<{/.}>
182 Basename of input line without extension. This replacement string will
183 be replaced by the input with the directory and extension part
184 removed. It is a combination of B<{/}> and B<{.}>.
186 The replacement string B<{/.}> can be changed with
187 B<--basenameextensionreplace>.
189 To understand replacement strings see B<{}>.
192 =item B<{#}>
194 Sequence number of the job to run. This replacement string will be
195 replaced by the sequence number of the job being run. It contains the
196 same number as $PARALLEL_SEQ.
198 The replacement string B<{#}> can be changed with B<--seqreplace>.
200 To understand replacement strings see B<{}>.
203 =item B<{%}>
205 Job slot number. This replacement string will be replaced by the job's
206 slot number between 1 and number of jobs to run in parallel. There
207 will never be 2 jobs running at the same time with the same job slot
208 number.
210 The replacement string B<{%}> can be changed with B<--slotreplace>.
212 If the job needs to be retried (e.g using B<--retries> or
213 B<--retry-failed>) the job slot is not automatically updated. You
214 should then instead use B<$PARALLEL_JOBSLOT>:
216 $ do_test() {
217 id="$3 {%}=$1 PARALLEL_JOBSLOT=$2"
218 echo run "$id";
219 sleep 1
220 # fail if {%} is odd
221 return `echo $1%2 | bc`
223 $ export -f do_test
224 $ parallel -j3 --jl mylog do_test {%} \$PARALLEL_JOBSLOT {} ::: A B C D
225 run A {%}=1 PARALLEL_JOBSLOT=1
226 run B {%}=2 PARALLEL_JOBSLOT=2
227 run C {%}=3 PARALLEL_JOBSLOT=3
228 run D {%}=1 PARALLEL_JOBSLOT=1
229 $ parallel --retry-failed -j3 --jl mylog do_test {%} \$PARALLEL_JOBSLOT {} ::: A B C D
230 run A {%}=1 PARALLEL_JOBSLOT=1
231 run C {%}=3 PARALLEL_JOBSLOT=2
232 run D {%}=1 PARALLEL_JOBSLOT=3
234 Notice how {%} and $PARALLEL_JOBSLOT differ in the retry run of C and D.
236 To understand replacement strings see B<{}>.
239 =item B<{>I<n>B<}>
241 Argument from input source I<n> or the I<n>'th argument. This
242 positional replacement string will be replaced by the input from input
243 source I<n> (when used with B<-a> or B<::::>) or with the I<n>'th
244 argument (when used with B<-N>). If I<n> is negative it refers to the
245 I<n>'th last argument.
247 To understand replacement strings see B<{}>.
250 =item B<{>I<n>.B<}>
252 Argument from input source I<n> or the I<n>'th argument without
253 extension. It is a combination of B<{>I<n>B<}> and B<{.}>.
255 This positional replacement string will be replaced by the input from
256 input source I<n> (when used with B<-a> or B<::::>) or with the
257 I<n>'th argument (when used with B<-N>). The input will have the
258 extension removed.
260 To understand positional replacement strings see B<{>I<n>B<}>.
263 =item B<{>I<n>/B<}>
265 Basename of argument from input source I<n> or the I<n>'th argument.
266 It is a combination of B<{>I<n>B<}> and B<{/}>.
268 This positional replacement string will be replaced by the input from
269 input source I<n> (when used with B<-a> or B<::::>) or with the
270 I<n>'th argument (when used with B<-N>). The input will have the
271 directory (if any) removed.
273 To understand positional replacement strings see B<{>I<n>B<}>.
276 =item B<{>I<n>//B<}>
278 Dirname of argument from input source I<n> or the I<n>'th argument.
279 It is a combination of B<{>I<n>B<}> and B<{//}>.
281 This positional replacement string will be replaced by the dir of the
282 input from input source I<n> (when used with B<-a> or B<::::>) or with
283 the I<n>'th argument (when used with B<-N>). See B<dirname>(1).
285 To understand positional replacement strings see B<{>I<n>B<}>.
288 =item B<{>I<n>/.B<}>
290 Basename of argument from input source I<n> or the I<n>'th argument
291 without extension. It is a combination of B<{>I<n>B<}>, B<{/}>, and
292 B<{.}>.
294 This positional replacement string will be replaced by the input from
295 input source I<n> (when used with B<-a> or B<::::>) or with the
296 I<n>'th argument (when used with B<-N>). The input will have the
297 directory (if any) and extension removed.
299 To understand positional replacement strings see B<{>I<n>B<}>.
302 =item B<{=>I<perl expression>B<=}>
304 Replace with calculated I<perl expression>. B<$_> will contain the
305 same as B<{}>. After evaluating I<perl expression> B<$_> will be used
306 as the value. It is recommended to only change $_ but you have full
307 access to all of GNU B<parallel>'s internal functions and data
308 structures. A few convenience functions and data structures have been
309 made:
311 =over 15
313 =item Z<> B<Q(>I<string>B<)>
315 shell quote a string
317 =item Z<> B<pQ(>I<string>B<)>
319 perl quote a string
321 =item Z<> B<uq()> (or B<uq>)
323 do not quote current replacement string
325 =item Z<> B<total_jobs()>
327 number of jobs in total
329 =item Z<> B<slot()>
331 slot number of job
333 =item Z<> B<seq()>
335 sequence number of job
337 =item Z<> B<@arg>
339 the arguments
341 =back
343 Example:
345 seq 10 | parallel echo {} + 1 is {= '$_++' =}
346 parallel csh -c {= '$_="mkdir ".Q($_)' =} ::: '12" dir'
347 seq 50 | parallel echo job {#} of {= '$_=total_jobs()' =}
349 See also: B<--rpl> B<--parens>
352 =item B<{=>I<n> I<perl expression>B<=}>
354 Positional equivalent to B<{=perl expression=}>. To understand
355 positional replacement strings see B<{>I<n>B<}>.
357 See also: B<{=perl expression=}> B<{>I<n>B<}>.
360 =item B<:::> I<arguments>
362 Use arguments from the command line as input source instead of stdin
363 (standard input). Unlike other options for GNU B<parallel> B<:::> is
364 placed after the I<command> and before the arguments.
366 The following are equivalent:
368 (echo file1; echo file2) | parallel gzip
369 parallel gzip ::: file1 file2
370 parallel gzip {} ::: file1 file2
371 parallel --arg-sep ,, gzip {} ,, file1 file2
372 parallel --arg-sep ,, gzip ,, file1 file2
373 parallel ::: "gzip file1" "gzip file2"
375 To avoid treating B<:::> as special use B<--arg-sep> to set the
376 argument separator to something else. See also B<--arg-sep>.
378 If multiple B<:::> are given, each group will be treated as an input
379 source, and all combinations of input sources will be
380 generated. E.g. ::: 1 2 ::: a b c will result in the combinations
381 (1,a) (1,b) (1,c) (2,a) (2,b) (2,c). This is useful for replacing
382 nested for-loops.
384 B<:::> and B<::::> can be mixed. So these are equivalent:
386 parallel echo {1} {2} {3} ::: 6 7 ::: 4 5 ::: 1 2 3
387 parallel echo {1} {2} {3} :::: <(seq 6 7) <(seq 4 5) \
388 :::: <(seq 1 3)
389 parallel -a <(seq 6 7) echo {1} {2} {3} :::: <(seq 4 5) \
390 :::: <(seq 1 3)
391 parallel -a <(seq 6 7) -a <(seq 4 5) echo {1} {2} {3} \
392 ::: 1 2 3
393 seq 6 7 | parallel -a - -a <(seq 4 5) echo {1} {2} {3} \
394 ::: 1 2 3
395 seq 4 5 | parallel echo {1} {2} {3} :::: <(seq 6 7) - \
396 ::: 1 2 3
399 =item B<:::+> I<arguments>
401 Like B<:::> but linked like B<--link> to the previous input source.
403 Contrary to B<--link>, values do not wrap: The shortest input source
404 determines the length.
406 Example:
408 parallel echo ::: a b c :::+ 1 2 3 ::: X Y :::+ 11 22
411 =item B<::::> I<argfiles>
413 Another way to write B<-a> I<argfile1> B<-a> I<argfile2> ...
415 B<:::> and B<::::> can be mixed.
417 See B<-a>, B<:::> and B<--link>.
420 =item B<::::+> I<argfiles>
422 Like B<::::> but linked like B<--link> to the previous input source.
424 Contrary to B<--link>, values do not wrap: The shortest input source
425 determines the length.
428 =item B<--null>
430 =item B<-0>
432 Use NUL as delimiter. Normally input lines will end in \n
433 (newline). If they end in \0 (NUL), then use this option. It is useful
434 for processing arguments that may contain \n (newline).
437 =item B<--arg-file> I<input-file>
439 =item B<-a> I<input-file>
441 Use I<input-file> as input source. If you use this option, stdin
442 (standard input) is given to the first process run. Otherwise, stdin
443 (standard input) is redirected from /dev/null.
445 If multiple B<-a> are given, each I<input-file> will be treated as an
446 input source, and all combinations of input sources will be
447 generated. E.g. The file B<foo> contains B<1 2>, the file B<bar>
448 contains B<a b c>. B<-a foo> B<-a bar> will result in the combinations
449 (1,a) (1,b) (1,c) (2,a) (2,b) (2,c). This is useful for replacing
450 nested for-loops.
452 See also B<--link> and B<{>I<n>B<}>.
455 =item B<--arg-file-sep> I<sep-str>
457 Use I<sep-str> instead of B<::::> as separator string between command
458 and argument files. Useful if B<::::> is used for something else by the
459 command.
461 See also: B<::::>.
464 =item B<--arg-sep> I<sep-str>
466 Use I<sep-str> instead of B<:::> as separator string. Useful if B<:::>
467 is used for something else by the command.
469 Also useful if you command uses B<:::> but you still want to read
470 arguments from stdin (standard input): Simply change B<--arg-sep> to a
471 string that is not in the command line.
473 See also: B<:::>.
476 =item B<--bar>
478 Show progress as a progress bar. In the bar is shown: % of jobs
479 completed, estimated seconds left, and number of jobs started.
481 It is compatible with B<zenity>:
483 seq 1000 | parallel -j30 --bar '(echo {};sleep 0.1)' \
484 2> >(perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
485 zenity --progress --auto-kill) | wc
487 =item B<--basefile> I<file>
489 =item B<--bf> I<file>
491 I<file> will be transferred to each sshlogin before a job is
492 started. It will be removed if B<--cleanup> is active. The file may be
493 a script to run or some common base data needed for the job.
494 Multiple B<--bf> can be specified to transfer more basefiles. The
495 I<file> will be transferred the same way as B<--transferfile>.
498 =item B<--basenamereplace> I<replace-str>
500 =item B<--bnr> I<replace-str>
502 Use the replacement string I<replace-str> instead of B<{/}> for
503 basename of input line.
506 =item B<--basenameextensionreplace> I<replace-str>
508 =item B<--bner> I<replace-str>
510 Use the replacement string I<replace-str> instead of B<{/.}> for basename of input line without extension.
513 =item B<--bin> I<binexpr>
515 Use I<binexpr> as binning key and bin input to the jobs.
517 I<binexpr> is [column number|column name] [perlexpression] e.g. 3,
518 Address, 3 $_%=100, Address s/\D//g.
520 Each input line is split using B<--colsep>. The value of the column is
521 put into $_, the perl expression is executed, the resulting value is
522 is the job slot that will be given the line. If the value is bigger
523 than the number of jobslots the value will be modulo number of jobslots.
525 This is similar to B<--shard> but the hashing algorithm is a simple
526 modulo, which makes it predictible which jobslot will receive which
527 value.
529 The performance is in the order of 100K rows per second. Faster if the
530 I<bincol> is small (<10), slower if it is big (>100).
532 B<--bin> requires B<--pipe> and a fixed numeric value for B<--jobs>.
534 See also B<--shard>, B<--group-by>, B<--roundrobin>.
537 =item B<--bg>
539 Run command in background thus GNU B<parallel> will not wait for
540 completion of the command before exiting. This is the default if
541 B<--semaphore> is set.
543 See also: B<--fg>, B<man sem>.
545 Implies B<--semaphore>.
548 =item B<--bibtex>
550 =item B<--citation>
552 Print the citation notice and BibTeX entry for GNU B<parallel>,
553 silence citation notice for all future runs, and exit. It will not run
554 any commands.
556 If it is impossible for you to run B<--citation> you can instead use
557 B<--will-cite>, which will run commands, but which will only silence
558 the citation notice for this single run.
560 If you use B<--will-cite> in scripts to be run by others you are
561 making it harder for others to see the citation notice. The
562 development of GNU B<parallel> is indirectly financed through
563 citations, so if your users do not know they should cite then you are
564 making it harder to finance development. However, if you pay 10000
565 EUR, you have done your part to finance future development and should
566 feel free to use B<--will-cite> in scripts.
568 If you do not want to help financing future development by letting
569 other users see the citation notice or by paying, then please use
570 another tool instead of GNU B<parallel>. You can find some of the
571 alternatives in B<man parallel_alternatives>.
574 =item B<--block> I<size>
576 =item B<--block-size> I<size>
578 Size of block in bytes to read at a time. The I<size> can be postfixed
579 with K, M, G, T, P, E, k, m, g, t, p, or e which would multiply the
580 size with 1024, 1048576, 1073741824, 1099511627776, 1125899906842624,
581 1152921504606846976, 1000, 1000000, 1000000000, 1000000000000,
582 1000000000000000, or 1000000000000000000 respectively.
584 GNU B<parallel> tries to meet the block size but can be off by the
585 length of one record. For performance reasons I<size> should be bigger
586 than a two records. GNU B<parallel> will warn you and automatically
587 increase the size if you choose a I<size> that is too small.
589 If you use B<-N>, B<--block-size> should be bigger than N+1 records.
591 I<size> defaults to 1M.
593 When using B<--pipepart> a negative block size is not interpreted as a
594 blocksize but as the number of blocks each jobslot should have. So
595 this will run 10*5 = 50 jobs in total:
597 parallel --pipepart -a myfile --block -10 -j5 wc
599 This is an efficient alternative to B<--roundrobin> because data is
600 never read by GNU B<parallel>, but you can still have very few
601 jobslots process a large amount of data.
603 See B<--pipe> and B<--pipepart> for use of this.
606 =item B<--blocktimeout> I<duration>
608 =item B<--bt> I<duration>
610 Time out for reading block when using B<--pipe>. If it takes longer
611 than I<duration> to read a full block, use the partial block read so
612 far.
614 I<duration> must be in whole seconds, but can be expressed as floats
615 postfixed with B<s>, B<m>, B<h>, or B<d> which would multiply the
616 float by 1, 60, 3600, or 86400. Thus these are equivalent:
617 B<--blocktimeout 100000> and B<--blocktimeout 1d3.5h16.6m4s>.
621 =item B<--cat>
623 Create a temporary file with content. Normally B<--pipe>/B<--pipepart>
624 will give data to the program on stdin (standard input). With B<--cat>
625 GNU B<parallel> will create a temporary file with the name in B<{}>, so
626 you can do: B<parallel --pipe --cat wc {}>.
628 Implies B<--pipe> unless B<--pipepart> is used.
630 See also B<--fifo>.
633 =item B<--cleanup>
635 Remove transferred files. B<--cleanup> will remove the transferred
636 files on the remote computer after processing is done.
638 find log -name '*gz' | parallel \
639 --sshlogin server.example.com --transferfile {} \
640 --return {.}.bz2 --cleanup "zcat {} | bzip -9 >{.}.bz2"
642 With B<--transferfile {}> the file transferred to the remote computer
643 will be removed on the remote computer. Directories created will not
644 be removed - even if they are empty.
646 With B<--return> the file transferred from the remote computer will be
647 removed on the remote computer. Directories created will not be
648 removed - even if they are empty.
650 B<--cleanup> is ignored when not used with B<--transferfile> or
651 B<--return>.
654 =item B<--colsep> I<regexp>
656 =item B<-C> I<regexp>
658 Column separator. The input will be treated as a table with I<regexp>
659 separating the columns. The n'th column can be accessed using
660 B<{>I<n>B<}> or B<{>I<n>.B<}>. E.g. B<{3}> is the 3rd column.
662 If there are more input sources, each input source will be separated,
663 but the columns from each input source will be linked (see B<--link>).
665 parallel --colsep '-' echo {4} {3} {2} {1} \
666 ::: A-B C-D ::: e-f g-h
668 B<--colsep> implies B<--trim rl>, which can be overridden with
669 B<--trim n>.
671 I<regexp> is a Perl Regular Expression:
672 http://perldoc.perl.org/perlre.html
675 =item B<--compress>
677 Compress temporary files. If the output is big and very compressible
678 this will take up less disk space in $TMPDIR and possibly be faster
679 due to less disk I/O.
681 GNU B<parallel> will try B<pzstd>, B<lbzip2>, B<pbzip2>, B<zstd>,
682 B<pigz>, B<lz4>, B<lzop>, B<plzip>, B<lzip>, B<lrz>, B<gzip>, B<pxz>,
683 B<lzma>, B<bzip2>, B<xz>, B<clzip>, in that order, and use the first
684 available.
687 =item B<--compress-program> I<prg>
689 =item B<--decompress-program> I<prg>
691 Use I<prg> for (de)compressing temporary files. It is assumed that I<prg
692 -dc> will decompress stdin (standard input) to stdout (standard
693 output) unless B<--decompress-program> is given.
696 =item B<--csv>
698 Treat input as CSV-format. B<--colsep> sets the field delimiter. It
699 works very much like B<--colsep> except it deals correctly with
700 quoting:
702 echo '"1 big, 2 small","2""x4"" plank",12.34' |
703 parallel --csv echo {1} of {2} at {3}
705 Even quoted newlines are parsed correctly:
707 (echo '"Start of field 1 with newline'
708 echo 'Line 2 in field 1";value 2') |
709 parallel --csv --colsep ';' echo Field 1: {1} Field 2: {2}
711 When used with B<--pipe> only pass full CSV-records.
714 =item B<--delay> I<mytime>
716 Delay starting next job by I<mytime>. GNU B<parallel> will pause
717 I<mytime> after starting each job. I<mytime> is normally in seconds,
718 but can be floats postfixed with B<s>, B<m>, B<h>, or B<d> which would
719 multiply the float by 1, 60, 3600, or 86400. Thus these are
720 equivalent: B<--delay 100000> and B<--delay 1d3.5h16.6m4s>.
723 =item B<--delimiter> I<delim>
725 =item B<-d> I<delim>
727 Input items are terminated by I<delim>. Quotes and backslash are not
728 special; every character in the input is taken literally. Disables
729 the end-of-file string, which is treated like any other argument. The
730 specified delimiter may be characters, C-style character escapes such
731 as \n, or octal or hexadecimal escape codes. Octal and hexadecimal
732 escape codes are understood as for the printf command. Multibyte
733 characters are not supported.
736 =item B<--dirnamereplace> I<replace-str>
738 =item B<--dnr> I<replace-str>
740 Use the replacement string I<replace-str> instead of B<{//}> for
741 dirname of input line.
744 =item B<--dry-run>
746 Print the job to run on stdout (standard output), but do not run the
747 job. Use B<-v -v> to include the wrapping that GNU B<parallel>
748 generates (for remote jobs, B<--tmux>, B<--nice>, B<--pipe>,
749 B<--pipepart>, B<--fifo> and B<--cat>). Do not count on this
750 literally, though, as the job may be scheduled on another computer or
751 the local computer if : is in the list.
754 =item B<-E> I<eof-str>
756 Set the end of file string to I<eof-str>. If the end of file string
757 occurs as a line of input, the rest of the input is not read. If
758 neither B<-E> nor B<-e> is used, no end of file string is used.
761 =item B<--eof>[=I<eof-str>]
763 =item B<-e>[I<eof-str>]
765 This option is a synonym for the B<-E> option. Use B<-E> instead,
766 because it is POSIX compliant for B<xargs> while this option is not.
767 If I<eof-str> is omitted, there is no end of file string. If neither
768 B<-E> nor B<-e> is used, no end of file string is used.
771 =item B<--embed>
773 Embed GNU B<parallel> in a shell script. If you need to distribute your
774 script to someone who does not want to install GNU B<parallel> you can
775 embed GNU B<parallel> in your own shell script:
777 parallel --embed > new_script
779 After which you add your code at the end of B<new_script>. This is tested
780 on B<ash>, B<bash>, B<dash>, B<ksh>, B<sh>, and B<zsh>.
783 =item B<--env> I<var>
785 Copy environment variable I<var>. This will copy I<var> to the
786 environment that the command is run in. This is especially useful for
787 remote execution.
789 In Bash I<var> can also be a Bash function - just remember to B<export
790 -f> the function, see B<command>.
792 The variable '_' is special. It will copy all exported environment
793 variables except for the ones mentioned in ~/.parallel/ignored_vars.
795 To copy the full environment (both exported and not exported
796 variables, arrays, and functions) use B<env_parallel>.
798 See also: B<--record-env>, B<--session>.
801 =item B<--eta>
803 Show the estimated number of seconds before finishing. This forces GNU
804 B<parallel> to read all jobs before starting to find the number of
805 jobs. GNU B<parallel> normally only reads the next job to run.
807 The estimate is based on the runtime of finished jobs, so the first
808 estimate will only be shown when the first job has finished.
810 Implies B<--progress>.
812 See also: B<--bar>, B<--progress>.
815 =item B<--fg>
817 Run command in foreground.
819 With B<--tmux> and B<--tmuxpane> GNU B<parallel> will start B<tmux> in
820 the foreground.
822 With B<--semaphore> GNU B<parallel> will run the command in the
823 foreground (opposite B<--bg>), and wait for completion of the command
824 before exiting.
827 See also B<--bg>, B<man sem>.
830 =item B<--fifo>
832 Create a temporary fifo with content. Normally B<--pipe> and
833 B<--pipepart> will give data to the program on stdin (standard
834 input). With B<--fifo> GNU B<parallel> will create a temporary fifo
835 with the name in B<{}>, so you can do: B<parallel --pipe --fifo wc {}>.
837 Beware: If data is not read from the fifo, the job will block forever.
839 Implies B<--pipe> unless B<--pipepart> is used.
841 See also B<--cat>.
844 =item B<--filter-hosts>
846 Remove down hosts. For each remote host: check that login through ssh
847 works. If not: do not use this host.
849 For performance reasons, this check is performed only at the start and
850 every time B<--sshloginfile> is changed. If an host goes down after
851 the first check, it will go undetected until B<--sshloginfile> is
852 changed; B<--retries> can be used to mitigate this.
854 Currently you can I<not> put B<--filter-hosts> in a profile,
855 $PARALLEL, /etc/parallel/config or similar. This is because GNU
856 B<parallel> uses GNU B<parallel> to compute this, so you will get an
857 infinite loop. This will likely be fixed in a later release.
860 =item B<--gnu>
862 Behave like GNU B<parallel>. This option historically took precedence
863 over B<--tollef>. The B<--tollef> option is now retired, and therefore
864 may not be used. B<--gnu> is kept for compatibility.
867 =item B<--group>
869 Group output. Output from each job is grouped together and is only
870 printed when the command is finished. Stdout (standard output) first
871 followed by stderr (standard error).
873 This takes in the order of 0.5ms per job and depends on the speed of
874 your disk for larger output. It can be disabled with B<-u>, but this
875 means output from different commands can get mixed.
877 B<--group> is the default. Can be reversed with B<-u>.
879 See also: B<--line-buffer> B<--ungroup>
882 =item B<--group-by> I<val> (beta testing)
884 Group input by value. Combined with B<--pipe>/B<--pipepart>
885 B<--group-by> groups lines with the same value into a record.
887 The value can be computed from the full line or from a single column.
889 I<val> can be:
891 =over 15
893 =item Z<> column number
895 Use the value in the column numbered.
897 =item Z<> column name
899 Treat the first line as a header and use the value in the column
900 named.
902 (Not supported with B<--pipepart>).
904 =item Z<> perl expression
906 Run the perl expression and use $_ as the value.
908 =item Z<> column number perl expression
910 Put the value of the column put in $_, run the perl expression, and use $_ as the value.
912 =item Z<> column name perl expression
914 Put the value of the column put in $_, run the perl expression, and use $_ as the value.
916 (Not supported with B<--pipepart>).
918 =back
920 Example:
922 UserID, Consumption
923 123, 1
924 123, 2
925 12-3, 1
926 221, 3
927 221, 1
928 2/21, 5
930 If you want to group 123, 12-3, 221, and 2/21 into 4 records and pass
931 one record at a time to B<wc>:
933 tail -n +2 table.csv | \
934 parallel --pipe --colsep , --group-by 1 -kN1 wc
936 Make GNU B<parallel> treat the first line as a header:
938 cat table.csv | \
939 parallel --pipe --colsep , --header : --group-by 1 -kN1 wc
941 Address column by column name:
943 cat table.csv | \
944 parallel --pipe --colsep , --header : --group-by UserID -kN1 wc
946 If 12-3 and 123 are really the same UserID, remove non-digits in
947 UserID when grouping:
949 cat table.csv | parallel --pipe --colsep , --header : \
950 --group-by 'UserID s/\D//g' -kN1 wc
952 See also B<--shard>, B<--roundrobin>.
955 =item B<--help>
957 =item B<-h>
959 Print a summary of the options to GNU B<parallel> and exit.
962 =item B<--halt-on-error> I<val>
964 =item B<--halt> I<val>
966 When should GNU B<parallel> terminate? In some situations it makes no
967 sense to run all jobs. GNU B<parallel> should simply give up as soon
968 as a condition is met.
970 I<val> defaults to B<never>, which runs all jobs no matter what.
972 I<val> can also take on the form of I<when>,I<why>.
974 I<when> can be 'now' which means kill all running jobs and halt
975 immediately, or it can be 'soon' which means wait for all running jobs
976 to complete, but start no new jobs.
978 I<why> can be 'fail=X', 'fail=Y%', 'success=X', 'success=Y%',
979 'done=X', or 'done=Y%' where X is the number of jobs that has to fail,
980 succeed, or be done before halting, and Y is the percentage of jobs
981 that has to fail, succeed, or be done before halting.
983 Example:
985 =over 23
987 =item Z<> --halt now,fail=1
989 exit when the first job fails. Kill running jobs.
991 =item Z<> --halt soon,fail=3
993 exit when 3 jobs fail, but wait for running jobs to complete.
995 =item Z<> --halt soon,fail=3%
997 exit when 3% of the jobs have failed, but wait for running jobs to complete.
999 =item Z<> --halt now,success=1
1001 exit when a job succeeds. Kill running jobs.
1003 =item Z<> --halt soon,success=3
1005 exit when 3 jobs succeeds, but wait for running jobs to complete.
1007 =item Z<> --halt now,success=3%
1009 exit when 3% of the jobs have succeeded. Kill running jobs.
1011 =item Z<> --halt now,done=1
1013 exit when one of the jobs finishes. Kill running jobs.
1015 =item Z<> --halt soon,done=3
1017 exit when 3 jobs finishes, but wait for running jobs to complete.
1019 =item Z<> --halt now,done=3%
1021 exit when 3% of the jobs have finished. Kill running jobs.
1023 =back
1025 For backwards compatibility these also work:
1027 =over 12
1029 =item Z<>0
1031 never
1033 =item Z<>1
1035 soon,fail=1
1037 =item Z<>2
1039 now,fail=1
1041 =item Z<>-1
1043 soon,success=1
1045 =item Z<>-2
1047 now,success=1
1049 =item Z<>1-99%
1051 soon,fail=1-99%
1053 =back
1056 =item B<--header> I<regexp>
1058 Use regexp as header. For normal usage the matched header (typically
1059 the first line: B<--header '.*\n'>) will be split using B<--colsep>
1060 (which will default to '\t') and column names can be used as
1061 replacement variables: B<{column name}>, B<{column name/}>, B<{column
1062 name//}>, B<{column name/.}>, B<{column name.}>, B<{=column name perl
1063 expression =}>, ..
1065 For B<--pipe> the matched header will be prepended to each output.
1067 B<--header :> is an alias for B<--header '.*\n'>.
1069 If I<regexp> is a number, it is a fixed number of lines.
1072 =item B<--hostgroups>
1074 =item B<--hgrp>
1076 Enable hostgroups on arguments. If an argument contains '@' the string
1077 after '@' will be removed and treated as a list of hostgroups on which
1078 this job is allowed to run. If there is no B<--sshlogin> with a
1079 corresponding group, the job will run on any hostgroup.
1081 Example:
1083 parallel --hostgroups \
1084 --sshlogin @grp1/myserver1 -S @grp1+grp2/myserver2 \
1085 --sshlogin @grp3/myserver3 \
1086 echo ::: my_grp1_arg@grp1 arg_for_grp2@grp2 third@grp1+grp3
1088 B<my_grp1_arg> may be run on either B<myserver1> or B<myserver2>,
1089 B<third> may be run on either B<myserver1> or B<myserver3>,
1090 but B<arg_for_grp2> will only be run on B<myserver2>.
1092 See also: B<--sshlogin>.
1095 =item B<-I> I<replace-str>
1097 Use the replacement string I<replace-str> instead of B<{}>.
1100 =item B<--replace>[=I<replace-str>]
1102 =item B<-i>[I<replace-str>]
1104 This option is a synonym for B<-I>I<replace-str> if I<replace-str> is
1105 specified, and for B<-I {}> otherwise. This option is deprecated;
1106 use B<-I> instead.
1109 =item B<--joblog> I<logfile>
1111 Logfile for executed jobs. Save a list of the executed jobs to
1112 I<logfile> in the following TAB separated format: sequence number,
1113 sshlogin, start time as seconds since epoch, run time in seconds,
1114 bytes in files transferred, bytes in files returned, exit status,
1115 signal, and command run.
1117 For B<--pipe> bytes transferred and bytes returned are number of input
1118 and output of bytes.
1120 If B<logfile> is prepended with '+' log lines will be appended to the
1121 logfile.
1123 To convert the times into ISO-8601 strict do:
1125 cat logfile | perl -a -F"\t" -ne \
1126 'chomp($F[2]=`date -d \@$F[2] +%FT%T`); print join("\t",@F)'
1128 If the host is long, you can use B<column -t> to pretty print it:
1130 cat joblog | column -t
1132 See also B<--resume> B<--resume-failed>.
1135 =item B<--jobs> I<N>
1137 =item B<-j> I<N>
1139 =item B<--max-procs> I<N>
1141 =item B<-P> I<N>
1143 Number of jobslots on each machine. Run up to N jobs in parallel. 0
1144 means as many as possible. Default is 100% which will run one job per
1145 CPU on each machine.
1147 If B<--semaphore> is set, the default is 1 thus making a mutex.
1150 =item B<--jobs> I<+N>
1152 =item B<-j> I<+N>
1154 =item B<--max-procs> I<+N>
1156 =item B<-P> I<+N>
1158 Add N to the number of CPUs. Run this many jobs in parallel. See
1159 also B<--use-cores-instead-of-threads> and
1160 B<--use-sockets-instead-of-threads>.
1163 =item B<--jobs> I<-N>
1165 =item B<-j> I<-N>
1167 =item B<--max-procs> I<-N>
1169 =item B<-P> I<-N>
1171 Subtract N from the number of CPUs. Run this many jobs in parallel.
1172 If the evaluated number is less than 1 then 1 will be used. See also
1173 B<--use-cores-instead-of-threads> and
1174 B<--use-sockets-instead-of-threads>.
1177 =item B<--jobs> I<N>%
1179 =item B<-j> I<N>%
1181 =item B<--max-procs> I<N>%
1183 =item B<-P> I<N>%
1185 Multiply N% with the number of CPUs. Run this many jobs in
1186 parallel. See also B<--use-cores-instead-of-threads> and
1187 B<--use-sockets-instead-of-threads>.
1190 =item B<--jobs> I<procfile>
1192 =item B<-j> I<procfile>
1194 =item B<--max-procs> I<procfile>
1196 =item B<-P> I<procfile>
1198 Read parameter from file. Use the content of I<procfile> as parameter
1199 for I<-j>. E.g. I<procfile> could contain the string 100% or +2 or
1200 10. If I<procfile> is changed when a job completes, I<procfile> is
1201 read again and the new number of jobs is computed. If the number is
1202 lower than before, running jobs will be allowed to finish but new jobs
1203 will not be started until the wanted number of jobs has been reached.
1204 This makes it possible to change the number of simultaneous running
1205 jobs while GNU B<parallel> is running.
1208 =item B<--keep-order>
1210 =item B<-k>
1212 Keep sequence of output same as the order of input. Normally the
1213 output of a job will be printed as soon as the job completes. Try this
1214 to see the difference:
1216 parallel -j4 sleep {}\; echo {} ::: 2 1 4 3
1217 parallel -j4 -k sleep {}\; echo {} ::: 2 1 4 3
1219 If used with B<--onall> or B<--nonall> the output will grouped by
1220 sshlogin in sorted order.
1222 If used with B<--pipe --roundrobin> and the same input, the jobslots
1223 will get the same blocks in the same order in every run.
1225 B<-k> only affects the order in which the output is printed - not the
1226 order in which jobs are run.
1229 =item B<-L> I<recsize>
1231 When used with B<--pipe>: Read records of I<recsize>.
1233 When used otherwise: Use at most I<recsize> nonblank input lines per
1234 command line. Trailing blanks cause an input line to be logically
1235 continued on the next input line.
1237 B<-L 0> means read one line, but insert 0 arguments on the command
1238 line.
1240 Implies B<-X> unless B<-m>, B<--xargs>, or B<--pipe> is set.
1243 =item B<--max-lines>[=I<recsize>]
1245 =item B<-l>[I<recsize>]
1247 When used with B<--pipe>: Read records of I<recsize> lines.
1249 When used otherwise: Synonym for the B<-L> option. Unlike B<-L>, the
1250 I<recsize> argument is optional. If I<recsize> is not specified,
1251 it defaults to one. The B<-l> option is deprecated since the POSIX
1252 standard specifies B<-L> instead.
1254 B<-l 0> is an alias for B<-l 1>.
1256 Implies B<-X> unless B<-m>, B<--xargs>, or B<--pipe> is set.
1259 =item B<--limit> "I<command> I<args>"
1261 Dynamic job limit. Before starting a new job run I<command> with
1262 I<args>. The exit value of I<command> determines what GNU B<parallel>
1263 will do:
1265 =over 4
1267 =item Z<>0
1269 Below limit. Start another job.
1271 =item Z<>1
1273 Over limit. Start no jobs.
1275 =item Z<>2
1277 Way over limit. Kill the youngest job.
1279 =back
1281 You can use any shell command. There are 3 predefined commands:
1283 =over 10
1285 =item "io I<n>"
1287 Limit for I/O. The amount of disk I/O will be computed as a value
1288 0-100, where 0 is no I/O and 100 is at least one disk is 100%
1289 saturated.
1291 =item "load I<n>"
1293 Similar to B<--load>.
1295 =item "mem I<n>"
1297 Similar to B<--memfree>.
1299 =back
1302 =item B<--line-buffer>
1304 =item B<--lb>
1306 Buffer output on line basis. B<--group> will keep the output together
1307 for a whole job. B<--ungroup> allows output to mixup with half a line
1308 coming from one job and half a line coming from another
1309 job. B<--line-buffer> fits between these two: GNU B<parallel> will
1310 print a full line, but will allow for mixing lines of different jobs.
1312 B<--line-buffer> takes more CPU power than both B<--group> and
1313 B<--ungroup>, but can be much faster than B<--group> if the CPU is not
1314 the limiting factor.
1316 Normally B<--line-buffer> does not buffer on disk, and can thus
1317 process an infinite amount of data, but it will buffer on disk when
1318 combined with: B<--keep-order>, B<--results>, B<--compress>, and
1319 B<--files>. This will make it as slow as B<--group> and will limit
1320 output to the available disk space.
1322 With B<--keep-order> B<--line-buffer> will output lines from the first
1323 job continuously while it is running, then lines from the second job
1324 while that is running. It will buffer full lines, but jobs will not
1325 mix. Compare:
1327 parallel -j0 'echo {};sleep {};echo {}' ::: 1 3 2 4
1328 parallel -j0 --lb 'echo {};sleep {};echo {}' ::: 1 3 2 4
1329 parallel -j0 -k --lb 'echo {};sleep {};echo {}' ::: 1 3 2 4
1331 See also: B<--group> B<--ungroup>
1334 =item B<--xapply>
1336 =item B<--link>
1338 Link input sources. Read multiple input sources like B<xapply>. If
1339 multiple input sources are given, one argument will be read from each
1340 of the input sources. The arguments can be accessed in the command as
1341 B<{1}> .. B<{>I<n>B<}>, so B<{1}> will be a line from the first input
1342 source, and B<{6}> will refer to the line with the same line number
1343 from the 6th input source.
1345 Compare these two:
1347 parallel echo {1} {2} ::: 1 2 3 ::: a b c
1348 parallel --link echo {1} {2} ::: 1 2 3 ::: a b c
1350 Arguments will be recycled if one input source has more arguments than the others:
1352 parallel --link echo {1} {2} {3} \
1353 ::: 1 2 ::: I II III ::: a b c d e f g
1355 See also B<--header>, B<:::+>, B<::::+>.
1358 =item B<--load> I<max-load>
1360 Do not start new jobs on a given computer unless the number of running
1361 processes on the computer is less than I<max-load>. I<max-load> uses
1362 the same syntax as B<--jobs>, so I<100%> for one per CPU is a valid
1363 setting. Only difference is 0 which is interpreted as 0.01.
1366 =item B<--controlmaster>
1368 =item B<-M>
1370 Use ssh's ControlMaster to make ssh connections faster. Useful if jobs
1371 run remote and are very fast to run. This is disabled for sshlogins
1372 that specify their own ssh command.
1375 =item B<-m>
1377 Multiple arguments. Insert as many arguments as the command line
1378 length permits. If multiple jobs are being run in parallel: distribute
1379 the arguments evenly among the jobs. Use B<-j1> or B<--xargs> to avoid this.
1381 If B<{}> is not used the arguments will be appended to the
1382 line. If B<{}> is used multiple times each B<{}> will be replaced
1383 with all the arguments.
1385 Support for B<-m> with B<--sshlogin> is limited and may fail.
1387 See also B<-X> for context replace. If in doubt use B<-X> as that will
1388 most likely do what is needed.
1391 =item B<--memfree> I<size>
1393 Minimum memory free when starting another job. The I<size> can be
1394 postfixed with K, M, G, T, P, k, m, g, t, or p which would multiply
1395 the size with 1024, 1048576, 1073741824, 1099511627776,
1396 1125899906842624, 1000, 1000000, 1000000000, 1000000000000, or
1397 1000000000000000, respectively.
1399 If the jobs take up very different amount of RAM, GNU B<parallel> will
1400 only start as many as there is memory for. If less than I<size> bytes
1401 are free, no more jobs will be started. If less than 50% I<size> bytes
1402 are free, the youngest job will be killed, and put back on the queue
1403 to be run later.
1405 B<--retries> must be set to determine how many times GNU B<parallel>
1406 should retry a given job.
1409 =item B<--minversion> I<version>
1411 Print the version GNU B<parallel> and exit. If the current version of
1412 GNU B<parallel> is less than I<version> the exit code is
1413 255. Otherwise it is 0.
1415 This is useful for scripts that depend on features only available from
1416 a certain version of GNU B<parallel>.
1419 =item B<--max-args>=I<max-args>
1421 =item B<-n> I<max-args>
1423 Use at most I<max-args> arguments per command line. Fewer than
1424 I<max-args> arguments will be used if the size (see the B<-s> option)
1425 is exceeded, unless the B<-x> option is given, in which case
1426 GNU B<parallel> will exit.
1428 B<-n 0> means read one argument, but insert 0 arguments on the command
1429 line.
1431 Implies B<-X> unless B<-m> is set.
1434 =item B<--max-replace-args>=I<max-args>
1436 =item B<-N> I<max-args>
1438 Use at most I<max-args> arguments per command line. Like B<-n> but
1439 also makes replacement strings B<{1}> .. B<{>I<max-args>B<}> that
1440 represents argument 1 .. I<max-args>. If too few args the B<{>I<n>B<}> will
1441 be empty.
1443 B<-N 0> means read one argument, but insert 0 arguments on the command
1444 line.
1446 This will set the owner of the homedir to the user:
1448 tr ':' '\n' < /etc/passwd | parallel -N7 chown {1} {6}
1450 Implies B<-X> unless B<-m> or B<--pipe> is set.
1452 When used with B<--pipe> B<-N> is the number of records to read. This
1453 is somewhat slower than B<--block>.
1456 =item B<--nonall>
1458 B<--onall> with no arguments. Run the command on all computers given
1459 with B<--sshlogin> but take no arguments. GNU B<parallel> will log
1460 into B<--jobs> number of computers in parallel and run the job on the
1461 computer. B<-j> adjusts how many computers to log into in parallel.
1463 This is useful for running the same command (e.g. uptime) on a list of
1464 servers.
1467 =item B<--onall>
1469 Run all the jobs on all computers given with B<--sshlogin>. GNU
1470 B<parallel> will log into B<--jobs> number of computers in parallel
1471 and run one job at a time on the computer. The order of the jobs will
1472 not be changed, but some computers may finish before others.
1474 When using B<--group> the output will be grouped by each server, so
1475 all the output from one server will be grouped together.
1477 B<--joblog> will contain an entry for each job on each server, so
1478 there will be several job sequence 1.
1481 =item B<--output-as-files>
1483 =item B<--outputasfiles>
1485 =item B<--files>
1487 Instead of printing the output to stdout (standard output) the output
1488 of each job is saved in a file and the filename is then printed.
1490 See also: B<--results>
1493 =item B<--pipe>
1495 =item B<--spreadstdin>
1497 Spread input to jobs on stdin (standard input). Read a block of data
1498 from stdin (standard input) and give one block of data as input to one
1499 job.
1501 The block size is determined by B<--block>. The strings B<--recstart>
1502 and B<--recend> tell GNU B<parallel> how a record starts and/or
1503 ends. The block read will have the final partial record removed before
1504 the block is passed on to the job. The partial record will be
1505 prepended to next block.
1507 If B<--recstart> is given this will be used to split at record start.
1509 If B<--recend> is given this will be used to split at record end.
1511 If both B<--recstart> and B<--recend> are given both will have to
1512 match to find a split position.
1514 If neither B<--recstart> nor B<--recend> are given B<--recend>
1515 defaults to '\n'. To have no record separator use B<--recend "">.
1517 B<--files> is often used with B<--pipe>.
1519 B<--pipe> maxes out at around 1 GB/s input, and 100 MB/s output. If
1520 performance is important use B<--pipepart>.
1522 See also: B<--recstart>, B<--recend>, B<--fifo>, B<--cat>,
1523 B<--pipepart>, B<--files>.
1526 =item B<--pipepart>
1528 Pipe parts of a physical file. B<--pipepart> works similar to
1529 B<--pipe>, but is much faster.
1531 B<--pipepart> has a few limitations:
1533 =over 3
1535 =item *
1537 The file must be a normal file or a block device (technically it must
1538 be seekable) and must be given using B<-a> or B<::::>. The file cannot
1539 be a pipe or a fifo as they are not seekable.
1541 If using a block device with lot of NUL bytes, remember to set
1542 B<--recend ''>.
1544 =item *
1546 Record counting (B<-N>) and line counting (B<-L>/B<-l>) do not work.
1548 =back
1551 =item B<--plain>
1553 Ignore any B<--profile>, $PARALLEL, and ~/.parallel/config to get full
1554 control on the command line (used by GNU B<parallel> internally when
1555 called with B<--sshlogin>).
1558 =item B<--plus>
1560 Activate additional replacement strings: {+/} {+.} {+..} {+...} {..}
1561 {...} {/..} {/...} {##}. The idea being that '{+foo}' matches the opposite of
1562 '{foo}' and {} = {+/}/{/} = {.}.{+.} = {+/}/{/.}.{+.} = {..}.{+..} =
1563 {+/}/{/..}.{+..} = {...}.{+...} = {+/}/{/...}.{+...}
1565 B<{##}> is the total number of jobs to be run. It is incompatible with
1566 B<-X>/B<-m>/B<--xargs>.
1568 B<{choose_k}> is inspired by n choose k: Given a list of n elements,
1569 choose k. k is the number of input sources and n is the number of
1570 arguments in an input source. The content of the input sources must
1571 be the same and the arguments must be unique.
1573 Shorthands for variables:
1575 {slot} $PARALLEL_JOBSLOT (see {%})
1576 {sshlogin} $PARALLEL_SSHLOGIN
1577 {host} $PARALLEL_SSHHOST
1579 The following dynamic replacement strings are also activated. They are
1580 inspired by bash's parameter expansion:
1582 {:-str} str if the value is empty
1583 {:num} remove the first num characters
1584 {:num1:num2} characters from num1 to num2
1585 {#str} remove prefix str
1586 {%str} remove postfix str
1587 {/str1/str2} replace str1 with str2
1588 {^str} uppercase str if found at the start
1589 {^^str} uppercase str
1590 {,str} lowercase str if found at the start
1591 {,,str} lowercase str
1594 =item B<--progress>
1596 Show progress of computations. List the computers involved in the task
1597 with number of CPUs detected and the max number of jobs to run. After
1598 that show progress for each computer: number of running jobs, number
1599 of completed jobs, and percentage of all jobs done by this
1600 computer. The percentage will only be available after all jobs have
1601 been scheduled as GNU B<parallel> only read the next job when ready to
1602 schedule it - this is to avoid wasting time and memory by reading
1603 everything at startup.
1605 By sending GNU B<parallel> SIGUSR2 you can toggle turning on/off
1606 B<--progress> on a running GNU B<parallel> process.
1608 See also B<--eta> and B<--bar>.
1611 =item B<--max-line-length-allowed>
1613 Print the maximal number of characters allowed on the command line and
1614 exit (used by GNU B<parallel> itself to determine the line length
1615 on remote computers).
1618 =item B<--number-of-cpus> (obsolete)
1620 Print the number of physical CPU cores and exit.
1623 =item B<--number-of-cores>
1625 Print the number of physical CPU cores and exit (used by GNU B<parallel> itself
1626 to determine the number of physical CPU cores on remote computers).
1629 =item B<--number-of-sockets>
1631 Print the number of filled CPU sockets and exit (used by GNU
1632 B<parallel> itself to determine the number of filled CPU sockets on
1633 remote computers).
1636 =item B<--number-of-threads>
1638 Print the number of hyperthreaded CPU cores and exit (used by GNU
1639 B<parallel> itself to determine the number of hyperthreaded CPU cores
1640 on remote computers).
1643 =item B<--no-keep-order>
1645 Overrides an earlier B<--keep-order> (e.g. if set in
1646 B<~/.parallel/config>).
1649 =item B<--nice> I<niceness>
1651 Run the command at this niceness.
1653 By default GNU B<parallel> will run jobs at the same nice level as GNU
1654 B<parallel> is started - both on the local machine and remote servers,
1655 so you are unlikely to ever use this option.
1657 Setting B<--nice> will override this nice level. If the nice level is
1658 smaller than the current nice level, it will only affect remote jobs
1659 (e.g. if current level is 10 then B<--nice 5> will cause local jobs to
1660 be run at level 10, but remote jobs run at nice level 5).
1663 =item B<--interactive>
1665 =item B<-p>
1667 Prompt the user about whether to run each command line and read a line
1668 from the terminal. Only run the command line if the response starts
1669 with 'y' or 'Y'. Implies B<-t>.
1672 =item B<--parens> I<parensstring>
1674 Define start and end parenthesis for B<{= perl expression =}>. The
1675 left and the right parenthesis can be multiple characters and are
1676 assumed to be the same length. The default is B<{==}> giving B<{=> as
1677 the start parenthesis and B<=}> as the end parenthesis.
1679 Another useful setting is B<,,,,> which would make both parenthesis
1680 B<,,>:
1682 parallel --parens ,,,, echo foo is ,,s/I/O/g,, ::: FII
1684 See also: B<--rpl> B<{= perl expression =}>
1687 =item B<--profile> I<profilename>
1689 =item B<-J> I<profilename>
1691 Use profile I<profilename> for options. This is useful if you want to
1692 have multiple profiles. You could have one profile for running jobs in
1693 parallel on the local computer and a different profile for running jobs
1694 on remote computers. See the section PROFILE FILES for examples.
1696 I<profilename> corresponds to the file ~/.parallel/I<profilename>.
1698 You can give multiple profiles by repeating B<--profile>. If parts of
1699 the profiles conflict, the later ones will be used.
1701 Default: config
1704 =item B<--quote>
1706 =item B<-q>
1708 Quote I<command>. If your command contains special characters that
1709 should not be interpreted by the shell (e.g. ; \ | *), use B<--quote> to
1710 escape these. The command must be a simple command (see B<man
1711 bash>) without redirections and without variable assignments.
1713 See the section QUOTING. Most people will not need this. Quoting is
1714 disabled by default.
1717 =item B<--no-run-if-empty>
1719 =item B<-r>
1721 If the stdin (standard input) only contains whitespace, do not run the command.
1723 If used with B<--pipe> this is slow.
1726 =item B<--noswap>
1728 Do not start new jobs on a given computer if there is both swap-in and
1729 swap-out activity.
1731 The swap activity is only sampled every 10 seconds as the sampling
1732 takes 1 second to do.
1734 Swap activity is computed as (swap-in)*(swap-out) which in practice is
1735 a good value: swapping out is not a problem, swapping in is not a
1736 problem, but both swapping in and out usually indicates a problem.
1738 B<--memfree> may give better results, so try using that first.
1741 =item B<--record-env>
1743 Record current environment variables in ~/.parallel/ignored_vars. This
1744 is useful before using B<--env _>.
1746 See also B<--env>, B<--session>.
1749 =item B<--recstart> I<startstring>
1751 =item B<--recend> I<endstring>
1753 If B<--recstart> is given I<startstring> will be used to split at record start.
1755 If B<--recend> is given I<endstring> will be used to split at record end.
1757 If both B<--recstart> and B<--recend> are given the combined string
1758 I<endstring>I<startstring> will have to match to find a split
1759 position. This is useful if either I<startstring> or I<endstring>
1760 match in the middle of a record.
1762 If neither B<--recstart> nor B<--recend> are given then B<--recend>
1763 defaults to '\n'. To have no record separator use B<--recend "">.
1765 B<--recstart> and B<--recend> are used with B<--pipe>.
1767 Use B<--regexp> to interpret B<--recstart> and B<--recend> as regular
1768 expressions. This is slow, however.
1771 =item B<--regexp>
1773 Use B<--regexp> to interpret B<--recstart> and B<--recend> as regular
1774 expressions. This is slow, however.
1777 =item B<--remove-rec-sep>
1779 =item B<--removerecsep>
1781 =item B<--rrs>
1783 Remove the text matched by B<--recstart> and B<--recend> before piping
1784 it to the command.
1786 Only used with B<--pipe>.
1789 =item B<--results> I<name>
1791 =item B<--res> I<name>
1793 Save the output into files.
1795 B<Simple string output dir>
1797 If I<name> does not contain replacement strings and does not end in
1798 B<.csv/.tsv>, the output will be stored in a directory tree rooted at
1799 I<name>. Within this directory tree, each command will result in
1800 three files: I<name>/<ARGS>/stdout and I<name>/<ARGS>/stderr,
1801 I<name>/<ARGS>/seq, where <ARGS> is a sequence of directories
1802 representing the header of the input source (if using B<--header :>)
1803 or the number of the input source and corresponding values.
1805 E.g:
1807 parallel --header : --results foo echo {a} {b} \
1808 ::: a I II ::: b III IIII
1810 will generate the files:
1812 foo/a/II/b/III/seq
1813 foo/a/II/b/III/stderr
1814 foo/a/II/b/III/stdout
1815 foo/a/II/b/IIII/seq
1816 foo/a/II/b/IIII/stderr
1817 foo/a/II/b/IIII/stdout
1818 foo/a/I/b/III/seq
1819 foo/a/I/b/III/stderr
1820 foo/a/I/b/III/stdout
1821 foo/a/I/b/IIII/seq
1822 foo/a/I/b/IIII/stderr
1823 foo/a/I/b/IIII/stdout
1827 parallel --results foo echo {1} {2} ::: I II ::: III IIII
1829 will generate the files:
1831 foo/1/II/2/III/seq
1832 foo/1/II/2/III/stderr
1833 foo/1/II/2/III/stdout
1834 foo/1/II/2/IIII/seq
1835 foo/1/II/2/IIII/stderr
1836 foo/1/II/2/IIII/stdout
1837 foo/1/I/2/III/seq
1838 foo/1/I/2/III/stderr
1839 foo/1/I/2/III/stdout
1840 foo/1/I/2/IIII/seq
1841 foo/1/I/2/IIII/stderr
1842 foo/1/I/2/IIII/stdout
1845 B<CSV file output>
1847 If I<name> ends in B<.csv>/B<.tsv> the output will be a CSV-file
1848 named I<name>.
1850 B<.csv> gives a comma separated value file. B<.tsv> gives a TAB
1851 separated value file.
1853 B<-.csv>/B<-.tsv> are special: It will give the file on stdout
1854 (standard output).
1857 B<Replacement string output file>
1859 If I<name> contains a replacement string and the replaced result does
1860 not end in /, then the standard output will be stored in a file named
1861 by this result. Standard error will be stored in the same file name
1862 with '.err' added, and the sequence number will be stored in the same
1863 file name with '.seq' added.
1865 E.g.
1867 parallel --results my_{} echo ::: foo bar baz
1869 will generate the files:
1871 my_bar
1872 my_bar.err
1873 my_bar.seq
1874 my_baz
1875 my_baz.err
1876 my_baz.seq
1877 my_foo
1878 my_foo.err
1879 my_foo.seq
1882 B<Replacement string output dir>
1884 If I<name> contains a replacement string and the replaced result ends
1885 in /, then output files will be stored in the resulting dir.
1887 E.g.
1889 parallel --results my_{}/ echo ::: foo bar baz
1891 will generate the files:
1893 my_bar/seq
1894 my_bar/stderr
1895 my_bar/stdout
1896 my_baz/seq
1897 my_baz/stderr
1898 my_baz/stdout
1899 my_foo/seq
1900 my_foo/stderr
1901 my_foo/stdout
1903 See also B<--files>, B<--tag>, B<--header>, B<--joblog>.
1906 =item B<--resume>
1908 Resumes from the last unfinished job. By reading B<--joblog> or the
1909 B<--results> dir GNU B<parallel> will figure out the last unfinished
1910 job and continue from there. As GNU B<parallel> only looks at the
1911 sequence numbers in B<--joblog> then the input, the command, and
1912 B<--joblog> all have to remain unchanged; otherwise GNU B<parallel>
1913 may run wrong commands.
1915 See also B<--joblog>, B<--results>, B<--resume-failed>, B<--retries>.
1918 =item B<--resume-failed>
1920 Retry all failed and resume from the last unfinished job. By reading
1921 B<--joblog> GNU B<parallel> will figure out the failed jobs and run
1922 those again. After that it will resume last unfinished job and
1923 continue from there. As GNU B<parallel> only looks at the sequence
1924 numbers in B<--joblog> then the input, the command, and B<--joblog>
1925 all have to remain unchanged; otherwise GNU B<parallel> may run wrong
1926 commands.
1928 See also B<--joblog>, B<--resume>, B<--retry-failed>, B<--retries>.
1931 =item B<--retry-failed>
1933 Retry all failed jobs in joblog. By reading B<--joblog> GNU
1934 B<parallel> will figure out the failed jobs and run those again.
1936 B<--retry-failed> ignores the command and arguments on the command
1937 line: It only looks at the joblog.
1939 B<Differences between --resume, --resume-failed, --retry-failed>
1941 In this example B<exit {= $_%=2 =}> will cause every other job to fail.
1943 timeout -k 1 4 parallel --joblog log -j10 \
1944 'sleep {}; exit {= $_%=2 =}' ::: {10..1}
1946 4 jobs completed. 2 failed:
1948 Seq [...] Exitval Signal Command
1949 10 [...] 1 0 sleep 1; exit 1
1950 9 [...] 0 0 sleep 2; exit 0
1951 8 [...] 1 0 sleep 3; exit 1
1952 7 [...] 0 0 sleep 4; exit 0
1954 B<--resume> does not care about the Exitval, but only looks at Seq. If
1955 the Seq is run, it will not be run again. So if needed, you can change
1956 the command for the seqs not run yet:
1958 parallel --resume --joblog log -j10 \
1959 'sleep .{}; exit {= $_%=2 =}' ::: {10..1}
1961 Seq [...] Exitval Signal Command
1962 [... as above ...]
1963 1 [...] 0 0 sleep .10; exit 0
1964 6 [...] 1 0 sleep .5; exit 1
1965 5 [...] 0 0 sleep .6; exit 0
1966 4 [...] 1 0 sleep .7; exit 1
1967 3 [...] 0 0 sleep .8; exit 0
1968 2 [...] 1 0 sleep .9; exit 1
1970 B<--resume-failed> cares about the Exitval, but also only looks at Seq
1971 to figure out which commands to run. Again this means you can change
1972 the command, but not the arguments. It will run the failed seqs and
1973 the seqs not yet run:
1975 parallel --resume-failed --joblog log -j10 \
1976 'echo {};sleep .{}; exit {= $_%=3 =}' ::: {10..1}
1978 Seq [...] Exitval Signal Command
1979 [... as above ...]
1980 10 [...] 1 0 echo 1;sleep .1; exit 1
1981 8 [...] 0 0 echo 3;sleep .3; exit 0
1982 6 [...] 2 0 echo 5;sleep .5; exit 2
1983 4 [...] 1 0 echo 7;sleep .7; exit 1
1984 2 [...] 0 0 echo 9;sleep .9; exit 0
1986 B<--retry-failed> cares about the Exitval, but takes the command from
1987 the joblog. It ignores any arguments or commands given on the command
1988 line:
1990 parallel --retry-failed --joblog log -j10 this part is ignored
1992 Seq [...] Exitval Signal Command
1993 [... as above ...]
1994 10 [...] 1 0 echo 1;sleep .1; exit 1
1995 6 [...] 2 0 echo 5;sleep .5; exit 2
1996 4 [...] 1 0 echo 7;sleep .7; exit 1
1998 See also B<--joblog>, B<--resume>, B<--resume-failed>, B<--retries>.
2001 =item B<--retries> I<n>
2003 If a job fails, retry it on another computer on which it has not
2004 failed. Do this I<n> times. If there are fewer than I<n> computers in
2005 B<--sshlogin> GNU B<parallel> will re-use all the computers. This is
2006 useful if some jobs fail for no apparent reason (such as network
2007 failure).
2010 =item B<--return> I<filename>
2012 Transfer files from remote computers. B<--return> is used with
2013 B<--sshlogin> when the arguments are files on the remote computers. When
2014 processing is done the file I<filename> will be transferred
2015 from the remote computer using B<rsync> and will be put relative to
2016 the default login dir. E.g.
2018 echo foo/bar.txt | parallel --return {.}.out \
2019 --sshlogin server.example.com touch {.}.out
2021 This will transfer the file I<$HOME/foo/bar.out> from the computer
2022 I<server.example.com> to the file I<foo/bar.out> after running
2023 B<touch foo/bar.out> on I<server.example.com>.
2025 parallel -S server --trc out/./{}.out touch {}.out ::: in/file
2027 This will transfer the file I<in/file.out> from the computer
2028 I<server.example.com> to the files I<out/in/file.out> after running
2029 B<touch in/file.out> on I<server>.
2031 echo /tmp/foo/bar.txt | parallel --return {.}.out \
2032 --sshlogin server.example.com touch {.}.out
2034 This will transfer the file I</tmp/foo/bar.out> from the computer
2035 I<server.example.com> to the file I</tmp/foo/bar.out> after running
2036 B<touch /tmp/foo/bar.out> on I<server.example.com>.
2038 Multiple files can be transferred by repeating the option multiple
2039 times:
2041 echo /tmp/foo/bar.txt | parallel \
2042 --sshlogin server.example.com \
2043 --return {.}.out --return {.}.out2 touch {.}.out {.}.out2
2045 B<--return> is often used with B<--transferfile> and B<--cleanup>.
2047 B<--return> is ignored when used with B<--sshlogin :> or when not used
2048 with B<--sshlogin>.
2051 =item B<--round-robin>
2053 =item B<--round>
2055 Normally B<--pipe> will give a single block to each instance of the
2056 command. With B<--roundrobin> all blocks will at random be written to
2057 commands already running. This is useful if the command takes a long
2058 time to initialize.
2060 B<--keep-order> will not work with B<--roundrobin> as it is
2061 impossible to track which input block corresponds to which output.
2063 B<--roundrobin> implies B<--pipe>, except if B<--pipepart> is given.
2065 See also B<--group-by>, B<--shard>.
2068 =item B<--rpl> 'I<tag> I<perl expression>'
2070 Use I<tag> as a replacement string for I<perl expression>. This makes
2071 it possible to define your own replacement strings. GNU B<parallel>'s
2072 7 replacement strings are implemented as:
2074 --rpl '{} '
2075 --rpl '{#} 1 $_=$job->seq()'
2076 --rpl '{%} 1 $_=$job->slot()'
2077 --rpl '{/} s:.*/::'
2078 --rpl '{//} $Global::use{"File::Basename"} ||=
2079 eval "use File::Basename; 1;"; $_ = dirname($_);'
2080 --rpl '{/.} s:.*/::; s:\.[^/.]+$::;'
2081 --rpl '{.} s:\.[^/.]+$::'
2083 The B<--plus> replacement strings are implemented as:
2085 --rpl '{+/} s:/[^/]*$::'
2086 --rpl '{+.} s:.*\.::'
2087 --rpl '{+..} s:.*\.([^.]*\.):$1:'
2088 --rpl '{+...} s:.*\.([^.]*\.[^.]*\.):$1:'
2089 --rpl '{..} s:\.[^/.]+$::; s:\.[^/.]+$::'
2090 --rpl '{...} s:\.[^/.]+$::; s:\.[^/.]+$::; s:\.[^/.]+$::'
2091 --rpl '{/..} s:.*/::; s:\.[^/.]+$::; s:\.[^/.]+$::'
2092 --rpl '{/...} s:.*/::;s:\.[^/.]+$::;s:\.[^/.]+$::;s:\.[^/.]+$::'
2093 --rpl '{##} $_=total_jobs()'
2094 --rpl '{:-(.+?)} $_ ||= $$1'
2095 --rpl '{:(\d+?)} substr($_,0,$$1) = ""'
2096 --rpl '{:(\d+?):(\d+?)} $_ = substr($_,$$1,$$2);'
2097 --rpl '{#([^#].*?)} s/^$$1//;'
2098 --rpl '{%(.+?)} s/$$1$//;'
2099 --rpl '{/(.+?)/(.*?)} s/$$1/$$2/;'
2100 --rpl '{^(.+?)} s/^($$1)/uc($1)/e;'
2101 --rpl '{^^(.+?)} s/($$1)/uc($1)/eg;'
2102 --rpl '{,(.+?)} s/^($$1)/lc($1)/e;'
2103 --rpl '{,,(.+?)} s/($$1)/lc($1)/eg;'
2106 If the user defined replacement string starts with '{' it can also be
2107 used as a positional replacement string (like B<{2.}>).
2109 It is recommended to only change $_ but you have full access to all
2110 of GNU B<parallel>'s internal functions and data structures.
2112 Here are a few examples:
2114 Is the job sequence even or odd?
2115 --rpl '{odd} $_ = seq() % 2 ? "odd" : "even"'
2116 Pad job sequence with leading zeros to get equal width
2117 --rpl '{0#} $f=1+int("".(log(total_jobs())/log(10)));
2118 $_=sprintf("%0${f}d",seq())'
2119 Job sequence counting from 0
2120 --rpl '{#0} $_ = seq() - 1'
2121 Job slot counting from 2
2122 --rpl '{%1} $_ = slot() + 1'
2123 Remove all extensions
2124 --rpl '{:} s:(\.[^/]+)*$::'
2126 You can have dynamic replacement strings by including parenthesis in
2127 the replacement string and adding a regular expression between the
2128 parenthesis. The matching string will be inserted as $$1:
2130 parallel --rpl '{%(.*?)} s/$$1//' echo {%.tar.gz} ::: my.tar.gz
2131 parallel --rpl '{:%(.+?)} s:$$1(\.[^/]+)*$::' \
2132 echo {:%_file} ::: my_file.tar.gz
2133 parallel -n3 --rpl '{/:%(.*?)} s:.*/(.*)$$1(\.[^/]+)*$:$1:' \
2134 echo job {#}: {2} {2.} {3/:%_1} ::: a/b.c c/d.e f/g_1.h.i
2136 You can even use multiple matches:
2138 parallel --rpl '{/(.+?)/(.*?)} s/$$1/$$2/;'
2139 echo {/replacethis/withthis} {/b/C} ::: a_replacethis_b
2141 parallel --rpl '{(.*?)/(.*?)} $_="$$2$_$$1"' \
2142 echo {swap/these} ::: -middle-
2144 See also: B<{= perl expression =}> B<--parens>
2147 =item B<--rsync-opts> I<options>
2149 Options to pass on to B<rsync>. Setting B<--rsync-opts> takes
2150 precedence over setting the environment variable $PARALLEL_RSYNC_OPTS.
2153 =item B<--max-chars>=I<max-chars>
2155 =item B<-s> I<max-chars>
2157 Use at most I<max-chars> characters per command line, including the
2158 command and initial-arguments and the terminating nulls at the ends of
2159 the argument strings. The largest allowed value is system-dependent,
2160 and is calculated as the argument length limit for exec, less the size
2161 of your environment. The default value is the maximum.
2163 Implies B<-X> unless B<-m> is set.
2166 =item B<--show-limits>
2168 Display the limits on the command-line length which are imposed by the
2169 operating system and the B<-s> option. Pipe the input from /dev/null
2170 (and perhaps specify --no-run-if-empty) if you don't want GNU B<parallel>
2171 to do anything.
2174 =item B<--semaphore>
2176 Work as a counting semaphore. B<--semaphore> will cause GNU
2177 B<parallel> to start I<command> in the background. When the number of
2178 jobs given by B<--jobs> is reached, GNU B<parallel> will wait for one of
2179 these to complete before starting another command.
2181 B<--semaphore> implies B<--bg> unless B<--fg> is specified.
2183 B<--semaphore> implies B<--semaphorename `tty`> unless
2184 B<--semaphorename> is specified.
2186 Used with B<--fg>, B<--wait>, and B<--semaphorename>.
2188 The command B<sem> is an alias for B<parallel --semaphore>.
2190 See also B<man sem>.
2193 =item B<--semaphorename> I<name>
2195 =item B<--id> I<name>
2197 Use B<name> as the name of the semaphore. Default is the name of the
2198 controlling tty (output from B<tty>).
2200 The default normally works as expected when used interactively, but
2201 when used in a script I<name> should be set. I<$$> or I<my_task_name>
2202 are often a good value.
2204 The semaphore is stored in ~/.parallel/semaphores/
2206 Implies B<--semaphore>.
2208 See also B<man sem>.
2211 =item B<--semaphoretimeout> I<secs>
2213 =item B<--st> I<secs>
2215 If I<secs> > 0: If the semaphore is not released within I<secs> seconds, take it anyway.
2217 If I<secs> < 0: If the semaphore is not released within I<secs> seconds, exit.
2219 Implies B<--semaphore>.
2221 See also B<man sem>.
2224 =item B<--seqreplace> I<replace-str>
2226 Use the replacement string I<replace-str> instead of B<{#}> for
2227 job sequence number.
2230 =item B<--session>
2232 Record names in current environment in B<$PARALLEL_IGNORED_NAMES> and
2233 exit. Only used with B<env_parallel>. Aliases, functions, and
2234 variables with names in B<$PARALLEL_IGNORED_NAMES> will not be copied.
2236 Only supported in B<Ash, Bash, Dash, Ksh, Sh, and Zsh>.
2238 See also B<--env>, B<--record-env>.
2241 =item B<--shard> I<shardexpr>
2243 Use I<shardexpr> as shard key and shard input to the jobs.
2245 I<shardexpr> is [column number|column name] [perlexpression] e.g. 3,
2246 Address, 3 $_%=100, Address s/\d//g.
2248 Each input line is split using B<--colsep>. The value of the column is
2249 put into $_, the perl expression is executed, the resulting value is
2250 hashed so that all lines of a given value is given to the same job
2251 slot.
2253 This is similar to sharding in databases.
2255 The performance is in the order of 100K rows per second. Faster if the
2256 I<shardcol> is small (<10), slower if it is big (>100).
2258 B<--shard> requires B<--pipe> and a fixed numeric value for B<--jobs>.
2260 See also B<--bin>, B<--group-by>, B<--roundrobin>.
2263 =item B<--shebang>
2265 =item B<--hashbang>
2267 GNU B<parallel> can be called as a shebang (#!) command as the first
2268 line of a script. The content of the file will be treated as
2269 inputsource.
2271 Like this:
2273 #!/usr/bin/parallel --shebang -r wget
2275 https://ftpmirror.gnu.org/parallel/parallel-20120822.tar.bz2
2276 https://ftpmirror.gnu.org/parallel/parallel-20130822.tar.bz2
2277 https://ftpmirror.gnu.org/parallel/parallel-20140822.tar.bz2
2279 B<--shebang> must be set as the first option.
2281 On FreeBSD B<env> is needed:
2283 #!/usr/bin/env -S parallel --shebang -r wget
2285 https://ftpmirror.gnu.org/parallel/parallel-20120822.tar.bz2
2286 https://ftpmirror.gnu.org/parallel/parallel-20130822.tar.bz2
2287 https://ftpmirror.gnu.org/parallel/parallel-20140822.tar.bz2
2289 There are many limitations of shebang (#!) depending on your operating
2290 system. See details on http://www.in-ulm.de/~mascheck/various/shebang/
2293 =item B<--shebang-wrap>
2295 GNU B<parallel> can parallelize scripts by wrapping the shebang
2296 line. If the program can be run like this:
2298 cat arguments | parallel the_program
2300 then the script can be changed to:
2302 #!/usr/bin/parallel --shebang-wrap /original/parser --options
2304 E.g.
2306 #!/usr/bin/parallel --shebang-wrap /usr/bin/python
2308 If the program can be run like this:
2310 cat data | parallel --pipe the_program
2312 then the script can be changed to:
2314 #!/usr/bin/parallel --shebang-wrap --pipe /orig/parser --opts
2316 E.g.
2318 #!/usr/bin/parallel --shebang-wrap --pipe /usr/bin/perl -w
2320 B<--shebang-wrap> must be set as the first option.
2323 =item B<--shellquote>
2325 Does not run the command but quotes it. Useful for making quoted
2326 composed commands for GNU B<parallel>.
2328 Multiple B<--shellquote> with quote the string multiple times, so
2329 B<parallel --shellquote | parallel --shellquote> can be written as
2330 B<parallel --shellquote --shellquote>.
2333 =item B<--shuf>
2335 Shuffle jobs. When having multiple input sources it is hard to
2336 randomize jobs. --shuf will generate all jobs, and shuffle them before
2337 running them. This is useful to get a quick preview of the results
2338 before running the full batch.
2341 =item B<--skip-first-line>
2343 Do not use the first line of input (used by GNU B<parallel> itself
2344 when called with B<--shebang>).
2347 =item B<--sql> I<DBURL> (obsolete)
2349 Use B<--sqlmaster> instead.
2352 =item B<--sqlmaster> I<DBURL>
2354 Submit jobs via SQL server. I<DBURL> must point to a table, which will
2355 contain the same information as B<--joblog>, the values from the input
2356 sources (stored in columns V1 .. Vn), and the output (stored in
2357 columns Stdout and Stderr).
2359 If I<DBURL> is prepended with '+' GNU B<parallel> assumes the table is
2360 already made with the correct columns and appends the jobs to it.
2362 If I<DBURL> is not prepended with '+' the table will be dropped and
2363 created with the correct amount of V-columns unless
2365 B<--sqlmaster> does not run any jobs, but it creates the values for
2366 the jobs to be run. One or more B<--sqlworker> must be run to actually
2367 execute the jobs.
2369 If B<--wait> is set, GNU B<parallel> will wait for the jobs to
2370 complete.
2372 The format of a DBURL is:
2374 [sql:]vendor://[[user][:pwd]@][host][:port]/[db]/table
2376 E.g.
2378 sql:mysql://hr:hr@localhost:3306/hrdb/jobs
2379 mysql://scott:tiger@my.example.com/pardb/paralleljobs
2380 sql:oracle://scott:tiger@ora.example.com/xe/parjob
2381 postgresql://scott:tiger@pg.example.com/pgdb/parjob
2382 pg:///parjob
2383 sqlite3:///%2Ftmp%2Fpardb.sqlite/parjob
2384 csv:///%2Ftmp%2Fpardb/parjob
2386 Notice how / in the path of sqlite and CVS must be encoded as
2387 %2F. Except the last / in CSV which must be a /.
2389 It can also be an alias from ~/.sql/aliases:
2391 :myalias mysql:///mydb/paralleljobs
2394 =item B<--sqlandworker> I<DBURL>
2396 Shorthand for: B<--sqlmaster> I<DBURL> B<--sqlworker> I<DBURL>.
2399 =item B<--sqlworker> I<DBURL>
2401 Execute jobs via SQL server. Read the input sources variables from the
2402 table pointed to by I<DBURL>. The I<command> on the command line
2403 should be the same as given by B<--sqlmaster>.
2405 If you have more than one B<--sqlworker> jobs may be run more than
2406 once.
2408 If B<--sqlworker> runs on the local machine, the hostname in the SQL
2409 table will not be ':' but instead the hostname of the machine.
2412 =item B<--ssh> I<sshcommand>
2414 GNU B<parallel> defaults to using B<ssh> for remote access. This can
2415 be overridden with B<--ssh>. It can also be set on a per server
2416 basis (see B<--sshlogin>).
2419 =item B<--sshdelay> I<secs>
2421 Delay starting next ssh by I<secs> seconds. GNU B<parallel> will pause
2422 I<secs> seconds after starting each ssh. I<secs> can be less than 1
2423 seconds.
2426 =item B<-S> I<[@hostgroups/][ncpus/]sshlogin[,[@hostgroups/][ncpus/]sshlogin[,...]]>
2428 =item B<-S> I<@hostgroup>
2430 =item B<--sshlogin> I<[@hostgroups/][ncpus/]sshlogin[,[@hostgroups/][ncpus/]sshlogin[,...]]>
2432 =item B<--sshlogin> I<@hostgroup>
2434 Distribute jobs to remote computers. The jobs will be run on a list of
2435 remote computers.
2437 If I<hostgroups> is given, the I<sshlogin> will be added to that
2438 hostgroup. Multiple hostgroups are separated by '+'. The I<sshlogin>
2439 will always be added to a hostgroup named the same as I<sshlogin>.
2441 If only the I<@hostgroup> is given, only the sshlogins in that
2442 hostgroup will be used. Multiple I<@hostgroup> can be given.
2444 GNU B<parallel> will determine the number of CPUs on the remote
2445 computers and run the number of jobs as specified by B<-j>. If the
2446 number I<ncpus> is given GNU B<parallel> will use this number for
2447 number of CPUs on the host. Normally I<ncpus> will not be
2448 needed.
2450 An I<sshlogin> is of the form:
2452 [sshcommand [options]] [username@]hostname
2454 The sshlogin must not require a password (B<ssh-agent>,
2455 B<ssh-copy-id>, and B<sshpass> may help with that).
2457 The sshlogin ':' is special, it means 'no ssh' and will therefore run
2458 on the local computer.
2460 The sshlogin '..' is special, it read sshlogins from ~/.parallel/sshloginfile or
2461 $XDG_CONFIG_HOME/parallel/sshloginfile
2463 The sshlogin '-' is special, too, it read sshlogins from stdin
2464 (standard input).
2466 To specify more sshlogins separate the sshlogins by comma, newline (in
2467 the same string), or repeat the options multiple times.
2469 For examples: see B<--sshloginfile>.
2471 The remote host must have GNU B<parallel> installed.
2473 B<--sshlogin> is known to cause problems with B<-m> and B<-X>.
2475 B<--sshlogin> is often used with B<--transferfile>, B<--return>,
2476 B<--cleanup>, and B<--trc>.
2479 =item B<--sshloginfile> I<filename>
2481 =item B<--slf> I<filename>
2483 File with sshlogins. The file consists of sshlogins on separate
2484 lines. Empty lines and lines starting with '#' are ignored. Example:
2486 server.example.com
2487 username@server2.example.com
2488 8/my-8-cpu-server.example.com
2489 2/my_other_username@my-dualcore.example.net
2490 # This server has SSH running on port 2222
2491 ssh -p 2222 server.example.net
2492 4/ssh -p 2222 quadserver.example.net
2493 # Use a different ssh program
2494 myssh -p 2222 -l myusername hexacpu.example.net
2495 # Use a different ssh program with default number of CPUs
2496 //usr/local/bin/myssh -p 2222 -l myusername hexacpu
2497 # Use a different ssh program with 6 CPUs
2498 6//usr/local/bin/myssh -p 2222 -l myusername hexacpu
2499 # Assume 16 CPUs on the local computer
2500 16/:
2501 # Put server1 in hostgroup1
2502 @hostgroup1/server1
2503 # Put myusername@server2 in hostgroup1+hostgroup2
2504 @hostgroup1+hostgroup2/myusername@server2
2505 # Force 4 CPUs and put 'ssh -p 2222 server3' in hostgroup1
2506 @hostgroup1/4/ssh -p 2222 server3
2508 When using a different ssh program the last argument must be the hostname.
2510 Multiple B<--sshloginfile> are allowed.
2512 GNU B<parallel> will first look for the file in current dir; if that
2513 fails it look for the file in ~/.parallel.
2515 The sshloginfile '..' is special, it read sshlogins from
2516 ~/.parallel/sshloginfile
2518 The sshloginfile '.' is special, it read sshlogins from
2519 /etc/parallel/sshloginfile
2521 The sshloginfile '-' is special, too, it read sshlogins from stdin
2522 (standard input).
2524 If the sshloginfile is changed it will be re-read when a job finishes
2525 though at most once per second. This makes it possible to add and
2526 remove hosts while running.
2528 This can be used to have a daemon that updates the sshloginfile to
2529 only contain servers that are up:
2531 cp original.slf tmp2.slf
2532 while [ 1 ] ; do
2533 nice parallel --nonall -j0 -k --slf original.slf \
2534 --tag echo | perl 's/\t$//' > tmp.slf
2535 if diff tmp.slf tmp2.slf; then
2536 mv tmp.slf tmp2.slf
2538 sleep 10
2539 done &
2540 parallel --slf tmp2.slf ...
2543 =item B<--slotreplace> I<replace-str>
2545 Use the replacement string I<replace-str> instead of B<{%}> for
2546 job slot number.
2549 =item B<--silent>
2551 Silent. The job to be run will not be printed. This is the default.
2552 Can be reversed with B<-v>.
2555 =item B<--tty>
2557 Open terminal tty. If GNU B<parallel> is used for starting a program
2558 that accesses the tty (such as an interactive program) then this
2559 option may be needed. It will default to starting only one job at a
2560 time (i.e. B<-j1>), not buffer the output (i.e. B<-u>), and it will
2561 open a tty for the job.
2563 You can of course override B<-j1> and B<-u>.
2565 Using B<--tty> unfortunately means that GNU B<parallel> cannot kill
2566 the jobs (with B<--timeout>, B<--memfree>, or B<--halt>). This is due
2567 to GNU B<parallel> giving each child its own process group, which is
2568 then killed. Process groups are dependant on the tty.
2571 =item B<--tag>
2573 Tag lines with arguments. Each output line will be prepended with the
2574 arguments and TAB (\t). When combined with B<--onall> or B<--nonall>
2575 the lines will be prepended with the sshlogin instead.
2577 B<--tag> is ignored when using B<-u>.
2580 =item B<--tagstring> I<str>
2582 Tag lines with a string. Each output line will be prepended with
2583 I<str> and TAB (\t). I<str> can contain replacement strings such as
2584 B<{}>.
2586 B<--tagstring> is ignored when using B<-u>, B<--onall>, and B<--nonall>.
2589 =item B<--tee>
2591 Pipe all data to all jobs. Used with B<--pipe>/B<--pipepart> and
2592 B<:::>.
2594 seq 1000 | parallel --pipe --tee -v wc {} ::: -w -l -c
2596 How many numbers in 1..1000 contain 0..9, and how many bytes do they
2597 fill:
2599 seq 1000 | parallel --pipe --tee --tag \
2600 'grep {1} | wc {2}' ::: {0..9} ::: -l -c
2602 How many words contain a..z and how many bytes do they fill?
2604 parallel -a /usr/share/dict/words --pipepart --tee --tag \
2605 'grep {1} | wc {2}' ::: {a..z} ::: -l -c
2608 =item B<--termseq> I<sequence>
2610 Termination sequence. When a job is killed due to B<--timeout>,
2611 B<--memfree>, B<--halt>, or abnormal termination of GNU B<parallel>,
2612 I<sequence> determines how the job is killed. The default is:
2614 TERM,200,TERM,100,TERM,50,KILL,25
2616 which sends a TERM signal, waits 200 ms, sends another TERM signal,
2617 waits 100 ms, sends another TERM signal, waits 50 ms, sends a KILL
2618 signal, waits 25 ms, and exits. GNU B<parallel> detects if a process
2619 dies before the waiting time is up.
2622 =item B<--tmpdir> I<dirname>
2624 Directory for temporary files. GNU B<parallel> normally buffers output
2625 into temporary files in /tmp. By setting B<--tmpdir> you can use a
2626 different dir for the files. Setting B<--tmpdir> is equivalent to
2627 setting $TMPDIR.
2630 =item B<--tmux> (Long beta testing)
2632 Use B<tmux> for output. Start a B<tmux> session and run each job in a
2633 window in that session. No other output will be produced.
2636 =item B<--tmuxpane> (Long beta testing)
2638 Use B<tmux> for output but put output into panes in the first window.
2639 Useful if you want to monitor the progress of less than 100 concurrent
2640 jobs.
2643 =item B<--timeout> I<duration>
2645 Time out for command. If the command runs for longer than I<duration>
2646 seconds it will get killed as per B<--termseq>.
2648 If I<duration> is followed by a % then the timeout will dynamically be
2649 computed as a percentage of the median average runtime of successful
2650 jobs. Only values > 100% will make sense.
2652 I<duration> is normally in seconds, but can be floats postfixed with
2653 B<s>, B<m>, B<h>, or B<d> which would multiply the float by 1, 60,
2654 3600, or 86400. Thus these are equivalent: B<--timeout 100000> and
2655 B<--timeout 1d3.5h16.6m4s>.
2658 =item B<--verbose>
2660 =item B<-t>
2662 Print the job to be run on stderr (standard error).
2664 See also B<-v>, B<-p>.
2667 =item B<--transfer>
2669 Transfer files to remote computers. Shorthand for: B<--transferfile {}>.
2672 =item B<--transferfile> I<filename>
2674 =item B<--tf> I<filename>
2676 B<--transferfile> is used with B<--sshlogin> to transfer files to the
2677 remote computers. The files will be transferred using B<rsync> and
2678 will be put relative to the default work dir. If the path contains /./
2679 the remaining path will be relative to the work dir. E.g.
2681 echo foo/bar.txt | parallel --transferfile {} \
2682 --sshlogin server.example.com wc
2684 This will transfer the file I<foo/bar.txt> to the computer
2685 I<server.example.com> to the file I<$HOME/foo/bar.txt> before running
2686 B<wc foo/bar.txt> on I<server.example.com>.
2688 echo /tmp/foo/bar.txt | parallel --transferfile {} \
2689 --sshlogin server.example.com wc
2691 This will transfer the file I</tmp/foo/bar.txt> to the computer
2692 I<server.example.com> to the file I</tmp/foo/bar.txt> before running
2693 B<wc /tmp/foo/bar.txt> on I<server.example.com>.
2695 echo /tmp/./foo/bar.txt | parallel --transferfile {} \
2696 --sshlogin server.example.com wc {= s:.*/./:./: =}
2698 This will transfer the file I</tmp/foo/bar.txt> to the computer
2699 I<server.example.com> to the file I<foo/bar.txt> before running
2700 B<wc ./foo/bar.txt> on I<server.example.com>.
2702 B<--transferfile> is often used with B<--return> and B<--cleanup>. A
2703 shorthand for B<--transferfile {}> is B<--transfer>.
2705 B<--transferfile> is ignored when used with B<--sshlogin :> or when
2706 not used with B<--sshlogin>.
2709 =item B<--trc> I<filename>
2711 Transfer, Return, Cleanup. Shorthand for:
2713 B<--transferfile {}> B<--return> I<filename> B<--cleanup>
2716 =item B<--trim> <n|l|r|lr|rl>
2718 Trim white space in input.
2720 =over 4
2722 =item n
2724 No trim. Input is not modified. This is the default.
2726 =item l
2728 Left trim. Remove white space from start of input. E.g. " a bc " -> "a bc ".
2730 =item r
2732 Right trim. Remove white space from end of input. E.g. " a bc " -> " a bc".
2734 =item lr
2736 =item rl
2738 Both trim. Remove white space from both start and end of input. E.g. "
2739 a bc " -> "a bc". This is the default if B<--colsep> is used.
2741 =back
2744 =item B<--ungroup>
2746 =item B<-u>
2748 Ungroup output. Output is printed as soon as possible and bypasses
2749 GNU B<parallel> internal processing. This may cause output from
2750 different commands to be mixed thus should only be used if you do not
2751 care about the output. Compare these:
2753 seq 4 | parallel -j0 \
2754 'sleep {};echo -n start{};sleep {};echo {}end'
2755 seq 4 | parallel -u -j0 \
2756 'sleep {};echo -n start{};sleep {};echo {}end'
2758 It also disables B<--tag>. GNU B<parallel> outputs faster with
2759 B<-u>. Compare the speeds of these:
2761 parallel seq ::: 300000000 >/dev/null
2762 parallel -u seq ::: 300000000 >/dev/null
2763 parallel --line-buffer seq ::: 300000000 >/dev/null
2765 Can be reversed with B<--group>.
2767 See also: B<--line-buffer> B<--group>
2770 =item B<--extensionreplace> I<replace-str>
2772 =item B<--er> I<replace-str>
2774 Use the replacement string I<replace-str> instead of B<{.}> for input
2775 line without extension.
2778 =item B<--use-sockets-instead-of-threads>
2780 =item B<--use-cores-instead-of-threads>
2782 =item B<--use-cpus-instead-of-cores> (obsolete)
2784 Determine how GNU B<parallel> counts the number of CPUs. GNU
2785 B<parallel> uses this number when the number of jobslots is computed
2786 relative to the number of CPUs (e.g. 100% or +1).
2788 CPUs can be counted in three different ways:
2790 =over 8
2792 =item sockets
2794 The number of filled CPU sockets (i.e. the number of physical chips).
2796 =item cores
2798 The number of physical cores (i.e. the number of physical compute
2799 cores).
2801 =item threads
2803 The number of hyperthreaded cores (i.e. the number of virtual
2804 cores - with some of them possibly being hyperthreaded)
2806 =back
2808 Normally the number of CPUs is computed as the number of CPU
2809 threads. With B<--use-sockets-instead-of-threads> or
2810 B<--use-cores-instead-of-threads> you can force it to be computed as
2811 the number of filled sockets or number of cores instead.
2813 Most users will not need these options.
2815 B<--use-cpus-instead-of-cores> is a (misleading) alias for
2816 B<--use-sockets-instead-of-threads> and is kept for backwards
2817 compatibility.
2820 =item B<-v>
2822 Verbose. Print the job to be run on stdout (standard output). Can be reversed
2823 with B<--silent>. See also B<-t>.
2825 Use B<-v> B<-v> to print the wrapping ssh command when running remotely.
2828 =item B<--version>
2830 =item B<-V>
2832 Print the version GNU B<parallel> and exit.
2835 =item B<--workdir> I<mydir>
2837 =item B<--wd> I<mydir>
2839 Jobs will be run in the dir I<mydir>.
2841 Files transferred using B<--transferfile> and B<--return> will be
2842 relative to I<mydir> on remote computers.
2844 The special I<mydir> value B<...> will create working dirs under
2845 B<~/.parallel/tmp/>. If B<--cleanup> is given these dirs will be
2846 removed.
2848 The special I<mydir> value B<.> uses the current working dir. If the
2849 current working dir is beneath your home dir, the value B<.> is
2850 treated as the relative path to your home dir. This means that if your
2851 home dir is different on remote computers (e.g. if your login is
2852 different) the relative path will still be relative to your home dir.
2854 To see the difference try:
2856 parallel -S server pwd ::: ""
2857 parallel --wd . -S server pwd ::: ""
2858 parallel --wd ... -S server pwd ::: ""
2860 I<mydir> can contain GNU B<parallel>'s replacement strings.
2863 =item B<--wait>
2865 Wait for all commands to complete.
2867 Used with B<--semaphore> or B<--sqlmaster>.
2869 See also B<man sem>.
2872 =item B<-X>
2874 Multiple arguments with context replace. Insert as many arguments as
2875 the command line length permits. If multiple jobs are being run in
2876 parallel: distribute the arguments evenly among the jobs. Use B<-j1>
2877 to avoid this.
2879 If B<{}> is not used the arguments will be appended to the line. If
2880 B<{}> is used as part of a word (like I<pic{}.jpg>) then the whole
2881 word will be repeated. If B<{}> is used multiple times each B<{}> will
2882 be replaced with the arguments.
2884 Normally B<-X> will do the right thing, whereas B<-m> can give
2885 unexpected results if B<{}> is used as part of a word.
2887 Support for B<-X> with B<--sshlogin> is limited and may fail.
2889 See also B<-m>.
2892 =item B<--exit>
2894 =item B<-x>
2896 Exit if the size (see the B<-s> option) is exceeded.
2899 =item B<--xargs>
2901 Multiple arguments. Insert as many arguments as the command line
2902 length permits.
2904 If B<{}> is not used the arguments will be appended to the
2905 line. If B<{}> is used multiple times each B<{}> will be replaced
2906 with all the arguments.
2908 Support for B<--xargs> with B<--sshlogin> is limited and may fail.
2910 See also B<-X> for context replace. If in doubt use B<-X> as that will
2911 most likely do what is needed.
2914 =back
2916 =head1 EXAMPLE: Working as xargs -n1. Argument appending
2918 GNU B<parallel> can work similar to B<xargs -n1>.
2920 To compress all html files using B<gzip> run:
2922 find . -name '*.html' | parallel gzip --best
2924 If the file names may contain a newline use B<-0>. Substitute FOO BAR with
2925 FUBAR in all files in this dir and subdirs:
2927 find . -type f -print0 | \
2928 parallel -q0 perl -i -pe 's/FOO BAR/FUBAR/g'
2930 Note B<-q> is needed because of the space in 'FOO BAR'.
2933 =head1 EXAMPLE: Simple network scanner
2935 B<prips> can generate IP-addresses from CIDR notation. With GNU
2936 B<parallel> you can build a simple network scanner to see which
2937 addresses respond to B<ping>:
2939 prips 130.229.16.0/20 | \
2940 parallel --timeout 2 -j0 \
2941 'ping -c 1 {} >/dev/null && echo {}' 2>/dev/null
2944 =head1 EXAMPLE: Reading arguments from command line
2946 GNU B<parallel> can take the arguments from command line instead of
2947 stdin (standard input). To compress all html files in the current dir
2948 using B<gzip> run:
2950 parallel gzip --best ::: *.html
2952 To convert *.wav to *.mp3 using LAME running one process per CPU run:
2954 parallel lame {} -o {.}.mp3 ::: *.wav
2957 =head1 EXAMPLE: Inserting multiple arguments
2959 When moving a lot of files like this: B<mv *.log destdir> you will
2960 sometimes get the error:
2962 bash: /bin/mv: Argument list too long
2964 because there are too many files. You can instead do:
2966 ls | grep -E '\.log$' | parallel mv {} destdir
2968 This will run B<mv> for each file. It can be done faster if B<mv> gets
2969 as many arguments that will fit on the line:
2971 ls | grep -E '\.log$' | parallel -m mv {} destdir
2973 In many shells you can also use B<printf>:
2975 printf '%s\0' *.log | parallel -0 -m mv {} destdir
2978 =head1 EXAMPLE: Context replace
2980 To remove the files I<pict0000.jpg> .. I<pict9999.jpg> you could do:
2982 seq -w 0 9999 | parallel rm pict{}.jpg
2984 You could also do:
2986 seq -w 0 9999 | perl -pe 's/(.*)/pict$1.jpg/' | parallel -m rm
2988 The first will run B<rm> 10000 times, while the last will only run
2989 B<rm> as many times needed to keep the command line length short
2990 enough to avoid B<Argument list too long> (it typically runs 1-2 times).
2992 You could also run:
2994 seq -w 0 9999 | parallel -X rm pict{}.jpg
2996 This will also only run B<rm> as many times needed to keep the command
2997 line length short enough.
3000 =head1 EXAMPLE: Compute intensive jobs and substitution
3002 If ImageMagick is installed this will generate a thumbnail of a jpg
3003 file:
3005 convert -geometry 120 foo.jpg thumb_foo.jpg
3007 This will run with number-of-cpus jobs in parallel for all jpg files
3008 in a directory:
3010 ls *.jpg | parallel convert -geometry 120 {} thumb_{}
3012 To do it recursively use B<find>:
3014 find . -name '*.jpg' | \
3015 parallel convert -geometry 120 {} {}_thumb.jpg
3017 Notice how the argument has to start with B<{}> as B<{}> will include path
3018 (e.g. running B<convert -geometry 120 ./foo/bar.jpg
3019 thumb_./foo/bar.jpg> would clearly be wrong). The command will
3020 generate files like ./foo/bar.jpg_thumb.jpg.
3022 Use B<{.}> to avoid the extra .jpg in the file name. This command will
3023 make files like ./foo/bar_thumb.jpg:
3025 find . -name '*.jpg' | \
3026 parallel convert -geometry 120 {} {.}_thumb.jpg
3029 =head1 EXAMPLE: Substitution and redirection
3031 This will generate an uncompressed version of .gz-files next to the .gz-file:
3033 parallel zcat {} ">"{.} ::: *.gz
3035 Quoting of > is necessary to postpone the redirection. Another
3036 solution is to quote the whole command:
3038 parallel "zcat {} >{.}" ::: *.gz
3040 Other special shell characters (such as * ; $ > < | >> <<) also need
3041 to be put in quotes, as they may otherwise be interpreted by the shell
3042 and not given to GNU B<parallel>.
3045 =head1 EXAMPLE: Composed commands
3047 A job can consist of several commands. This will print the number of
3048 files in each directory:
3050 ls | parallel 'echo -n {}" "; ls {}|wc -l'
3052 To put the output in a file called <name>.dir:
3054 ls | parallel '(echo -n {}" "; ls {}|wc -l) >{}.dir'
3056 Even small shell scripts can be run by GNU B<parallel>:
3058 find . | parallel 'a={}; name=${a##*/};' \
3059 'upper=$(echo "$name" | tr "[:lower:]" "[:upper:]");'\
3060 'echo "$name - $upper"'
3062 ls | parallel 'mv {} "$(echo {} | tr "[:upper:]" "[:lower:]")"'
3064 Given a list of URLs, list all URLs that fail to download. Print the
3065 line number and the URL.
3067 cat urlfile | parallel "wget {} 2>/dev/null || grep -n {} urlfile"
3069 Create a mirror directory with the same filenames except all files and
3070 symlinks are empty files.
3072 cp -rs /the/source/dir mirror_dir
3073 find mirror_dir -type l | parallel -m rm {} '&&' touch {}
3075 Find the files in a list that do not exist
3077 cat file_list | parallel 'if [ ! -e {} ] ; then echo {}; fi'
3080 =head1 EXAMPLE: Composed command with perl replacement string
3082 You have a bunch of file. You want them sorted into dirs. The dir of
3083 each file should be named the first letter of the file name.
3085 parallel 'mkdir -p {=s/(.).*/$1/=}; mv {} {=s/(.).*/$1/=}' ::: *
3088 =head1 EXAMPLE: Composed command with multiple input sources
3090 You have a dir with files named as 24 hours in 5 minute intervals:
3091 00:00, 00:05, 00:10 .. 23:55. You want to find the files missing:
3093 parallel [ -f {1}:{2} ] "||" echo {1}:{2} does not exist \
3094 ::: {00..23} ::: {00..55..5}
3097 =head1 EXAMPLE: Calling Bash functions
3099 If the composed command is longer than a line, it becomes hard to
3100 read. In Bash you can use functions. Just remember to B<export -f> the
3101 function.
3103 doit() {
3104 echo Doing it for $1
3105 sleep 2
3106 echo Done with $1
3108 export -f doit
3109 parallel doit ::: 1 2 3
3111 doubleit() {
3112 echo Doing it for $1 $2
3113 sleep 2
3114 echo Done with $1 $2
3116 export -f doubleit
3117 parallel doubleit ::: 1 2 3 ::: a b
3119 To do this on remote servers you need to transfer the function using
3120 B<--env>:
3122 parallel --env doit -S server doit ::: 1 2 3
3123 parallel --env doubleit -S server doubleit ::: 1 2 3 ::: a b
3125 If your environment (aliases, variables, and functions) is small you
3126 can copy the full environment without having to B<export -f>
3127 anything. See B<env_parallel>.
3130 =head1 EXAMPLE: Function tester
3132 To test a program with different parameters:
3134 tester() {
3135 if (eval "$@") >&/dev/null; then
3136 perl -e 'printf "\033[30;102m[ OK ]\033[0m @ARGV\n"' "$@"
3137 else
3138 perl -e 'printf "\033[30;101m[FAIL]\033[0m @ARGV\n"' "$@"
3141 export -f tester
3142 parallel tester my_program ::: arg1 arg2
3143 parallel tester exit ::: 1 0 2 0
3145 If B<my_program> fails a red FAIL will be printed followed by the failing
3146 command; otherwise a green OK will be printed followed by the command.
3149 =head1 EXAMPLE: Continously show the latest line of output
3151 It can be useful to monitor the output of running jobs.
3153 This shows the most recent output line until a job finishes. After
3154 which the output of the job is printed in full:
3156 parallel '{} | tee >(cat >&3)' ::: 'command 1' 'command 2' \
3157 3> >(perl -ne '$|=1;chomp;printf"%.'$COLUMNS's\r",$_." "x100')
3160 =head1 EXAMPLE: Log rotate
3162 Log rotation renames a logfile to an extension with a higher number:
3163 log.1 becomes log.2, log.2 becomes log.3, and so on. The oldest log is
3164 removed. To avoid overwriting files the process starts backwards from
3165 the high number to the low number. This will keep 10 old versions of
3166 the log:
3168 seq 9 -1 1 | parallel -j1 mv log.{} log.'{= $_++ =}'
3169 mv log log.1
3172 =head1 EXAMPLE: Removing file extension when processing files
3174 When processing files removing the file extension using B<{.}> is
3175 often useful.
3177 Create a directory for each zip-file and unzip it in that dir:
3179 parallel 'mkdir {.}; cd {.}; unzip ../{}' ::: *.zip
3181 Recompress all .gz files in current directory using B<bzip2> running 1
3182 job per CPU in parallel:
3184 parallel "zcat {} | bzip2 >{.}.bz2 && rm {}" ::: *.gz
3186 Convert all WAV files to MP3 using LAME:
3188 find sounddir -type f -name '*.wav' | parallel lame {} -o {.}.mp3
3190 Put all converted in the same directory:
3192 find sounddir -type f -name '*.wav' | \
3193 parallel lame {} -o mydir/{/.}.mp3
3196 =head1 EXAMPLE: Removing strings from the argument
3198 If you have directory with tar.gz files and want these extracted in
3199 the corresponding dir (e.g foo.tar.gz will be extracted in the dir
3200 foo) you can do:
3202 parallel --plus 'mkdir {..}; tar -C {..} -xf {}' ::: *.tar.gz
3204 If you want to remove a different ending, you can use {%string}:
3206 parallel --plus echo {%_demo} ::: mycode_demo keep_demo_here
3208 You can also remove a starting string with {#string}
3210 parallel --plus echo {#demo_} ::: demo_mycode keep_demo_here
3212 To remove a string anywhere you can use regular expressions with
3213 {/regexp/replacement} and leave the replacement empty:
3215 parallel --plus echo {/demo_/} ::: demo_mycode remove_demo_here
3218 =head1 EXAMPLE: Download 24 images for each of the past 30 days
3220 Let us assume a website stores images like:
3222 http://www.example.com/path/to/YYYYMMDD_##.jpg
3224 where YYYYMMDD is the date and ## is the number 01-24. This will
3225 download images for the past 30 days:
3227 getit() {
3228 date=$(date -d "today -$1 days" +%Y%m%d)
3229 num=$2
3230 echo wget http://www.example.com/path/to/${date}_${num}.jpg
3232 export -f getit
3234 parallel getit ::: $(seq 30) ::: $(seq -w 24)
3236 B<$(date -d "today -$1 days" +%Y%m%d)> will give the dates in
3237 YYYYMMDD with B<$1> days subtracted.
3240 =head1 EXAMPLE: Download world map from NASA
3242 NASA provides tiles to download on earthdata.nasa.gov. Download tiles
3243 for Blue Marble world map and create a 10240x20480 map.
3245 base=https://map1a.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi
3246 service="SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0"
3247 layer="LAYER=BlueMarble_ShadedRelief_Bathymetry"
3248 set="STYLE=&TILEMATRIXSET=EPSG4326_500m&TILEMATRIX=5"
3249 tile="TILEROW={1}&TILECOL={2}"
3250 format="FORMAT=image%2Fjpeg"
3251 url="$base?$service&$layer&$set&$tile&$format"
3253 parallel -j0 -q wget "$url" -O {1}_{2}.jpg ::: {0..19} ::: {0..39}
3254 parallel eval convert +append {}_{0..39}.jpg line{}.jpg ::: {0..19}
3255 convert -append line{0..19}.jpg world.jpg
3258 =head1 EXAMPLE: Download Apollo-11 images from NASA using jq
3260 Search NASA using their API to get JSON for images related to 'apollo
3261 11' and has 'moon landing' in the description.
3263 The search query returns JSON containing URLs to JSON containing
3264 collections of pictures. One of the pictures in each of these
3265 collection is I<large>.
3267 B<wget> is used to get the JSON for the search query. B<jq> is then
3268 used to extract the URLs of the collections. B<parallel> then calls
3269 B<wget> to get each collection, which is passed to B<jq> to extract
3270 the URLs of all images. B<grep> filters out the I<large> images, and
3271 B<parallel> finally uses B<wget> to fetch the images.
3273 base="https://images-api.nasa.gov/search"
3274 q="q=apollo 11"
3275 description="description=moon landing"
3276 media_type="media_type=image"
3277 wget -O - "$base?$q&$description&$media_type" |
3278 jq -r .collection.items[].href |
3279 parallel wget -O - |
3280 jq -r .[] |
3281 grep large |
3282 parallel wget
3285 =head1 EXAMPLE: Download video playlist in parallel
3287 B<youtube-dl> is an excellent tool to download videos. It can,
3288 however, not download videos in parallel. This takes a playlist and
3289 downloads 10 videos in parallel.
3291 url='youtu.be/watch?v=0wOf2Fgi3DE&list=UU_cznB5YZZmvAmeq7Y3EriQ'
3292 export url
3293 youtube-dl --flat-playlist "https://$url" |
3294 parallel --tagstring {#} --lb -j10 \
3295 youtube-dl --playlist-start {#} --playlist-end {#} '"https://$url"'
3298 =head1 EXAMPLE: Prepend last modified date (ISO8601) to file name
3300 parallel mv {} '{= $a=pQ($_); $b=$_;' \
3301 '$_=qx{date -r "$a" +%FT%T}; chomp; $_="$_ $b" =}' ::: *
3303 B<{=> and B<=}> mark a perl expression. B<pQ> perl-quotes the
3304 string. B<date +%FT%T> is the date in ISO8601 with time.
3306 =head1 EXAMPLE: Save output in ISO8601 dirs
3308 Save output from B<ps aux> every second into dirs named
3309 yyyy-mm-ddThh:mm:ss+zz:zz.
3311 seq 1000 | parallel -N0 -j1 --delay 1 \
3312 --results '{= $_=`date -Isec`; chomp=}/' ps aux
3315 =head1 EXAMPLE: Digital clock with "blinking" :
3317 The : in a digital clock blinks. To make every other line have a ':'
3318 and the rest a ' ' a perl expression is used to look at the 3rd input
3319 source. If the value modulo 2 is 1: Use ":" otherwise use " ":
3321 parallel -k echo {1}'{=3 $_=$_%2?":":" "=}'{2}{3} \
3322 ::: {0..12} ::: {0..5} ::: {0..9}
3325 =head1 EXAMPLE: Aggregating content of files
3327 This:
3329 parallel --header : echo x{X}y{Y}z{Z} \> x{X}y{Y}z{Z} \
3330 ::: X {1..5} ::: Y {01..10} ::: Z {1..5}
3332 will generate the files x1y01z1 .. x5y10z5. If you want to aggregate
3333 the output grouping on x and z you can do this:
3335 parallel eval 'cat {=s/y01/y*/=} > {=s/y01//=}' ::: *y01*
3337 For all values of x and z it runs commands like:
3339 cat x1y*z1 > x1z1
3341 So you end up with x1z1 .. x5z5 each containing the content of all
3342 values of y.
3345 =head1 EXAMPLE: Breadth first parallel web crawler/mirrorer
3347 This script below will crawl and mirror a URL in parallel. It
3348 downloads first pages that are 1 click down, then 2 clicks down, then
3349 3; instead of the normal depth first, where the first link link on
3350 each page is fetched first.
3352 Run like this:
3354 PARALLEL=-j100 ./parallel-crawl http://gatt.org.yeslab.org/
3356 Remove the B<wget> part if you only want a web crawler.
3358 It works by fetching a page from a list of URLs and looking for links
3359 in that page that are within the same starting URL and that have not
3360 already been seen. These links are added to a new queue. When all the
3361 pages from the list is done, the new queue is moved to the list of
3362 URLs and the process is started over until no unseen links are found.
3364 #!/bin/bash
3366 # E.g. http://gatt.org.yeslab.org/
3367 URL=$1
3368 # Stay inside the start dir
3369 BASEURL=$(echo $URL | perl -pe 's:#.*::; s:(//.*/)[^/]*:$1:')
3370 URLLIST=$(mktemp urllist.XXXX)
3371 URLLIST2=$(mktemp urllist.XXXX)
3372 SEEN=$(mktemp seen.XXXX)
3374 # Spider to get the URLs
3375 echo $URL >$URLLIST
3376 cp $URLLIST $SEEN
3378 while [ -s $URLLIST ] ; do
3379 cat $URLLIST |
3380 parallel lynx -listonly -image_links -dump {} \; \
3381 wget -qm -l1 -Q1 {} \; echo Spidered: {} \>\&2 |
3382 perl -ne 's/#.*//; s/\s+\d+.\s(\S+)$/$1/ and
3383 do { $seen{$1}++ or print }' |
3384 grep -F $BASEURL |
3385 grep -v -x -F -f $SEEN | tee -a $SEEN > $URLLIST2
3386 mv $URLLIST2 $URLLIST
3387 done
3389 rm -f $URLLIST $URLLIST2 $SEEN
3392 =head1 EXAMPLE: Process files from a tar file while unpacking
3394 If the files to be processed are in a tar file then unpacking one file
3395 and processing it immediately may be faster than first unpacking all
3396 files.
3398 tar xvf foo.tgz | perl -ne 'print $l;$l=$_;END{print $l}' | \
3399 parallel echo
3401 The Perl one-liner is needed to make sure the file is complete before
3402 handing it to GNU B<parallel>.
3405 =head1 EXAMPLE: Rewriting a for-loop and a while-read-loop
3407 for-loops like this:
3409 (for x in `cat list` ; do
3410 do_something $x
3411 done) | process_output
3413 and while-read-loops like this:
3415 cat list | (while read x ; do
3416 do_something $x
3417 done) | process_output
3419 can be written like this:
3421 cat list | parallel do_something | process_output
3423 For example: Find which host name in a list has IP address 1.2.3 4:
3425 cat hosts.txt | parallel -P 100 host | grep 1.2.3.4
3427 If the processing requires more steps the for-loop like this:
3429 (for x in `cat list` ; do
3430 no_extension=${x%.*};
3431 do_step1 $x scale $no_extension.jpg
3432 do_step2 <$x $no_extension
3433 done) | process_output
3435 and while-loops like this:
3437 cat list | (while read x ; do
3438 no_extension=${x%.*};
3439 do_step1 $x scale $no_extension.jpg
3440 do_step2 <$x $no_extension
3441 done) | process_output
3443 can be written like this:
3445 cat list | parallel "do_step1 {} scale {.}.jpg ; do_step2 <{} {.}" |\
3446 process_output
3448 If the body of the loop is bigger, it improves readability to use a function:
3450 (for x in `cat list` ; do
3451 do_something $x
3452 [... 100 lines that do something with $x ...]
3453 done) | process_output
3455 cat list | (while read x ; do
3456 do_something $x
3457 [... 100 lines that do something with $x ...]
3458 done) | process_output
3460 can both be rewritten as:
3462 doit() {
3463 x=$1
3464 do_something $x
3465 [... 100 lines that do something with $x ...]
3467 export -f doit
3468 cat list | parallel doit
3470 =head1 EXAMPLE: Rewriting nested for-loops
3472 Nested for-loops like this:
3474 (for x in `cat xlist` ; do
3475 for y in `cat ylist` ; do
3476 do_something $x $y
3477 done
3478 done) | process_output
3480 can be written like this:
3482 parallel do_something {1} {2} :::: xlist ylist | process_output
3484 Nested for-loops like this:
3486 (for colour in red green blue ; do
3487 for size in S M L XL XXL ; do
3488 echo $colour $size
3489 done
3490 done) | sort
3492 can be written like this:
3494 parallel echo {1} {2} ::: red green blue ::: S M L XL XXL | sort
3497 =head1 EXAMPLE: Finding the lowest difference between files
3499 B<diff> is good for finding differences in text files. B<diff | wc -l>
3500 gives an indication of the size of the difference. To find the
3501 differences between all files in the current dir do:
3503 parallel --tag 'diff {1} {2} | wc -l' ::: * ::: * | sort -nk3
3505 This way it is possible to see if some files are closer to other
3506 files.
3509 =head1 EXAMPLE: for-loops with column names
3511 When doing multiple nested for-loops it can be easier to keep track of
3512 the loop variable if is is named instead of just having a number. Use
3513 B<--header :> to let the first argument be an named alias for the
3514 positional replacement string:
3516 parallel --header : echo {colour} {size} \
3517 ::: colour red green blue ::: size S M L XL XXL
3519 This also works if the input file is a file with columns:
3521 cat addressbook.tsv | \
3522 parallel --colsep '\t' --header : echo {Name} {E-mail address}
3525 =head1 EXAMPLE: All combinations in a list
3527 GNU B<parallel> makes all combinations when given two lists.
3529 To make all combinations in a single list with unique values, you
3530 repeat the list and use replacement string B<{choose_k}>:
3532 parallel --plus echo {choose_k} ::: A B C D ::: A B C D
3534 parallel --plus echo 2{2choose_k} 1{1choose_k} ::: A B C D ::: A B C D
3536 B<{choose_k}> works for any number of input sources:
3538 parallel --plus echo {choose_k} ::: A B C D ::: A B C D ::: A B C D
3541 =head1 EXAMPLE: From a to b and b to c
3543 Assume you have input like:
3545 aardvark
3546 babble
3549 each
3551 and want to run combinations like:
3553 aardvark babble
3554 babble cab
3555 cab dab
3556 dab each
3558 If the input is in the file in.txt:
3560 parallel echo {1} - {2} ::::+ <(head -n -1 in.txt) <(tail -n +2 in.txt)
3562 If the input is in the array $a here are two solutions:
3564 seq $((${#a[@]}-1)) | \
3565 env_parallel --env a echo '${a[{=$_--=}]} - ${a[{}]}'
3566 parallel echo {1} - {2} ::: "${a[@]::${#a[@]}-1}" :::+ "${a[@]:1}"
3569 =head1 EXAMPLE: Count the differences between all files in a dir
3571 Using B<--results> the results are saved in /tmp/diffcount*.
3573 parallel --results /tmp/diffcount "diff -U 0 {1} {2} | \
3574 tail -n +3 |grep -v '^@'|wc -l" ::: * ::: *
3576 To see the difference between file A and file B look at the file
3577 '/tmp/diffcount/1/A/2/B'.
3580 =head1 EXAMPLE: Speeding up fast jobs
3582 Starting a job on the local machine takes around 10 ms. This can be a
3583 big overhead if the job takes very few ms to run. Often you can group
3584 small jobs together using B<-X> which will make the overhead less
3585 significant. Compare the speed of these:
3587 seq -w 0 9999 | parallel touch pict{}.jpg
3588 seq -w 0 9999 | parallel -X touch pict{}.jpg
3590 If your program cannot take multiple arguments, then you can use GNU
3591 B<parallel> to spawn multiple GNU B<parallel>s:
3593 seq -w 0 9999999 | \
3594 parallel -j10 -q -I,, --pipe parallel -j0 touch pict{}.jpg
3596 If B<-j0> normally spawns 252 jobs, then the above will try to spawn
3597 2520 jobs. On a normal GNU/Linux system you can spawn 32000 jobs using
3598 this technique with no problems. To raise the 32000 jobs limit raise
3599 /proc/sys/kernel/pid_max to 4194303.
3601 If you do not need GNU B<parallel> to have control over each job (so
3602 no need for B<--retries> or B<--joblog> or similar), then it can be
3603 even faster if you can generate the command lines and pipe those to a
3604 shell. So if you can do this:
3606 mygenerator | sh
3608 Then that can be parallelized like this:
3610 mygenerator | parallel --pipe --block 10M sh
3612 E.g.
3614 mygenerator() {
3615 seq 10000000 | perl -pe 'print "echo This is fast job number "';
3617 mygenerator | parallel --pipe --block 10M sh
3619 The overhead is 100000 times smaller namely around 100 nanoseconds per
3620 job.
3623 =head1 EXAMPLE: Using shell variables
3625 When using shell variables you need to quote them correctly as they
3626 may otherwise be interpreted by the shell.
3628 Notice the difference between:
3630 ARR=("My brother's 12\" records are worth <\$\$\$>"'!' Foo Bar)
3631 parallel echo ::: ${ARR[@]} # This is probably not what you want
3633 and:
3635 ARR=("My brother's 12\" records are worth <\$\$\$>"'!' Foo Bar)
3636 parallel echo ::: "${ARR[@]}"
3638 When using variables in the actual command that contains special
3639 characters (e.g. space) you can quote them using B<'"$VAR"'> or using
3640 "'s and B<-q>:
3642 VAR="My brother's 12\" records are worth <\$\$\$>"
3643 parallel -q echo "$VAR" ::: '!'
3644 export VAR
3645 parallel echo '"$VAR"' ::: '!'
3647 If B<$VAR> does not contain ' then B<"'$VAR'"> will also work
3648 (and does not need B<export>):
3650 VAR="My 12\" records are worth <\$\$\$>"
3651 parallel echo "'$VAR'" ::: '!'
3653 If you use them in a function you just quote as you normally would do:
3655 VAR="My brother's 12\" records are worth <\$\$\$>"
3656 export VAR
3657 myfunc() { echo "$VAR" "$1"; }
3658 export -f myfunc
3659 parallel myfunc ::: '!'
3662 =head1 EXAMPLE: Group output lines
3664 When running jobs that output data, you often do not want the output
3665 of multiple jobs to run together. GNU B<parallel> defaults to grouping
3666 the output of each job, so the output is printed when the job
3667 finishes. If you want full lines to be printed while the job is
3668 running you can use B<--line-buffer>. If you want output to be
3669 printed as soon as possible you can use B<-u>.
3671 Compare the output of:
3673 parallel wget --limit-rate=100k \
3674 https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
3675 ::: {12..16}
3676 parallel --line-buffer wget --limit-rate=100k \
3677 https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
3678 ::: {12..16}
3679 parallel -u wget --limit-rate=100k \
3680 https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
3681 ::: {12..16}
3683 =head1 EXAMPLE: Tag output lines
3685 GNU B<parallel> groups the output lines, but it can be hard to see
3686 where the different jobs begin. B<--tag> prepends the argument to make
3687 that more visible:
3689 parallel --tag wget --limit-rate=100k \
3690 https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
3691 ::: {12..16}
3693 B<--tag> works with B<--line-buffer> but not with B<-u>:
3695 parallel --tag --line-buffer wget --limit-rate=100k \
3696 https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
3697 ::: {12..16}
3699 Check the uptime of the servers in I<~/.parallel/sshloginfile>:
3701 parallel --tag -S .. --nonall uptime
3704 =head1 EXAMPLE: Colorize output
3706 Give each job a new color. Most terminals support ANSI colors with the
3707 escape code "\033[30;3Xm" where 0 <= X <= 7:
3709 seq 10 | \
3710 parallel --tagstring '\033[30;3{=$_=++$::color%8=}m' seq {}
3711 parallel --rpl '{color} $_="\033[30;3".(++$::color%8)."m"' \
3712 --tagstring {color} seq {} ::: {1..10}
3714 To get rid of the initial \t (which comes from B<--tagstring>):
3716 ... | perl -pe 's/\t//'
3719 =head1 EXAMPLE: Keep order of output same as order of input
3721 Normally the output of a job will be printed as soon as it
3722 completes. Sometimes you want the order of the output to remain the
3723 same as the order of the input. This is often important, if the output
3724 is used as input for another system. B<-k> will make sure the order of
3725 output will be in the same order as input even if later jobs end
3726 before earlier jobs.
3728 Append a string to every line in a text file:
3730 cat textfile | parallel -k echo {} append_string
3732 If you remove B<-k> some of the lines may come out in the wrong order.
3734 Another example is B<traceroute>:
3736 parallel traceroute ::: qubes-os.org debian.org freenetproject.org
3738 will give traceroute of qubes-os.org, debian.org and
3739 freenetproject.org, but it will be sorted according to which job
3740 completed first.
3742 To keep the order the same as input run:
3744 parallel -k traceroute ::: qubes-os.org debian.org freenetproject.org
3746 This will make sure the traceroute to qubes-os.org will be printed
3747 first.
3749 A bit more complex example is downloading a huge file in chunks in
3750 parallel: Some internet connections will deliver more data if you
3751 download files in parallel. For downloading files in parallel see:
3752 "EXAMPLE: Download 10 images for each of the past 30 days". But if you
3753 are downloading a big file you can download the file in chunks in
3754 parallel.
3756 To download byte 10000000-19999999 you can use B<curl>:
3758 curl -r 10000000-19999999 http://example.com/the/big/file >file.part
3760 To download a 1 GB file we need 100 10MB chunks downloaded and
3761 combined in the correct order.
3763 seq 0 99 | parallel -k curl -r \
3764 {}0000000-{}9999999 http://example.com/the/big/file > file
3767 =head1 EXAMPLE: Parallel grep
3769 B<grep -r> greps recursively through directories. On multicore CPUs
3770 GNU B<parallel> can often speed this up.
3772 find . -type f | parallel -k -j150% -n 1000 -m grep -H -n STRING {}
3774 This will run 1.5 job per CPU, and give 1000 arguments to B<grep>.
3777 =head1 EXAMPLE: Grepping n lines for m regular expressions.
3779 The simplest solution to grep a big file for a lot of regexps is:
3781 grep -f regexps.txt bigfile
3783 Or if the regexps are fixed strings:
3785 grep -F -f regexps.txt bigfile
3787 There are 3 limiting factors: CPU, RAM, and disk I/O.
3789 RAM is easy to measure: If the B<grep> process takes up most of your
3790 free memory (e.g. when running B<top>), then RAM is a limiting factor.
3792 CPU is also easy to measure: If the B<grep> takes >90% CPU in B<top>,
3793 then the CPU is a limiting factor, and parallelization will speed this
3796 It is harder to see if disk I/O is the limiting factor, and depending
3797 on the disk system it may be faster or slower to parallelize. The only
3798 way to know for certain is to test and measure.
3801 =head2 Limiting factor: RAM
3803 The normal B<grep -f regexs.txt bigfile> works no matter the size of
3804 bigfile, but if regexps.txt is so big it cannot fit into memory, then
3805 you need to split this.
3807 B<grep -F> takes around 100 bytes of RAM and B<grep> takes about 500
3808 bytes of RAM per 1 byte of regexp. So if regexps.txt is 1% of your
3809 RAM, then it may be too big.
3811 If you can convert your regexps into fixed strings do that. E.g. if
3812 the lines you are looking for in bigfile all looks like:
3814 ID1 foo bar baz Identifier1 quux
3815 fubar ID2 foo bar baz Identifier2
3817 then your regexps.txt can be converted from:
3819 ID1.*Identifier1
3820 ID2.*Identifier2
3822 into:
3824 ID1 foo bar baz Identifier1
3825 ID2 foo bar baz Identifier2
3827 This way you can use B<grep -F> which takes around 80% less memory and
3828 is much faster.
3830 If it still does not fit in memory you can do this:
3832 parallel --pipepart -a regexps.txt --block 1M grep -Ff - -n bigfile | \
3833 sort -un | perl -pe 's/^\d+://'
3835 The 1M should be your free memory divided by the number of CPU threads and
3836 divided by 200 for B<grep -F> and by 1000 for normal B<grep>. On
3837 GNU/Linux you can do:
3839 free=$(awk '/^((Swap)?Cached|MemFree|Buffers):/ { sum += $2 }
3840 END { print sum }' /proc/meminfo)
3841 percpu=$((free / 200 / $(parallel --number-of-threads)))k
3843 parallel --pipepart -a regexps.txt --block $percpu --compress \
3844 grep -F -f - -n bigfile | \
3845 sort -un | perl -pe 's/^\d+://'
3847 If you can live with duplicated lines and wrong order, it is faster to do:
3849 parallel --pipepart -a regexps.txt --block $percpu --compress \
3850 grep -F -f - bigfile
3852 =head2 Limiting factor: CPU
3854 If the CPU is the limiting factor parallelization should be done on
3855 the regexps:
3857 cat regexp.txt | parallel --pipe -L1000 --roundrobin --compress \
3858 grep -f - -n bigfile | \
3859 sort -un | perl -pe 's/^\d+://'
3861 The command will start one B<grep> per CPU and read I<bigfile> one
3862 time per CPU, but as that is done in parallel, all reads except the
3863 first will be cached in RAM. Depending on the size of I<regexp.txt> it
3864 may be faster to use B<--block 10m> instead of B<-L1000>.
3866 Some storage systems perform better when reading multiple chunks in
3867 parallel. This is true for some RAID systems and for some network file
3868 systems. To parallelize the reading of I<bigfile>:
3870 parallel --pipepart --block 100M -a bigfile -k --compress \
3871 grep -f regexp.txt
3873 This will split I<bigfile> into 100MB chunks and run B<grep> on each of
3874 these chunks. To parallelize both reading of I<bigfile> and I<regexp.txt>
3875 combine the two using B<--fifo>:
3877 parallel --pipepart --block 100M -a bigfile --fifo cat regexp.txt \
3878 \| parallel --pipe -L1000 --roundrobin grep -f - {}
3880 If a line matches multiple regexps, the line may be duplicated.
3882 =head2 Bigger problem
3884 If the problem is too big to be solved by this, you are probably ready
3885 for Lucene.
3888 =head1 EXAMPLE: Using remote computers
3890 To run commands on a remote computer SSH needs to be set up and you
3891 must be able to login without entering a password (The commands
3892 B<ssh-copy-id>, B<ssh-agent>, and B<sshpass> may help you do that).
3894 If you need to login to a whole cluster, you typically do not want to
3895 accept the host key for every host. You want to accept them the first
3896 time and be warned if they are ever changed. To do that:
3898 # Add the servers to the sshloginfile
3899 (echo servera; echo serverb) > .parallel/my_cluster
3900 # Make sure .ssh/config exist
3901 touch .ssh/config
3902 cp .ssh/config .ssh/config.backup
3903 # Disable StrictHostKeyChecking temporarily
3904 (echo 'Host *'; echo StrictHostKeyChecking no) >> .ssh/config
3905 parallel --slf my_cluster --nonall true
3906 # Remove the disabling of StrictHostKeyChecking
3907 mv .ssh/config.backup .ssh/config
3909 The servers in B<.parallel/my_cluster> are now added in B<.ssh/known_hosts>.
3911 To run B<echo> on B<server.example.com>:
3913 seq 10 | parallel --sshlogin server.example.com echo
3915 To run commands on more than one remote computer run:
3917 seq 10 | parallel --sshlogin s1.example.com,s2.example.net echo
3921 seq 10 | parallel --sshlogin server.example.com \
3922 --sshlogin server2.example.net echo
3924 If the login username is I<foo> on I<server2.example.net> use:
3926 seq 10 | parallel --sshlogin server.example.com \
3927 --sshlogin foo@server2.example.net echo
3929 If your list of hosts is I<server1-88.example.net> with login I<foo>:
3931 seq 10 | parallel -Sfoo@server{1..88}.example.net echo
3933 To distribute the commands to a list of computers, make a file
3934 I<mycomputers> with all the computers:
3936 server.example.com
3937 foo@server2.example.com
3938 server3.example.com
3940 Then run:
3942 seq 10 | parallel --sshloginfile mycomputers echo
3944 To include the local computer add the special sshlogin ':' to the list:
3946 server.example.com
3947 foo@server2.example.com
3948 server3.example.com
3951 GNU B<parallel> will try to determine the number of CPUs on each of
3952 the remote computers, and run one job per CPU - even if the remote
3953 computers do not have the same number of CPUs.
3955 If the number of CPUs on the remote computers is not identified
3956 correctly the number of CPUs can be added in front. Here the computer
3957 has 8 CPUs.
3959 seq 10 | parallel --sshlogin 8/server.example.com echo
3962 =head1 EXAMPLE: Transferring of files
3964 To recompress gzipped files with B<bzip2> using a remote computer run:
3966 find logs/ -name '*.gz' | \
3967 parallel --sshlogin server.example.com \
3968 --transfer "zcat {} | bzip2 -9 >{.}.bz2"
3970 This will list the .gz-files in the I<logs> directory and all
3971 directories below. Then it will transfer the files to
3972 I<server.example.com> to the corresponding directory in
3973 I<$HOME/logs>. On I<server.example.com> the file will be recompressed
3974 using B<zcat> and B<bzip2> resulting in the corresponding file with
3975 I<.gz> replaced with I<.bz2>.
3977 If you want the resulting bz2-file to be transferred back to the local
3978 computer add I<--return {.}.bz2>:
3980 find logs/ -name '*.gz' | \
3981 parallel --sshlogin server.example.com \
3982 --transfer --return {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
3984 After the recompressing is done the I<.bz2>-file is transferred back to
3985 the local computer and put next to the original I<.gz>-file.
3987 If you want to delete the transferred files on the remote computer add
3988 I<--cleanup>. This will remove both the file transferred to the remote
3989 computer and the files transferred from the remote computer:
3991 find logs/ -name '*.gz' | \
3992 parallel --sshlogin server.example.com \
3993 --transfer --return {.}.bz2 --cleanup "zcat {} | bzip2 -9 >{.}.bz2"
3995 If you want run on several computers add the computers to I<--sshlogin>
3996 either using ',' or multiple I<--sshlogin>:
3998 find logs/ -name '*.gz' | \
3999 parallel --sshlogin server.example.com,server2.example.com \
4000 --sshlogin server3.example.com \
4001 --transfer --return {.}.bz2 --cleanup "zcat {} | bzip2 -9 >{.}.bz2"
4003 You can add the local computer using I<--sshlogin :>. This will disable the
4004 removing and transferring for the local computer only:
4006 find logs/ -name '*.gz' | \
4007 parallel --sshlogin server.example.com,server2.example.com \
4008 --sshlogin server3.example.com \
4009 --sshlogin : \
4010 --transfer --return {.}.bz2 --cleanup "zcat {} | bzip2 -9 >{.}.bz2"
4012 Often I<--transfer>, I<--return> and I<--cleanup> are used together. They can be
4013 shortened to I<--trc>:
4015 find logs/ -name '*.gz' | \
4016 parallel --sshlogin server.example.com,server2.example.com \
4017 --sshlogin server3.example.com \
4018 --sshlogin : \
4019 --trc {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
4021 With the file I<mycomputers> containing the list of computers it becomes:
4023 find logs/ -name '*.gz' | parallel --sshloginfile mycomputers \
4024 --trc {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
4026 If the file I<~/.parallel/sshloginfile> contains the list of computers
4027 the special short hand I<-S ..> can be used:
4029 find logs/ -name '*.gz' | parallel -S .. \
4030 --trc {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
4033 =head1 EXAMPLE: Distributing work to local and remote computers
4035 Convert *.mp3 to *.ogg running one process per CPU on local computer
4036 and server2:
4038 parallel --trc {.}.ogg -S server2,: \
4039 'mpg321 -w - {} | oggenc -q0 - -o {.}.ogg' ::: *.mp3
4042 =head1 EXAMPLE: Running the same command on remote computers
4044 To run the command B<uptime> on remote computers you can do:
4046 parallel --tag --nonall -S server1,server2 uptime
4048 B<--nonall> reads no arguments. If you have a list of jobs you want
4049 to run on each computer you can do:
4051 parallel --tag --onall -S server1,server2 echo ::: 1 2 3
4053 Remove B<--tag> if you do not want the sshlogin added before the
4054 output.
4056 If you have a lot of hosts use '-j0' to access more hosts in parallel.
4059 =head1 EXAMPLE: Running 'sudo' on remote computers
4061 Put the password into passwordfile then run:
4063 parallel --ssh 'cat passwordfile | ssh' --nonall \
4064 -S user@server1,user@server2 sudo -S ls -l /root
4067 =head1 EXAMPLE: Using remote computers behind NAT wall
4069 If the workers are behind a NAT wall, you need some trickery to get to
4070 them.
4072 If you can B<ssh> to a jumphost, and reach the workers from there,
4073 then the obvious solution would be this, but it B<does not work>:
4075 parallel --ssh 'ssh jumphost ssh' -S host1 echo ::: DOES NOT WORK
4077 It does not work because the command is dequoted by B<ssh> twice where
4078 as GNU B<parallel> only expects it to be dequoted once.
4080 You can use a bash function and have GNU B<parallel> quote the command:
4082 jumpssh() { ssh -A jumphost ssh $(parallel --shellquote ::: "$@"); }
4083 export -f jumpssh
4084 parallel --ssh jumpssh -S host1 echo ::: this works
4086 Or you can instead put this in B<~/.ssh/config>:
4088 Host host1 host2 host3
4089 ProxyCommand ssh jumphost.domain nc -w 1 %h 22
4091 It requires B<nc(netcat)> to be installed on jumphost. With this you
4092 can simply:
4094 parallel -S host1,host2,host3 echo ::: This does work
4096 =head2 No jumphost, but port forwards
4098 If there is no jumphost but each server has port 22 forwarded from the
4099 firewall (e.g. the firewall's port 22001 = port 22 on host1, 22002 = host2,
4100 22003 = host3) then you can use B<~/.ssh/config>:
4102 Host host1.v
4103 Port 22001
4104 Host host2.v
4105 Port 22002
4106 Host host3.v
4107 Port 22003
4108 Host *.v
4109 Hostname firewall
4111 And then use host{1..3}.v as normal hosts:
4113 parallel -S host1.v,host2.v,host3.v echo ::: a b c
4115 =head2 No jumphost, no port forwards
4117 If ports cannot be forwarded, you need some sort of VPN to traverse
4118 the NAT-wall. TOR is one options for that, as it is very easy to get
4119 working.
4121 You need to install TOR and setup a hidden service. In B<torrc> put:
4123 HiddenServiceDir /var/lib/tor/hidden_service/
4124 HiddenServicePort 22 127.0.0.1:22
4126 Then start TOR: B</etc/init.d/tor restart>
4128 The TOR hostname is now in B</var/lib/tor/hidden_service/hostname> and
4129 is something similar to B<izjafdceobowklhz.onion>. Now you simply
4130 prepend B<torsocks> to B<ssh>:
4132 parallel --ssh 'torsocks ssh' -S izjafdceobowklhz.onion \
4133 -S zfcdaeiojoklbwhz.onion,auclucjzobowklhi.onion echo ::: a b c
4135 If not all hosts are accessible through TOR:
4137 parallel -S 'torsocks ssh izjafdceobowklhz.onion,host2,host3' \
4138 echo ::: a b c
4140 See more B<ssh> tricks on https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Jump_Hosts
4143 =head1 EXAMPLE: Parallelizing rsync
4145 B<rsync> is a great tool, but sometimes it will not fill up the
4146 available bandwidth. Running multiple B<rsync> in parallel can fix
4147 this.
4149 cd src-dir
4150 find . -type f |
4151 parallel -j10 -X rsync -zR -Ha ./{} fooserver:/dest-dir/
4153 Adjust B<-j10> until you find the optimal number.
4155 B<rsync -R> will create the needed subdirectories, so all files are
4156 not put into a single dir. The B<./> is needed so the resulting command
4157 looks similar to:
4159 rsync -zR ././sub/dir/file fooserver:/dest-dir/
4161 The B</./> is what B<rsync -R> works on.
4163 If you are unable to push data, but need to pull them and the files
4164 are called digits.png (e.g. 000000.png) you might be able to do:
4166 seq -w 0 99 | parallel rsync -Havessh fooserver:src/*{}.png destdir/
4169 =head1 EXAMPLE: Use multiple inputs in one command
4171 Copy files like foo.es.ext to foo.ext:
4173 ls *.es.* | perl -pe 'print; s/\.es//' | parallel -N2 cp {1} {2}
4175 The perl command spits out 2 lines for each input. GNU B<parallel>
4176 takes 2 inputs (using B<-N2>) and replaces {1} and {2} with the inputs.
4178 Count in binary:
4180 parallel -k echo ::: 0 1 ::: 0 1 ::: 0 1 ::: 0 1 ::: 0 1 ::: 0 1
4182 Print the number on the opposing sides of a six sided die:
4184 parallel --link -a <(seq 6) -a <(seq 6 -1 1) echo
4185 parallel --link echo :::: <(seq 6) <(seq 6 -1 1)
4187 Convert files from all subdirs to PNG-files with consecutive numbers
4188 (useful for making input PNG's for B<ffmpeg>):
4190 parallel --link -a <(find . -type f | sort) \
4191 -a <(seq $(find . -type f|wc -l)) convert {1} {2}.png
4193 Alternative version:
4195 find . -type f | sort | parallel convert {} {#}.png
4198 =head1 EXAMPLE: Use a table as input
4200 Content of table_file.tsv:
4202 foo<TAB>bar
4203 baz <TAB> quux
4205 To run:
4207 cmd -o bar -i foo
4208 cmd -o quux -i baz
4210 you can run:
4212 parallel -a table_file.tsv --colsep '\t' cmd -o {2} -i {1}
4214 Note: The default for GNU B<parallel> is to remove the spaces around
4215 the columns. To keep the spaces:
4217 parallel -a table_file.tsv --trim n --colsep '\t' cmd -o {2} -i {1}
4220 =head1 EXAMPLE: Output to database
4222 GNU B<parallel> can output to a database table and a CSV-file:
4224 dburl=csv:///%2Ftmp%2Fmydir
4225 dbtableurl=$dburl/mytable.csv
4226 parallel --sqlandworker $dbtableurl seq ::: {1..10}
4228 It is rather slow and takes up a lot of CPU time because GNU
4229 B<parallel> parses the whole CSV file for each update.
4231 A better approach is to use an SQLite-base and then convert that to CSV:
4233 dburl=sqlite3:///%2Ftmp%2Fmy.sqlite
4234 dbtableurl=$dburl/mytable
4235 parallel --sqlandworker $dbtableurl seq ::: {1..10}
4236 sql $dburl '.headers on' '.mode csv' 'SELECT * FROM mytable;'
4238 This takes around a second per job.
4240 If you have access to a real database system, such as PostgreSQL, it
4241 is even faster:
4243 dburl=pg://user:pass@host/mydb
4244 dbtableurl=$dburl/mytable
4245 parallel --sqlandworker $dbtableurl seq ::: {1..10}
4246 sql $dburl \
4247 "COPY (SELECT * FROM mytable) TO stdout DELIMITER ',' CSV HEADER;"
4249 Or MySQL:
4251 dburl=mysql://user:pass@host/mydb
4252 dbtableurl=$dburl/mytable
4253 parallel --sqlandworker $dbtableurl seq ::: {1..10}
4254 sql -p -B $dburl "SELECT * FROM mytable;" > mytable.tsv
4255 perl -pe 's/"/""/g; s/\t/","/g; s/^/"/; s/$/"/;
4256 %s=("\\" => "\\", "t" => "\t", "n" => "\n");
4257 s/\\([\\tn])/$s{$1}/g;' mytable.tsv
4260 =head1 EXAMPLE: Output to CSV-file for R
4262 If you have no need for the advanced job distribution control that a
4263 database provides, but you simply want output into a CSV file that you
4264 can read into R or LibreCalc, then you can use B<--results>:
4266 parallel --results my.csv seq ::: 10 20 30
4268 > mydf <- read.csv("my.csv");
4269 > print(mydf[2,])
4270 > write(as.character(mydf[2,c("Stdout")]),'')
4273 =head1 EXAMPLE: Use XML as input
4275 The show Aflyttet on Radio 24syv publishes an RSS feed with their audio
4276 podcasts on: http://arkiv.radio24syv.dk/audiopodcast/channel/4466232
4278 Using B<xpath> you can extract the URLs for 2019 and download them
4279 using GNU B<parallel>:
4281 wget -O - http://arkiv.radio24syv.dk/audiopodcast/channel/4466232 | \
4282 xpath -e "//pubDate[contains(text(),'2019')]/../enclosure/@url" | \
4283 parallel -u wget '{= s/ url="//; s/"//; =}'
4286 =head1 EXAMPLE: Run the same command 10 times
4288 If you want to run the same command with the same arguments 10 times
4289 in parallel you can do:
4291 seq 10 | parallel -n0 my_command my_args
4294 =head1 EXAMPLE: Working as cat | sh. Resource inexpensive jobs and evaluation
4296 GNU B<parallel> can work similar to B<cat | sh>.
4298 A resource inexpensive job is a job that takes very little CPU, disk
4299 I/O and network I/O. Ping is an example of a resource inexpensive
4300 job. wget is too - if the webpages are small.
4302 The content of the file jobs_to_run:
4304 ping -c 1 10.0.0.1
4305 wget http://example.com/status.cgi?ip=10.0.0.1
4306 ping -c 1 10.0.0.2
4307 wget http://example.com/status.cgi?ip=10.0.0.2
4309 ping -c 1 10.0.0.255
4310 wget http://example.com/status.cgi?ip=10.0.0.255
4312 To run 100 processes simultaneously do:
4314 parallel -j 100 < jobs_to_run
4316 As there is not a I<command> the jobs will be evaluated by the shell.
4319 =head1 EXAMPLE: Call program with FASTA sequence
4321 FASTA files have the format:
4323 >Sequence name1
4324 sequence
4325 sequence continued
4326 >Sequence name2
4327 sequence
4328 sequence continued
4329 more sequence
4331 To call B<myprog> with the sequence as argument run:
4333 cat file.fasta |
4334 parallel --pipe -N1 --recstart '>' --rrs \
4335 'read a; echo Name: "$a"; myprog $(tr -d "\n")'
4338 =head1 EXAMPLE: Processing a big file using more CPUs
4340 To process a big file or some output you can use B<--pipe> to split up
4341 the data into blocks and pipe the blocks into the processing program.
4343 If the program is B<gzip -9> you can do:
4345 cat bigfile | parallel --pipe --recend '' -k gzip -9 > bigfile.gz
4347 This will split B<bigfile> into blocks of 1 MB and pass that to B<gzip
4348 -9> in parallel. One B<gzip> will be run per CPU. The output of B<gzip
4349 -9> will be kept in order and saved to B<bigfile.gz>
4351 B<gzip> works fine if the output is appended, but some processing does
4352 not work like that - for example sorting. For this GNU B<parallel> can
4353 put the output of each command into a file. This will sort a big file
4354 in parallel:
4356 cat bigfile | parallel --pipe --files sort |\
4357 parallel -Xj1 sort -m {} ';' rm {} >bigfile.sort
4359 Here B<bigfile> is split into blocks of around 1MB, each block ending
4360 in '\n' (which is the default for B<--recend>). Each block is passed
4361 to B<sort> and the output from B<sort> is saved into files. These
4362 files are passed to the second B<parallel> that runs B<sort -m> on the
4363 files before it removes the files. The output is saved to
4364 B<bigfile.sort>.
4366 GNU B<parallel>'s B<--pipe> maxes out at around 100 MB/s because every
4367 byte has to be copied through GNU B<parallel>. But if B<bigfile> is a
4368 real (seekable) file GNU B<parallel> can by-pass the copying and send
4369 the parts directly to the program:
4371 parallel --pipepart --block 100m -a bigfile --files sort |\
4372 parallel -Xj1 sort -m {} ';' rm {} >bigfile.sort
4375 =head1 EXAMPLE: Grouping input lines
4377 When processing with B<--pipe> you may have lines grouped by a
4378 value. Here is I<my.csv>:
4380 Transaction Customer Item
4381 1 a 53
4382 2 b 65
4383 3 b 82
4384 4 c 96
4385 5 c 67
4386 6 c 13
4387 7 d 90
4388 8 d 43
4389 9 d 91
4390 10 d 84
4391 11 e 72
4392 12 e 102
4393 13 e 63
4394 14 e 56
4395 15 e 74
4397 Let us assume you want GNU B<parallel> to process each customer. In
4398 other words: You want all the transactions for a single customer to be
4399 treated as a single record.
4401 To do this we preprocess the data with a program that inserts a record
4402 separator before each customer (column 2 = $F[1]). Here we first make
4403 a 50 character random string, which we then use as the separator:
4405 sep=`perl -e 'print map { ("a".."z","A".."Z")[rand(52)] } (1..50);'`
4406 cat my.csv | \
4407 perl -ape '$F[1] ne $l and print "'$sep'"; $l = $F[1]' | \
4408 parallel --recend $sep --rrs --pipe -N1 wc
4410 If your program can process multiple customers replace B<-N1> with a
4411 reasonable B<--blocksize>.
4414 =head1 EXAMPLE: Running more than 250 jobs workaround
4416 If you need to run a massive amount of jobs in parallel, then you will
4417 likely hit the filehandle limit which is often around 250 jobs. If you
4418 are super user you can raise the limit in /etc/security/limits.conf
4419 but you can also use this workaround. The filehandle limit is per
4420 process. That means that if you just spawn more GNU B<parallel>s then
4421 each of them can run 250 jobs. This will spawn up to 2500 jobs:
4423 cat myinput |\
4424 parallel --pipe -N 50 --roundrobin -j50 parallel -j50 your_prg
4426 This will spawn up to 62500 jobs (use with caution - you need 64 GB
4427 RAM to do this, and you may need to increase /proc/sys/kernel/pid_max):
4429 cat myinput |\
4430 parallel --pipe -N 250 --roundrobin -j250 parallel -j250 your_prg
4433 =head1 EXAMPLE: Working as mutex and counting semaphore
4435 The command B<sem> is an alias for B<parallel --semaphore>.
4437 A counting semaphore will allow a given number of jobs to be started
4438 in the background. When the number of jobs are running in the
4439 background, GNU B<sem> will wait for one of these to complete before
4440 starting another command. B<sem --wait> will wait for all jobs to
4441 complete.
4443 Run 10 jobs concurrently in the background:
4445 for i in *.log ; do
4446 echo $i
4447 sem -j10 gzip $i ";" echo done
4448 done
4449 sem --wait
4451 A mutex is a counting semaphore allowing only one job to run. This
4452 will edit the file I<myfile> and prepends the file with lines with the
4453 numbers 1 to 3.
4455 seq 3 | parallel sem sed -i -e '1i{}' myfile
4457 As I<myfile> can be very big it is important only one process edits
4458 the file at the same time.
4460 Name the semaphore to have multiple different semaphores active at the
4461 same time:
4463 seq 3 | parallel sem --id mymutex sed -i -e '1i{}' myfile
4466 =head1 EXAMPLE: Mutex for a script
4468 Assume a script is called from cron or from a web service, but only
4469 one instance can be run at a time. With B<sem> and B<--shebang-wrap>
4470 the script can be made to wait for other instances to finish. Here in
4471 B<bash>:
4473 #!/usr/bin/sem --shebang-wrap -u --id $0 --fg /bin/bash
4475 echo This will run
4476 sleep 5
4477 echo exclusively
4479 Here B<perl>:
4481 #!/usr/bin/sem --shebang-wrap -u --id $0 --fg /usr/bin/perl
4483 print "This will run ";
4484 sleep 5;
4485 print "exclusively\n";
4487 Here B<python>:
4489 #!/usr/local/bin/sem --shebang-wrap -u --id $0 --fg /usr/bin/python
4491 import time
4492 print "This will run ";
4493 time.sleep(5)
4494 print "exclusively";
4497 =head1 EXAMPLE: Start editor with filenames from stdin (standard input)
4499 You can use GNU B<parallel> to start interactive programs like emacs or vi:
4501 cat filelist | parallel --tty -X emacs
4502 cat filelist | parallel --tty -X vi
4504 If there are more files than will fit on a single command line, the
4505 editor will be started again with the remaining files.
4508 =head1 EXAMPLE: Running sudo
4510 B<sudo> requires a password to run a command as root. It caches the
4511 access, so you only need to enter the password again if you have not
4512 used B<sudo> for a while.
4514 The command:
4516 parallel sudo echo ::: This is a bad idea
4518 is no good, as you would be prompted for the sudo password for each of
4519 the jobs. You can either do:
4521 sudo echo This
4522 parallel sudo echo ::: is a good idea
4526 sudo parallel echo ::: This is a good idea
4528 This way you only have to enter the sudo password once.
4531 =head1 EXAMPLE: GNU Parallel as queue system/batch manager
4533 GNU B<parallel> can work as a simple job queue system or batch manager.
4534 The idea is to put the jobs into a file and have GNU B<parallel> read
4535 from that continuously. As GNU B<parallel> will stop at end of file we
4536 use B<tail> to continue reading:
4538 true >jobqueue; tail -n+0 -f jobqueue | parallel
4540 To submit your jobs to the queue:
4542 echo my_command my_arg >> jobqueue
4544 You can of course use B<-S> to distribute the jobs to remote
4545 computers:
4547 true >jobqueue; tail -n+0 -f jobqueue | parallel -S ..
4549 If you keep this running for a long time, jobqueue will grow. A way of
4550 removing the jobs already run is by making GNU B<parallel> stop when
4551 it hits a special value and then restart. To use B<--eof> to make GNU
4552 B<parallel> exit, B<tail> also needs to be forced to exit:
4554 true >jobqueue;
4555 while true; do
4556 tail -n+0 -f jobqueue |
4557 (parallel -E StOpHeRe -S ..; echo GNU Parallel is now done;
4558 perl -e 'while(<>){/StOpHeRe/ and last};print <>' jobqueue > j2;
4559 (seq 1000 >> jobqueue &);
4560 echo Done appending dummy data forcing tail to exit)
4561 echo tail exited;
4562 mv j2 jobqueue
4563 done
4565 In some cases you can run on more CPUs and computers during the night:
4567 # Day time
4568 echo 50% > jobfile
4569 cp day_server_list ~/.parallel/sshloginfile
4570 # Night time
4571 echo 100% > jobfile
4572 cp night_server_list ~/.parallel/sshloginfile
4573 tail -n+0 -f jobqueue | parallel --jobs jobfile -S ..
4575 GNU B<parallel> discovers if B<jobfile> or B<~/.parallel/sshloginfile>
4576 changes.
4578 There is a a small issue when using GNU B<parallel> as queue
4579 system/batch manager: You have to submit JobSlot number of jobs before
4580 they will start, and after that you can submit one at a time, and job
4581 will start immediately if free slots are available. Output from the
4582 running or completed jobs are held back and will only be printed when
4583 JobSlots more jobs has been started (unless you use --ungroup or
4584 --line-buffer, in which case the output from the jobs are printed
4585 immediately). E.g. if you have 10 jobslots then the output from the
4586 first completed job will only be printed when job 11 has started, and
4587 the output of second completed job will only be printed when job 12
4588 has started.
4591 =head1 EXAMPLE: GNU Parallel as dir processor
4593 If you have a dir in which users drop files that needs to be processed
4594 you can do this on GNU/Linux (If you know what B<inotifywait> is
4595 called on other platforms file a bug report):
4597 inotifywait -qmre MOVED_TO -e CLOSE_WRITE --format %w%f my_dir |\
4598 parallel -u echo
4600 This will run the command B<echo> on each file put into B<my_dir> or
4601 subdirs of B<my_dir>.
4603 You can of course use B<-S> to distribute the jobs to remote
4604 computers:
4606 inotifywait -qmre MOVED_TO -e CLOSE_WRITE --format %w%f my_dir |\
4607 parallel -S .. -u echo
4609 If the files to be processed are in a tar file then unpacking one file
4610 and processing it immediately may be faster than first unpacking all
4611 files. Set up the dir processor as above and unpack into the dir.
4613 Using GNU B<parallel> as dir processor has the same limitations as
4614 using GNU B<parallel> as queue system/batch manager.
4617 =head1 EXAMPLE: Locate the missing package
4619 If you have downloaded source and tried compiling it, you may have seen:
4621 $ ./configure
4622 [...]
4623 checking for something.h... no
4624 configure: error: "libsomething not found"
4626 Often it is not obvious which package you should install to get that
4627 file. Debian has `apt-file` to search for a file. `tracefile` from
4628 https://gitlab.com/ole.tange/tangetools can tell which files a program
4629 tried to access. In this case we are interested in one of the last
4630 files:
4632 $ tracefile -un ./configure | tail | parallel -j0 apt-file search
4635 =head1 SPREADING BLOCKS OF DATA
4637 B<--round-robin>, B<--pipe-part>, B<--shard>, B<--bin> and
4638 B<--group-by> are all specialized versions of B<--pipe>.
4640 In the following I<n> is the number of jobslots given by B<--jobs>. A
4641 record starts with B<--recstart> and ends with B<--recend>. It is
4642 typically a full line. A chunk is a number of full records that is
4643 approximately the size of a block. A block can contain half records, a
4644 chunk cannot.
4646 B<--pipe> starts one job per chunk. It reads blocks from stdin
4647 (standard input). It finds a record end near a block border and passes
4648 a chunk to the program.
4650 B<--pipe-part> starts one job per chunk - just like normal
4651 B<--pipe>. It first finds record endings near all block borders in the
4652 file and then starts the jobs. By using B<--block -1> it will set the
4653 block size to 1/I<n> * size-of-file. Used this way it will start I<n>
4654 jobs in total.
4656 B<--round-robin> starts I<n> jobs in total. It reads a block and
4657 passes a chunk to whichever job is ready to read. It does not parse
4658 the content except for identifying where a record ends to make sure it
4659 only passes full records.
4661 B<--shard> starts I<n> jobs in total. It parses each line to read the
4662 value in the given column. Based on this value the line is passed to
4663 one of the I<n> jobs. All lines having this value will be given to the
4664 same jobslot.
4666 B<--bin> works like B<--shard> but the value of the column is the
4667 jobslot number it will be passed to. If the value is bigger than I<n>,
4668 then I<n> will be subtracted from the value until the values is
4669 smaller than or equal to I<n>.
4671 B<--group-by> starts one job per chunk. Record borders are not given
4672 by B<--recend>/B<--recstart>. Instead a record is defined by a number
4673 of lines having the same value in a given column. So the value of a
4674 given column changes at a chunk border. With B<--pipe> every line is
4675 parsed, with B<--pipe-part> only a few lines are parsed to find the
4676 chunk border.
4678 B<--group-by> can be combined with B<--round-robin> or B<--pipe-part>.
4680 =head1 QUOTING
4682 GNU B<parallel> is very liberal in quoting. You only need to quote
4683 characters that have special meaning in shell:
4685 ( ) $ ` ' " < > ; | \
4687 and depending on context these needs to be quoted, too:
4689 ~ & # ! ? space * {
4691 Therefore most people will never need more quoting than putting '\'
4692 in front of the special characters.
4694 Often you can simply put \' around every ':
4696 perl -ne '/^\S+\s+\S+$/ and print $ARGV,"\n"' file
4698 can be quoted:
4700 parallel perl -ne \''/^\S+\s+\S+$/ and print $ARGV,"\n"'\' ::: file
4702 However, when you want to use a shell variable you need to quote the
4703 $-sign. Here is an example using $PARALLEL_SEQ. This variable is set
4704 by GNU B<parallel> itself, so the evaluation of the $ must be done by
4705 the sub shell started by GNU B<parallel>:
4707 seq 10 | parallel -N2 echo seq:\$PARALLEL_SEQ arg1:{1} arg2:{2}
4709 If the variable is set before GNU B<parallel> starts you can do this:
4711 VAR=this_is_set_before_starting
4712 echo test | parallel echo {} $VAR
4714 Prints: B<test this_is_set_before_starting>
4716 It is a little more tricky if the variable contains more than one space in a row:
4718 VAR="two spaces between each word"
4719 echo test | parallel echo {} \'"$VAR"\'
4721 Prints: B<test two spaces between each word>
4723 If the variable should not be evaluated by the shell starting GNU
4724 B<parallel> but be evaluated by the sub shell started by GNU
4725 B<parallel>, then you need to quote it:
4727 echo test | parallel VAR=this_is_set_after_starting \; echo {} \$VAR
4729 Prints: B<test this_is_set_after_starting>
4731 It is a little more tricky if the variable contains space:
4733 echo test |\
4734 parallel VAR='"two spaces between each word"' echo {} \'"$VAR"\'
4736 Prints: B<test two spaces between each word>
4738 $$ is the shell variable containing the process id of the shell. This
4739 will print the process id of the shell running GNU B<parallel>:
4741 seq 10 | parallel echo $$
4743 And this will print the process ids of the sub shells started by GNU
4744 B<parallel>.
4746 seq 10 | parallel echo \$\$
4748 If the special characters should not be evaluated by the sub shell
4749 then you need to protect it against evaluation from both the shell
4750 starting GNU B<parallel> and the sub shell:
4752 echo test | parallel echo {} \\\$VAR
4754 Prints: B<test $VAR>
4756 GNU B<parallel> can protect against evaluation by the sub shell by
4757 using -q:
4759 echo test | parallel -q echo {} \$VAR
4761 Prints: B<test $VAR>
4763 This is particularly useful if you have lots of quoting. If you want
4764 to run a perl script like this:
4766 perl -ne '/^\S+\s+\S+$/ and print $ARGV,"\n"' file
4768 It needs to be quoted like one of these:
4770 ls | parallel perl -ne '/^\\S+\\s+\\S+\$/\ and\ print\ \$ARGV,\"\\n\"'
4771 ls | parallel perl -ne \''/^\S+\s+\S+$/ and print $ARGV,"\n"'\'
4773 Notice how spaces, \'s, "'s, and $'s need to be quoted. GNU B<parallel>
4774 can do the quoting by using option -q:
4776 ls | parallel -q perl -ne '/^\S+\s+\S+$/ and print $ARGV,"\n"'
4778 However, this means you cannot make the sub shell interpret special
4779 characters. For example because of B<-q> this WILL NOT WORK:
4781 ls *.gz | parallel -q "zcat {} >{.}"
4782 ls *.gz | parallel -q "zcat {} | bzip2 >{.}.bz2"
4784 because > and | need to be interpreted by the sub shell.
4786 If you get errors like:
4788 sh: -c: line 0: syntax error near unexpected token
4789 sh: Syntax error: Unterminated quoted string
4790 sh: -c: line 0: unexpected EOF while looking for matching `''
4791 sh: -c: line 1: syntax error: unexpected end of file
4792 zsh:1: no matches found:
4794 then you might try using B<-q>.
4796 If you are using B<bash> process substitution like B<<(cat foo)> then
4797 you may try B<-q> and prepending I<command> with B<bash -c>:
4799 ls | parallel -q bash -c 'wc -c <(echo {})'
4801 Or for substituting output:
4803 ls | parallel -q bash -c \
4804 'tar c {} | tee >(gzip >{}.tar.gz) | bzip2 >{}.tar.bz2'
4806 B<Conclusion>: To avoid dealing with the quoting problems it may be
4807 easier just to write a small script or a function (remember to
4808 B<export -f> the function) and have GNU B<parallel> call that.
4811 =head1 LIST RUNNING JOBS
4813 If you want a list of the jobs currently running you can run:
4815 killall -USR1 parallel
4817 GNU B<parallel> will then print the currently running jobs on stderr
4818 (standard error).
4821 =head1 COMPLETE RUNNING JOBS BUT DO NOT START NEW JOBS
4823 If you regret starting a lot of jobs you can simply break GNU B<parallel>,
4824 but if you want to make sure you do not have half-completed jobs you
4825 should send the signal B<SIGHUP> to GNU B<parallel>:
4827 killall -HUP parallel
4829 This will tell GNU B<parallel> to not start any new jobs, but wait until
4830 the currently running jobs are finished before exiting.
4833 =head1 ENVIRONMENT VARIABLES
4835 =over 9
4837 =item $PARALLEL_HOME
4839 Dir where GNU B<parallel> stores config files, semaphores, and caches
4840 information between invocations. Default: $HOME/.parallel.
4842 =item $PARALLEL_JOBSLOT
4844 Set by GNU B<parallel> and can be used in jobs run by GNU B<parallel>.
4845 Remember to quote the $, so it gets evaluated by the correct shell. Or
4846 use B<--plus> and {slot}.
4848 $PARALLEL_JOBSLOT is the jobslot of the job. It is equal to {%} unless
4849 the job is being retried. See {%} for details.
4852 =item $PARALLEL_PID
4854 Set by GNU B<parallel> and can be used in jobs run by GNU B<parallel>.
4855 Remember to quote the $, so it gets evaluated by the correct shell.
4857 This makes it possible for the jobs to communicate directly to GNU
4858 B<parallel>.
4860 B<Example:> If each of the jobs tests a solution and one of jobs finds
4861 the solution the job can tell GNU B<parallel> not to start more jobs
4862 by: B<kill -HUP $PARALLEL_PID>. This only works on the local
4863 computer.
4866 =item $PARALLEL_RSYNC_OPTS
4868 Options to pass on to B<rsync>. Defaults to: -rlDzR.
4871 =item $PARALLEL_SHELL
4873 Use this shell for the commands run by GNU B<parallel>:
4875 =over 2
4877 =item *
4879 $PARALLEL_SHELL. If undefined use:
4881 =item *
4883 The shell that started GNU B<parallel>. If that cannot be determined:
4885 =item *
4887 $SHELL. If undefined use:
4889 =item *
4891 /bin/sh
4893 =back
4896 =item $PARALLEL_SSH
4898 GNU B<parallel> defaults to using the B<ssh> command for remote
4899 access. This can be overridden with $PARALLEL_SSH, which again can be
4900 overridden with B<--ssh>. It can also be set on a per server basis
4901 (see B<--sshlogin>).
4904 =item $PARALLEL_SSHHOST
4906 Set by GNU B<parallel> and can be used in jobs run by GNU B<parallel>.
4907 Remember to quote the $, so it gets evaluated by the correct shell. Or
4908 use B<--plus> and {host}.
4911 $PARALLEL_SSHHOST is the host part of an sshlogin line. E.g.
4913 4//usr/bin/specialssh user@host
4915 becomes:
4917 host
4920 =item $PARALLEL_SSHLOGIN
4922 Set by GNU B<parallel> and can be used in jobs run by GNU B<parallel>.
4923 Remember to quote the $, so it gets evaluated by the correct shell. Or
4924 use B<--plus> and {sshlogin}.
4927 The value is the sshlogin line with number of cores removed. E.g.
4929 4//usr/bin/specialssh user@host
4931 becomes:
4933 /usr/bin/specialssh user@host
4936 =item $PARALLEL_SEQ
4938 Set by GNU B<parallel> and can be used in jobs run by GNU B<parallel>.
4939 Remember to quote the $, so it gets evaluated by the correct shell.
4941 $PARALLEL_SEQ is the sequence number of the job running.
4943 B<Example:>
4945 seq 10 | parallel -N2 \
4946 echo seq:'$'PARALLEL_SEQ arg1:{1} arg2:{2}
4948 {#} is a shorthand for $PARALLEL_SEQ.
4951 =item $PARALLEL_TMUX
4953 Path to B<tmux>. If unset the B<tmux> in $PATH is used.
4956 =item $TMPDIR
4958 Directory for temporary files. See: B<--tmpdir>.
4961 =item $PARALLEL
4963 The environment variable $PARALLEL will be used as default options for
4964 GNU B<parallel>. If the variable contains special shell characters
4965 (e.g. $, *, or space) then these need to be to be escaped with \.
4967 B<Example:>
4969 cat list | parallel -j1 -k -v ls
4970 cat list | parallel -j1 -k -v -S"myssh user@server" ls
4972 can be written as:
4974 cat list | PARALLEL="-kvj1" parallel ls
4975 cat list | PARALLEL='-kvj1 -S myssh\ user@server' \
4976 parallel echo
4978 Notice the \ after 'myssh' is needed because 'myssh' and 'user@server'
4979 must be one argument.
4981 =back
4984 =head1 DEFAULT PROFILE (CONFIG FILE)
4986 The global configuration file /etc/parallel/config, followed by user
4987 configuration file ~/.parallel/config (formerly known as .parallelrc)
4988 will be read in turn if they exist. Lines starting with '#' will be
4989 ignored. The format can follow that of the environment variable
4990 $PARALLEL, but it is often easier to simply put each option on its own
4991 line.
4993 Options on the command line take precedence, followed by the
4994 environment variable $PARALLEL, user configuration file
4995 ~/.parallel/config, and finally the global configuration file
4996 /etc/parallel/config.
4998 Note that no file that is read for options, nor the environment
4999 variable $PARALLEL, may contain retired options such as B<--tollef>.
5001 =head1 PROFILE FILES
5003 If B<--profile> set, GNU B<parallel> will read the profile from that
5004 file rather than the global or user configuration files. You can have
5005 multiple B<--profiles>.
5007 Profiles are searched for in B<~/.parallel>. If the name starts with
5008 B</> it is seen as an absolute path. If the name starts with B<./> it
5009 is seen as a relative path from current dir.
5011 Example: Profile for running a command on every sshlogin in
5012 ~/.ssh/sshlogins and prepend the output with the sshlogin:
5014 echo --tag -S .. --nonall > ~/.parallel/n
5015 parallel -Jn uptime
5017 Example: Profile for running every command with B<-j-1> and B<nice>
5019 echo -j-1 nice > ~/.parallel/nice_profile
5020 parallel -J nice_profile bzip2 -9 ::: *
5022 Example: Profile for running a perl script before every command:
5024 echo "perl -e '\$a=\$\$; print \$a,\" \",'\$PARALLEL_SEQ',\" \";';" \
5025 > ~/.parallel/pre_perl
5026 parallel -J pre_perl echo ::: *
5028 Note how the $ and " need to be quoted using \.
5030 Example: Profile for running distributed jobs with B<nice> on the
5031 remote computers:
5033 echo -S .. nice > ~/.parallel/dist
5034 parallel -J dist --trc {.}.bz2 bzip2 -9 ::: *
5037 =head1 EXIT STATUS
5039 Exit status depends on B<--halt-on-error> if one of these is used:
5040 success=X, success=Y%, fail=Y%.
5042 =over 6
5044 =item Z<>0
5046 All jobs ran without error. If success=X is used: X jobs ran without
5047 error. If success=Y% is used: Y% of the jobs ran without error.
5049 =item Z<>1-100
5051 Some of the jobs failed. The exit status gives the number of failed
5052 jobs. If Y% is used the exit status is the percentage of jobs that
5053 failed.
5055 =item Z<>101
5057 More than 100 jobs failed.
5059 =item Z<>255
5061 Other error.
5063 =item Z<>-1 (In joblog and SQL table)
5065 Killed by Ctrl-C, timeout, not enough memory or similar.
5067 =item Z<>-2 (In joblog and SQL table)
5069 skip() was called in B<{= =}>.
5071 =item Z<>-1000 (In SQL table)
5073 Job is ready to run (set by --sqlmaster).
5075 =item Z<>-1220 (In SQL table)
5077 Job is taken by worker (set by --sqlworker).
5079 =back
5081 If fail=1 is used, the exit status will be the exit status of the
5082 failing job.
5085 =head1 DIFFERENCES BETWEEN GNU Parallel AND ALTERNATIVES
5087 See: B<man parallel_alternatives>
5090 =head1 BUGS
5092 =head2 Quoting of newline
5094 Because of the way newline is quoted this will not work:
5096 echo 1,2,3 | parallel -vkd, "echo 'a{}b'"
5098 However, these will all work:
5100 echo 1,2,3 | parallel -vkd, echo a{}b
5101 echo 1,2,3 | parallel -vkd, "echo 'a'{}'b'"
5102 echo 1,2,3 | parallel -vkd, "echo 'a'"{}"'b'"
5105 =head2 Speed
5107 =head3 Startup
5109 GNU B<parallel> is slow at starting up - around 250 ms the first time
5110 and 150 ms after that.
5112 =head3 Job startup
5114 Starting a job on the local machine takes around 10 ms. This can be a
5115 big overhead if the job takes very few ms to run. Often you can group
5116 small jobs together using B<-X> which will make the overhead less
5117 significant. Or you can run multiple GNU B<parallel>s as described in
5118 B<EXAMPLE: Speeding up fast jobs>.
5120 =head3 SSH
5122 When using multiple computers GNU B<parallel> opens B<ssh> connections
5123 to them to figure out how many connections can be used reliably
5124 simultaneously (Namely SSHD's MaxStartups). This test is done for each
5125 host in serial, so if your B<--sshloginfile> contains many hosts it may
5126 be slow.
5128 If your jobs are short you may see that there are fewer jobs running
5129 on the remote systems than expected. This is due to time spent logging
5130 in and out. B<-M> may help here.
5132 =head3 Disk access
5134 A single disk can normally read data faster if it reads one file at a
5135 time instead of reading a lot of files in parallel, as this will avoid
5136 disk seeks. However, newer disk systems with multiple drives can read
5137 faster if reading from multiple files in parallel.
5139 If the jobs are of the form read-all-compute-all-write-all, so
5140 everything is read before anything is written, it may be faster to
5141 force only one disk access at the time:
5143 sem --id diskio cat file | compute | sem --id diskio cat > file
5145 If the jobs are of the form read-compute-write, so writing starts
5146 before all reading is done, it may be faster to force only one reader
5147 and writer at the time:
5149 sem --id read cat file | compute | sem --id write cat > file
5151 If the jobs are of the form read-compute-read-compute, it may be
5152 faster to run more jobs in parallel than the system has CPUs, as some
5153 of the jobs will be stuck waiting for disk access.
5155 =head2 --nice limits command length
5157 The current implementation of B<--nice> is too pessimistic in the max
5158 allowed command length. It only uses a little more than half of what
5159 it could. This affects B<-X> and B<-m>. If this becomes a real problem for
5160 you, file a bug-report.
5162 =head2 Aliases and functions do not work
5164 If you get:
5166 Can't exec "command": No such file or directory
5170 open3: exec of by command failed
5174 /bin/bash: command: command not found
5176 it may be because I<command> is not known, but it could also be
5177 because I<command> is an alias or a function. If it is a function you
5178 need to B<export -f> the function first or use B<env_parallel>. An
5179 alias will only work if you use B<env_parallel>.
5181 =head2 Database with MySQL fails randomly
5183 The B<--sql*> options may fail randomly with MySQL. This problem does
5184 not exist with PostgreSQL.
5187 =head1 REPORTING BUGS
5189 Report bugs to <bug-parallel@gnu.org> or
5190 https://savannah.gnu.org/bugs/?func=additem&group=parallel
5192 See a perfect bug report on
5193 https://lists.gnu.org/archive/html/bug-parallel/2015-01/msg00000.html
5195 Your bug report should always include:
5197 =over 2
5199 =item *
5201 The error message you get (if any). If the error message is not from
5202 GNU B<parallel> you need to show why you think GNU B<parallel> caused
5203 this.
5205 =item *
5207 The complete output of B<parallel --version>. If you are not running
5208 the latest released version (see http://ftp.gnu.org/gnu/parallel/) you
5209 should specify why you believe the problem is not fixed in that
5210 version.
5212 =item *
5214 A minimal, complete, and verifiable example (See description on
5215 https://stackoverflow.com/help/mcve).
5217 It should be a complete example that others can run which shows the
5218 problem including all files needed to run the example. This should
5219 preferably be small and simple, so try to remove as many options as
5220 possible. A combination of B<yes>, B<seq>, B<cat>, B<echo>, B<wc>, and
5221 B<sleep> can reproduce most errors. If your example requires large
5222 files, see if you can make them with something like B<seq 100000000> >
5223 B<bigfile> or B<yes | head -n 1000000000> > B<file>. If you need
5224 multiple columns: B<paste <(seq 1000) <(seq 1000 1999)>
5226 If your example requires remote execution, see if you can use
5227 B<localhost> - maybe using another login.
5229 If you have access to a different system (maybe a VirtualBox on your
5230 own machine), test if the MCVE shows the problem on that system.
5232 =item *
5234 The output of your example. If your problem is not easily reproduced
5235 by others, the output might help them figure out the problem.
5237 =item *
5239 Whether you have watched the intro videos
5240 (http://www.youtube.com/playlist?list=PL284C9FF2488BC6D1), walked
5241 through the tutorial (man parallel_tutorial), and read the EXAMPLE
5242 section in the man page (man parallel - search for EXAMPLE:).
5244 =back
5246 If you suspect the error is dependent on your environment or
5247 distribution, please see if you can reproduce the error on one of
5248 these VirtualBox images:
5249 http://sourceforge.net/projects/virtualboximage/files/
5250 http://www.osboxes.org/virtualbox-images/
5252 Specifying the name of your distribution is not enough as you may have
5253 installed software that is not in the VirtualBox images.
5255 If you cannot reproduce the error on any of the VirtualBox images
5256 above, see if you can build a VirtualBox image on which you can
5257 reproduce the error. If not you should assume the debugging will be
5258 done through you. That will put more burden on you and it is extra
5259 important you give any information that help. In general the problem
5260 will be fixed faster and with less work for you if you can reproduce
5261 the error on a VirtualBox.
5264 =head1 AUTHOR
5266 When using GNU B<parallel> for a publication please cite:
5268 O. Tange (2011): GNU Parallel - The Command-Line Power Tool, ;login:
5269 The USENIX Magazine, February 2011:42-47.
5271 This helps funding further development; and it won't cost you a cent.
5272 If you pay 10000 EUR you should feel free to use GNU Parallel without citing.
5274 Copyright (C) 2007-10-18 Ole Tange, http://ole.tange.dk
5276 Copyright (C) 2008-2010 Ole Tange, http://ole.tange.dk
5278 Copyright (C) 2010-2020 Ole Tange, http://ole.tange.dk and Free
5279 Software Foundation, Inc.
5281 Parts of the manual concerning B<xargs> compatibility is inspired by
5282 the manual of B<xargs> from GNU findutils 4.4.2.
5285 =head1 LICENSE
5287 This program is free software; you can redistribute it and/or modify
5288 it under the terms of the GNU General Public License as published by
5289 the Free Software Foundation; either version 3 of the License, or
5290 at your option any later version.
5292 This program is distributed in the hope that it will be useful,
5293 but WITHOUT ANY WARRANTY; without even the implied warranty of
5294 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5295 GNU General Public License for more details.
5297 You should have received a copy of the GNU General Public License
5298 along with this program. If not, see <http://www.gnu.org/licenses/>.
5300 =head2 Documentation license I
5302 Permission is granted to copy, distribute and/or modify this documentation
5303 under the terms of the GNU Free Documentation License, Version 1.3 or
5304 any later version published by the Free Software Foundation; with no
5305 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
5306 Texts. A copy of the license is included in the file fdl.txt.
5308 =head2 Documentation license II
5310 You are free:
5312 =over 9
5314 =item B<to Share>
5316 to copy, distribute and transmit the work
5318 =item B<to Remix>
5320 to adapt the work
5322 =back
5324 Under the following conditions:
5326 =over 9
5328 =item B<Attribution>
5330 You must attribute the work in the manner specified by the author or
5331 licensor (but not in any way that suggests that they endorse you or
5332 your use of the work).
5334 =item B<Share Alike>
5336 If you alter, transform, or build upon this work, you may distribute
5337 the resulting work only under the same, similar or a compatible
5338 license.
5340 =back
5342 With the understanding that:
5344 =over 9
5346 =item B<Waiver>
5348 Any of the above conditions can be waived if you get permission from
5349 the copyright holder.
5351 =item B<Public Domain>
5353 Where the work or any of its elements is in the public domain under
5354 applicable law, that status is in no way affected by the license.
5356 =item B<Other Rights>
5358 In no way are any of the following rights affected by the license:
5360 =over 2
5362 =item *
5364 Your fair dealing or fair use rights, or other applicable
5365 copyright exceptions and limitations;
5367 =item *
5369 The author's moral rights;
5371 =item *
5373 Rights other persons may have either in the work itself or in
5374 how the work is used, such as publicity or privacy rights.
5376 =back
5378 =back
5380 =over 9
5382 =item B<Notice>
5384 For any reuse or distribution, you must make clear to others the
5385 license terms of this work.
5387 =back
5389 A copy of the full license is included in the file as cc-by-sa.txt.
5392 =head1 DEPENDENCIES
5394 GNU B<parallel> uses Perl, and the Perl modules Getopt::Long,
5395 IPC::Open3, Symbol, IO::File, POSIX, and File::Temp.
5397 For B<--csv> it uses the Perl module Text::CSV.
5399 For remote usage it uses B<rsync> with B<ssh>.
5402 =head1 SEE ALSO
5404 B<parallel_tutorial>(1), B<env_parallel>(1), B<parset>(1),
5405 B<parsort>(1), B<parallel_alternatives>(1), B<parallel_design>(7),
5406 B<niceload>(1), B<sql>(1), B<ssh>(1), B<ssh-agent>(1), B<sshpass>(1),
5407 B<ssh-copy-id>(1), B<rsync>(1)
5409 =cut