手册编译
1. 环境的准备
1.1 Fortran编译器
[qihuanye@QHY ~]$ gfortran --version
GNU Fortran (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5)
Copyright (C) 2021 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.
GFortran当前版本为11.5.0,而要求GFortran >= 13,下载并配置GFortran 13到启动文件
sudo dnf install -y gcc-toolset-13-gcc-gfortran
echo 'source /opt/rh/gcc-toolset-13/enable' >> ~/.bashrc
source ~/.bashrc
再次检查版本
[qihuanye@QHY ~]$ gfortran --version
GNU Fortran (GCC) 13.3.1 20240611 (Red Hat 13.3.1-2)
Copyright (C) 2023 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.
完成
1.2 MPI框架
检查发现无openmpi,安装openmpi并添加到环境变量:
[qihuanye@QHY ~]$ sudo dnf install -y openmpi openmpi-devel
[qihuanye@QHY ~]$ echo 'export PATH=/usr/lib64/openmpi/bin:$PATH' >> ~/.bashrc
[qihuanye@QHY ~]$ source ~/.bashrc
[qihuanye@QHY ~]$ mpirun --version
mpirun (Open MPI) 4.1.1
Report bugs to http://www.open-mpi.org/community/help/
完成
1.3 CMake
[qihuanye@QHY ~]$ cmake --version
cmake version 3.26.5
CMake suite maintained and supported by Kitware (kitware.com/cmake).
完成
1.4 BLAS & LAPACK
检查发现无两个库,安装并检查:
[qihuanye@QHY ~]$ sudo dnf install -y openblas openblas-devel lapack lapack-devel
[qihuanye@QHY ~]$ pkg-config --exists blas && echo "y" || echo "n"
y
[qihuanye@QHY ~]$ pkg-config --exists lapack && echo "y" || echo "n"
y
1.5 ScaLAPACK
无ScaLAPACK库,安装:
[qihuanye@QHY ~]$ sudo dnf install -y scalapack scalapack-devel
Last metadata expiration check: 0:45:41 ago on Sun 14 Dec 2025 05:20:13 PM CST.
No match for argument: scalapack
No match for argument: scalapack-devel
Error: Unable to find a match: scalapack scalapack-devel
产生以上错误,搜索scalapack库:
[qihuanye@QHY ~]$ dnf search scalapack
Last metadata expiration check: 0:49:19 ago on Sun 14 Dec 2025 05:19:25 PM CST.
========================================== Name & Summary Matched: scalapack ===========================================
scalapack-common.x86_64 : Common files for scalapack
scalapack-openmpi.x86_64 : ScaLAPACK libraries compiled against openmpi
scalapack-openmpi-devel.x86_64 : Development libraries for ScaLAPACK (openmpi)
scalapack-openmpi-static.x86_64 : Static libraries for ScaLAPACK (openmpi)
找到正确的scalapack库,安装并配置:
[qihuanye@QHY ~]$ sudo dnf install -y scalapack-openmpi scalapack-openmpi-devel
[qihuanye@QHY ~]$ find /usr -name "*scalapack*" 2>/dev/null | grep -E ".(so|a)$"
/usr/lib64/openmpi/lib/libscalapack.so
[qihuanye@QHY ~]$ echo 'export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
[qihuanye@QHY ~]$ source ~/.bashrc
[qihuanye@QHY ~]$ pkg-config --exists scalapack && echo "y" || echo "n"
n
按理说我应该正确配置了,但为什么仍旧无法查询到正确的库?查询发现ScaLAPACK的OpenMPI版本通常不提供pkg-config支持
完成
1.6 ELSI库
搜索发现没有,先安装ELSI的依赖:
sudo dnf install -y gcc-gfortran gcc-c++ make cmake git
我准备从源码开始构建:
[qihuanye@QHY ~]$ mkdir -p ~/build && cd ~/build
[qihuanye@QHY build]$ git clone https://gitlab.com/elsi_project/elsi_interface.git elsi
[qihuanye@QHY build]$ cd elsi
[qihuanye@QHY elsi]$ git checkout v2.12.0
[qihuanye@QHY elsi]$ vim my_toolchain.cmake
在创建的工具链文件中写入:
set(CMAKE_Fortran_COMPILER "/usr/lib64/openmpi/bin/mpif90" CACHE STRING "MPI Fortran compiler")
set(CMAKE_C_COMPILER "/usr/lib64/openmpi/bin/mpicc" CACHE STRING "MPI C compiler")
set(CMAKE_Fortran_FLAGS "-O3 -ffree-line-length-none -fallow-argument-mismatch" CACHE STRING "Fortran flags")
set(CMAKE_C_FLAGS "-O3 -std=c99" CACHE STRING "C flags")
set(LIB_PATHS "/usr/lib64/openmpi/lib" CACHE STRING "External library paths")
set(LIBS "scalapack openblas lapack" CACHE STRING "External libraries")
set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE STRING "Installation path")
编译:
[qihuanye@QHY build]$ cmake -DCMAKE_TOOLCHAIN_FILE=../my_toolchain.cmake
-DENABLE_PEXSI=OFF
-DENABLE_SIPS=OFF
-DENABLE_NTPOLY=OFF
-DENABLE_BSEPACK=OFF
-DENABLE_TEST=OFF
..
[qihuanye@QHY build]$ make -j$(nproc)
安装:
[qihuanye@QHY build]$ sudo make install
完成
2. 下载DFTB+ 24.1
[qihuanye@QHY build]$ cd ~
[qihuanye@QHY ~]$ mkdir -p dftbplus-build && cd dftbplus-build
[qihuanye@QHY dftbplus-build]$ wget https://github.com/dftbplus/dftbplus/releases/download/24.1/dftbplus-24.1.tar.xz
[qihuanye@QHY dftbplus-build]$ tar -xf dftbplus-24.1.tar.xz
[qihuanye@QHY dftbplus-build]$ cd dftbplus-24.1
3. 配置编译DFTB+
3.1 配置环境变量
[qihuanye@QHY dftbplus-24.1]$ echo 'export FC=mpif90' >> ~/.bashrc
[qihuanye@QHY dftbplus-24.1]$ echo 'export CC=mpicc' >> ~/.bashrc
[qihuanye@QHY dftbplus-24.1]$ echo 'export CMAKE_PREFIX_PATH="/usr/local:/usr/lib64/openmpi:$CMAKE_PREFIX_PATH"' >> ~/.bashrc
[qihuanye@QHY dftbplus-24.1]$ source ~/.bashrc
检查环境变量
[qihuanye@QHY dftbplus-24.1]$ echo $CC && echo $FC
mpicc
mpif90
完成
3.2 构建配置
[qihuanye@QHY dftbplus-24.1]$ mkdir build && cd build
[qihuanye@QHY build]$ cmake ..
-DCMAKE_INSTALL_PREFIX=/usr/local
-DWITH_MPI=ON
-DWITH_ELSI=ON
-DWITH_OMP=ON
-DWITH_ARPACK=OFF
-DWITH_GPU=OFF
-DWITH_TRANSPORT=OFF
-DWITH_SOCKETS=OFF
-DSCALAPACK_LIBRARY=scalapack
#编译
[qihuanye@QHY build]$ make -j$(nproc)
4. 测试DFTB+
4.1 下载参数文件并测试:
[qihuanye@QHY dftbplus-24.1]$ ./utils/get_opt_externals slakos
[qihuanye@QHY dftbplus-24.1]$ cd build
[qihuanye@QHY build]$ ctest -j$(nproc)
得到如下结果:
99% tests passed, 2 tests failed out of 229
Total Test time (real) = 169.71 sec
The following tests FAILED:
115 - dftb+_solvation/gbsa_param1 (Failed)
116 - dftb+_solvation/gbsa_param3 (Failed)
Errors while running CTest
Output from these tests are in: /home/qihuanye/dftbplus-build/dftbplus-24.1/build/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
关于GBSA隐式溶剂化模型的参数测试失败,查看日志:
Status: FAIL
Start 116: dftb+_solvation/gbsa_param3
2/2 Test #116: dftb+_solvation/gbsa_param3 ......***Failed 1.40 sec
cp: cannot stat 'solvation/gbsa_param3/param_gbsa_dmso.txt': No such file or directory
solvation/gbsa_param3: Test script returned non-zero exit code: deleting file 'autotest.tag'
TODO.
失败的原因是缺少溶剂化模型的参数文件,但暂且与DFTB+核心功能无关,不影响正常使用,故而先忽略
4.2 安装DFTB+到系统
[qihuanye@QHY build]$ which dftb+
/usr/local/bin/dftb+
[qihuanye@QHY build]$ dftb+ --version
|===============================================================================
|
| DFTB+ release 24.1
|
| Copyright (C) 2006 - 2024 DFTB+ developers group
|
|===============================================================================
|
| When publishing results obtained with DFTB+, please cite the following
| reference:
|
| * DFTB+, a software package for efficient approximate density functional
| theory based atomistic simulations, J. Chem. Phys. 152, 124101 (2020).
| [doi: 10.1063/1.5143190]
|
| You should also cite additional publications crediting the parametrization
| data you use. Please consult the documentation of the SK-files for the
| references.
|
|===============================================================================
ERROR!
-> No input file 'dftb_in.hsd' not found.
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 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.
DFTB+已成功安装并可以运行,错误信息是正常的,因为确实没有输入文件dftb_in.hsd
4.3 sic测试
[qihuanye@QHY build]$ cd ~
[qihuanye@QHY ~]$ mkdir -p dftbplus-test && cd dftbplus-test
[qihuanye@QHY dftbplus-test]$ wget https://hpcadvisorycouncil.atlassian.net/wiki/download/attachments/3759866661/SiC.0064.tar.xz
[qihuanye@QHY dftbplus-test]$ wget https://hpcadvisorycouncil.atlassian.net/wiki/download/attachments/3759866661/pbc-0-3.tar.xz
[qihuanye@QHY dftbplus-test]$ tar -xf SiC.0064.tar.xz
[qihuanye@QHY dftbplus-test]$ tar -xf pbc-0-3.tar.xz
[qihuanye@QHY dftbplus-test]$ mkdir -p ~/opt/slakos
[qihuanye@QHY dftbplus-test]$ mv pbc-0-3/* ~/opt/slakos/
[qihuanye@QHY SiC.0064]$ DFTBPLUS_PARAM_DIR=~/opt/slakos dftb+
|===============================================================================
|
| DFTB+ release 24.1
|
| Copyright (C) 2006 - 2024 DFTB+ developers group
|
|===============================================================================
|
| When publishing results obtained with DFTB+, please cite the following
| reference:
|
| * DFTB+, a software package for efficient approximate density functional
| theory based atomistic simulations, J. Chem. Phys. 152, 124101 (2020).
| [doi: 10.1063/1.5143190]
|
| You should also cite additional publications crediting the parametrization
| data you use. Please consult the documentation of the SK-files for the
| references.
|
|===============================================================================
Reading input file 'dftb_in.hsd'
Parser version: 14
--------------------------------------------------------------------------------
ERROR!
-> SK file with generated name 'pbc-0-3/Si-Si.skf' does not exist.
Path: dftbplusinput/Hamiltonian/DFTB/SlaterKosterFiles/Type2FileNames
Line: 16-20 (File: dftb_in.hsd)
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 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.
--------------------------------------------------------------------------
错误提示sk文件路径不对,调整目录结构,再次运行,依旧报错:
WARNING!
-> Dipole printed for extended system : value printed is not well defined
MPI processes: 1
OpenMP threads: 6
ERROR!
-> You must explicitely enable OpenMP threads (UseOmpThreads = Yes) if you wish to run an MPI-parallelised binary with OpenMP threads. If not, make sure that the environment variable OMP_NUM_THREADS is set to 1.
错误信息提示一个mpi进程,6个openMP线程,查询可知:
DFTB+ 24.1在MPI构建中存在一个运行时检查机制:
- 代码逻辑:当检测到MPI并行构建时(WITH_MPI=ON),程序会强制检查OpenMP线程配置
- 检查条件:如果OMP_NUM_THREADS未设置或值>1,且输入文件中没有UseOmpThreads = Yes,程序会报错终止
我们先设置环境变量进行测试:[qihuanye@QHY SiC.0064]$ export OMP_NUM_THREADS=1 [qihuanye@QHY SiC.0064]$ DFTBPLUS_PARAM_DIR=~/opt/slakos dftb+得到如下输出:
Mode: Static calculation Self consistent charges: Yes SCC-tolerance: 0.100000E-04 Max. scc iterations: 100 Shell resolved Hubbard: No Spin polarisation: No Nr. of up electrons: 128.000000 Nr. of down electrons: 128.000000 Periodic boundaries: Yes Electronic solver: Relatively robust Mixer: Broyden mixer Mixing parameter: 0.200000 Maximal SCC-cycles: 100 Nr. of chrg. vec. in memory: 100 Electronic temperature: 0.126673E-03 H 0.344694E-02 eV Initial charges: Set automatically (system chrg: 0.000E+00) Included shells: Si: s, p C: s, p K-points and weights: 1: 0.125000 0.125000 0.125000 0.031250 2: 0.125000 0.125000 0.375000 0.031250 3: 0.125000 0.125000 0.625000 0.031250 4: 0.125000 0.125000 0.875000 0.031250 5: 0.125000 0.375000 0.125000 0.031250 6: 0.125000 0.375000 0.375000 0.031250 7: 0.125000 0.375000 0.625000 0.031250 8: 0.125000 0.375000 0.875000 0.031250 9: 0.125000 0.625000 0.125000 0.031250 10: 0.125000 0.625000 0.375000 0.031250 11: 0.125000 0.625000 0.625000 0.031250 12: 0.125000 0.625000 0.875000 0.031250 13: 0.125000 0.875000 0.125000 0.031250 14: 0.125000 0.875000 0.375000 0.031250 15: 0.125000 0.875000 0.625000 0.031250 16: 0.125000 0.875000 0.875000 0.031250 17: 0.375000 0.125000 0.125000 0.031250 18: 0.375000 0.125000 0.375000 0.031250 19: 0.375000 0.125000 0.625000 0.031250 20: 0.375000 0.125000 0.875000 0.031250 21: 0.375000 0.375000 0.125000 0.031250 22: 0.375000 0.375000 0.375000 0.031250 23: 0.375000 0.375000 0.625000 0.031250 24: 0.375000 0.375000 0.875000 0.031250 25: 0.375000 0.625000 0.125000 0.031250 26: 0.375000 0.625000 0.375000 0.031250 27: 0.375000 0.625000 0.625000 0.031250 28: 0.375000 0.625000 0.875000 0.031250 29: 0.375000 0.875000 0.125000 0.031250 30: 0.375000 0.875000 0.375000 0.031250 31: 0.375000 0.875000 0.625000 0.031250 32: 0.375000 0.875000 0.875000 0.031250