【发布时间】:2021-08-27 14:30:45
【问题描述】:
我在等待 R 4.1。和原生 Apple 芯片支持,以针对其他平台进行一些基准测试。我使用 M1 芯片的 MacBook Pro 上的结果让我感到不安。让我们从 Mac 开始:
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.4
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.0 tools_4.1.0
基准测试的结果是:
> N <- 20000
> M <- 2000
> X <- matrix(rnorm(N*M),N)
> system.time(crossprod(X))
user system elapsed
49.954 0.109 50.056
有趣的是,sessionInfo 在 R 控制台中有不同的输出,但结果是一样的:
> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.4
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.0
显然 R 使用了 Acclerate 框架的 BLAS 库,但基准测试相似:
> system.time(crossprod(X))
user system elapsed
49.909 0.117 50.015
在 Windows 下使用我的 Thinkpad E 580 则完全不同:
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] microbenchmark_1.4-7 RevoUtils_11.0.2 RevoUtilsMath_11.0.0
loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2 grid_4.0.2 lattice_0.20-41
计算要快得多:
> system.time(crossprod(X))
user system elapsed
2.60 0.03 0.70
Windows 使用 Microsoft R Open,这可以解释差异。在 Ubuntu 或 Fedora 上,在同一台笔记本电脑上使用 OpenBlas,结果与 Windows 相似。我不知道这是否可以预期。对我来说,macOS R 的速度莫名其妙。
【问题讨论】: