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,
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
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:
# 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
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
attached base packages:
 stats graphics grDevices utils datasets methods base
other attached packages:
 RevoUtils_11.0.3 RevoUtilsMath_11.0.0
loaded via a namespace (and not attached):
 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...