# Eigenvectors: Mathematica vs. LAPACK dgeev

I've been using LAPACK dgeev in FORTRAN in the last months spending hours to diagonalize ~4000*4000 matrices. It takes about 2'75 hours to find eigenvalues and eigenvectors this way. I thought FORTRAN should be faster than Mathematica as it usually is for this kind of tasks. After all this hard work and coding effort I have just realized Mathematica does the same in <15 minutes. What is happening?

The LAPACK/BLAS implementation surely matters, but even with the reference BLAS (via the Numpy python library) it took less than 15 minutes (on a Core i7 laptop) to compute the eigenvalues for a random 4000*4000 real matrix.

Was your matrix real or complex? Are you able to check the performance from eg. R or python, just to exclude the chance of errors in the Fortran code?

• My matrix is a tridiagonal non-symmetric real matrix. I'm sorry I can not compare with other tools, but if it helps, everything in the code that is not the diagonalization call is analogous in both codes, and the output (eigenvalues and eigenvectors) are the same. Sep 29 '13 at 21:39

The LAPACK routine dgeev in turn calls routines from the BLAS library to perform more basic linear algebra such as matrix-matrix multiplications. It's likely that the slow performance of dgeev on your problem is caused by using a BLAS library that isn't highly optimized.

Do you know which implementation of BLAS you're using with your Fortran code?

• I use the BLAS that comes with this LAPACK version Sep 29 '13 at 21:33

dgeev is meant for smallish matrices where you need all eigenvalues. It may be that Mathematica is using a smarter but completely different method, such as Krylov subspace methods to generate the eigenvalues for your matrices.