问题
Using an alternative BLAS for R has several advantages, see e.g. https://cran.r-project.org/web/packages/gcbd/vignettes/gcbd.pdf.
Microsoft R Open https://mran.revolutionanalytics.com/documents/rro/installation/#sysreq is using Intel's MKL instead of the default Reference BLAS to speed up calculations.
My question is:
What would be the exact steps to link Intel's MKL library **manually to R**'s most recent version on Windows (https://cran.r-project.org/bin/windows/base/)?
UPDATE 20-07-2016: Here is very detailed description on how to build a OpenBLAS-based Rblas.dll for 64-bit R for Windows for R ≥ 3.3.0: http://www.avrahamadler.com/r-tips/build-openblas-for-windows-r64/
回答1:
I found that on Windows if in directory Program Files/R/R-XX.XX.XX/bin/x64 (e.g. the latest R distribution) you overwrite files libiomp5md.dll, Rblas.dll and Rlapack.dll with their Intel MKL counterpart that you will have multithreaded matrix operations. For me this usually results in a ca 10 fold increase in the speed of matrix operations, so it's well worth it! Let me know if this works for you! Aside from via the dropbox link given above you can get those files also if you just install Microsoft Open R, and copy the files from there to your latest R installation (just remember to also tell RStudio to use your regular version of R instead of Microsoft Open R). This is a whole lot easier than have to recompile the whole of R...
回答2:
I was able to link R 3.6.0 with custom dlls you create using the builder. Basically you have to export the same symbols Rblas.dll
and Rlapack.dll
do. Start the Compiler 19.0 Update 4 for Intel 64 Visual Studio 2017 environment
command prompt:
Get the symbols:
dumpbin /exports Rblas.dll > Rblas_list
dumpbin /exports Rlapack.dll > Rlapack_list_R
Edit both files deleting the "header" and "footer" and have all the lines with the symbol names (ex.: 248 F7 00138CE0 dgeevx_
) be like dgeevx_
(only with the names).
Copy the builder
directory to somewhere in your pc and inside it run:
# blas links fine
nmake libintel64 export=..path..\Rblas_list name=Rblas
# save lapack errors in another list
nmake libintel64 export=..path..\Rlapack_list_R name=Rlapack 1> undefined_symbols_list
Edit undefined_symbols_list
keep only the names in each line and create a new
list with the difference
findstr /v /g:undefined_symbols_list Rlapack_list_R > Rlapack_list
nmake libintel64 export=..path..\Rlapack_list name=Rlapack
With dumpbin /dependents Rlapack.dll
, you can see that they depend on libiomp5md.dll
, which you can find inside the redist
folder in mkl installation.
Method 2
This method uses more disk space, but it's simpler. 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 a copy of mkl_rt.dll
and rename one of them Rblas.dll
and the other Rlapack.dll
(replacing the originals).
回答3:
just tried for R 3.5.1 installation. I installed Microsoft R Open alongside with the CRAN R and copy libiomp5md.dll and overwrite Rblas.dll, Rlapack.dll from MRO MKL counterparts to link to CRAN R on Windows (similar to another answer above but need to copy the file libiomp5md.dll as well). This worked out fine and the CRAN R runs as fast as MRO according to the version.compare package on Github (https://github.com/andrie/version.compare)
来源:https://stackoverflow.com/questions/38090206/linking-intels-math-kernel-library-mkl-to-r-on-windows