Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run jobs in parallel

I would like to run a large number of intensive processes in parallel, where I loop over different parameters with for loops. A number of answers to similar questions mention that running processes in parallel can be done with xargs, but none of them seem to mention if or how this can be done if the parameters change for each command.

As an example (pseudo code):

for paramA in 1 2 3
  for paramB in 1 2 3
    ./intensiveCommand $paramA $paramB
  end
end

I would like to parallellize intensiveCommand

Or is there an easier way then using xargs?

like image 757
MaVe Avatar asked Nov 29 '13 11:11

MaVe


People also ask

What is parallel job execution?

Parallel job execution helps systems scale in performance by making optimal use of hardware resources. If your system's CPUs and disk controllers are already heavily loaded, you need to lighten the system's load or increase the hardware resources before using parallel execution to improve performance.

Why is it better to run multiple jobs in parallel versus sequentially?

You can take advantage of the cluster even better when running your jobs in parallel than in series. This way, you could execute much more tasks at once (simultaneously) and achieve a faster result. The image above depicts how a task is serially executed by a single processor.

Do GitLab jobs run in parallel?

GitLab provides a method to make clones of a job and run them in parallel for faster execution using the parallel: keyword. While parallel jobs may not help in reducing the consumption of CI minutes, they definitely help increase work productivity.


1 Answers

You can use GNU parallel. It has a --load option avoid overloading the computer.

parallel --load 100% ./intensiveCommand ::: 1 2 3 ::: 1 2 3
like image 50
damienfrancois Avatar answered Oct 12 '22 12:10

damienfrancois