motumeril
Posts: 4
Joined: Fri Feb 27, 2015 10:35 am

Using multiple cores on RPi2

Fri Mar 06, 2015 2:36 pm

Hello,

I was wondering how to use the multiple cores of my RPi2. I was integrating OpenCV and came across a step called make here, so, I could either construct the libraries by just typing make or make -j4. The second option allowed me to use all the four cores and the process was much quicker. I came across this here http://www.pyimagesearch.com/2015/02/23 ... ent-283619 in the comments.


I wanted to know how to use all the four cores while installing say scipy or matplotlib. I am installing them via pip so I tried

Code: Select all

sudo pip install matplotlib -j4
. I get an error saying

Code: Select all

install: error: no such option: -j
.

I understand that all processes cannot utilize all the cores simultaneously, but I haven't really understood the concept well. How do I differentiate which processes can use the four cores and if something can how do I enable it to do so?

Thanks in advance!

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 21531
Joined: Sat Jul 30, 2011 7:41 pm

Re: Using multiple cores on RPi2

Fri Mar 06, 2015 4:13 pm

-j [x] is just for make, and tells it how many simultaneous jobs it can do. I find 1.5x number of cores works quite well on a desktop, may not be the same on a Pi2.

Things like installing will only probably use one core - it's not a particularly easy to multithread process.

By default the Pi2 will be using more than one core anyway - the OS will be running lots of processes (ps ax to see them all!) , and they will be spread out over the cores, leaving even single threaded app with a core all to itself. Multithreaded apps, there are quite a few, will automatically know when they can use multi cores.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

motumeril
Posts: 4
Joined: Fri Feb 27, 2015 10:35 am

Re: Using multiple cores on RPi2

Mon Mar 09, 2015 1:53 pm

Hi Jamesh,
Thanks for the reply!
Okay, understood, shall try and this post updated if I find anything useful.

MikB
Posts: 18
Joined: Sat Mar 07, 2015 12:58 pm

Re: Using multiple cores on RPi2

Mon Mar 09, 2015 7:36 pm

Although I'm sure Linux is adept at spreading the load around the cores, especially when busy -- is there an easy way to shut down 1 or more of the cores -- to enter a "low power" mode as it were? Effectively allowing the PI2 to run single core, but with the option to bring the others back up when needed? Just wondering for portable/battery applications ...

cpc464
Posts: 187
Joined: Tue Jul 08, 2014 5:10 pm
Contact: Website

Re: Using multiple cores on RPi2

Tue Mar 10, 2015 2:09 pm

On the Pi 2, use this command to show which CPU core each process is running on:

ps -elfP

Check the PSR column. For multi-threaded apps like Epiphany, use this command to see which core each thread is on:

ps -eLfP | grep epip
Unix engineer since 1989

crumble
Posts: 66
Joined: Sat Feb 07, 2015 7:34 pm

Re: Using multiple cores on RPi2

Tue Mar 10, 2015 7:16 pm

Hi,

compiling openCV on all cores will show you the limits of your SD-card. The timings of your link shows that the author has a real good SD-card. Mine lags when the load gets too high. After a few minutes the lage became so bad, that it is faster to compile such a huge project with only one core.

You will see the real performance of your Pi2, if you mount /tmp, /var/log and /var/run into a tempfs and iif you nstall gcc 4.9 which can use better optimizations for the newer CPU.

It will be nice, if such basic tweaks can be integrated into raspi-config. This can save a lot of time for Linux newbies. There are many howtos in the web, but you have to no the right words.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 21531
Joined: Sat Jul 30, 2011 7:41 pm

Re: Using multiple cores on RPi2

Wed Mar 11, 2015 8:22 am

crumble wrote:Hi,

compiling openCV on all cores will show you the limits of your SD-card. The timings of your link shows that the author has a real good SD-card. Mine lags when the load gets too high. After a few minutes the lage became so bad, that it is faster to compile such a huge project with only one core.

You will see the real performance of your Pi2, if you mount /tmp, /var/log and /var/run into a tempfs and iif you nstall gcc 4.9 which can use better optimizations for the newer CPU.

It will be nice, if such basic tweaks can be integrated into raspi-config. This can save a lot of time for Linux newbies. There are many howtos in the web, but you have to no the right words.
I suspect that is more to do with memory than SD card speed. Multiple builds at the same times uses a LOT of memory. If you exceed the 1GB, then it will start to swap, and that is very slow. Will be especially noticeable on C++ builds that use templates which require large amounts of memory.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

ziddey
Posts: 19
Joined: Thu Mar 10, 2016 7:42 am

Re: Using multiple cores on RPi2

Thu Mar 10, 2016 7:48 am

This might help: http://stackoverflow.com/questions/2622 ... -multicore

--install-option="--jobs=4"

Or 6 if 1.5x cores is optimal

ziddey
Posts: 19
Joined: Thu Mar 10, 2016 7:42 am

Re: Using multiple cores on RPi2

Thu Mar 10, 2016 8:10 am

My last post is still in moderation, but I just did a test installing pandas. Using --jobs=6 didn't seem to have an effect. However, at one point, it failed because six didn't recognize the flag. I tried -j6, and it seemed to work. However, I segfaulted. Not sure if it's because my overclock is unstable or I ran out of memory (also segfaulted on a 512mb rpi1 before I upped the swap). Just got the rpi3 today and have been running it at 1400 +6 from the get-go.

Edit: seems to be a bust as well. Sorry for getting your hopes up

Return to “Advanced users”