如何编译lapack,以便在安装octave的过程中可以正确使用? [英] how to compile lapack so that it can be used correctly during installation of octave?

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

问题描述

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

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:

这些是我用来构建自己的 BLASLAPACK 的步骤.BLAS 的来源在 ~/src/BLAS 而 LAPACK 的来源在 ~/src/lapack-3.5.0 和 octave 3.8.1 的来源是在 ~/src/octave-3.8.1 中.只加载了两个模块,1) pcre/8.33 2) acml/5.3.1/gfortran64,我使用

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

和静态库使用

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

然后我将共享库 libblas.so 复制到 ~/src/octave-3.8.1.lapack目录下make.inc文件的内容是:

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

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

Then I type make to compile LAPACK. After compilation, I copied the output liblapack.a to ~/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 来尝试构建 octave 3.8.1,我得到了上述错误.

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

make.inc文件可以看出,我已经按照编译器recompile with -fPIC"的建议,对make.inc进行了相应的修改.我还在 OPTS 变量中添加了 -shared 开关.此外,我尝试过使用旧的 LAPACK 版本但无法正常工作.我真的不知道为什么错误仍然出现.所以我想知道您是否可以告诉我如何编译 LAPACK 库,以便在安装 octave 3.8.1 期间可以正确使用它.以下两点可能值得考虑.(1) 我应该将 lapack 编译为静态库还是共享库?(2) -fPIC 开关应该应用于lapack 编译还是octave 的make?如果是后者,如何应用-fPIC来制作?您不必局限于上述两点,因为错误可能还有其他原因.欢迎任何解决此问题的建议.如果您需要任何其他信息,请告诉我.谢谢你.

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.

推荐答案

刚刚在我老板的野兽上编译了lapack共享库...这里是一个链接,几乎做对了.我做了一些更改:

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) 添加-fPIC到

(1) Adding -fPIC to

OPTS & NOOPT in make.inc

(2)将make.inc中的名字改为.so

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

BLASLIB = ../../libblas.so

LAPACKLIB = ../liblapack.so

(3) 在 ./SRC 中,将 Makefile 更改为

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

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

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

因为 lapack 正在调用 blas,如果你错过了最后一部分,你的 liblapack.so 将会失败!您需要针对 libblas.so 链接 liblapack.so ( libatlas.so 也可以).您可以使用ldd liblapack.so"来检查它的依赖关系.如果您在其中看到 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) 在 ./BLAS/SRC 中,将 Makefile 更改为

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

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

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

(5) 我不需要 libtmg.so 所以我没有更改它...运行

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

make blaslib 

然后

make lapacklib

您将编译它们.我检查 liblapack.so 并在其上构建一个 numpy 并加载 Python ctypes.cdll.我所有的工作都是为了解决特征值和特征向量......所以应该没问题......

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) 您可能需要将 LD_LIBRARY_PATH 设置到您保存库文件的位置.google一下...如果不是管理员设置的,那么

(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

如果已经设置,那么

export LD_LIBRARY_PATH=path-to-lib:$LD_LIBRARY_PATH

覆盖您的默认库.

这样您就不会出现 ld 链接错误.祝你好运!!

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

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

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

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

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