FastR with Intel MKL
Follow the instructions here => Quick Linking MKL to R.
Note: If you are building from the source and want to use 3rd party tools such as RStudio, pay attention to point #1.
- Use the
--enable-R-shliboption when configuring. - The offline Intel MKL installer will try to install a bunch more packages by default. You just need to install the MKL library. Everything else is truely optional.
- The location of the
libmkl_rt.sois not the same as indicated in the link above. In my case, I usedfindto locate the library. - Just don’t
make install. After themakecommand, your R is fully functional. - Check that your
R.HOME_DIRvariable inR/bin/Ris correctly set. - The MKL related environment variables need to be set every time you run R. Add the following lines to your
~/.bashrcfile.
# Intel MKL oneAPI MKL
source /opt/intel/oneapi/mkl/latest/env/vars.sh
export MKL_INTERFACE_LAYER=GNU,LP64
export MKL_THREADING_LAYER=GNU
To see whether this makes any difference, try benchmarking it (R-benchmark-25). On my old 4th gen intel Core i7 laptop, MKL scored 4.8 secs while the default library scored 38 secs.
There has been a time when Intel intentionally crippled code generation on AMD processors. But I believe it is not the case now. At least it is not as obvious as it used to be, so if you have an AMD processor, feel free to upgrade as well.