简体   繁体   中英

Running an executable over multiple cores using a bash script

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

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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM