本文介绍了从源代码构建R:到共享库的链接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在抓我的头一个多星期,没有回答我的问题。
我想用英特尔MKL 作为共享库。这里是我用来测试我的配置的小脚本:

 #! / bin / sh 
export MKL = / opt / intel / compilers_and_libraries_2016.0.109 / linux / mkl
MKL =-L $ {_ mkllibpath} \
-Wl, - start-group \
-lmkl_gf_lp64 \
-lmkl_gnu_thread \
-lmkl_core \
-Wl, - end-group \
-lgomp -lpthread

./configure --prefix = / usr \
--libdir = / usr / lib \
--datarootdir = / usr / share \
rsharedir = / usr / share / R / \
rincludedir = / usr / include / R / \
rdocdir = / usr / share / doc / R / \
--with -blas =$ {MKL}\
--with-lapack \
--enable-R-shlib

make -j4



此小脚本执行以下操作:


  1. 使用gcc和gfortran在x86_64上构建R

  2. 使用gnu线程构建R

  3. 将路径导出到英特尔MKL库

  4. 将BLAS动态链接到intel MKL

现在我开始疯狂的部分。
在一个系统上, Archlinux ,构建将允许我在build目录下面输入ldd的内容。

  $ ldd bin / exec / R 
.....
libmkl_gf_lp64.so => /opt/intel/mkl/lib/intel64/libmkl_gf_lp64.so(0x00007f7707797000)
libmkl_core.so => /opt/intel/mkl/lib/intel64/libmkl_core.so(0x00007f7705c2a000)
libmkl_gnu_thread.so => /opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so(0x00007f7704ed3000)
libimf.so => /opt/intel/lib/libimf.so(0x00007f7704814000)
libintlc.so.5 => /opt/intel/lib/libintlc.so.5(0x00007f770284b000)
.......

这正是我要找的。现在,相同的脚本与英特尔MKL安装在相同的路径,运行 Fedora22

  $ ldd bin / exec / R 
linux-vdso.so.1(0x00007ffe9a9c5000)
libR.so => /usr/lib64/R/lib/libR.so(0x00007f45d9b69000)
libgomp.so.1 => /lib64/libgomp.so.1(0x00007f45d9947000)
libpthread.so.0 => /lib64/libpthread.so.0(0x00007f45d972a000)
libc.so.6 => /lib64/libc.so.6(0x00007f45d936a000)
libblas.so.3 => /lib64/libblas.so.3(0x00007f45d9111000)
libgfortran.so.3 => /lib64/libgfortran.so.3(0x00007f45d8de5000)
......

正如所见,根本没有链接到英特尔MKL。



我玩过各种制作选项,LD_PATHS,链接器选项等;我已经检查环境变量;我检查了ldconfig缓存;仍然不可能得到与Fedora的正确链接。



我会感激任何提示,在哪里可以找到我的问题的根源。

$经过多次尝试,下面是使用英特尔MKL和ICC构建R-cran的正确脚本:


$ b $ b

 #! / bin / sh 

source /opt/intel/compilers_and_libraries_2016.0.109/linux/bin/mklvars intel64
source /opt/intel/bin/compilervars.sh intel64
_icclibpath = /opt/intel/compilers_and_libraries_2016.0.109/linux/compiler/intel64/
_mkllibpath = $ {MKLROOT} / lib / intel64 /
MKL =-L $ {_ mkllibpath} -lmkl_rt -lpthread

export CC =icc
export CXX =icpc
export AR =xiar
export LD =xild
export F77 = ifort

export CFLAGS = - g -O3 -xHost -I $ {MKLROOT} / include
export CXXFLAGS = - g -O3 -xHost-I $ {MKLROOT} / include
export FFLAGS = - I $ {MKLROOT} / include
export FCFLAGS = - I $ {MKLROOT} / include

#shared libs
./configure --with-blas =$ {MKL}--enable-R-shlib --enable-BLAS-shlib
#static libs
#。/ configure --with-blas =$ {MKL}--with-lapack

make -j4

注意:


  1. 该脚本正在为Parallel studio 2016写入。如果composerxe 2015,请更改路径

  2. libRlib和libRblas可以构建为共享或静态库。

  3. 可以添加更多选项进行配置。

  4. 是在脚本中源mklvars和compilervars,所以它不会
    polluated你的shell环境一旦构建完成。


