如何编译lapack以便在安装八度时能够正确使用它? [英] how to compile lapack so that it can be used correctly during installation of octave?

查看:580
本文介绍了如何编译lapack以便在安装八度时能够正确使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在运行redhat + IBM LSF的群集中从源代码安装最新的倍频程3.8.1。除了我自己的主目录之外,我没有其他任何地方的写入权限,这就是为什么我必须从源代码安装八度。群集提供的blas和lapack不起作用,所以我必须自己构建它们。我现在已经完成了对blas和lapack的编译,并且通过了 ./configure ,但是当我运行make时,报错如下:



这些是我用来构建我自己的 BLAS LAPACK 的步骤。 BLAS的来源位于〜/ src / BLAS 中,而LAPACK的来源位于〜/ src / lapack-3.5.0 ,而八度音阶3.8.1的来源位于〜/ src / octave-3.8.1 中。
只有两个模块, 1)pcre / 8.33 2)acml / 5.3.1 / gfortran64 ,加载后,我使用

编译BLAS共享库

  gfortran -shared -O2 * .f -o libblas.so -fPIC 


< fPIC
ar cr libblas.a * .o

然后我复制共享库 libblas.so 到〜/ src / octave-3.8.1。

  make.inc 文件的内容是lapack的目录。 ################################################## ################# 
#LAPACK使包含文件。 #
#LAPACK,版本3.5.0#
#2013年11月#
######################### ############### $ b SHELL = / bin / sh

#修改FORTRAN和OPTS定义以引用您的机器的
#编译器和所需的编译器选项。 NOOPT
#表示选择NO OPTIMIZATION为
#时所需的编译器选项。定义LOADER和LOADOPTS以指代您的机器的加载器和
#所需加载选项。

FORTRAN = gfortran
OPTS = -shared -O2 -fPIC
DRVOPTS = $(OPTS)
NOOPT = -O0 -f递归
LOADER = gfortran
LOADOPTS =

#SECOND和DSECND例程的定时器

#默认值:SECOND和DSECND将使用对EXTERNAL FUNCTION ETIME
#TIMER = EXT_ETIME
#对于RS6K:SECOND和DSECND将使用对EXTERNAL FUNCTION的调用ETIME_
#TIMER = EXT_ETIME_
#对于gfortran编译器:SECOND和DSECND将使用一个调用到INTERNAL FUNCTION ETIME
TIMER = INT_ETIME
#如果Fortran编译器不提供etime(如Nag Fortran编译器等)
#SECOND和DSECND将使用内部函数CPU_TIME
#TIMER = INT_CPU_TIME
#如果这两者都不起作用...您可以使用NONE值...在这种情况下,SECOND和DSECND将始终返回0
#TIMER = NONE

#配置LAPACKE:本地C接口到LAPACK
#生成LAPACK E库:键入'make lapackelib'
#配置文件:关闭(默认)
#复杂类型:C99(默认)
#名称模式:混合大小写(默认)
#(64位)数据模型:LP64(默认)

#CC是C编译器,通常用选项CFLAGS调用。

CC = gcc
CFLAGS = -O3

#建立归档文件(库)时使用的归档文件和标志(库)
#如果你的系统没有ranlib,请设置RANLIB = echo。

ARCH = ar
ARCHFLAGS = cr
RANLIB = ranlib

#扩展精度BLAS(XBLAS)Fortran库$ b的位置$ b#用于构建和测试扩展精度例程。
#相关例程将被编译,XBLAS只有在
#USEXBLAS被定义时才会被链接。

#USEXBLAS =是
XBLASLIB =
#XBLASLIB = -lxblas

#您将链接到的库的位置。 (只要
#可以使用
#机器特定的优化BLAS库。)

#BLASLIB = ../../librefblas.a
BLASLIB =〜/ src / BLAS / libblas.a
LAPACKLIB = liblapack.a
TMGLIB = libtmglib.a
LAPACKELIB = liblapacke.a

然后输入make来编译LAPACK。编译后,我将输出 liblapack.a 复制到〜/ src / octave-3.8.1。



./configure 命令行是:

  ./ configure --prefix = $ HOME / bin / octave --with-blas =。/ libblas.so --with-lapack = $ HOME / src / octave-3.8.1 / liblapack.a --disable-readline --enable-64 

我可以通过./configure。然后我输入 make 来尝试构建八度音3.8.1,并且我得到了上面的错误。



code> make.inc 文件,可以看到我遵循编译器的建议用-fPIC重新编译并修改make.inc相应地。我还在 OPTS 变量中添加了 -shared 开关。另外,我尝试使用旧的LAPACK版本,但没有工作。我真的不知道为什么错误仍然出来。所以我想知道是否可以请告诉我如何编译 LAPACK 库,以便在安装八度音阶3.8.1时可以正确使用它。以下两点可能值得考虑。 (1)我应该将lapack编译为静态库还是共享库? (2)应将 -fPIC 开关应用于lapack编译或八度的 make ?如果后者,如何应用-fPIC来制作?您不必拘泥于上述两点,因为可能有其他原因导致错误。欢迎任何解决此问题的建议。如果您需要任何其他信息,请告诉我。谢谢。

