I have built a custom package with some functions written in RcppEigen. I also have Microsoft R open with Intel MKL enabled. How could I link the R package to the Intel MKL feature?
Setup 1:
Below are procedures that I have tried to link the package with MKL in the normal R, but failed:
The Eigen documents says I need:
1. #define EIGEN_USE_MKL_ALL
2. link your program to MKL libraries
Based on 2, in my file Makevars
PKG_CXXFLAGS = -I/opt/intel/mkl/include
PKG_LIBS = ${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS} -L/opt/intel/mkl/lib/intel64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
I got the errors when compiling the package:
Error in dyn.load(dllfile) :
unable to load shared object '/home/path/RPackageName.so':
libmkl_intel_lp64.so: cannot open shared object file: No such file or directory
Update based on Ralf's comment: in the Makevars file add the option <,-rpath,'path'>, the errors are gone.
PKG_CXXFLAGS = -DMKL_LP64 -m64 -I/opt/intel/mkl/include
PKG_LIBS = ${LAPACK_LIBS} ${BLAS_LIBS} ${FLIBS} -L/opt/intel/mkl/lib/intel64 -Wl,--no-as-needed,-rpath,'/opt/intel/mkl/lib/intel64' -lmkl_intel_lp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl
The package compiled successfully, but with these messages below, which I do not understand.
/home/shen/R/x86_64-pc-linux-gnu-
library/3.4/RcppEigen/include/Eigen/src/Core/Assign_MKL.h: In
instantiation of ‘static void Eigen::internal::Assignment<DstXprType,
Eigen::CwiseUnaryOp<Eigen::internal::scalar_log_op<double>,
SrcXprNested>, Eigen::internal::assign_op<double, double>,
Eigen::internal::Dense2Dense, typename
Eigen::internal::enable_if<Eigen::internal::vml_assign_traits<Dst,
Src>::EnableVml>::type>::run(DstXprType&, const SrcXprType&, const
Eigen::internal::assign_op<double, double>&) [with DstXprType =
Eigen::Matrix<double, -1, 1>; SrcXprNested = const
Eigen::ArrayWrapper<const Eigen::Matrix<double, -1, -1> >;
Eigen::internal::Assignment<DstXprType,
Eigen::CwiseUnaryOp<Eigen::internal::scalar_log_op<double>,
SrcXprNested>, Eigen::internal::assign_op<double, double>,
Eigen::internal::Dense2Dense, typename
Eigen::internal::enable_if<Eigen::internal::vml_assign_traits<Dst,
Src>::EnableVml>::type>::SrcXprType =
Eigen::CwiseUnaryOp<Eigen::internal::scalar_log_op<double>, const
Eigen::ArrayWrapper<const Eigen::Matrix<double, -1, -1> > >]’:
/home/shen/R/x86_64-pc-linux-gnu-
library/3.4/RcppEigen/include/Eigen/src/Core/AssignEvaluator.h:836:49:
required from ‘void Eigen::internal::call_assignment_no_alias(Dst&,
const Src&, const Func&) [with Dst = Eigen::Matrix<double, -1, 1>; Src
= Eigen::CwiseUnaryOp<Eigen::internal::scalar_log_op<double>, const
Eigen::ArrayWrapper<const Eigen::Matrix<double, -1, -1> > >; Func =
Eigen::internal::assign_op<double, double>]’
Setup 2 I compiled directly in MRO without any special arguments in the file Makevars, got the errors below:
/home/shen/R/x86_64-pc-linux-gnu-
library/3.3/RcppEigen/include/Eigen/src/Core/util/MKL_support.h:57:21:
fatal error: mkl.h: No such file or directory
PS: My experiences with the Microsoft R open are that they could accelerate the normal R scripts and functions in Armadillo without doing anything. Just run them normally in the Microsoft R Open.