Julia的本征分解比Mathematica慢5倍? [英] Eigendecompositions are 5 times slower in Julia than in Mathematica?

查看:124
本文介绍了Julia的本征分解比Mathematica慢5倍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Julia的新手,主要在Mathematica工作,所以我可能会有一些基本的错误.我试图确定朱莉娅计算随机矩阵的本征系统所花的时间,发现它比Mathematica慢5-6倍.

I am new to Julia and primarily work in Mathematica, so I probably have a few elementary mistakes floating around. I attempted to time how long Julia took to compute the eigensystem of a random matrix, and found it was 5-6 times slower than in Mathematica.

在朱莉娅中:

D=1000*(rand(1000,1000)-0.5);
@time (E,F)=eig(D);

Out: elapsed time: 7.47950706 seconds (79638920 bytes allocated*)

在Mathematica中:

In Mathematica:

First@Timing@Eigensystem[RandomReal[{-500, 500}, {1000, 1000}]]

Out: 1.310408

对于2000 x 2000数组,这是相似的,尽管Julia的结果速度比等效的Mathematica调用慢一些,但速度仍然较慢.朱莉娅需要22秒,而Mathematica则需要8秒.

For 2000 x 2000 arrays it's similar, although the Julia result slowed down slightly less than the equivalent Mathematica call, but it's still slower; Julia takes 22 seconds, whereas Mathematica computes it in 8 seconds.

据我在 Julia标准线性库代数,分解是通过调用LAPACK来实现的,我认为这应该是非常好的,所以我对为什么Julia代码运行得这么慢感到困惑.有人知道为什么会这样吗?它正在执行Mathematica不执行的某种平衡或数组对称检测吗?还是实际上更慢?

As far as I read in the Julia standard library for linear algebra, decompositions are implemented by calling LAPACK, which I thought was supposed to be very good, so I'm confused as to why the Julia code is running so much slower. Does anyone know why this is the case? Is it doing some kind of balancing or array-symmetry-detection that Mathematica doesn't do? Or is it actually slower?

此外,这是一个语法问题,并且可能是一个愚蠢的错误,但是您如何更改Julia的平衡?我尝试过

Also, this is a syntax question and probably a silly error, but how do you change the balancing in Julia? I tried

@time (E,F)=eig(D[, balance=:nobalance]);

与从Julia手册中复制和粘贴的完全相同,但是它只是出现了语法错误,所以出了点问题.

exactly as copied and pasted from the Julia manual, but it just gave a syntax error, so something's wrong.

我正在使用Windows 7 64位版本和Julia版本0.2.0 64位版本,并使用

I am using Windows 7 64-bit, with Julia version 0.2.0 64-bit, installed using the instructions at Steven Johnson's site, with Anaconda installed first to take care of prerequisites. I am using Mathematica student edition version 9.0.1.

执行versioninfo()已产生

Julia Version 0.2.0
Commit 05c6461 (2013-11-16 23:44 UTC)
Platform Info:
System: Windows (x86_64-w64-mingw32)
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY)
LAPACK: libopenblas
LIBM: libopenlibm

因此,看来我正在将openBLAS用于LAPACK和BLAS.一旦获得Mathematica实施信息,我也将添加它.

So it looks like I'm using the openBLAS for LAPACK and BLAS. Once I get the Mathematica implementation info I will add that as well.

Windows Mathematica似乎 可能使用Intel MKL BLAS .

It appears that Windows Mathematica probably uses Intel MKL BLAS.

推荐答案

Julia中的本征计算外包给 LAPACK BLAS ,我认为Mathematica也是如此. Julia可以使用BLAS和LAPACK的不同版本,因此,您可以有效地将您选择的Julia的LAPACK和BLAS与Mathematica的LAPACK和BLAS(可能是英特尔MKL)进行比较.

The eigen calculation in Julia is outsourced to LAPACK and BLAS, and I think it is also the case for Mathematica. Julia can use different versions of BLAS and LAPACK and you are therefore effectively comparing your choice of LAPACK and BLAS for Julia with Mathematica's LAPACK and BLAS (probably Intel MKL).

Julia的默认选择是 OpenBLAS ,它在大多数体系结构上都非常快,在我的机器上,Julia在特征值计算方面比Mathematica快. .如果您使用的是Linux,并且已从存储库中选择了BLAS和LAPACK,则它们很可能比OpenBLAS慢得多.

The default choice for Julia is OpenBLAS which is fast on most architectures and on my machine Julia is faster than Mathematica for the eigen calculation. If you are on Linux and have chosen BLAS and LAPACK from a repo, it is very likely that they are much slower than OpenBLAS.

用于平衡的选项最近已添加到Julia中,并且错误地未将选项添加到函数eig中,该函数只是eigfact函数的MATLAB兼容接口.编写eigfact(A,balance=:nobalance)应该可以.

The option for balancing has recently been added to Julia and mistakenly the option was not added to the function eig, which is only a MATLAB compatible interface to the eigfact function. Writing eigfact(A,balance=:nobalance) should work.

进一步的研究表明,差异是由于Windows上的OpenBLAS中的线程问题所致.如果将Julia的BLAS限制为一个线程,则计时时间与Mathematica相当,但是如果允许更多线程,则计算速度会降低.在Mac或Linux上,这似乎不是问题,但是如上所述,通常,OpenBLAS的性能取决于体系结构.

Edit 1: Further investigation has shown that the difference is due to a threading problem in OpenBLAS on Windows. If Julia's BLAS is restricted to one thread the timings are comparable to Mathematica, but if more threads are allowed the calculation slows down. This doesn't seem to be a problem on Mac or Linux, but as mentioned above, in general the performance of OpenBLAS depends on the architecture.

最近,平衡选项已更改.可以通过编写eigfact(A,permute=false,scale=false)关闭平衡.

Edit 2: Recently, the balancing option has changed. Balancing can be switched off by writing eigfact(A,permute=false,scale=false).

这篇关于Julia的本征分解比Mathematica慢5倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