2

Sorry if this is a repeat question and I know there are a lot of similar questions out there, but I am really struggling to find a simple answer that works.

I want to run an executable many times eg.

seq 100 | xargs -Iz ./program

However I would like to run this over multiple cores on my machine (currently on a macbook pro so 4 cores) to speed things up.

I have tried using gnu parallel by looking at other answers on here as that seems to be what I want and have it installed but I can't work out how parallel works and what arguments I need in what order. Non of the readme is helping as it is trying to do much more complicated things than I want to.

Could anyone help me? Thanks

5
  • 1
    It helps if you edit your question and show the first 3 commands that you would want GNU Parallel to run... then we can work out the incantation! Commented Apr 27, 2020 at 13:10
  • I just want to run the same executable in parallel rather than sequence. It is exactly the same every time it just takes around 6 hours to do 100 runs using the above code. Commented Apr 27, 2020 at 13:42
  • So you want run ./program then ./program then ./program all with no arguments and in parallel? Commented Apr 27, 2020 at 13:44
  • Yeah. The program already has all its input arguments. I want to evaluate a variable in the program and how it generates each time so do to that I need to run the whole thing lots and lots of times. Commented Apr 27, 2020 at 13:58
  • You could just add -n 1 -P 8 to your xargs command Commented Apr 27, 2020 at 16:39

1 Answer 1

2

So, in order to run ./program 100 times, with GNU Parallel all you need is:

parallel -N0 ./program ::: {1..100}

If your CPU has 8 cores, it will keep 8 running in parallel till all jobs are done. If you want to run, say 12, in parallel:

parallel -j 12 -N0 ./program ::: {1..100}
Sign up to request clarification or add additional context in comments.

2 Comments

That's perfect. I knew it would be simple I just could work out which arguments i needed and in which order and all the examples were trying to do more complicated things! If I wanted to limit it so that it only ran on 3 out of 4 cores so I could carry on working what would I change?
You could use parallel -j 3 -N0 ... or parallel -j 75% -N0 ... for 3 cores out of 4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.