1

I'm a new Julia user and I need to find eigenvectors of large matrices as quickly as possible*. I'm having trouble getting Julia to run as fast as Matlab for the following example:

Julia

const j = 1000 ::Int

A = Array{Float64}(j,j)

B = Array{Float64}(j,j)

f(x) = eigvecs(x)

A = randn(j,j)

B = f(A)

@time f(A)

output for time: 2.950973 seconds (12.31 k allocations: 76.445 MB, 0.11% gc time)

Matlab

j = 1000;

A = randn(j,j);

tic

[v, d] = eig(A);

toc

Elapsed time is 1.161133 seconds.

I have also checked Matlab with 1 thread to compare using maxNumCompThreads = 1 but it still gives a similar time (1.16s) to before. I've also tried to speed up Julia by running twice to precompile, and also setting blas_set_num_threads(4) but this isn't helping.

I'd really appreciate any advice about how to improve my Julia code!

*(I am using Matlab 2015b and Julia 0.4.7 on OSX El Capitan 10.11.6)

Sam
  • 11
  • 4
  • 1
    Possible duplicate of [Eigendecompositions are 5 times slower in Julia than in Mathematica?](http://stackoverflow.com/questions/21641621/eigendecompositions-are-5-times-slower-in-julia-than-in-mathematica) – Dirk Eddelbuettel Oct 14 '16 at 04:34
  • 1
    Yes. Please see the other question. MKL seems to be faster than OpenBLAS for this problem. – Andreas Noack Oct 14 '16 at 14:32

1 Answers1

5

Kind of a duplicate of this discussion.

Usually when talking about Julia performance, you're talking about how the language actually works. In this case, both Julia and MATLAB are just calling well-optimized C/Fortran libraries for doing the eigenvalue calculation. This is reliant on the BLAS configuration. MATLAB ships with a version of MKL, so it's also just using a different library which in many cases is faster than OpenBLAS, but you can build Julia with MKL using the instructions in the README on the Julia Github repo. Maybe rebuilding your sysimg could help:

include(joinpath(dirname(JULIA_HOME),"share","julia","build_sysimg.jl")); build_sysimg(force=true)

If you are using a pre-built binary then it's not optimized for your system, and this will enable the optimizations.

Community
  • 1
  • 1
Chris Rackauckas
  • 18,645
  • 3
  • 50
  • 81