简体   繁体   English

使用 bash 脚本在多个内核上运行可执行文件

[英]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.但是,我想在我的机器上的多个内核上运行它(目前在 macbook pro 上,所以 4 个内核)以加快速度。

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.我已经尝试通过查看此处的其他答案来使用 gnu 并行,因为这似乎是我想要的并安装了它,但我无法弄清楚并行的工作原理以及我需要的 arguments 的顺序。 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:因此,为了运行./program 100 次,使用GNU Parallel你只需要:

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

If your CPU has 8 cores, it will keep 8 running in parallel till all jobs are done.如果您的 CPU 有 8 个内核,它将保持 8 个并行运行,直到所有作业完成。 If you want to run, say 12, in parallel:如果你想并行运行,比如说 12:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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