当前位置: 首页 > 工具软件 > siesta > 使用案例 >

SIESTA安装——材料计算入门指引

晏沈义
2023-12-01

前言

SIESTA是材料计算常用软件。区别于VASP的平面波基底,SIESTA基于原子轨道基底,且是免费的。科学研究人员可以免费获得其源码及赝势文件。
作为刚入门材料计算的小白,在此贴出安装SIESTA的整个流程,希望能给后来者以指引。
本次安装基于CentOS7.4 版本。因为是安装在所里服务器集群上,所以没有root权限,无法使用yum指令,很多都只能下载-编译-安装。如果你是安装在自己的pc上,可以自行查询更简单的yum指令,并相应配置环境变量。

[zwnie@admin1 gcc_install]$ lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.4.1708 (Core) 
Release:	7.4.1708
Codename:	Core

CentOS 7 下SIESTA的安装配置

  • GCC
  • OpenMPI
  • 数学库(BLAS,LAPACK,ScaLAPACK,BLACS)
  • SIESTA

gcc的安装

gcc用来编译C/C++, FORTRAN等语言,可以看到目前系统上已存在 gcc 4.8.5,虽然它足以承载本次SIESTA安装要求,但为了把安装流程完整走一遍,我们本次安装最新版的 gcc 8.3.0,注意要求在系统已存在编译器的情况下安装。

安装gcc依赖库文件

gcc的安装需要GMP, MPFR, MPC这三个库,不然接下来的配置过程会报错如下

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations

可在ftp://gcc.gnu.org/pub/gcc/infrastructure/找到库的压缩文件

[zwnie@admin1 ~]$ mkdir lib
[zwnie@admin1 ~]$ cd lib/
[zwnie@admin1 lib]$ wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
[zwnie@admin1 lib]$ wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
[zwnie@admin1 lib]$ wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
[zwnie@admin1 lib]$ tar -jxvf gmp-6.1.0.tar.bz2
[zwnie@admin1 lib]$ tar -jxvf mpfr-3.1.4.tar.bz2
[zwnie@admin1 lib]$ tar -xzvf mpc-1.0.3.tar.gz

[zwnie@admin1 lib]$ mkdir gmp_install
[zwnie@admin1 lib]$ cd gmp_install/
[zwnie@admin1 gmp_install]$ ../gmp-6.1.0/configure --prefix=/public/home/zwnie/lib/gmp_install
[zwnie@admin1 gmp_install]$ make
[zwnie@admin1 gmp_install]$ make install

[zwnie@admin1 gmp_install]$ mkdir ../mpfr_install
[zwnie@admin1 gmp_install]$ cd ../mpfr_install/
[zwnie@admin1 mpfr_install]$ ../mpfr-3.1.4/configure --prefix=/public/home/zwnie/lib/mpfr_install --with-gmp=/public/home/zwnie/lib/gmp_install
[zwnie@admin1 mpfr_install]$ make
[zwnie@admin1 mpfr_install]$ make install

[zwnie@admin1 mpfr_install]$ mkdir ../mpc_install
[zwnie@admin1 mpfr_install]$ cd ../mpc_install/
[zwnie@admin1 mpc_install]$ ../mpc-1.0.3/configure --prefix=/public/home/zwnie/lib/mpc_install --with-gmp=/public/home/zwnie/lib/gmp_install --with-mpfr=/public/home/zwnie/lib/mpfr_install
[zwnie@admin1 mpc_install]$ make
[zwnie@admin1 mpc_install]$ make install

INSTALL GCC

目前我们的gcc版本

[zwnie@admin1 ~]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

新建一个目录并进入

[zwnie@admin1 ~]$ mkdir compiler
[zwnie@admin1 ~]$ cd compiler/

下载最新版本gcc

[zwnie@admin1 compiler]$ wget ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-8.3.0/gcc-8.3.0.tar.gz

由于下载太慢,我是在本地下载然后上传到服务器上,结果都是一样的

[zwnie@admin1 compiler]$ ll
total 121391
-rw-r--r-- 1 zwnie users 124304709 Sep 12  2019 gcc-8.3.0.tar.gz

解压缩并进入编译目录,这可能需要一点时间
其中gcc_compiled, gcc_install区别于源目录,前者用来存放稍后的编译结果,后者是编译器的安装路径

