本教程基于 Apple Silicon M4 芯片的 macOS 系统,默认 Shell 为 zsh
,包管理器为 Homebrew。
1. 安装依赖工具
使用 Homebrew 安装所需组件:
brew install gcc # 安装 gfortran
brew install open-mpi # 安装 mpif90 等 MPI 工具
brew install cmake # 构建 Spglib 使用
brew install lapack # 线性代数库
2. 编译并安装 Spglib 动态库
2.1 获取并构建 Spglib
git clone https://github.com/spglib/spglib.git
cd spglib
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/homebrew
make
make install
2.2 验证动态库生成
ls /opt/homebrew/lib/libsymspg.dylib
3. 配置动态库路径
为使系统能找到 Spglib 的动态链接库,需设置环境变量:
echo 'export DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH' >> ~/.zshrc
source ~/.zshrc
验证环境变量设置:
echo $DYLD_LIBRARY_PATH
4. 下载并编译 ShengBTE
4.1 获取源码并准备编译配置
git clone https://github.com/shengbte/shengbte.git
cd shengbte
cp arch.make.example Src/arch.make
cd Src
4.2 检查工具路径(推荐)
确认实际路径以便正确配置 arch.make
:
which mpif90
which gfortran
find /opt/homebrew -name mpi.mod
以我安装的路径为例:
/opt/homebrew/bin/mpif90
/opt/homebrew/Cellar/open-mpi/5.0.7/include/mpi.mod
4.3 编辑 arch.make
根据路径填写如下内容:
MPIFC = /opt/homebrew/bin/mpif90
FCFLAGS = -O3 -fopenmp \
-I/opt/homebrew/include \
-I/opt/homebrew/Cellar/open-mpi/5.0.7/include
LDFLAGS = -fopenmp \
-L/opt/homebrew/lib \
-L/opt/homebrew/Cellar/open-mpi/5.0.7/lib
LIBS = -llapack -lblas -lsymspg
4.4 修复 OpenMP 报错
若出现如下编译错误:
Function 'omp_get_thread_num' has no IMPLICIT type
应在 processes.f90
文件开头添加:
use omp_lib
4.5 编译 ShengBTE
完成设置后开始编译:
make clean
make
成功后将在上级目录生成 ShengBTE
可执行文件。
5. 运行 ShengBTE 自带示例
ShengBTE 提供了包含 Si 材料的测试输入文件,可直接运行测试:
cd Test-QE
mpirun -np 2 ../ShengBTE
运行成功则显示:
Info: symmetry group F-43m detected
Info: 24 symmetry operations
Info: This calculation is running on 2 MPI process(es)
Info: Ntot = 1728
Info: Nlist = 72
Info: about to obtain the spectrum
Info: expecting Quantum Espresso 2nd-order format
Info: about to set the acoustic frequencies at Gamma to zero
Info: original values:
Info: omega(1,1) = -1.0637325153768564E-006 rad/ps
Info: omega(1,2) = -7.1685042455799367E-007 rad/ps
Info: omega(1,3) = -3.6795686840623725E-007 rad/ps
Info: spectrum calculation finished in .220 seconds
Info: start calculating specific heat and kappa in the small-grain limit
Info: Temperature = 300.00000000000000
Info: Ntotal_plus = 744806
Info: Ntotal_minus = 889888
Info: max(N_plus), max(N_minus) 4193 4226
Info: calculating Vp_plus and Vp_minus at 1.406 seconds
Info: 100% done.
Info: start calculating kappa at 53.353 seconds
Info: Temperature= 300.00000000000000
Info: Iteration : 1 Timer : 54.701 seconds
Info: Relative change = 4.3050694775070453E-002
Info: Iteration : 2 Timer : 54.965 seconds
Info: Relative change = 2.2918199207035368E-002
Info: Iteration : 3 Timer : 55.227 seconds
Info: Relative change = 1.0854734510184971E-003
Info: Iteration : 4 Timer : 55.494 seconds
Info: Relative change = 1.1990264474953931E-003
Info: Iteration : 5 Timer : 55.762 seconds
Info: Relative change = 3.6190955255322710E-005
Info: Iteration : 6 Timer : 56.041 seconds
Info: Relative change = 8.6267549862898885E-005
Info: Iteration : 7 Timer : 56.308 seconds
Info: Relative change = 1.1841815598354433E-005
Info: Iteration : 8 Timer : 56.563 seconds
Info: Relative change = 7.5852438801879826E-006
Info: normal exit after 56.580 seconds