Skip to content

Order and Output

Jobs finish when they finish, which is rarely the order they started. Parallel gives you three ways to live with that, all run for real in transcripts t08 and t08b. The demo jobs sleep for their own input's worth of seconds — 3, 1 and 2 — so they complete 1, 2, 3 while they started 3, 1, 2.

Default: output in finish order

$ parallel -j3 'sleep {}; echo job {} finished' ::: 3 1 2
job 1 finished
job 2 finished
job 3 finished

Each job's output is printed when the job completes. Note what did not happen: the lines never interleave. Parallel collects each job's output and prints it as one block — a job's lines stay together even though the jobs overlapped. For logs and reports, that atomicity is the valuable part.

-k: output in input order

$ parallel -j3 -k 'sleep {}; echo job {} finished' ::: 3 1 2
job 3 finished
job 1 finished
job 2 finished

--keep-order holds each job's output until every earlier job's output has been printed. Jobs still run in parallel — only the printing waits. The price is memory and patience: a job whose output is held is buffered, and one slow early job delays everything behind it. Use -k when the output will be compared, diffed, or fed to something that expects the list's order — the checksum transcript in chapter 9 reads cleanly because of it.

--ungroup: output as it happens

$ parallel -j2 --ungroup 'echo start {}; sleep 1; echo end {}' ::: A B
start A
start B
end A
end B

--ungroup streams each job's output live instead of collecting it. The lines of different jobs can now interleave — here they happen to fall neatly, but two jobs printing at the same moment will mix mid-line. Its middle sibling --line-buffer streams whole lines: still live, never torn. Reach for these when watching a long job matters more than tidy output — a build or an encode you want to see moving. For anything you will read afterwards, leave the default grouping on.