Tom Wenseleers
2019-Dec-27 12:57 UTC
[Rd] Providing R binaries compiled against a multithreaded BLAS like Intel MKL by default?
Dear all, Given that the Intel MKL multithreaded BLAS is now free (https://software.intel.com/en-us/mkl/choose-download, released under the very permissive Intel Simplified Software License, https://software.intel.com/en-us/license/intel-simplified-software-license) and that this BLAS comes out as the fastest in most benchmarks, and that Microsoft R Open compiled against Intel MKL seems to be really lagging behind in being updated (it's still stuck at version 3.5.3 and uses package versions of April 2019, and they also dropped Mac support) I was wondering if there are any plans by any chance to compile the default R binaries against this BLAS? Or if it would be possible perhaps for R to detect if Intel MKL is installed on one's system, and if it is, to make use of it? I see that Intel has a rough guide for Linux systems showing how to compile R against Intel MKL, https://software.intel.com/en-us/articles/using-intel-mkl-with-r,<https://software.intel.com/en-us/articles/using-intel-mkl-with-r> but I haven't seen any detailed guides for Windows though (they do also provide this link advisor though with recommended compilers on different systems, https://software.intel.com/sites/products/mkl/mkl_link_line_advisor.htm)<https://software.intel.com/sites/products/mkl/mkl_link_line_advisor.htm> (the guide here https://csantill.github.io/RPerformanceWBLAS/ is only targeted at Linux & Mac as well and the only other guide about installing an optimized BLAS, OpenBLAS on Windows also doesn't seem to be for the faint of heart, https://www.avrahamadler.com/r-tips/build-openblas-for-windows-r64/;<https://www.avrahamadler.com/r-tips/build-openblas-for-windows-r64/> for Linux there is the excellent guide by Dirk Eddelbuittel though, https://github.com/eddelbuettel/mkl4deb which is great in that it does not require recompilation of the whole of R). Is any of you perhaps aware of a good online guide to get R to use the Intel MKL on Windows systems? In the meantime I found that the following recipes work to get the latest R 3.6.2 up and running with Intel MKL on Windows systems, just by copying across some of the Intel MKL BLAS DLLs from Microsoft R Open 3.5.3 (see https://stackoverflow.com/questions/38090206/linking-intels-math-kernel-library-mkl-to-r-on-windows)<https://stackoverflow.com/questions/38090206/linking-intels-math-kernel-library-mkl-to-r-on-windows> : Method 1: 1. Install Microsoft R Open from https://mran.microsoft.com/download, which comes with the outdated R version 3.5.3 but also with the Intel MKL multithreaded BLAS libraries 2. Install the latest version of R from https://cran.r-project.org/bin/windows/base/, i.e. currently R 3.6.2 3. copy files libiomp5md.dll, Rblas.dll and Rlapack.dll from C:\Program Files\Microsoft\R Open\R-3.5.3\bin\x64 to C:\Program Files\R\R-3.6.2\bin\x64 (you can back up your existing default non-hyperthreaded Rblas.dll and Rlapack.dll files first if you like) 4. copy Microsoft R Open libraries/packages MicrosoftR, RevoIOQ, RevoMods, RevoUtils, RevoUtilsMath and doParallel from C:\Program Files\Microsoft\R Open\R-3.5.5\library to your default package directory, e.g. C:\Documents\R\win-library\3.6 5. copy files Rprofile.site and Renviron.site from directory C:\Program Files\Microsoft\R Open\R-3.5.5\etc to C:\Progral Files\R\R-3.6.2\etc 6. replace line 24 in file Rprofile.site options(repos=r) with options(repos="https://cran.rstudio.com") (or your favourite CRAN repository - you can also use "https://cran.revolutionanalytics.com", the MRO repository that has the latest daily builds of all packages) to make sure that it will install the latest CRAN packages as opposed to the outdated mran.microsoft.com mirror that has outdated package versions, frozen at the 15th of April 2019. Also comment out lines 153, 154 and 155 with a # Method 2: only relying on copying across some files from the free Intel MKL, without requiring copying files from MRO 1. Install Intel MKL from https://software.intel.com/en-us/mkl/choose-download (free) 2. Copy all the contents from inside these folders C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\redist\intel64\mkl C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows\redist\intel64\compiler to C:\Program Files\R\R-3.6.1\bin\x64 Inside the destination folder, create 2 copies of mkl_rt.dll and rename one of them Rblas.dll and the other Rlapack.dll replacing the originals and also keeping mkl_rt.dll. 3. Slight problem here is that we are still lacking the setMKLthreads() and getMKLthreads() functions to set the nr of intel MKL threads, unless there is a CRAN package to do this? Would any of you be aware of this? In MRO these are in the RevoUtilsMath package, so one could still have to copy this across from MRO, or else just stick with the default nr of threads equal to the nr of physical cores... I was wondering if any of you would have any thoughts about which of these two methods would be most recommended? After restarting RStudio we can check that it works, e.g. using a small SVD benchmark on my Intel Core i7-4700HQ 2.4GHz 4 core/8 thread laptop: getMKLthreads() 4 # Singular Value Decomposition m <- 10000 n <- 2000 A <- matrix (runif (m*n),m,n) system.time (S <- svd (A,nu=0,nv=0)) user system elapsed 15.20 0.64 4.17> sessionInfo()R version 3.6.2 (2019-12-12) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 18362) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RevoUtils_11.0.3 RevoUtilsMath_11.0.0 loaded via a namespace (and not attached): [1] compiler_3.6.2 tools_3.6.2 That same benchmark without Intel MKL installed ran at user system elapsed 35.11 0.10 35.21 Unfortunately calling the RevoUtilsMath::setMKLthreads() function crashes RStudio (this was already the case in MRO 3.5.3 as well though), but it does work OK when called from the R console. If any of you would happen to know of a better non-crashing alternative, please let me know! In general I think it would be really handy if R binaries, compiled against some optimized BLAS like Intel MKL or OpenBlas would be readily available on all systems, including Windows, as this partly determines how one would develop packages (e.g. veering towards the use of RcppEigen, which uses multithreaded matrix algebra on all systems independently of the BLAS one has installed, or RcppArmadillo, which uses whatever BLAS one has compiled R against, but which is only a good option then if R versions with multithreaded BLAS are readily available on all systems). Or even, if it could be made possible to switch the type of BLAS used also on Windows, as is possible on Ubuntu... Any thoughts most welcome! cheers & happy holidays, Tom Prof. Tom Wenseleers Laboratory of Socioecology and Social Evolution Dept. of Biology University of Leuven Naamsestraat 59 3000 Leuven Belgium https://bio.kuleuven.be/ento/wenseleers/twenseleers.htm [[alternative HTML version deleted]]
Seemingly Similar Threads
- Debate: Shall some of Microsoft R Open Code be ported to mainstream R?
- Debate: Shall some of Microsoft R Open Code be ported to mainstream R?
- Debate: Shall some of Microsoft R Open Code be ported to mainstream R?
- Debate: Shall some of Microsoft R Open Code be ported to mainstream R?
- nlminb with constraints failing on some platforms