[zwnie@admin1 compiler]$ tar -xzvf gcc-8.3.0.tar.gz
[zwnie@admin1 compiler]$ mkdir gcc_install
[zwnie@admin1 compiler]$ mkdir gcc_compiled
[zwnie@admin1 compiler]$ ll
total 121403
drwxr-xr-x 36 zwnie users      4096 Aug 12 15:57 gcc-8.3.0
-rw-r--r--  1 zwnie users 124304709 Sep 12 15:46 gcc-8.3.0.tar.gz
drwxr-xr-x  2 zwnie users      4096 Sep 12 15:59 gcc_compiled
drwxr-xr-x  2 zwnie users      4096 Sep 12 15:52 gcc_install
[zwnie@admin1 compiler]$ cd gcc_compiled/

配置可以查看./gcc-8.3.0/INSTALL下的html文件,其中configure.html的说明如下:
*–enable-languages=lang1,lang2,…
Specify that only a particular subset of compilers and their runtime libraries should be built. For a list of valid values for langN you can issue the following command in the gcc directory of your GCC source tree:

grep ^language= /config-lang.in
Currently, you can use any of the following: all, default, ada, c, c++, d, fortran, go, jit, lto, objc, obj-c++.
–prefix=dirname
Specify the toplevel installation directory. This is the recommended way to install the tools into a directory other than the default. The toplevel installation directory defaults to /usr/local.

其余读者自行阅读
这里用到了我们上一步的库文件

[zwnie@admin1 gcc_compiled]$ ../gcc-8.3.0/configure --prefix=/public/home/zwnie/compiler/gcc_install -enable-threads=posix -disable-checking -disable-multilib -enable-languages=c,c++ --with-gmp=/public/home/zwnie/lib/gmp_install --with-mpfr=/public/home/zwnie/lib/mpfr_install --with-mpc=/public/home/zwnie/lib/mpc_install

经电脑测试,gcc 8.3.0, g++ 8.3.0, gfortran 4.8.5是可以编译安装SIESTA的,其它版本可能会报错,读者自行尝试

[zwnie@admin1 gcc_compiled]$ make -j36
[zwnie@admin1 gcc_compiled]$ make install

gcc已经安装完成,查看

[zwnie@admin1 gcc_compiled]$ cd ../gcc_install/
[zwnie@admin1 gcc_install]$ ll
total 24
drwxr-xr-x 2 zwnie users 4096 Sep 12 22:04 bin
drwxr-xr-x 3 zwnie users 4096 Sep 12 22:05 include
drwxr-xr-x 3 zwnie users 4096 Sep 12 22:04 lib
drwxr-xr-x 2 zwnie users 4096 Sep 12 22:05 lib64
drwxr-xr-x 3 zwnie users 4096 Sep 12 22:04 libexec
drwxr-xr-x 6 zwnie users 4096 Sep 12 22:05 share

GCC的所有文件都在此目录下。命令文件放在bin目录下,库文件放在lib下,头文件放在include下等。
接下来添加环境变量

[zwnie@admin1 bin]$ vim ~/.bashrc

在末尾添加

######### gcc-8.3.0 path #########
export LD_LIBRARY_PATH=/public/home/zwnie/compiler/gcc_install/lib64:$LD_LIBRARY_PATH
export PATH=/public/home/zwnie/compiler/gcc_install/bin:$PATH

source一下

[zwnie@admin1 bin]$ source ~/.bashrc

之后,我们就能看到gcc的编译器都更新了

[zwnie@admin1 bin]$ gcc --version
gcc (GCC) 8.3.0
...
[zwnie@admin1 bin]$ g++ --version
g++ (GCC) 8.3.0
...
[zwnie@admin1 bin]$ gfortran --version
GNU Fortran (GCC) 4.8.5
...

至此,gcc安装完成!接下来我们将用GCC对库文件和程序进行编译。
此外,我以上安装都是基于无管理员权限下。如果你是在自己的pc上,可利用yum等指令,便捷许多。
最后,接下来的编译要始终用一个编译器。我之前曾使用gcc编译的数学库和intel编译器编译的openmpi共同编译SIESTA,这会raise一个关于gfortran的错误

