VASP 编译

介绍


VASP 编译

编译前须知

1
2
3
4
5
6
7
8
9
10
11
# Intel Composer suite and oneAPI Base + HPC toolkits for CPUs
makefile.include.linux_intel # VASP.5.4.4
makefile.include.intel # VASP.6.3.X 或 VASP.6.4.X
makefile.include.oneapi # VASP.6.4.X

# GNU compilers for CPUs
makefile.include.linux_gnu # VASP.5.4.4
makefile.include.gnu # VASP.6.X.X

# NVIDIA HPC-SDK for CPU and GPU
makefile.include.nvhpc_ompi_mkl_omp_acc # VASP.6.X.X GPU
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
vasp.X.X.X (root directory)
|
---------------------------------------
| | | |
arch bin build src
|
---------------
| | |
lib parser CUDA


arch # 针对不同架构的 Makefile 模板
bin # 编译后的可执行程序文件目录
build # 编译时自动复制 src 目录内源码后执行编译,会分别创建三个版本的子目录
src # 源码目录
lib # 库目录,对应以前的 vasp.lib 目录
CUDA # GPU CUDA 代码目录
  • VASP.6.X.X 源代码目录结构
1
2
3
4
5
6
7
8
9
           vasp.x.x.x (root directory)
|
------------------------------------------------
| | | | | |
arch bin build src testsuite tools
|
-------------
| | |
lib parser fftlib
  • 三种版本可分开进行编译:make stdmake gammake ncl

  • bin 目录若出现 vasp_stdvasp_gamvasp_ncl 可执行文件,则表示编译成功

  • 编译得到的三个版本

1
2
3
vasp_std             # standard 标准版本
vasp_ncl # non-collinear 非共线版本;考虑磁性,如 SOC
vasp_gam # gamma-only 版本
  • VASP.6.4.3中新功能:固定轴优化

  • makefile.include 中的 OFLAG 参数里加入 -xhost,会使得编译出的程序能够利用当前机器 CPU 能支持的最高可用的指令集以加速计算


CPU 版本 + Intel oneAPI 套件

  • 安装步骤
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 超算平台编译步骤;Master 可忽略此步骤
# 导入 oneAPI 套件
module purge
module load intel-oneapi-compilers/2021.4.0
module load intel-oneapi-mpi/2021.4.0
module load intel-oneapi-mkl/2021.4.0

