8

Is there a significant performance difference between Matlab numerical routines exposed as a C/C++ dll through Matlab mcc versus equivalent routines found in Math Kernel Library?

I'm particularly interested in the performance of linear least square solvers such as ?gels and fourier transform routines.

dave
  • 81
  • 2
  • 4
    Matlab uses MKL underneath so I suspect not a big difference. (Switched from Atlas to MKL some years ago). I don't know exactly for what though. – robince Apr 10 '11 at 09:21
  • Perhaps a step in the right direction? https://dpinte.wordpress.com/2010/03/16/numpymkl-vs-matlab-performance/ – Chris Apr 11 '11 at 04:10
  • If your code is good, then C++ together with MKL will be faster than Matlab, where an extra layer exists. – xis Jul 28 '11 at 16:10
  • I have made a [MEX wrapper](http://www.imm.dtu.dk/~guuru/) around a non-linear least-squares function written in C ([CMPFIT](http://www.physics.wisc.edu/~craigm/idl/cmpfit.html)), which runs about a order of magnitude faster than the Optim. Toolbox provided `lsqnonlin` function. I guess due to algorithm differences and # of fcn calls, and a little part C. – Juhl Aug 22 '11 at 15:23
  • 1
    Matrix inversion was faster using optimally compiled C++ libraries such as UMFPACK – Mikhail Sep 29 '11 at 07:41
  • I have no concrete examples, but as @Misha says: if you can get hold of the correct C/C++ code expect it to be faster than matlab. Also don't forget that with mcc you have to transfer your data -> mwArray -> matlab and back, which does mean extra overhead. – stijn Oct 04 '11 at 10:24

2 Answers2

2

Matlab adds a layer to anything it calls, fftw, lapack, mkl.

If you compile a special version, of whatever code, it will always run faster without the matlab overhead.

If you don't know what you're doing, use built-in libs, if you're an old f77 hacker like me, I write my own routines and only use the built-in libs when I'm feeling lazy or prototyping an algorithm.

sth
  • 222,467
  • 53
  • 283
  • 367
0

For the Fourier Transform routines, I would recommand FFTW depending on the usage scenario. FFTW is optimized for a prepare-once, reuse-often scenario. So if you need to compute the same kind of transform, let's say a 1024x2000 (non-power-of-2) transform inside a loop, FFTW will be faster. If you need to compute a different transform type (dimensions change every time), then MKL will be faster.

The way FFTW works is that your software first call the prepare routine, which can take from a few ms to a few seconds (you can configure this) to check your particular platform and choose the most optimized routine. Then you can call repeatedly the transform routine with optimized parameter.

All other known libraries have fix-ed-optimization, which may or may not be optimal for your platform.

Francois
  • 23
  • 1
  • 4