I have been scratching my head for more than a week, with no answer to my issue.I want to build R from cran source with Intel MKL1 as a shared library. Here is the small script I use to test my configuration:

#! /bin/sh
export MKL=/opt/intel/compilers_and_libraries_2016.0.109/linux/mkl
MKL=" -L${_mkllibpath} \
-Wl,--start-group \
    -lmkl_gf_lp64 \
    -lmkl_gnu_thread \
    -lmkl_core \
-Wl,--end-group \
-lgomp -lpthread"

./configure --prefix=/usr \
--libdir=/usr/lib \
--datarootdir=/usr/share \
rsharedir=/usr/share/R/ \
rincludedir=/usr/include/R/ \
rdocdir=/usr/share/doc/R/ \
--with-blas="${MKL}" \
--with-lapack \
--enable-R-shlib

make -j4

This small script do the following:

  1. build R with gcc and gfortran on x86_64
  2. build R with gnu threads
  3. export the path to Intel MKL libraries
  4. dynamically link BLAS to intel MKL

Now the part where I start getting mad.On one system, Archlinux, the build will let me with the following output from ldd ran inside the build directory

$ ldd bin/exec/R
.....
libmkl_gf_lp64.so => /opt/intel/mkl/lib/intel64/libmkl_gf_lp64.so    (0x00007f7707797000)
libmkl_core.so => /opt/intel/mkl/lib/intel64/libmkl_core.so (0x00007f7705c2a000)
libmkl_gnu_thread.so => /opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so (0x00007f7704ed3000)
libimf.so => /opt/intel/lib/libimf.so (0x00007f7704814000)
libintlc.so.5 => /opt/intel/lib/libintlc.so.5 (0x00007f770284b000)
.......

This is exactly what I am looking for. Now, same script with Intel MKL installed in same path, run on Fedora22.

$ ldd bin/exec/R
linux-vdso.so.1 (0x00007ffe9a9c5000)
libR.so => /usr/lib64/R/lib/libR.so (0x00007f45d9b69000)
libgomp.so.1 => /lib64/libgomp.so.1 (0x00007f45d9947000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f45d972a000)
libc.so.6 => /lib64/libc.so.6 (0x00007f45d936a000)
libblas.so.3 => /lib64/libblas.so.3 (0x00007f45d9111000)
libgfortran.so.3 => /lib64/libgfortran.so.3 (0x00007f45d8de5000)
......

As seen, not links at all to Intel MKL.

I have played with all kinds of make options, with LD_PATHS, with linker options etc; I have checked environment varaibles; I have checked ldconfig cache; etc. Still impossible to get the correct linking with Fedora.

I would appreciate any hints, where to look at for finding the root of my issue.

解决方案

After many tries, below is the correct script to build R-cran with Intel MKL and ICC:

#! /bin/sh

source /opt/intel/compilers_and_libraries_2016.0.109/linux/bin/mklvars intel64
source /opt/intel/bin/compilervars.sh intel64
_icclibpath=/opt/intel/compilers_and_libraries_2016.0.109/linux/compiler/intel64/
_mkllibpath=${MKLROOT}/lib/intel64/
MKL=" -L${_mkllibpath} -lmkl_rt -lpthread"

export CC="icc"
export CXX="icpc"
export AR="xiar"
export LD="xild"
export F77="ifort"

export CFLAGS="-g -O3 -xHost -I${MKLROOT}/include"
export CXXFLAGS="-g -O3 -xHost -I${MKLROOT}/include"
export FFLAGS="-I${MKLROOT}/include"
export FCFLAGS="-I${MKLROOT}/include"

# shared libs
./configure --with-blas="${MKL}" --enable-R-shlib --enable-BLAS-shlib
# static libs
#./configure --with-blas="${MKL}" --with-lapack

make -j4

NOTE:

  1. the script is writen for Parallel studio 2016. Change pathaccordingly if composerxe 2015.
  2. libRlib and libRblas can be build as shared or static librairies.
  3. More options can be added to configure.
  4. Best is to source mklvars and compilervars in a script so it won'tpolluated your shell environment once the build is done.

这篇关于从源代码构建R:到共享库的链接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 17:26