Ubuntu下的lammps GPU加速(真的香)

参考

Lammps实现GPU加速,博客界面很好看。

显卡驱动安装(本文默认为英伟达)

- 检查自己的驱动是否安装成功

nvidia-smi

如果安装成功会有如下输出:
在这里插入图片描述
如果未安装会有如下结果:

nvidia-smi command not found

- 安装驱动

ubuntu-drivers devices  			 # 查询所有ubuntu推荐的驱动
sudo ubuntu-drivers autoinstall

手动安装可以部分参考我的另一篇博客报错解决:Before you can run VMware, several modules must be compiled and …(更換內核)

禁用nouveau driver

nouveau开源驱动,性能很差,基本都禁用它,之前安装Ubuntu系统时,引导文件里就进行了禁用:

sudo vi /etc/modprobe.d/blacklist.conf

最后添加:

blacklist nouveau
options nouveau modeset=0

保存退出后,终端输入:

sudo update-initramfs -u
sudo reboot

reboot之后输入:

lsmod | grep nouveau

无输出代表禁用成功

CUDA Toolkit 安装

上NVIDIA官网进行下载:CUDA Toolkit 10.2 Download,安装流程很详细,但是网速很感人,建议大家翻墙…
在这里插入图片描述
安装完cuda之后添加环境变量:

vi .bashrc
export PATH=$PATH:/usr/local/cuda-10.2/bin

之后输入:nvcc -V,就会以下信息:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

Generic Linux Makefile for CUDA文件配置

进入gpu目录,修改Makefile.linux

cd lammps-3Mar20/lib/gpu
vim Makefile.linux

修改以下信息,符合自己的机子和计算要求即可:

CUDA_HOME = /usr/local/cuda-10.2			#注意版本
# Turing hardware
CUDA_ARCH = -arch=sm_75
CUDA_PRECISION = -D_SINGLE_DOUBLE		#我选的计算过程中的精度

hardware参数可以见维基的介绍CUDA,我的gtx 1660ti对应的Micro-architecture和Compute capability (version)分别为Turing,7.5,所以应该选择sm_75。
在这里插入图片描述
之后进行make:

make -f Makefile.linux

如果之后更改Makefile.linux 中的内容之后需要重新编译需要先 make clean 一下:

make -f Makefile.linux clean

Lammps GPU package

cd lammps-3Mar20/src
make package-status				#查阅自己的package安装信息
make yes-gpu					#添加gpu包
make mpi						#编译mpi

如果编译过mpi文件,则可以先clean一波:make clean-all,如果还是有问题,可以考虑万能的sudo

测试

官网的例子,还是shear:

cd lammps/lammps-3Mar20/examples/shear

12线程无GPU:

mpirun -np 12 lmp_mpi < in.shear

12线程1GPU:

mpirun -np 12 lmp_mpi -sf gpu -pk gpu 1 -in in.friction

由于是小体系的example,GPU加速效果不是很明显,甚至慢很多,但是跑自己的程序,原子数目一多,GPU加速特别明显!!!!!!!!!!!!大概是五倍以上的速度!!!!

一万多原子,4000步摩擦,12线程无GPU花了3:28s,12线程1GPU只花了37s,真的太香了。

每10秒输出一次显卡状态:

watch -n 10 nvidia-smi

在这里插入图片描述

To run LAMMPS with GPU acceleration on Ubuntu using NVIDIA GPUs, you need to follow these steps: 1. Install NVIDIA driver: Ensure that you have the latest NVIDIA driver installed on your system. You can use the instructions provided earlier to install or update the NVIDIA driver on Ubuntu. 2. Install CUDA Toolkit: LAMMPS requires CUDA to run on GPUs. Install the CUDA Toolkit, which includes the necessary libraries and tools for GPU computing. You can download the CUDA Toolkit from the NVIDIA website and follow their installation instructions. 3. Download and compile LAMMPS: Obtain the LAMMPS source code from the official LAMMPS website or GitHub repository. Extract the source code to a directory of your choice. 4. Set up Makefile: Navigate to the LAMMPS source code directory and locate the Makefile. Open the Makefile and modify it to include GPU support. Uncomment or add the appropriate lines for GPU acceleration using CUDA. For example, you may need to set `GPU` to `yes`, specify the CUDA path, and select the appropriate CUDA architecture. 5. Compile LAMMPS: In the terminal, navigate to the LAMMPS source code directory and run `make mpi` or `make serial` depending on your desired configuration. This will compile LAMMPS with GPU support enabled. 6. Run LAMMPS with GPU acceleration: Once the compilation is complete, you can run LAMMPS with GPU acceleration by using the `lmp_mpi` or `lmp_serial` executable generated during the compilation process. Be sure to specify the appropriate input script and any necessary command-line options. For example, to run a LAMMPS input file named "input.lammps" using multiple GPUs, you can use the following command: ``` mpirun -np <number of MPI processes> lmp_mpi -sf gpu -pk gpu <number of GPUs> -in input.lammps ``` Replace `<number of MPI processes>` with the desired number of MPI processes, and `<number of GPUs>` with the number of GPUs you want to use. Please note that the specific steps and commands may vary depending on your LAMMPS version, GPU configuration, and system setup. Refer to the LAMMPS documentation and CUDA Toolkit documentation for more detailed instructions and troubleshooting information.
评论 25
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YuanbaoQiang

你的鼓励将是我创作的最大动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值