文章目錄
- 0.環境準備
- 0.1 配置支持nvidia的docker環境
- 0.2 **docker運行容器時,指定nvidia:**
- 1. 拉取代cuda的鏡像
- 1.1 設定好cuda環境
- 2. 安裝Inter編譯器
- 2.1 安裝oneAPI套件
- 2.2 添加環境變數
- 2.3 編譯fftw
- 3. 安裝VASP6.1
- 3.1 修改檔案makefile.include的注意事項
- 3.1.1 主要修改的地方
- 3.1.2我的`makefile.include` 組態檔
- 3.1.3 可能遇到的錯誤
- 4. 測驗VASP
- 5. 參考鏈接
0.環境準備
- 顯卡:3090 * (1-4)
- ubunt20.04
0.1 配置支持nvidia的docker環境
- 安裝nvidia-docker2
想要在容器使用nvidia-smi,需要安裝nvidia-docker2
sudo apt-get install -y nvidia-docker2 - 測驗安裝
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi
0.2 docker運行容器時,指定nvidia:
docker run -itd \
--runtime=nvidia --gpus=all \
-e NVIDIA_DRIVER_CAPABILITIES=compute,utility,video,graphics \
image_name
1. 拉取代cuda的鏡像
因為隨便從dockerhub拉一個帶cuda的鏡像都可以,我拉的是ubuntu:20.04,cuda11.1的版本,對docker不熟悉的可以參考docker快速入門,其中記錄了常用的命令,
docker pull alexartemis/cuda11.1-cudnn8-ubuntu20.0
- docker運行容器時,指定nvidia:
docker run -itd \
--runtime=nvidia --gpus=all \
-e NVIDIA_DRIVER_CAPABILITIES=compute,utility,video,graphics \
image_name
登錄自己的容器,最好是root權限安裝編譯,如果使用root用戶安裝,下面的命令去掉sudo 即可,
sudo apt-get install build-essential
1.1 設定好cuda環境
export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
輸入nvcc --version可以查看cuda版本,nvidia-smi查看顯卡資訊,

2. 安裝Inter編譯器
由于intel不再更新parallel studio xe,可以用OneAPI代替,網上的好多教程都是用的parallel studio xe,還需要激活碼,可以使用OneAPI(免費)下的MPI編譯vasp,
2.1 安裝oneAPI套件
oneAPI Base Toolkit
oneAPI HPC Toolkit
- 我下載的是離線版本,可以命令列安裝也可以界面安裝,我使用的是默認路徑
/opt/intel/oneapi/,

## 安裝oneAPI Base Toolki
wget https://registrationcenter-download.intel.com/akdlm/irc_nas/18236/l_BaseKit_p_2021.4.0.3422.s
sudo bash l_BaseKit_p_2021.4.0.3422.s
## 安裝oneAPI HPC Toolkit
wget https://registrationcenter-download.intel.com/akdlm/irc_nas/18211/l_HPCKit_p_2021.4.0.3347.sh
sudo bash l_HPCKit_p_2021.4.0.3347.s
- 我這里安裝intel全家桶,其實:
oneAPI Base Toolki只需要安裝MKL庫,(即Math Kernel library),
oneAPI HPC Toolkit只需要安裝MPI庫、c/c+編譯器、Fortan編譯器三部分即可,
2.2 添加環境變數
把intel的MPI替換系統可能裝好的openMPI,運行該目錄下的setvars.sh檔案
# 編輯 ~/.bashrc或在/etc/profile中添加以下命令
source /opt/intel/oneapi/setvars.sh intel64
2.3 編譯fftw
cd /opt/intel/oneapi/mkl/2021.2.0/interfaces/fftw3xf/
make libintel64 #沒有權限的可將/opt/intel/oneapi修改user
- 查看是否安裝成功
$ ifort --version
# 或者
$ fpp -V

