I am trying to run a single R file multiple times at the same time with different arguments. GNU Parallel is not an option for me because I am running this on a server where I'm not authorized to install Parallel. So I chose the bash command &.
command1 & command2 & command3 ..... command30
However, when I run this, it is not behaving as expected. In the commands I am saving the output of each command to a new file and I notice that some of the files are empty. Actually most of them. So I'm guessing by only writing the above, some of the processes are being killed.
However, when I give
command1 &
command2 &
command3 &
command4 &
wait &
command5 &
command6 &
command7 &
command8 &
wait
.
.
.
It works fine, but the problem is it takes almost 5 time more time than running only command1 because it waits till the previous commands are finished. Time is very important factor here and I want all the commands to run in the same time (almost) as it would take for just one command.
- Why is this happening that without
waitit "crashes"? - Is there any way I can improve the time so that all the commands can run at the time taken by only one command?
- Is there any way I can implement this without using
wait?
(Technically I know & doesn't make processes run in parallel but it creates a different processes for every command).
Thanks in advance!
My original code:
Rscript svmRScript_v2.r 0.05 1 > output/out0.1-10.txt &
Rscript svmRScript_v2.r 0.05 2 > output/out0.05-2.txt &
Rscript svmRScript_v2.r 0.05 5 > output/out0.05-5.txt &
Rscript svmRScript_v2.r 0.05 10 > output/out0.05-10.txt &
wait &
Rscript svmRScript_v2.r 0.05 50 > output/out0.05-50.txt &
Rscript svmRScript_v2.r 0.05 100 > output/out0.05-100.txt &
Rscript svmRScript_v2.r 0.05 500 > output/out0.05-500.txt &
Rscript svmRScript_v2.r 0.01 1 > output/out0.1-10.txt &
wait &
Rscript svmRScript_v2.r 0.01 2 > output/out0.01-2.txt &
Rscript svmRScript_v2.r 0.01 5 > output/out0.01-5.txt &
Rscript svmRScript_v2.r 0.01 10 > output/out0.01-10.txt &
Rscript svmRScript_v2.r 0.01 50 > output/out0.01-50.txt &
wait &
Rscript svmRScript_v2.r 0.01 100 > output/out0.01-100.txt &
Rscript svmRScript_v2.r 0.01 500 > output/out0.01-500.txt &
Rscript svmRScript_v2.r 0.005 1 > output/out0.1-10.txt &
Rscript svmRScript_v2.r 0.005 2 > output/out0.005-2.txt
&is not a command. Technically, it's a command separator; but you could also view it as a postfix operator.waitshould be a process ID. It is extremely unlikely that any if your processes would obtain the PID 5.