Prerequisites
#mkdir parallel_tutorial
#cd parallel_tutorial
#GET=$(echo wget -qO -)
#LATEST=$($GET http://ftpmirror.gnu.org/parallel | perl -ne '/(parallel-\d{8})/ and print $1."\n"' | sort | tail -n1)
#$GET http://ftpmirror.gnu.org/parallel/$LATEST.tar.bz2 > $LATEST.tar.bz2
#$GET http://ftpmirror.gnu.org/parallel/$LATEST.tar.bz2.sig > $LATEST.tar.bz2.sig
#gpg --keyserver keys.gnupg.net --recv-key 88888888
#gpg --with-fingerprint $LATEST.tar.bz2.sig 2>&1 | grep -e RSA -e 'CDA0 1A42 08C4 F745 0610 7E7B D1AB 4516 8888 8888'
#bzip2 -dc $LATEST.tar.bz2 | tar xf -
#cd $LATEST
#./configure
#make
#make install
#echo -e '--gnu' > /etc/parallel/config
#cd ..
#rm -rf $LATEST*
#which parallel
#file /usr/local/bin/parallel
#parallel --bibtex
>will cite
#parallel -k echo ::: A B C > abc-file
#parallel -k echo ::: D E F > def-file
#perl -e 'printf "A\0B\0C\0"' > abc0-file
#perl -e 'printf "A_B_C_"' > abc_-file
#perl -e 'printf "f1\tf2\nA\tB\nC\tD\n"' > tsv-file.tsv
#perl -e 'for(1..30000){print "$_\n"}' > num30000
#perl -e 'for(1..1000000){print "$_\n"}' > num1000000
#(echo %head1; echo %head2; perl -e 'for(1..10){print "$_\n"}') > num_%header
#SERVER1=192.168.1.1
#SERVER2=192.168.1.2
#ssh-keygen
#ssh-copy-id -i /root/.ssh/id_rsa.pub $SERVER1
#ssh-copy-id -i /root/.ssh/id_rsa.pub $SERVER2
#ssh $SERVER1 echo works
#ssh $SERVER2 echo works
A single input source
#parallel echo ::: A B C
#parallel -a abc-file echo
#cat abc-file | parallel echo
Multiple input sources
#parallel echo ::: A B C ::: D E F
#parallel -a abc-file -a def-file echo
#cat abc-file | parallel -a - -a def-file echo
#cat abc-file | parallel echo :::: - def-file
#parallel echo ::: A B C :::: def-file
#parallel --xapply echo ::: A B C D E ::: F G
#parallel --xapply echo ::: A B C D E ::: F G
Changing the argument separator/delimiter
#parallel --arg-sep ,, --arg-file-sep // echo ,, A B C // def-file
#parallel -d _ echo :::: abc_-file
#parallel -d '\0' echo :::: abc0-file
#parallel -0 echo :::: abc0-file
End-of-file value for input source
# parallel -E stop echo ::: A B stop C D
Skipping empty lines
# echo -e "1\n\n\n\n\n2\n" | parallel --no-run-if-empty echo
No command means arguments are commands
# parallel ::: ls 'echo foo' pwd
The 5 replacement strings
#parallel echo ::: A/B.C
#parallel echo {} ::: A/B.C
#parallel echo {.} ::: A/B.C
#parallel echo {/} ::: A/B.C
#parallel echo {//} ::: A/B.C
#parallel echo {/.} ::: A/B.C
#parallel echo {#} ::: A B C # gives the job number
Changing the replacement strings
#parallel -I ,, echo ,, ::: A/B.C
#parallel --extensionreplace ,, echo ,, ::: A/B.C
#parallel --basenamereplace ,, echo ,, ::: A/B.C
#parallel --dirnamereplace ,, echo ,, ::: A/B.C
#parallel --basenameextensionreplace ,, echo ,, ::: A/B.C
#parallel --seqreplace ,, echo ,, ::: A B C
Positional replacement strings
#parallel echo {1} and {2} ::: A B ::: C D
#parallel echo /={1/} //={1//} /.={1/.} .={1.} ::: A/B.C D/E.F
#parallel echo 1={1} 2={2} 3={3} -1={-1} -2={-2} -3={-3} ::: A B ::: C D ::: E F
Input from columns
# parallel --colsep '\t' echo 1={1} 2={2} :::: tsv-file.tsv
Header defined replacement strings
# parallel --header : --colsep '\t' echo f1={f1} f2={f2} :::: tsv-file.tsv
More than one argument
#cat num30000 | parallel --xargs echo | wc -l
#cat num30000 | parallel --xargs -s 10000 echo | wc -l
#cat num30000 | parallel --jobs 4 -m echo | wc -l
#parallel --jobs 4 -m echo pre-{}-post ::: A B C D E F G
#parallel --jobs 4 -X echo pre-{}-post ::: A B C D E F G
#parallel -N3 echo ::: A B C D E F G H
Quoting
#parallel -q perl -e 'print "@ARGV\n"' ::: This works
#parallel perl -e \''print "@ARGV\n"'\' ::: This works
Trimming space
#parallel --trim r echo pre-{}-post ::: ' A '
#parallel --trim l echo pre-{}-post ::: ' A '
#parallel --trim lr echo pre-{}-post ::: ' A '
Controling the output
#parallel --tag echo foo-{} ::: A B C
#parallel --tagstring {}-bar echo foo-{} ::: A B C
#parallel --dryrun echo {} ::: A B C
#parallel --verbose echo {} ::: A B C
#parallel -j2 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
#parallel -j2 --ungroup 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
#parallel -j2 --linebuffer 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
#parallel -j2 -k 'printf "%s-start\n%s" {} {};sleep {};printf "%s\n" -middle;echo {}-end' ::: 4 2 1
Saving output into files
#parallel --files ::: A B C
#parallel --tmpdir /var/tmp --files ::: A B C
#TMPDIR=/var/tmp parallel --files ::: A B C
#parallel --results outdir echo ::: A B C
#find outdir | grep std
Number of simultaneous jobs
## 64 jobs/#core
#/usr/bin/time parallel -N0 -j64 sleep 1 ::: {1..128}
## 1 job/#core
#/usr/bin/time parallel -N0 sleep 1 ::: {1..128}
##2 jobs for each core
#/usr/bin/time parallel -N0 --jobs 200% sleep 1 ::: {1..128}
##Run as may jobs in parallel as possible
#/usr/bin/time parallel -N0 --jobs 0 sleep 1 ::: {1..128}
#parallel --use-cpus-instead-of-cores -N0 sleep 1 ::: {1..128}
Interactiveness
#parallel --interactive echo ::: 1 2 3
#parallel -X --dry-run --tty vi ::: 1 2 3
#parallel --dry-run --tty vi ::: 1 2 3
Timing
#parallel --delay 2.5 echo Starting {}\;date ::: 1 2 3
#parallel --timeout 2.1 sleep {}\; echo {} ::: 1 2 3 4
#parallel --timeout 200% sleep {}\; echo {} ::: 2.1 2.2 3 7 2.3
#parallel --eta sleep ::: 1 3 2 2 1 3 3 2 1
Progress
#parallel --progress sleep ::: 1 3 2 2 1 3 3 2 1
#parallel --joblog /tmp/log exit ::: 1 2 3 0
#cat /tmp/log
Termination
#parallel -j2 --halt 1 echo {}\; exit {} ::: 0 0 1 2 3
#parallel -j2 --halt 2 echo {}\; exit {} ::: 0 0 1 2 3
#parallel -k --retries 3 'echo tried {} >>/tmp/runs; echo completed {}; exit {}' ::: 1 2 0
#cat /tmp/runs
Limiting the ressources
#parallel --load 100% echo load is less than {} job per cpu ::: 1
#parallel --noswap echo the system is not swapping ::: now
#parallel --nice 17 echo this is being run with nice -n ::: 17
Sshlogin
#parallel -S 1/$SERVER1 echo running on {} (1 CPU)::: $SERVER1
#parallel -S $SERVER1,$SERVER2 'hostname; echo {}' ::: running on more hosts
Transferring files
#echo This is input_file > input_file
#parallel -S $SERVER1 --transfer --return {}.out --cleanup cat {} ">" {}.out ::: input_file
#cat input_file.out
#echo common data > common_file
#parallel --basefile common_file -S $SERVER1 --cleanup cat common_file\; echo {} ::: foo
Running the same commands on all hosts
#parallel --onall -S $SERVER1,$SERVER2 echo ::: foo bar
#parallel --nonall -S $SERVER1,$SERVER2 echo foo bar
References
http://www.gnu.org/software/parallel/parallel_tutorial.html
No comments:
Post a Comment