【Linux】Rocky Linux 编译安装 CP2K-2023.1

sudo dnf install tar wget bzip2 unzip patch zlib-devel gcc gcc-c++ perl cmake openmpi openmpi-devel  #是cp2k 安装过程中需要的依赖

然后在 .bashrc 文件中添加:

export PATH=/usr/lib64/openmpi/bin:PATH export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:LD_LIBRARY_PATH

添加完变量后:

wget https://github.com/cp2k/cp2k/releases/download/v2023.1/cp2k-2023.1.tar.bz2
cd ~/cp2k-2023.1/tools/toolchain/

重点来了:

./install_cp2k_toolchain.sh --with-gcc=system --with-openmpi=system --with-cmake=system

根据自己的平台和需求选择,这里gcc, openmpi, cmake 选择刚刚安装的,方便编译成功,具体参数的修改可以按照官方教程来。这里其他的保持cp2k默认的选项,他会安装对应的需要的库。最终结果如下,没有报错。

========================== usage ========================= Done! Now copy: cp /home/chn/cp2k-2023.1/tools/toolchain/install/arch/* to the cp2k/arch/ directory To use the installed tools and libraries and cp2k version compiled with it you will first need to execute at the prompt: source /home/chn/cp2k-2023.1/tools/toolchain/install/setup To build CP2K you should change directory: cd cp2k/ make -j 10 ARCH=local VERSION="ssmp sdbg psmp pdbg"
arch files for GPU enabled CUDA versions are named "local_cuda.*" arch files for GPU enabled HIP versions are named "local_hip.*" arch files for OpenCL (GPU) versions are named "local_opencl.*" arch files for coverage versions are named "local_coverage.*"
Note that these pre-built arch files are for the GNU compiler, users have to adapt them for other compilers. It is possible to use the provided CP2K arch files as guidance.

这里首先要复制生成的arch文件夹

cp /home/chn/cp2k-2023.1/tools/toolchain/install/arch/* /home/chn/cp2k-2023.1/arch/

虽然cp2k包内提供了预制的arch文件,但是不一定好用。

引用一下变量,切换文件夹,开始make

source /home/chn/cp2k-2023.1/tools/toolchain/install/setup
cd /home/chn/cp2k-2023.1/
make -j 10 ARCH=local VERSION="psmp"

-j 是编译使用的cpu数量,这里编译安装psmp版本,psmp是一个能大规模并行计算的版本,相对在特定计算的过程中能节省一些运行内存的使用。

最后加个test验证一下:

make -j 10 ARCH=local VERSION="psmp" test

最终全部通过测试!