3. 安裝VASP6.1
tar xvf vasp.6.1.0.tar.gz # 解壓vasp安裝包
cd vasp.6.1.0
cp arch/makefile.include.linux_intel makefile.include
#修改檔案makefile.include(注意看下面的注意事項,很關鍵)
make all
3.1 修改檔案makefile.include的注意事項
3.1.1 主要修改的地方
# 加入MKLROOT路徑
MKLROOT = /opt/intel/oneapi/mkl/2021.4.0
# 修改BLAS 和 LAPACK,默認為空
BLAS = -L$(MKL_PATH) -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread
LAPACK = -L$(MKL_PATH) -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread
# gpu設定部分, nvcc后的-allow-unsupported-compiler可以不用加
CUDA_ROOT ?= /usr/local/cuda/
NVCC := $(CUDA_ROOT)/bin/nvcc -ccbin=icc -allow-unsupported-compiler
CUDA_LIB := -L$(CUDA_ROOT)/lib64 -lnvToolsExt -lcudart -lcuda -lcufft -lcublas
GENCODE_ARCH := -gencode=arch=compute_60,code=\"sm_60,compute_60\" \
-gencode=arch=compute_70,code=\"sm_70,compute_70\" \
-gencode=arch=compute_72,code=\"sm_72,compute_72\" \
-gencode=arch=compute_80,code=\"sm_80,compute_80\"
I_MPI_ROOT = /opt/intel/oneapi/mpi/2021.4.0
MPI_INC = $(I_MPI_ROOT)/include
##
3.1.2我的makefile.include 組態檔
# Precompiler options
CPP_OPTIONS= -DHOST=\"LinuxIFC\"\
-DMPI -DMPI_BLOCK=8000 -Duse_collective \
-DscaLAPACK \
-DCACHE_SIZE=4000 \
-Davoidalloc \
-Dvasp6 \
-Duse_bse_te \
-Dtbdyn \
-Dfock_dblbuf
CPP = fpp -f_com=no -free -w0 $*$(FUFFIX) $*$(SUFFIX) $(CPP_OPTIONS)
FC = mpiifort
FCL = mpiifort -mkl=sequential
FREE = -free -names lowercase
FFLAGS = -assume byterecl -w -xHOST
OFLAG = -O2
OFLAG_IN = $(OFLAG)
DEBUG = -O0
MKLROOT = /opt/intel/oneapi/mkl/2021.4.0
MKL_PATH = $(MKLROOT)/lib/intel64
BLAS = -L$(MKL_PATH) -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread
LAPACK = -L$(MKL_PATH) -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread
BLACS = -lmkl_blacs_intelmpi_lp64
SCALAPACK = $(MKL_PATH)/libmkl_scalapack_lp64.a $(BLACS)
OBJECTS = fftmpiw.o fftmpi_map.o fft3dlib.o fftw3d.o
INCS =-I$(MKLROOT)/include/fftw
LLIBS = $(SCALAPACK) $(LAPACK) $(BLAS)
OBJECTS_O1 += fftw3d.o fftmpi.o fftmpiw.o
OBJECTS_O2 += fft3dlib.o
# For what used to be vasp.5.lib
CPP_LIB = $(CPP)
FC_LIB = $(FC)
CC_LIB = icc
CFLAGS_LIB = -O
FFLAGS_LIB = -O1
FREE_LIB = $(FREE)
OBJECTS_LIB= linpack_double.o getshmem.o
# For the parser library
CXX_PARS = icpc
LLIBS += -lstdc++
# Normally no need to change this
SRCDIR = ../../src
BINDIR = ../../bin
#================================================
# GPU Stuff
CPP_GPU = -DCUDA_GPU -DRPROMU_CPROJ_OVERLAP -DUSE_PINNED_MEMORY -DCUFFT_MIN=28 -UscaLAPACK -Ufock_dblbuf
OBJECTS_GPU= fftmpiw.o fftmpi_map.o fft3dlib.o fftw3d_gpu.o fftmpiw_gpu.o
CC = icc
CXX = icpc
CFLAGS = -fPIC -DADD_ -Wall -qopenmp -DMAGMA_WITH_MKL -DMAGMA_SETAFFINITY -DGPUSHMEM=300 -DHAVE_CUBLAS
CUDA_ROOT ?= /usr/local/cuda/
NVCC := $(CUDA_ROOT)/bin/nvcc -ccbin=icc -allow-unsupported-compiler
CUDA_LIB := -L$(CUDA_ROOT)/lib64 -lnvToolsExt -lcudart -lcuda -lcufft -lcublas
GENCODE_ARCH := -gencode=arch=compute_60,code=\"sm_60,compute_60\" \
-gencode=arch=compute_70,code=\"sm_70,compute_70\" \
-gencode=arch=compute_72,code=\"sm_72,compute_72\" \
-gencode=arch=compute_80,code=\"sm_80,compute_80\"
I_MPI_ROOT = /opt/intel/oneapi/mpi/2021.4.0
MPI_INC = $(I_MPI_ROOT)/include/
3.1.3 可能遇到的錯誤
如果出現error: #error directive: -- unsupported ICC configuration! Only ICC 15.0, ICC 16.0, ICC 17.0錯誤,如圖所示,需要在NVCC后加入-allow-unsupported-compiler引數—>(不知道會不會影響計算結果,懂得滴滴我)

編譯成功后,會在bin目錄下產生5個可執行檔案

4. 測驗VASP
將編譯好的檔案目錄添加到~/.bashrc.
export PATH=$PATH:/root/data/vasp/vasp.6.1.0/bin
然后 source ~/.bashrc,
準備好輸入檔案,運行mpirun -n 4 vasp_gpu, 這個4是顯卡的數量,
然后就可以看到計算速度刷刷的,,,cpu計算真的太慢了,

5. 參考鏈接
-
主要的
VASP 6.1.0 + VTST + intel新OneAPI 安裝編譯
VASP下的GPU並行編譯安裝
VASP GPU版本安裝 -
次要的
Nvidia官網教程
第一次GPU加速的VASP計算
新手linux安裝vasp_GPU版本的vasp5.4.4或者vasp6.1.0安裝
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/375087.html
標籤:其他
