如何手动构建和链接 BLAS 和 LAPACK 库以在集群上使用?

如何手动构建和链接 BLAS 和 LAPACK 库以在集群上使用?

我正在使用名为 的部分透视函数gesv。为了获取在 C++ 中实现此目的的库,我使用了一行命令安装 BLAS 和 LAPACK 包

sudo apt-get install libblas-dev liblapack-dev

然后我可以通过向编译指令中添加以下内容来链接库

g++ main.cpp -llapack -lblas

我的笔记本电脑 (Linux 2020) 的速度得到了极大的提升,但当我开始在集群上运行时,该方法在运行相同 (大型) 案例时非常慢。我认为集群上没有安装这两个库。代码运行,因此似乎提供速度提升的那个不在我正在使用的集群上。

是否可以“手动”构建然后链接lapackblas库,而不是执行apt-get命令?

感谢您的时间。

答案1

布拉斯

  • 下载最新版本 布拉斯

  • 打开终端并转到保存它的目录

tar -xvf blas-3.8.0.tgz  # unzip the blas source files
cd BLAS-3.8.0/ 
make
mv blas_LINUX.a libblas.a
mv *.a path/to/lib  # move the blas lib to the library you will be including at compile

拉帕克

tar -xvf lapack-3.9.0.tar.gz
cd lapack-3.9.0/
cp make.inc.example make.inc  # use example make as make
make
cp *.a path/to/lib

现在已经构建了库并将其存储在中path/to/lib,可以编译问题中的简短示例代码。

g++ main.cpp -L/path/to/lib -llapack -lblas -lgfortran  # compiles the code
./a.out  # runs the code

相关内容