作者:手机用户2502853923 | 来源:互联网 | 2023-09-01 09:24
SomeGNULinuxcommandlineprograms(suchoggenc,toencodeaudioinoggvorbisformat)useonly
Some GNU/Linux command line programs (such "oggenc", to encode audio in ogg vorbis format) use only 1 of all the cores from your CPU. The problem is that, in my case, I have got 4 cores and that programs just use 1 core, making work the CPU at 25% (just one of the cores is working at 100%, but the other 3 are at 0% for that task).
一些GNU/Linux命令行程序(这种“oggenc”,以ogg vorbis格式编码音频)只使用CPU中所有核心的1个。问题是,在我的例子中,我有4个内核,而程序只使用1个核心,使CPU的工作效率达到25%(其中一个内核的工作效率为100%,而另外3个内核的工作效率为0%)。
It could be possible to force the using of more cores for a command line program?
有可能强制命令行程序使用更多的内核吗?
It would be great with some kind of tasks like zip, tar, oggenc, etc.
如果能完成一些像zip、tar、oggenc之类的任务,那就太棒了。
PS: I have found a program called "parallel", but I'm not achieving how to make it work properly... :(
PS:我发现了一个叫做“并行”的程序,但是我还没有找到如何让它正常工作的方法……:(
2 个解决方案
2
With GNU Parallel you can do:
使用GNU并行你可以做:
parallel gzip ::: *
parallel opusenc {} {.}.opus ::: *.wav
GNU Parallel is a general parallelizer and makes is easy to run jobs in parallel on the same machine or on multiple machines you have ssh access to.
GNU Parallel是一种通用的并行程序,它使得在同一台机器上或在有ssh访问权限的多台机器上并行运行作业变得很容易。
If you have 32 different jobs you want to run on 4 CPUs, a straight forward way to parallelize is to run 8 jobs on each CPU:
如果您想在4个CPU上运行32个不同的作业,那么并行化的直接方法是在每个CPU上运行8个作业:
GNU Parallel instead spawns a new process when one finishes - keeping the CPUs active and thus saving time:
GNU并行在完成时产生一个新的进程——保持cpu的活跃,从而节省时间:
Installation
安装
For security reasons you should install GNU Parallel with your package manager, but if GNU Parallel is not packaged for your distribution, you can do a personal installation, which does not require root access. It can be done in 10 seconds by doing this:
出于安全原因,您应该在包管理器中安装GNU并行,但是如果没有为您的发行版打包GNU并行,那么您可以进行个人安装,不需要root访问。这可以在10秒内完成:
(wget -O - pi.dk/3 || curl pi.dk/3/ || fetch -o - http://pi.dk/3) | bash
For other installation options see http://git.savannah.gnu.org/cgit/parallel.git/tree/README
有关其他安装选项,请参见http://git.savannah.gnu.org/cgit/parallel.git/tree/README
Learn more
了解更多
See more examples: http://www.gnu.org/software/parallel/man.html
看到更多的例子:http://www.gnu.org/software/parallel/man.html
Watch the intro videos: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1
观看介绍视频:https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1
Walk through the tutorial: http://www.gnu.org/software/parallel/parallel_tutorial.html
浏览教程:http://www.gnu.org/software/parallel/parallel_tutorial.html
Sign up for the email list to get support: https://lists.gnu.org/mailman/listinfo/parallel
注册电子邮件列表以获得支持:https://lists.gnu.org/mailman/listinfo/parallel