解决方案

刚刚在我老板的野兽上编译了lapack共享库...这是一个链接,这几乎是正确的。
我做了一些修改:
$ b $(1)将-fPIC添加到

  OPTS& (2)将make.inc中的名称更改为.so   

>

  BLASLIB = ../../libblas.so 

LAPACKLIB = ../liblapack.so

(3)在./SRC中,将Makefile从

  ../$(LAPACKLIB):$(ALLOBJ)
$(ARCH)$(ARCHFLAGS)$ @ $(ALLOBJ)
$(RANLIB )$ @

  ../$(LAPACKLIB):$(ALLOBJ)
$(LOADER)$(LOADOPTS)-shared -Wl,-soname,liblapack.so -o $ @ $(ALLOBJ) ../libblas.so

如果你错过了最后一部分,Cuz lapack正在呼唤blas,你的liblapack.so会失败!你需要将liblapack.so与libblas.so联系起来(libatlas.so也是可以的)。你可以使用ldd liblapack.so来检查它的依赖。 (4)在./BLAS/SRC中,将Makefile从

更改为$($)。如果您在此处看到libblas.so,几乎可以做到这一点。


$ b b
$ b

  $(BLASLIB):$(ALLOBJ)
$(ARCH)$(ARCHFLAGS)$ @ $(ALLOBJ)
$(RANLIB)$ @



<$ ($ LOADOPTS)-z muldefs -shared -Wl,-soname,libblas.so -o $ @ $ $($)$($) (ALLOBJ)

(5)我不需要libtmg.so,因此我没有更改它...
运行

  make blaslib 

然后

  make lapacklib 

您将会编译它们。我检查liblapack.so并在其上构建numpy和Python ctypes.cdll加载。所有工作对我来说解决特征值和特征向量...所以它应该没问题...

(6)您可能需要设置LD_LIBRARY_PATH到您保留的位置库文件。
google it ...如果不是由admin设置,那么

  export LD_LIBRARY_PATH =路径到lib 

如果已经设置,那么

  export LD_LIBRARY_PATH = path-to-lib:$ LD_LIBRARY_PATH 

覆盖您的预设libs。



这样你就不会有ld链接错误。祝你好运!!



在lapack-3.7.0中,SRC / Makefile中有冗余行。只需删除它们即可解决您的错误。


I'm trying to install the latest octave 3.8.1 from source in a cluster running redhat+IBM LSF. I don't have write access to anywhere else except my own home dir, that's why I have to install octave from source. The blas and lapack provided by the cluster does not work so I have to build them by myself. I have now finished compiling both blas and lapack and passed the ./configure, but when I run make, an error is reported as follows:

These are steps I used to build my own BLAS and LAPACK. The source of BLAS is in ~/src/BLAS while the source of LAPACK is in ~/src/lapack-3.5.0 and the source of octave 3.8.1 is in ~/src/octave-3.8.1. With only two module, 1) pcre/8.33 2) acml/5.3.1/gfortran64, loaded, I compiled BLAS shared library using

gfortran -shared -O2 *.f -o libblas.so -fPIC

and static library using

gfortran -O2 -c *.f -fPIC
ar cr libblas.a *.o

Then I copy the shared library libblas.so to ~/src/octave-3.8.1. The contents of make.inc file in lapack's dir is:

####################################################################
#  LAPACK make include file.                                       #
#  LAPACK, Version 3.5.0                                           #
#  November 2013                                                   #
####################################################################
#
SHELL = /bin/sh
#  
#  Modify the FORTRAN and OPTS definitions to refer to the
#  compiler and desired compiler options for your machine.  NOOPT
#  refers to the compiler options desired when NO OPTIMIZATION is
#  selected.  Define LOADER and LOADOPTS to refer to the loader and 
#  desired load options for your machine.
#
FORTRAN  = gfortran 
OPTS     = -shared -O2 -fPIC
DRVOPTS  = $(OPTS)
NOOPT    = -O0 -frecursive
LOADER   = gfortran
LOADOPTS =
#
# Timer for the SECOND and DSECND routines
#
# Default : SECOND and DSECND will use a call to the EXTERNAL FUNCTION ETIME
#TIMER    = EXT_ETIME
# For RS6K : SECOND and DSECND will use a call to the EXTERNAL FUNCTION ETIME_
# TIMER    = EXT_ETIME_
# For gfortran compiler: SECOND and DSECND will use a call to the INTERNAL FUNCTION ETIME
TIMER    = INT_ETIME
# If your Fortran compiler does not provide etime (like Nag Fortran Compiler, etc...)
# SECOND and DSECND will use a call to the INTERNAL FUNCTION CPU_TIME
# TIMER    = INT_CPU_TIME
# If neither of this works...you can use the NONE value... In that case, SECOND and DSECND will always return 0
# TIMER     = NONE
#
#  Configuration LAPACKE: Native C interface to LAPACK
#  To generate LAPACKE library: type 'make lapackelib'
#  Configuration file: turned off (default)
#  Complex types: C99 (default)
#  Name pattern: mixed case (default)
#  (64-bit) Data model: LP64 (default)
#
# CC is the C compiler, normally invoked with options CFLAGS.
#
CC = gcc
CFLAGS = -O3
#
#  The archiver and the flag(s) to use when building archive (library)
#  If you system has no ranlib, set RANLIB = echo.
#
ARCH     = ar
ARCHFLAGS= cr
RANLIB   = ranlib
#
#  Location of the extended-precision BLAS (XBLAS) Fortran library
#  used for building and testing extended-precision routines.  The
#  relevant routines will be compiled and XBLAS will be linked only if
#  USEXBLAS is defined.
#
# USEXBLAS    = Yes
XBLASLIB     =
# XBLASLIB    = -lxblas
#
#  The location of the libraries to which you will link.  (The 
#  machine-specific, optimized BLAS library should be used whenever
#  possible.)
#
#BLASLIB      = ../../librefblas.a
BLASLIB      = ~/src/BLAS/libblas.a
LAPACKLIB    = liblapack.a
TMGLIB       = libtmglib.a
LAPACKELIB   = liblapacke.a

Then I type make to compile LAPACK. After compilation, I copied the output liblapack.a to ~/src/octave-3.8.1.

The ./configure command line is:

./configure --prefix=$HOME/bin/octave --with-blas=./libblas.so --with-lapack=$HOME/src/octave-3.8.1/liblapack.a --disable-readline --enable-64

I can pass the ./configure. Then I type make to try to build octave 3.8.1 and I got the above error.

From the make.inc file it can be seen that I have followed the suggestion of the compiler "recompile with -fPIC" and modified the make.inc accordingly. I also add -shared switch in the OPTS variable. In addition, I have tried using old LAPACK version but not working. I really have no idea why the error still comes out. So I wonder if you could please tell me how to compile the LAPACK library so that it can be correctly used during installation of octave 3.8.1. The following two points may be worth considering. (1) should I compile lapack as a static library or a shared library? (2) should -fPIC switch be applied to lapack compilation or octave's make? If the latter, how to apply -fPIC to make? You don't have to get restricted to the above two points since there may be other reasons for the error. Any advice to solve this problem is welcomed. If you need any other information please tell me. Thank you.

解决方案

Just compiled the lapack shared lib on my boss's beast... Here's a link which almost did it right. I made some changes:

(1) Adding -fPIC to

OPTS & NOOPT in make.inc

(2) Change the names in make.inc to .so

BLASLIB = ../../libblas.so

LAPACKLIB = ../liblapack.so

(3) In ./SRC, change the Makefile from

../$(LAPACKLIB): $(ALLOBJ)
    $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
    $(RANLIB) $@

to

../$(LAPACKLIB): $(ALLOBJ)
    $(LOADER) $(LOADOPTS) -shared -Wl,-soname,liblapack.so -o $@ $(ALLOBJ) ../libblas.so

Cuz lapack is calling blas, if you miss the very last part, your liblapack.so will fail! You need to LINK liblapack.so against libblas.so ( libatlas.so is also OK). You can use "ldd liblapack.so" to check its dependency. If you see libblas.so in there, pretty much you did it right.

(4) In ./BLAS/SRC, change the Makefile from

$(BLASLIB): $(ALLOBJ)
$(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
$(RANLIB) $@

to

$(BLASLIB): $(ALLOBJ)
$(LOADER) $(LOADOPTS) -z muldefs -shared -Wl,-soname,libblas.so -o $@ $(ALLOBJ)

(5) I don't need libtmg.so so that I didn't change it... Run

make blaslib 

Then

make lapacklib

You will have both of them compiled. I check the liblapack.so with building a numpy on it and Python ctypes.cdll loading. All work for me to solve eigenvalues and eigenvectors... So it should be fine...

(6) YOU MAY NEED TO SET UP LD_LIBRARY_PATH to where you keep your library files. google it... If not set by admin, then

export LD_LIBRARY_PATH=path-to-lib

If already set, then

export LD_LIBRARY_PATH=path-to-lib:$LD_LIBRARY_PATH

to overwrite your default libs.

So that you won't have ld linking errors. Good luck!!

In lapack-3.7.0, there are redundant lines in the SRC/Makefile. Simply deleting them will solve your error.

这篇关于如何编译lapack以便在安装八度时能够正确使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