# 删除 bulid 和 bin 目录中的内容
make veryclean
rm bin/*

# VASP.5.4.4
cp arch/makefile.include.linux_intel makefile.include
# VASP.6.3.0
cp arch/makefile.include.intel makefile.include
# AMD CPU 需将 FFLAGS 中的 -xHOST 参数去掉

# 编译;耗时 20-30 分钟
make # 或 make all
# 单独版本编译
make std # 或 make gam, make ncl

# 为 vasp_* 等设置符号链接


# 可修改内容
# 添加 -diag-disable=10441 不让 icc 和 icpc 编译器在编译代码时每调用一次就跳出弃用警告
# 修改前
CC_LIB      = icc
CXX_PARS    = icpc
# 修改后
CC_LIB      = icc -diag-disable=10441
CXX_PARS    = icpc -diag-disable=10441
  • VASP.5.4.4 编译最后可能会出现的 remark(无影响)
1
ifort: command line remark #10412: option '-mkl=sequential' is deprecated and will be removed in a future release. Please use the replacement option '-qmkl=sequential'
  • 对于 2024 及更新的的 Intel oneAPI,不再包含 C++ Compiler Classic(即无 icc、icpc),需对 makefile.include 文件内容进行修改
1
2
3
4
5
6
7
# 修改前
CC_LIB = icc
CXX_PARS  = icpc

# 修改后
CC_LIB = icx
CXX_PARS  = icpx
1
2
3
# AMD CPU 直接使用 makefile.include.intel
catastrophic error: Function return parameter requires SSE register while SSE is disabled.
compilation aborted for minimax_functions1D.f90 (code 1)
  • Master 上选择 intel_omp 编译,运行 mpirun -n 2 vasp_std 命令会报错;选择 Intel 编译正常

CPU 版本 + GNU 套件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# lib 路径
/usr/lib/x86_64-linux-gnu

# Open MPI
sudo apt install libopenmpi-dev

# 数值计算库
sudo apt install libfftw3-dev
sudo apt install libblas-dev # 或 libopenblas-dev (优化版 BLAS)
sudo apt install liblapack-dev
sudo apt install libscalapack-openmpi-dev # 或 libscalapack-mpi-dev

# VASP.5.4.4
cp arch/makefile.include.linux_gnu makefile.include
# VASP.6.3.0
cp arch/makefile.include.gnu makefile.include

# 修改数值计算库 lib 在 makefile.include 中的具体路径

make # 或 make all, make std

NVIDIA GPU 版本

1
2
3
4
5
6
7
8
9
10
export NVIDIA_HPC_SDK_ROOT=/opt/nvidia/hpc_sdk/Linux_x86_64/XX.X
export PATH=${NVIDIA_HPC_SDK_ROOT}/compilers/bin:$PATH
export PATH=${NVIDIA_HPC_SDK_ROOT}/comm_libs/mpi/bin:$PATH
export LD_LIBRARY_PATH=${NVIDIA_HPC_SDK_ROOT}/comm_libs/mpi/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=${NVIDIA_HPC_SDK_ROOT}/compilers/extras/qd/lib:$LD_LIBRARY_PATH

# 可选
# 单独激活 Intel oneAPI MKL
source /opt/intel/oneapi/mkl/XXXX.X.X/env/vars.sh intel64 --force
export MANPATH=${NVIDIA_HPC_SDK_ROOT}/compilers/man:$MANPATH
  • 修改 makefile.include 文件内容

    • 修改 CCFCFCL 中的 ccXX(计算能力与显卡型号匹配) 和 CUDA 版本(安装的 CUDA toolkit 版本)
    • Intel oneAPI MKL 有 SCALAPACK,可将 SCALAPACK_ROOT 所在的 2 行注释掉
  • 安装步骤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 设置 NVIDIA HPC-SDK 相关环境变量(使用 GPU 版本进行计算时也需要设置)

# 将 bin 目录中的 vasp_* 重命名为对应的 vasp_*_cpu

mkdir build-gpu

# 若已编译 CPU 版本,重命名
cp makefile.include makefile.include.cpu

cp arch/makefile.include.nvhpc_ompi_mkl_omp_acc makefile.include.gpu

# 设置符号链接
ln -s makefile.include.gpu makefile.include

# 修改 makefile.include 文件内容

# 编译 3 个版本
make PREFIX=./build-gpu
# std 版本单独编译
make PREFIX=./build-gpu std

# 将 bin 目录中的 vasp_* 重命名为对应的 vasp_*_gpu
1
2
3
4
5
6
7
8
9
10
11
# BCC Nb 4x4x4 128 个原子,KSPACING=0.15,静态计算
node2 60 CPU 核 耗时 42min
1 块 4090 耗时 46min
1 块 3090 耗时 1h 39min
2 块 3090 耗时 1h 10min

# BCC Nb 6x6x6 432 个原子,单个 Γ 点,静态计算(加速效果明显)
1 块 4090 耗时 1h 2min

# FCC Al 3x3x3 108 个原子,KSPACING=0.15,静态计算
1 块 3090 耗时 7min
  • 目前 openacc 版本的 VASP 用了 nccl,只能用一个 CPU 核带一块 GPU,因而 CPU 单核性能会对计算结果有影响

  • 游戏显卡,跑经典 MD 非常有优势,跑第一性原理无明显优势?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 只有 1 块 GPU,使用多个 CPU 核会报错
WARNING: INIT_ACC: several MPI-ranks need to share a GPU, which is not
supported by NCCL. The use of NCCL will be switched off. To avoid this,
reduce the number of MPI-ranks: #-of-ranks <= #-of-GPUs (on every node!).

The function MPI_FINALIZE was invoked multiple times in a single
process on host node2, PID 3122551.

This indicates an erroneous MPI program; MPI_FINALIZE is only allowed
to be invoked exactly once in a process.

MPI_ABORT was invoked on rank 11 in communicator MPI_COMM_WORLD
with errorcode 1.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.

AMD GPU 版本

1

  • 相关报错
1
2
3
4
5
# 使用 makefile.include.gnu_ompi_aocl_omp;只安装 aocl-linux-gcc
mpif90 -fopenmp -ffree-form -ffree-line-length-none -w -ffpe-summary=invalid,zero,overflow -march=native -fallow-argument-mismatch -O2 -I/opt/AMD/5.0.0/gcc/include -c minimax_functions1D.f90
f951: Fatal Error: Reading module ‘prec.mod’ at line 1 column 2: Unexpected EOF
compilation terminated.
make[2]: *** [makefile:166: minimax_functions1D.o] Error 1

HDF5

  • 安装步骤
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
wget https://hdf-wordpress-1.s3.amazonaws.com/wp-content/uploads/manual/HDF5/HDF5_1_14_3/src/hdf5-1.14.3.tar.gz

# 配置 Intel 版本
./configure --enable-parallel --enable-fortran --enable-cxx --enable-unsupported \
CC=mpiicc FC=mpiifort CXX=mpiicpc \
--prefix=${HOME}/local/hdf5

make
make install


# 显示 HDF5 的编译和配置详细信息
h5cc -showconfig # 或 h5c++ h5pcc

# 显示用于编译 HDF5 的编译器命令行,包括链接的库和编译器标志
h5cc -show
  • 未添加 --enable-parallel 参数会出现以下报错:
1
configure: error: --enable-cxx and --enable-parallel flags are incompatible. Use --enable-unsupported to override this error.
  • 使用
    • HDF5 Preview 插件:只能打开.hdf5 格式,无法打开.h5 格式
    • Pandas 的 read_hdf() 不太好用
    • vaspout.h5 - VASP Wiki
    • h5py 暂不能很好地解析 vaspout.h5 文件中的数据
1
2
3
4
5
6
7
8
9
10
h5ls data.h5     # 显示 Group 列表

# vaspout.h5 示例
input # Group
intermediate # Group
original # Group
results # Group
version # Group

h5dump data.h5 # 输出文件的详细结构和内容

VASP + HDF5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 超算平台编译步骤
# 导入 Intel oneAPI 套件;hdf5
module purge

module load intel-oneapi-compilers/2021.4.0
module load intel-oneapi-mpi/2021.4.0
module load hdf5/1.12.2-intel-2021.4.0

# 查看 hdf5/1.12.2-intel-2021.4.0 的安装路径
module show hdf5/1.12.2-intel-2021.4.0

cp arch/makefile.include.intel makefile.include
# 取消 HDF5 相关行注释,将 HDF5_ROOT ?= 后的内容替换为 hdf5 的安装路径

make # 或 make all, make std
  • 可能会出现以下报错
1
2
3
4
5
6
7
8
9
error while loading shared libraries: libhdf5_fortran.so.102: cannot open shared object file: No such file or directory

# 原因:缺少 libhdf5_fortran.so.102 动态链接库,其实 module load 的 hdf5/1.12.2-intel-2021.4.0 有该动态链接库,不过版本更新一些,为 libhdf5_fortran.so.200

# 解决方法:将 libhdf5_fortran.so.200 软链接为 libhdf5_fortran.so.102;将 ~/lib 写入到 LD_LIBRARY_PATH

ln -s /dssg/opt/icelake/linux-centos8-icelake/intel-2021.4.0/hdf5-1.12.2-nxwmp3tddhreojgbib25ldc7wusvzf3m/lib/libhdf5_fortran.so.200 ~/lib/libhdf5_fortran.so.102

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$HOME/lib

VASP + VTST


安装步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
# 替换前 第 3519 行附近
CALL CHAIN_FORCE(T_INFO%NIONS,DYN%POSION,TOTEN,TIFOR, &
LATT_CUR%A,LATT_CUR%B,IO%IU6)

# 替换后;添加了 TSIF,
CALL CHAIN_FORCE(T_INFO%NIONS,DYN%POSION,TOTEN,TIFOR, &
TSIF,LATT_CUR%A,LATT_CUR%B,IO%IU6)

# vasp.6.2 及以后,还需进行以下替换
# 替换前
IF (LCHAIN) CALL chain_init( T_INFO, IO)
# 替换后 第 925 行附近
CALL chain_init( T_INFO, IO)
  • 备份 src/chain.F;复制 vtstcode-XXX 中对应 VASP 版本(如 vtstcode5、vtstcode6.3;vtstcode6.3 中多了 ml_pyamff.F 文件和 pyamff_fortran/ 目录)的目录下的所有文件到 src/
1
2
3
cp src/chain.F src/chain.F-org

cp vtstcode-XXX/vtstcodeXXX/* src/
  • 修改 src/.objects 源码,在 chain.o 所在行前添加:
1
2
3
4
5
6
7
8
9
# vtstcode5 和 vtstcode6.1
bfgs.o dynmat.o instanton.o lbfgs.o sd.o cg.o dimer.o bbm.o \
fire.o lanczos.o neb.o qm.o opt.o \

# vtstcode6.3
bfgs.o dynmat.o instanton.o lbfgs.o sd.o cg.o dimer.o bbm.o \
fire.o lanczos.o neb.o qm.o \
pyamff_fortran/*.o ml_pyamff.o \
opt.o\
  • 使用 vtstcode6.3,还需修改 src/makefile 源码:
1
2
3
4
5
6
7
# 替换前
LIB= lib parser
dependencies: sources

# 替换后
LIB= lib parser pyamff_fortran
dependencies: sources libs
  • 编译:同 VASP 编译步骤

1
2
3
4
5
6
7
8
9
10
11
mpiifort -free -names lowercase -assume byterecl -w -xHOST -O2 -I/opt/software/intel/oneapi/mkl/2022.1.0/include/fftw  -c chain.f90
chain.F(179): error #6321: An unterminated block exists.
IF (LINTERACT) THEN
^
compilation aborted for chain.f90 (code 1)
make[2]: *** [makefile:168: chain.o] Error 1
make[2]: Leaving directory 'XXX/vtst-vasp630/build/std'
cp: cannot stat 'vasp': No such file or directory
make[1]: *** [makefile:130: all] Error 1
make[1]: Leaving directory 'XXX/vtst-vasp630/build/std'
make: *** [makefile:17: std] Error 2