rbuildlapackblasatlas

How can I determine which matrix libraries my R install is using?


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.


Solution

  • 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:

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

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

    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.

    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).

    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.