如何确定我的R安装使用的矩阵库?

时间:2021-07-05 23:31:42

I am having a matrix error when using the computer cluster at my university that I cannot reproduce on my local machine. I think it might be due to a difference of matrix libraries (BLAS, LAPACK, ATLAS, etc.). I don't know much about these libraries other than what I've read here, but I'm thinking there should be a way to get R to tell me which matrix libraries it was installed with (i.e. which ones it's using), analogous to sessionInfo() to tell me which version of R packages it's using.

在我的大学使用我无法在本地计算机上重现的计算机群集时出现矩阵错误。我认为这可能是由于矩阵库(BLAS,LAPACK,ATLAS等)的不同。除了我在这里阅读的内容之外,我对这些库知之甚少,但我认为应该有办法让R告诉我它安装了哪些矩阵库(即它使用的是哪些),类似的到sessionInfo()告诉我它正在使用哪个版本的R包。

3 个解决方案

#1


5  

Though there may not be an explicit R function for this, perhaps you can capitalize on shell commands (e.g., file and ldd) to get some clues without requiring rebuilding R nor root access on the cluster:

虽然可能没有明确的R函数,但也许你可以利用shell命令(例如,file和ldd)获得一些线索,而不需要在集群上重建R和root访问:

(rpath <- Sys.which("R"))
#            R
# "/usr/bin/R"

To make sure that ldd will work, see what type of file it is:

要确保ldd可以正常工作,请查看它是什么类型的文件:

system2("file", rpath)
# /usr/bin/R: Bourne-Again shell script, ASCII text executable

If yours shows an actual executable (such as ELF 64-bit LSB executable, x86-64, ...), then skip this one step.

如果您的显示实际可执行文件(例如ELF 64位LSB可执行文件,x86-64,...),则跳过此步骤。

script <- readLines(rpath)
script[grepl("/bin/", script)]
# [1] "#!/bin/bash"
# [2] "     if [ -x \"/usr/${libnn}/R/bin/exec/R\" ]; then"
# [3] "     elif [ -x \"/usr/${libnn_fallback}/R/bin/exec/R\" ]; then"
# [4] "## some systems have a more portable sed, e.g. /usr/xpg4/bin/sed on Solaris,"
# [5] "SED=/bin/sed"
# [6] "      exec sh \"${R_HOME}/bin/Rcmd\" \"${@}\" ;;"
# [7] "R_binary=\"${R_HOME}/bin/exec${R_ARCH}/R\""

This tells me that the actual executable is /usr/lib/R/bin/exec/R (or /usr/lib64/...). It is taking some inference, but it's a step. This is working for me with R-3.3.2 on ubuntu, so I can only assume it'll be similar on different OSes. If this is uninformative, you can also grep for "/lib" or "/exec" (or just examine the whole script file for other clues).

这告诉我实际的可执行文件是/ usr / lib / R / bin / exec / R(或/ usr / lib64 / ...)。这是一个推论,但这是一个步骤。这对我来说在Ubuntu上使用R-3.3.2,所以我只能假设它在不同的操作系统上是相似的。如果这是没有信息的,你也可以grep“/ lib”或“/ exec”(或者只是检查整个脚本文件以获取其他线索)。

Once you know the path called by the script (or if it isn't a script to begin with), find the shared library dependencies:

一旦您知道脚本调用的路径(或者它不是一个开头的脚本),找到共享库依赖项:

system2("ldd", "/usr/lib/R/bin/exec/R")
#         linux-vdso.so.1 =>  (0x00007ffcfadcd000)
#         libR.so => /usr/lib/R/lib/libR.so (0x00007f746f615000)
#         libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f746f3eb000)
#         libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f746f025000)
#         libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f746eda8000)
#         libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f746eaa2000)
#         libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007f746e85b000)
#         libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f746e61d000)
#         liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f746e3fb000)
#         libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f746e1ea000)
#         libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f746dfd1000)
#         librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f746ddc9000)
#         libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f746dbc4000)
#         libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f746d9b5000)
#         /lib64/ld-linux-x86-64.so.2 (0x0000560abd5fa000)
#         libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f746d78b000)

The 5th line of this output suggests that R is using the BLAS library, specifically libblas3.

此输出的第5行表明R正在使用BLAS库,特别是libblas3。

#2


4  

As far as I am aware there isn’t a specific function (especially not in base R) that will give you the BLAS version. R will most likely use the standard library that comes with your system (unless someone built it from source with a specific BLAS version).

据我所知,没有特定的功能(特别是在基础R中),它将为您提供BLAS版本。 R很可能会使用系统附带的标准库(除非有人使用特定的BLAS版本从源代码构建它)。

You’d have to do it from the terminal, type

您必须从终端进行输入,输入

locate libblas.so

It’s probably going to be in /usr/lib/libblas.so or /usr/lib64/libblas.so, and the location is probably a symlink. So follow the links

它可能会在/usr/lib/libblas.so或/usr/lib64/libblas.so中,并且该位置可能是符号链接。请按照链接进行操作

ls -l /usr/lib/libblas.so

If you want to to change the symbolic links to point to a different BLAS library, you can do update-alternatives --config libblas.so.3gf and select the version you want to use. This post explains it very nicely in more detail: https://www.r-bloggers.com/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to-switch-to-on-ubuntu/

如果要将符号链接更改为指向其他BLAS库,可以执行update-alternatives --config libblas.so.3gf并选择要使用的版本。这篇文章更详细地解释了它:https://www.r-bloggers.com/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to-switch-to-on- Ubuntu的/

Another way to definitely know what version you are using, would be to install whatever implementation of BLAS you want – for example OpenBLAS, and then replace the standard R BLAS library with a symlink to your new library. Make sure to install R with --with-shared-blas option, as explained in here: https://cran.r-project.org/doc/manuals/r-release/R-admin.html#BLAS Then you just need to:

另一种明确知道你正在使用的版本的方法是安装你想要的任何BLAS实现 - 例如OpenBLAS,然后用符号链接替换标准的R BLAS库到你的新库。确保使用--with-shared-blas选项安装R,如下所述:https://cran.r-project.org/doc/manuals/r-release/R-admin.html#BLAS然后你就是需要:

# navigate to your R directory
cd  …/path-to-R-installation/lib/R/lib
# backup the original 
mv libRblas.so libRblas.backup 
# create simlink
ln –s …/path-to-new-0blas-library/new-lib.so libRblas.so

#3


-3  

Is a bit of googling enough?: http://www.stat.cmu.edu/~nmv/2013/07/09/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to-switch-to-on-ubuntu/

是否有足够的谷歌搜索?:http://www.stat.cmu.edu/~nmv/2013/07/09/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to -SWITCH到上的ubuntu /

#1


5  

Though there may not be an explicit R function for this, perhaps you can capitalize on shell commands (e.g., file and ldd) to get some clues without requiring rebuilding R nor root access on the cluster:

虽然可能没有明确的R函数,但也许你可以利用shell命令(例如,file和ldd)获得一些线索,而不需要在集群上重建R和root访问:

(rpath <- Sys.which("R"))
#            R
# "/usr/bin/R"

To make sure that ldd will work, see what type of file it is:

要确保ldd可以正常工作,请查看它是什么类型的文件:

system2("file", rpath)
# /usr/bin/R: Bourne-Again shell script, ASCII text executable

If yours shows an actual executable (such as ELF 64-bit LSB executable, x86-64, ...), then skip this one step.

如果您的显示实际可执行文件(例如ELF 64位LSB可执行文件,x86-64,...),则跳过此步骤。

script <- readLines(rpath)
script[grepl("/bin/", script)]
# [1] "#!/bin/bash"
# [2] "     if [ -x \"/usr/${libnn}/R/bin/exec/R\" ]; then"
# [3] "     elif [ -x \"/usr/${libnn_fallback}/R/bin/exec/R\" ]; then"
# [4] "## some systems have a more portable sed, e.g. /usr/xpg4/bin/sed on Solaris,"
# [5] "SED=/bin/sed"
# [6] "      exec sh \"${R_HOME}/bin/Rcmd\" \"${@}\" ;;"
# [7] "R_binary=\"${R_HOME}/bin/exec${R_ARCH}/R\""

This tells me that the actual executable is /usr/lib/R/bin/exec/R (or /usr/lib64/...). It is taking some inference, but it's a step. This is working for me with R-3.3.2 on ubuntu, so I can only assume it'll be similar on different OSes. If this is uninformative, you can also grep for "/lib" or "/exec" (or just examine the whole script file for other clues).

这告诉我实际的可执行文件是/ usr / lib / R / bin / exec / R(或/ usr / lib64 / ...)。这是一个推论,但这是一个步骤。这对我来说在Ubuntu上使用R-3.3.2,所以我只能假设它在不同的操作系统上是相似的。如果这是没有信息的,你也可以grep“/ lib”或“/ exec”(或者只是检查整个脚本文件以获取其他线索)。

Once you know the path called by the script (or if it isn't a script to begin with), find the shared library dependencies:

一旦您知道脚本调用的路径(或者它不是一个开头的脚本),找到共享库依赖项:

system2("ldd", "/usr/lib/R/bin/exec/R")
#         linux-vdso.so.1 =>  (0x00007ffcfadcd000)
#         libR.so => /usr/lib/R/lib/libR.so (0x00007f746f615000)
#         libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f746f3eb000)
#         libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f746f025000)
#         libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f746eda8000)
#         libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f746eaa2000)
#         libreadline.so.6 => /lib/x86_64-linux-gnu/libreadline.so.6 (0x00007f746e85b000)
#         libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f746e61d000)
#         liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f746e3fb000)
#         libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f746e1ea000)
#         libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f746dfd1000)
#         librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f746ddc9000)
#         libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f746dbc4000)
#         libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f746d9b5000)
#         /lib64/ld-linux-x86-64.so.2 (0x0000560abd5fa000)
#         libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f746d78b000)

The 5th line of this output suggests that R is using the BLAS library, specifically libblas3.

此输出的第5行表明R正在使用BLAS库,特别是libblas3。

#2


4  

As far as I am aware there isn’t a specific function (especially not in base R) that will give you the BLAS version. R will most likely use the standard library that comes with your system (unless someone built it from source with a specific BLAS version).

据我所知,没有特定的功能(特别是在基础R中),它将为您提供BLAS版本。 R很可能会使用系统附带的标准库(除非有人使用特定的BLAS版本从源代码构建它)。

You’d have to do it from the terminal, type

您必须从终端进行输入,输入

locate libblas.so

It’s probably going to be in /usr/lib/libblas.so or /usr/lib64/libblas.so, and the location is probably a symlink. So follow the links

它可能会在/usr/lib/libblas.so或/usr/lib64/libblas.so中,并且该位置可能是符号链接。请按照链接进行操作

ls -l /usr/lib/libblas.so

If you want to to change the symbolic links to point to a different BLAS library, you can do update-alternatives --config libblas.so.3gf and select the version you want to use. This post explains it very nicely in more detail: https://www.r-bloggers.com/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to-switch-to-on-ubuntu/

如果要将符号链接更改为指向其他BLAS库,可以执行update-alternatives --config libblas.so.3gf并选择要使用的版本。这篇文章更详细地解释了它:https://www.r-bloggers.com/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to-switch-to-on- Ubuntu的/

Another way to definitely know what version you are using, would be to install whatever implementation of BLAS you want – for example OpenBLAS, and then replace the standard R BLAS library with a symlink to your new library. Make sure to install R with --with-shared-blas option, as explained in here: https://cran.r-project.org/doc/manuals/r-release/R-admin.html#BLAS Then you just need to:

另一种明确知道你正在使用的版本的方法是安装你想要的任何BLAS实现 - 例如OpenBLAS,然后用符号链接替换标准的R BLAS库到你的新库。确保使用--with-shared-blas选项安装R,如下所述:https://cran.r-project.org/doc/manuals/r-release/R-admin.html#BLAS然后你就是需要:

# navigate to your R directory
cd  …/path-to-R-installation/lib/R/lib
# backup the original 
mv libRblas.so libRblas.backup 
# create simlink
ln –s …/path-to-new-0blas-library/new-lib.so libRblas.so

#3


-3  

Is a bit of googling enough?: http://www.stat.cmu.edu/~nmv/2013/07/09/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to-switch-to-on-ubuntu/

是否有足够的谷歌搜索?:http://www.stat.cmu.edu/~nmv/2013/07/09/for-faster-r-use-openblas-instead-better-than-atlas-trivial-to -SWITCH到上的ubuntu /