Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

R linking to MKL

cml_nb
Beginner
1,122 Views

Hello there,

An attempt to dynamically link R to threaded MKL on a Linux workstation leads to a 'double complex BLAS...' error:

>/usr/lib/R$ export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64

>/usr/lib/R$ sudo /home/XXXX/Documents/R-2.15.1/configure --enable-R-shlib --enable-threads=posix --with-lapack --with-blas="-I/opt/intel/mkl/include -L/opt/intel/mkl/lib/intel64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -fopenmp -lpthread"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
the following error message   seems to be not infrequently cited by R users attempting to link against MKL on R forums:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
checking for cblas_cdotu_sub in vecLib framework... no
checking for dgemm_ in -I/opt/intel/mkl/include -L/opt/intel/mkl/lib/intel64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -fopenmp -lpthread -lm... yes
checking whether double complex BLAS can be used... no
checking iconv.h usability... yes
checking iconv.h presence... yes

>>>>>>>>> some additional diagnostic messages .... <<<<<<<<<<<<<<

R is now configured for x86_64-unknown-linux-gnu
 
  Source directory:          /home/XXXX/Documents/R-2.15.1
  Installation directory:    /usr/local
 
  C compiler:                gcc -std=gnu99  -g -O2
  Fortran 77 compiler:       gfortran  -g -O2
 
  C++ compiler:              g++  -g -O2
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:           
 
  Interfaces supported:      X11
  External libraries:        readline
  Additional capabilities:   PNG, JPEG, NLS
  Options enabled:           shared R library, shared BLAS, R profiling, Java
 
  Recommended packages:      yes

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#################################

Alternatively, using syntax suggested in R installation manual (which cites Intel engineer):


>/usr/lib/R$ export MKL_LIB_PATH=/opt/intel/mkl/lib/intel64

>/usr/lib/R$ MKL="-L${MKL_LIB_PATH} -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_lapack -lmkl_core -fopenmp -lpthread"

>/usr/lib/R$ sudo /home/XXXX/Documents/R-2.15.1/configure --enable-R-shlib --enable-threads=posix --with-blas="$MKL"
~~~~~~~~~~~~~~~
  checking whether ctanh exists and is declared... yes
checking for cblas_cdotu_sub in vecLib framework... no
checking for dgemm_ in -L/opt/intel/mkl/lib/intel64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_lapack -lmkl_core -fopenmp -lpthread... no
checking for dgemm_... no
checking for ATL_xerbla in -latlas... no
checking for dgemm_ in -lblas... yes
checking for dgemm_ in -ldgemm... no
checking for dgemm_ in -lblas... (cached) yes
checking for dgemm_ in -lessl... no
checking for dgemm_ in -lblas... (cached) yes
checking whether double complex BLAS can be used... yes
checking whether the BLAS is complete... yes

>>>>>>>>> some  additional diagnostic messages .... <<<<<<<<<<<<<<

R is now configured for x86_64-unknown-linux-gnu

  Source directory:          /home/XXXX/Documents/R-2.15.1
  Installation directory:    /usr/local

  C compiler:                gcc -std=gnu99  -g -O2
  Fortran 77 compiler:       gfortran  -g -O2

  C++ compiler:              g++  -g -O2
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:          

  Interfaces supported:      X11
  External libraries:        readline, BLAS(generic)
  Additional capabilities:   PNG, JPEG, NLS
  Options enabled:           shared R library, R profiling, Java

  Recommended packages:      yes

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thank you,

Constantine

0 Kudos
11 Replies
Zhang_Z_Intel
Employee
1,122 Views
Constantine, As you already observed, using the link line suggested in the official R installation instructions the "double complex BLAS" error goes away. So I do not see a problem here. Maybe, I misunderstood your question. Would you clarify what problems you see, please? Thank you, Zhang
0 Kudos
Sang_O_
Beginner
1,122 Views

I am having a similar issue.

When I compile R with intel compilers, everything works great.
 ================================
R is now configured for x86_64-unknown-linux-gnu 


Source directory: .
Installation directory: /usr/local

C compiler: icc -std=c99 -g -O3 -wd188 -ip
Fortran 77 compiler: ifort -g -O3

C++ compiler: icpc -g -O3
Fortran 90/95 compiler: ifort -g -O3
Obj-C compiler:

Interfaces supported: X11
External libraries: readline, BLAS(generic), LAPACK(in blas)
Additional capabilities: PNG, JPEG, NLS
Options enabled: shared R library, R profiling
================================ 

When I configure, I use the following options in "config.site"

================================
CC='icc -std=c99'
CFLAGS='-g -O3 -wd188 -ip '
F77='ifort'
FFLAGS='-g -O3 '
CXX='icpc'
CXXFLAGS='-g -O3 '
FC='ifort'
FCFLAGS='-g -O3 '
MKL_LIB_PATH=/opt/intel/mkl/lib/intel64
MKL=" -L${MKL_LIB_PATH} \ 
-Wl,--start-group \ 
-lmkl_intel_lp64 \ 
-lmkl_intel_thread \ 
-lmkl_core \ 
-Wl,--end-group \ 
-liomp5 -lpthread"
BLAS_LIBS="$MKL"
================================ 

However, if I try to use gcc as the compiler, I run into problems. Following is the "config.site"

================================
CFLAGS='-g -O2 '
FFLAGS='-g -O2 '
CXXFLAGS='-g -O2 '
FCFLAGS='-g -O2 '
MKL_LIB_PATH=/opt/intel/mkl/lib/intel64

MKL=" -L${MKL_LIB_PATH} \
-Wl,--start-group \
-lmkl_gf_ilp64 \
-lmkl_intel_thread \
-lmkl_core \
-Wl,--end-group \
-liomp5 -lpthread"
BLAS_LIBS="$MKL"
================================

The output indicate that dgemm_ in mkl_gf_lp64.so is not found:

~/Downloads/R-3.0.0$ nm -D /opt/intel/mkl/lib/intel64/libmkl_gf_lp64.so | grep dgemm_
00000000003309f0 T dgemm_

This is also reflected in the summary of the configure command:

================================
R is now configured for x86_64-unknown-linux-gnu 


Source directory: .
Installation directory: /usr/local

C compiler: gcc -std=gnu99 -g -O2
Fortran 77 compiler: gfortran -g -O2

C++ compiler: g++ -g -O2
Fortran 90/95 compiler: gfortran -g -O2
Obj-C compiler:

Interfaces supported: X11
External libraries: readline, BLAS(generic), LAPACK(generic)
Additional capabilities: PNG, JPEG, NLS
Options enabled: shared R library, R profiling

Recommended packages: yes
================================ 

Any help would be appreciated


 

================================ truncated
checking for cblas_cdotu_sub in vecLib framework... no
checking for dgemm_ in -l -L -Wl,--start-group -lmkl_gf_ilp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -liomp\
5 -lpthread... no
checking for dgemm_... no
checking for ATL_xerbla in -latlas... no
checking for dgemm_ in -lblas... yes
checking for dgemm_ in -ldgemm... no
checking for dgemm_ in -lblas... (cached) yes
checking for dgemm_ in -lessl... no
checking for dgemm_ in -lblas... (cached) yes
checking whether double complex BLAS can be used... yes
checking whether the BLAS is complete... yes
checking for dpstrf_... no
checking for dpstrf_ in -llapack... yes
================================ truncated


 

0 Kudos
Zhang_Z_Intel
Employee
1,122 Views
I got no problem with "complex double BLAS" checking. I don't see an issue here. I've tested R-2.15.1 with both MKL 10.3 and MKL 11.0. Here are my steps: - First, properly set MKL related env-variables (MKLROOT and LD_LIBRARY_PATH, etc.). This can be easily done by this command: source /opt/intel/mkl/bin/mklvars.sh intel64 - Next, configure R with this: ./configure --enable-R-shlib --enable-threads=posix --with-lapack --with-blas="-fopenmp -m64 -I$MKLROOT/include -L$MKLROOT/lib/intel64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lpthread -lm" The configure output did not show any complex double BLAS errors. My GCC version is 4.4.4. Please let me know if this helps you, or if you want us to investigate it further? Thanks, Zhang
0 Kudos
Zhang_Z_Intel
Employee
1,122 Views

Sang O. wrote:

However, if I try to use gcc as the compiler, I run into problems.

If you use gcc then you need "-lmkl_gnu_thread", instead of "-lmkl_intel_thread". Please check and let us know if this solves your problems.

0 Kudos
TimP
Honored Contributor III
1,122 Views

I suppose mkl_gnu_thread uses libgomp, while mkl_intel_thread uses libiomp5.  libiomp5 has support for all gcc/gfortran linux OpenMP syntax. libgomp would not work with mkl_intel_thread, nor would the application work if both libgomp and libiomp5 are linked in.  ldd would be a good check to assure that you don't have both OpenMP .so linked.

0 Kudos
Ying_H_Intel
Employee
1,122 Views

Hi all,

I did some check recently about mkl and R article recently,

http://software.intel.com/en-us/articles/build-r-301-with-intel-c-compiler-and-intel-mkl-on-linux
http://software.intel.com/en-us/articles/using-intel-mkl-with-r

I run into bunch of building problem (include sangs). most of them was tracked to environment finally.

So I'd like add notes here again  as Zhang mentioned,

properly (carefully) set MKL related env-variables (MKLROOT,LIBRARY_PATH  and LD_LIBRARY_PATH, etc.).
Or please use mkl varsetting bash for safe

source /opt/intel/mkl/bin/mklvars.sh intel64.

@ Constantine, i try your command line exactly with lastest MKL composer_xe_2013.4.183 and R version R-3.0.1. They works fine and double complex blas works too. you may try again. 