并行计算库OpenMPI的安装

去官网查看OpenMPI发行版本

[zwnie@admin1 ~]$ mkdir software
[zwnie@admin1 ~]$ cd software/
[zwnie@admin1 software]$ wget https://download.open-mpi.org/release/open-mpi/v3.1/openmpi-3.1.4.tar.gz

解压,准备编译和安装

[zwnie@admin1 software]$ tar -xzvf openmpi-3.1.4.tar.gz
[zwnie@admin1 software]$ mkdir openmpi_compile openmpi_install
[zwnie@admin1 software]$ cd openmpi_compile/

查看配置文件

[zwnie@admin1 openmpi_compile]$ ../openmpi-3.1.4/configure --help

–prefix=PREFIX install architecture-independent files in PREFIX
CC C compiler command
CXX C++ compiler command
FC Fortran compiler command

[zwnie@admin1 openmpi_compile]$ ../openmpi-3.1.4/configure --prefix=/public/home/zwnie/software/openmpi_install CC=gcc CXX=g++ FC=gfortran
[zwnie@admin1 openmpi_compile]$ make -j8
[zwnie@admin1 openmpi_compile]$ make install

安装完成,配置环境变量,接下来编译数学库需要使用

[zwnie@admin1 openmpi_install]$ vim ~/.bashrc

末尾加入以下内容

######## openmpi 3.1.4 path ########
OPENMPI=/public/home/zwnie/software/openmpi_install
export LD_LIBRARY_PATH=$OPENMPI/lib:$LD_LIBRARY_PATH
export PATH=$OPENMPI/bin:$PATH
export INCLUDE=$OPENMPI/include:$INCLUDE
export CPATH=$OPENMPI/include:$CPATH
export MANPATH=$OPENMPI/share/man:$MANPATH

source一下
可以看到

[zwnie@admin1 openmpi_install]$ source ~/.bashrc
[zwnie@admin1 openmpi_install]$ type mpirun mpif90
mpirun is /public/home/zwnie/software/openmpi_install/bin/mpirun
mpif90 is /public/home/zwnie/software/openmpi_install/bin/mpif90

至此,OpenMPI安装完成!

数学库编译及安装SIESTA

这个步骤困扰了我几天,通过尝试各种编译器版本和openmpi版本,最终在PC上成功手动编译安装,但在服务器上手动编译失败,只能自动编译。
怀疑scalapack编译有问题,可能是编译过程中服务器mpi和我编译的mpi版本冲突导致的。换言之,服务器“不干净”,未找到解决办法,遂放弃。
如果你想要学习各种编译安装操作,建议手动编译一遍;如果你只想装好SIESTA跑程序,自动编译即可

手动编译

[zwnie@admin1 openmpi_install]$ cd ~/lib/

安装BLAS, LAPACK

LAPACK是基于BLAS的,LAPACK装好后,BLAS会一并安装

[zwnie@admin1 lib]$ wget http://www.netlib.org/lapack/lapack-3.8.0.tar.gz
[zwnie@admin1 lib]$ tar -xzvf lapack-3.8.0.tar.gz
[zwnie@admin1 lib]$ cd lapack-3.8.0/
[zwnie@admin1 lapack-3.8.0]$ cp make.inc.example make.inc
[zwnie@admin1 lapack-3.8.0]$ vim make.inc

修改以下内容

FORTRAN = gfortran
OPTS    = -O2 -frecursive -fPIC -m64
DRVOPTS = $(OPTS)
NOOPT   = -O0 -frecursive -fPIC -m64
[zwnie@admin1 lapack-3.8.0]$ vim Makefile
#lib: lapacklib tmglib
lib: blaslib variants lapacklib tmglib
[zwnie@admin1 lapack-3.8.0]$ make -j2

编译,安装完成,可以查看,存在liblapack.a, librefblas.a两个静态库

[zwnie@admin1 lapack-3.8.0]$ ll
total 12955
...
-rw-r--r-- 1 zwnie users 12341640 Sep 13 10:29 liblapack.a
-rw-r--r-- 1 zwnie users   628096 Sep 13 10:27 librefblas.a
...

安装ScaLPACK,BLACS

可以去http://www.netlib.org/scalapack/#_scalapack_installer_for_linux查看ScaLAPACK版本
其中BLACK是集成在ScaLAPACK中的(是这样吗?),无需单独安装

