Sample Header Ad - 728x90

GNU parallel: why does diagnostic output look like sequential execution rather than parallel execution?

2 votes
1 answer
51 views
Scenario:
$ cat libs.txt
lib.a
lib1.a

$ cat t1a.sh
f1()
{
        local lib=$1
        stdbuf -o0 printf "job for $lib started\n"
        sleep 2
        stdbuf -o0 printf "job for $lib done\n"
}
export -f f1
cat libs.txt | SHELL=$(type -p bash) parallel --jobs 2 f1
Invocation and output:
$ time bash t1a.sh
job for lib.a started
job for lib.a done
job for lib1.a started
job for lib1.a done

real    0m2.129s
user    0m0.117s
sys     0m0.033s
Here we see that execution of f1 was indeed in parallel (real 0m2.129s). However, diagnostic output looks like execution was sequential. I expected the following diagnostic output:
job for lib.a started
job for lib1.a started
job for lib.a done
job for lib1.a done
Why does diagnostic output look like sequential execution rather than parallel execution? How to fix the diagnostic output so that it does look like parallel execution?
Asked by pmor (665 rep)
Feb 1, 2024, 12:45 PM
Last activity: Feb 1, 2024, 02:35 PM