Thursday, October 8, 2009

Is your NumPy using the right ATLAS?

Here's a tip I got from my colleague Martin. Making sure that your NumPy installation uses the right back-end can drastically improve performance. ATLAS is the software library used by NumPy (and Matlab, Octave etc.) to do linear algebra.

Try running the following 1000*1000 matrix multiplication test:

>>> from numpy import *
>>> import time
>>> A = random.random((1000,1000))
>>> B = random.random((1000,1000))
>>> t = time.time(); dot(A,B); print time.time()-t

Disappointed about the time this takes? Take a minute to check that you are running the right ATLAS for your computer. On my Mac this test was fast (0.2-0.3s) but on my desktop running Ubuntu very slow (5-6s). In Ubuntu, open the Package Manager and search for "atlas". If you find something like "libatlas3gf-base" you are using a generic version that works on most hardware. Unless your computer is antique, you can probably do better. Try selecting "libatlas3gf-sse2" (or even libatlas3gf-sse1 if this doesn't work) instead and run the test again. (on other linux platforms the process should be similar)

Tests I did on a couple of machines show speedup of a factor 4-10. Well worth the minute it takes to check and fix. Thanks Martin!

6 comments:

speedup pc with one click said...

Friend if you are again thinking about, “How to speed up your computer?” This is the exact answer that is computer speedup which will speedup your computer just by deleting corrupted files from your computer.

Dat Chu said...

A great post as always. I didn't realize Ubuntu comes with atlas packages built for SSE2. Thank you.

how to ollie said...

Excellent post and writing style. Bookmarked.

JoeK said...

Cool. Installed SSE2 lib and that test runs 4x faster!

andrewtcurtis said...

If you install atlas from source it will run a whole slew of benchmarks to tune itself to your hardware. The sse2 packages are still quite 'generic' in the sense that they are built for average values of memory and cache sizes and latencies.

While you won't see the huge gains compared to going from non sse to vectorized instruction sets, you could still be looking at a few percent!

The same is true for fftw!

Jenney said...

Wow this is very nice blog when I saw it then I become very happy so that i want to share my knowledge about a Canada Cartridge. Toner Parts Offer High Quality and affordable Ink and Toner Cartridges in Canada & US. Toner Cartridges US & Canada, Discount inkjet and toner cartridges, Inkjet Printer cartridges, and LaserJet Printer cartridges, Compatible and OEM Toner Cartridges.

Post a Comment