[zwnie@admin1 lib]$ cd ~/lib/
[zwnie@admin1 lib]$ wget http://www.netlib.org/scalapack/scalapack-2.0.2.tgz
[zwnie@admin1 lib]$ tar -xzvf scalapack-2.0.2.tgz
[zwnie@admin1 lib]$ cd scalapack-2.0.2/
[zwnie@admin1 scalapack-2.0.2]$ cp SLmake.inc.example SLmake.inc
[zwnie@admin1 scalapack-2.0.2]$ vim SLmake.inc

做如下修改

BLASLIB       = /public/home/zwnie/lib/lapack-3.8.0/librefblas.a
LAPACKLIB     = /public/home/zwnie/lib/lapack-3.8.0/liblapack.a
LIBS          = $(LAPACKLIB) $(BLASLIB)
[zwnie@admin1 scalapack-2.0.2]$ make -j8
[zwnie@admin1 scalapack-2.0.2]$ ll
total 4249
...
-rw------- 1 zwnie users 4222126 Sep 13 10:41 libscalapack.a
...

可以看到安装成功,至此我们的前期准备工作全部完成

安装SIESTA

去https://launchpad.net/siesta查看SIESTA版本,下载,解压,检查配置

[zwnie@admin1 scalapack-2.0.2]$ cd ~/software/
[zwnie@admin1 software]$ wget https://launchpad.net/siesta/4.0/4.0.2/+download/siesta-4.0.2.tar.gz
[zwnie@admin1 software]$ tar -xzvf siesta-4.0.2.tar.gz 
[zwnie@admin1 software]$ cd siesta-4.0.2/
[zwnie@admin1 siesta-4.0.2]$ mkdir openmpi_gcc_compile
[zwnie@admin1 siesta-4.0.2]$ cd openmpi_gcc_compile/

查看配置,建立安装目录

[zwnie@admin1 openmpi_gcc_compile]$ bash ../Src/obj_setup.sh 
[zwnie@admin1 openmpi_gcc_compile]$ ../Src/configure --help
[zwnie@admin1 openmpi_gcc_compile]$ mkdir ../../siesta_install
[zwnie@admin1 openmpi_gcc_compile]$ ../Src/configure --prefix=/public/home/zwnie/software/siesta_install --enable-mpi

修改make文件

[zwnie@admin1 openmpi_gcc_compile]$ vim arch.make 

改为如下

BLAS_LIBS=/public/home/zwnie/lib/lapack-3.8.0/librefblas.a
LAPACK_LIBS=/public/home/zwnie/lib/lapack-3.8.0/liblapack.a
BLACS_LIBS=
SCALAPACK_LIBS=/public/home/zwnie/lib/scalapack-2.0.2/libscalapack.a

安装,不要make -j8, 会报错

[zwnie@admin1 openmpi_gcc_compile]$ make

自动编译

这种方法简单快捷,官网已经写好了python脚本帮你自动编译数学库

数学库的安装

[zwnie@admin1 lib]$ wget http://www.netlib.org/scalapack/scalapack_installer.tgz
[zwnie@admin1 lib]$ tar -xzvf scalapack_installer.tgz
[zwnie@admin1 lib]$ cd scalapack_installer/
[zwnie@admin1 scalapack_installer]$ mkdir libs
[zwnie@admin1 scalapack_installer]$ ./setup.py --prefix=/public/home/zwnie/lib/scalapack_installer/libs --downall

安装SIESTA

改为如下

BLAS_LIBS=/public/home/zwnie/lib/scalapack_installer/libs/lib/librefblas.a
LAPACK_LIBS=/public/home/zwnie/lib/scalapack_installer/libs/lib/libreflapack.a
BLACS_LIBS=
SCALAPACK_LIBS=/public/home/zwnie/lib/scalapack_installer/libs/lib/libscalapack.a

安装成功

[zwnie@admin1 openmpi-gcc-compile]$ ll siesta
-rwxr-xr-x 1 zwnie users 12969616 Sep 17 19:23 siesta

提交任务脚本

服务器使用的PBS作业管理系统,后续我会在写一份在服务器上提交任务的pbs脚本。

 类似资料: