How to run parallel for loops

I am not very familiar with bash, but would like to break this code so that I can run it on a server with 12 processors:

#!/bin/bash #bashScript.sh for i in {1..209} do Rscript Compute.R $i done 

How can I achieve this?

Thanks!

+4
source share
3 answers

Use xargs with the --max-procs ( -P ) option. If there are enough arguments, xargs will use exactly this number of parallel processes to process input:

 #! /bin/bash seq 209 | xargs -P12 -r -n1 Rscript Compute.R 
+4
source

Try:

 #!/bin/bash #bashScript.sh for i in {1..209} do Rscript Compute.R $i & done 
+1
source

Using the GNU Parallel Interface:

 parallel Rscript Compute.R ::: {1..209} 

Installation in 10 seconds:

 wget -O - pi.dk/3 | sh 

Watch the video for a quick introduction: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

+1
source

Source: https://habr.com/ru/post/1492373/


All Articles