[Numpy-discussion] Slow Numpy/MKL vs Matlab/MKL

Derek Homeier derek at astro.physik.uni-goettingen.de
Wed Dec 7 16:50:17 EST 2011

On 07.12.2011, at 9:38PM, Oleg Mikulya wrote:

> Agree with your statement. Yes, it is MKL, indeed. For linear equations it is no difference, but there is difference for other functions. And yes, my suspicions is just threading options. How to pass them to MKL from python? Should I change some compiling options or environment options? 
You could check by monitoring the CPU usage while running the tasks - if it remains 
around 100% it is rather not using multiple threads. Generally MKL (if you linked the 
multi-threaded version, which seems to be the case, as mkl_intel_thread is in the libs) 
heeds the OMP_NUM_THREADS environment variable like other OpenMP programs. 
If that's set to your no. of cores before starting Python, it should be inherited; might also 
be possible to set it within Python (in any case you can check it with os.getenv()). 
I don't know if matlab sets different defaults so multiple threads are automatically used; 
normally I'd also expect Python to use all available cores if OMP_NUM_THREADS 
is not set at all…


> On Wed, Dec 7, 2011 at 2:02 AM, Pauli Virtanen <pav at iki.fi> wrote:
> 06.12.2011 23:31, Oleg Mikulya kirjoitti:
> > How to make Numpy to match Matlab in term of performance ? I have tryied
> > with different options, using different MKL libraries and ICC versions,
> > still Numpy is below Matalb for certain basic tasks by ~2x. About 5
> > years ago I was able to get about same speed, not anymore. Matlab
> > suppose to use same MKL, what it the reason of such Numpy slowness
> > (beside one, yet fundamental, task)?
> There should be no reason for a difference. It simply makes the calls to
> the external library, and the wrapper code is straightforward.
> If Numpy indeed is linked against MKL (check the build log), then one
> possible reason could be different threading options passed to MKL.
> --
> Pauli Virtanen
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

More information about the NumPy-Discussion mailing list