Other thing,You mentioned  using syntax suggested in R installation manual (which cites Intel engineer):and get
checking for dgemm_ in -L/opt/intel/mkl/lib/intel64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_lapack -lmkl_core -fopenmp -lpthread... no

Actually, the MKL library isn't work here. Please check config.log to see the exact error message for this. 

@Sang
When you try to use GCC and you call mkl_ilp64 interface,
MKL=" -L${MKL_LIB_PATH} \
-Wl,--start-group \
-lmkl_gf_ilp64 \
-lmkl_intel_thread \
-lmkl_core \
-Wl,--end-group \
-liomp5 -lpthread"

But you check the library of mkl_lp64.  nm -D /opt/intel/mkl/lib/intel64/libmkl_gf_lp64.so | grep dgemm_

Despite this, it should be ok to use ILP64 interface, but take care of the integer type.

The ILP64 interface provides for the following:

•Support large data arrays (with more than 231-1 elements)
•Enable compiling your Fortran code with the -i8 compiler option .

Please check if you have libmkl_gf_ilp64.so under the opt/intel/mkl/lib/intel64. 
 ( I prefer to use the exact path like opt/intel/composer_xe_2013.4.183/mkl/lib/intel64 , instead the quick link)

Second, regarding the gcc build fails, you have
checking for dgemm_ in -l -L -Wl,--start-group -lmkl_gf_ilp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -liomp\
5 -lpthread... no

as you see -L is blank,  MKL_LIB_PATH is even not there. So please check.

Third, you may run into next problem : can't found -liomp5. (please open config.log to check)
when using icc, you may set right environment for icc, thus the default path /opt/intel/composer_xe_2013.4.183/compiler/lib/intel64/  of libiomp5.so is ready.
but when using gcc, the path is not there. 

So you may try
for example,
MKL_LIB_PATH=/opt/intel/composer_xe_2013.4.183/mkl/lib/intel64
OMP_LIB_PATH=/opt/intel/composer_xe_2013.4.183/compiler/lib/intel64/  
export LD_LIBRARY_PATH=${MKL_LIB_PATH}:${OMP_LIB_PATH}
MKL=" -L${MKL_LIB_PATH}   -L${OMP_LIB_PATH}                \
      -Wl,--start-group                         \
          -lmkl_gf_lp64       \
          -lmkl_intel_thread    \
          -lmkl_core          \
      -Wl,--end-group                           \
      -liomp5 -lpthread"
./configure --with-blas="$MKL" --with-lapack ( I prefer to the exact path, instead the quick link).

Best Regards,
Ying

0 Kudos
Ying_H_Intel
Employee
1,122 Views

Link another topic, where checking whether double complex BLAS can be used... no  is resolved by linking libmkl_intel_lp64.so.

http://software.intel.com/en-us/forums/topic/397399

Regards,

Ying

0 Kudos
Michael_S_2
Beginner
1,122 Views

Hi,

I am not able to compile the MKL into R.  I am using gcc 4.6.3 and fgortran 4.6.3 compilers with MKL 11.1.0.080.

I use the following to configure as advised above for gnu though do not use shared libraries:

source /opt/intel/mkl/bin/mklvars.sh intel64

./configure  --enable-threads=posix --with-lapack --with-blas="-fopenmp -m64 -I$MKLROOT/include -L$MKLROOT/lib/intel64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lpthread -lm" --with-x=no

R is now configured for x86_64-unknown-linux-gnu

  Source directory:          .
  Installation directory:    /usr/local

  C compiler:                gcc -std=gnu99  -g -O2
  Fortran 77 compiler:       gfortran  -g -O2

  C++ compiler:              g++  -g -O2
  Fortran 90/95 compiler:    gfortran -g -O2
  Obj-C compiler:          

  Interfaces supported:      
  External libraries:        readline
  Additional capabilities:   NLS
  Options enabled:           shared BLAS, R profiling

  Recommended packages:      yes

After make, make install I run a benchmark.

The benchmark test described in http://software.intel.com/en-us/articles/using-intel-mkl-with-r shows it is only running with 1 core.  top shows the same

root@Ubuntu-1204-precise-64-minimal ~ # time R CMD BATCH R-benchmark-25.R --no-save

real    2m9.587s
user    2m8.124s
sys    0m1.052s

Please help.

0 Kudos
TimP
Honored Contributor III
1,122 Views

I would be concerned that you have linked against the default linux lapack for gfortran and that it may not use the MKL functions.  The MKL libraries you need have support for both lapack and blas.  The intel reference you cited states specifically that it won't work in the order you give.

0 Kudos
VipinKumar_E_Intel
1,122 Views

@Michael S.

Have you checked whether the MKL_NUM_THREADS or OMP_SET_NUM_THREADS or MKL_DYNAMIC env variables are set correctly?

--Vipin

 

0 Kudos
VipinKumar_E_Intel
1,122 Views

Sorry, OMP_NUM_THREADS env. variable.

0 Kudos
Reply