Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
technical:whitepaper:r-runtime-blas-lapack [2018-12-10 11:37] – [Substituting an alternate library] frey | technical:whitepaper:r-runtime-blas-lapack [2018-12-10 12:31] – [Runtime-configurable substitution] frey | ||
---|---|---|---|
Line 32: | Line 32: | ||
^Path ^Description^ | ^Path ^Description^ | ||
|'' | |'' | ||
+ | |'' | ||
+ | |'' | ||
|'' | |'' | ||
|'' | |'' | ||
Line 38: | Line 40: | ||
|'' | |'' | ||
+ | ==== R BLAS/LAPACK ==== | ||
+ | When we restructured the R '' | ||
+ | |||
+ | <code bash> | ||
+ | $ cd ${R_PREFIX}/ | ||
+ | $ rm -f libR{blas, | ||
+ | $ ln -s rblas/ | ||
+ | $ ln -s rblas/ | ||
+ | </ | ||
+ | |||
+ | ==== ATLAS ==== | ||
+ | |||
+ | The ATLAS library contains both BLAS and LAPACK APIs in a single shared library. | ||
+ | |||
+ | <code bash> | ||
+ | $ cd ${R_PREFIX}/ | ||
+ | $ rm -f libR{blas, | ||
+ | $ ln -s atlas/ | ||
+ | $ ln -s atlas/ | ||
+ | </ | ||
+ | |||
+ | ==== Sequential MKL ==== | ||
+ | |||
+ | A C source file containing a dummy function was created in '' | ||
+ | |||
+ | <file C shim.c> | ||
+ | int | ||
+ | mkl_shim_dummy(void) | ||
+ | { | ||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The shim library is then created thusly: | ||
+ | |||
+ | <code bash> | ||
+ | $ cd ${R_PREFIX}/ | ||
+ | $ icc -shared -o libRblas.so -mkl=sequential shim.c | ||
+ | $ ln -s libRblas.so libRlapack.so | ||
+ | </ | ||
+ | |||
+ | To configure R to use the sequential MKL: | ||
+ | |||
+ | <code bash> | ||
+ | $ cd ${R_PREFIX}/ | ||
+ | $ rm -f libR{blas, | ||
+ | $ ln -s mkl/ | ||
+ | $ ln -s mkl/ | ||
+ | </ | ||
+ | |||
+ | ==== Threaded MKL ==== | ||
+ | |||
+ | A C source file containing a dummy function was created in '' | ||
+ | |||
+ | <file C shim.c> | ||
+ | int | ||
+ | mkl_shim_dummy(void) | ||
+ | { | ||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Since our R build used the GNU C compiler, the threaded MKL variant only works if the shim library is built against the GNU OpenMP runtime. | ||
+ | |||
+ | <code bash> | ||
+ | $ cd ${R_PREFIX}/ | ||
+ | $ icc -shared -o libRblas.so shim.c -lmkl_gnu_thread -lmkl_core -lmkl_intel_lp64 | ||
+ | $ ln -s libRblas.so libRlapack.so | ||
+ | </ | ||
+ | |||
+ | To configure R to use the threaded MKL: | ||
+ | |||
+ | <code bash> | ||
+ | $ cd ${R_PREFIX}/ | ||
+ | $ rm -f libR{blas, | ||
+ | $ ln -s mkl/ | ||
+ | $ ln -s mkl/ | ||
+ | </ | ||
===== Runtime-configurable substitution ===== | ===== Runtime-configurable substitution ===== | ||
+ | |||
+ | By stashing each BLAS/LAPACK variant in its own subdirectory, | ||
+ | |||
+ | On our Caviness cluster we include no BLAS/LAPACK library symlinks in the base directory which R checks for shared libraries: | ||
+ | |||
+ | <code bash> | ||
+ | $ cd ${R_PREFIX}/ | ||
+ | $ rm -f libR{blas, | ||
+ | </ | ||
+ | |||
+ | In our VALET package definition for R we configure four variants that differ by BLAS/LAPACK (as a feature tag) | ||
+ | |||
+ | <code bash> | ||
+ | $ vpkg_versions r | ||
+ | : | ||
+ | r The R Project for Statistical Computing | ||
+ | 3.5 alias to r/3.5.1 | ||
+ | * 3.5.1 R 3.5.1 with system compilers, ATLAS | ||
+ | 3.5.1: | ||
+ | 3.5.1: | ||
+ | 3.5.1: | ||
+ | </ | ||
+ | |||
+ | with ATLAS as the default (recommended) choice of underlying BLAS/ | ||
+ | |||
+ | <code bash> | ||
+ | $ vpkg_require r/3.5.1 | ||
+ | Adding package `r/3.5.1` to your environment | ||
+ | $ echo $LD_LIBRARY_PATH | ||
+ | / | ||
+ | $ vpkg_rollback all | ||
+ | $ vpkg_require r/ | ||
+ | Adding package `r/ | ||
+ | $ echo $LD_LIBRARY_PATH | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | This works fine so long as you don't attempt to install any R modules that require the BLAS/LAPACK functionality. | ||
+ | |||
+ | < | ||
+ | BLAS_LIBS = -L" | ||
+ | </ | ||
+ | |||
+ | and | ||
+ | |||
+ | < | ||
+ | LAPACK_LIBS = -L" | ||
+ | </ |