4

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).

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.

PS: I have found a program called "parallel", but I'm not achieving how to make it work properly... :(

2
  • If the program hadn't written with multi-threading or multi-processing functions, you cannot make it run on multiple CPUs.You can run 2 instances of this command in the same time, and then they will probably use 2 CPUs. Commented Jun 13, 2017 at 14:53
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Unix & Linux Stack Exchange would be a better place to ask. If you feel its on-topic elsewhere, then ask for a migration Commented Jun 13, 2017 at 19:51

2 Answers 2

4

With GNU Parallel you can do:

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.

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:

Simple scheduling

GNU Parallel instead spawns a new process when one finishes - keeping the CPUs active and thus saving time:

GNU Parallel scheduling

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:

(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

Learn more

See more examples: http://www.gnu.org/software/parallel/man.html

Watch the intro videos: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

Walk through the tutorial: 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

Sign up to request clarification or add additional context in comments.

2 Comments

It sounds well, but... if the command is, for example, "oggenc -q 8 *.flac" , how would it be using parallel?
parallel oggenc -q 8 {} ::: *.flac Please walk through the tutorial before asking next question. gnu.org/software/parallel/parallel_tutorial.html
0

When you are build Linux kernel you can use -j parameter to make command.Then you can see the multiple core been used.

make -j X 

make -j number of cores + 1

Comments

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.