注意,使用GNU gcc4.8.5版本,因为cuda10.1需要centos7使用这个版本
1. 编译openblas和lapack
- openblas
这是nwchem编译需要使用的库,从官网上下载源代码。
若要删除openblas库,那么直接删除其所在文件就行。git clone https://github.com/xianyi/OpenBLAS.git #编译 make #安装到指定路径 make install PREFIX=/home/jrf/tools/openblas
- lapack
其实openblas包含了lapack库,就不需要再单独安装了.在编译Nwchem的时候,把lapack和blas的目录设置成一个就行了.(存疑?)
编译安装,参考https://www.jianshu.com/p/fe6c4f42aa0b 传送门
2.编译ucx
要使用的OpenMPI为4.0.1版本 所以使用ucx连接。 最开始下载和编译ucx通讯模块。
此处参考
https://github.com/openucx/ucx/wiki/OpenMPI-and-OpenSHMEM-installation-with-UCX
- 下载源代码
$ git clone https://github.com/openucx/ucx.git ucx $ cd ucx
- Run autogen:
$ ./autogen.sh
- Configure
这时遇到了错误:$ mkdir build $ cd build $ ../configure --prefix=/your_install_path
error: NUMA headers not found. Please reconfigure with --disable-numa. Warning: this may have negative impact on library performance. It is better to install libnuma-devel package
根据提示是因为少了libnuma-devel
包,由于是在集群上没有sudo权限,所以使用conda安装(注意,在centos7中对应的包名称是numactl-devel
。
在https://anaconda.org
里面寻找对应的包以及安装方式
但是装好之后发现conda install -c conda-forge numactl-devel-cos6-x86_64
configure
的时候找不到numa.h和libnuma.so文件,所以应当添加头文件和库文件的路径,具体环境变量通过./configure -h
可以得到,具体如下。应当注意,这里有preprocessor(仅预处理)、compile(仅预处理编译,不链接)、link(编译预处理链接)三个阶段对应的flag,都应该加上对应的路径,但是并不是多多益善,g++编译器没有用到这些头文件和库,就不要添加,否则会出错。最后写成了一个pccompile文件放在build
文件夹中。
pccompile文件如下CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a nonstandard directory <lib dir> LIBS libraries to pass to the linker, e.g. -l<library> CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if you have headers in a nonstandard directory <include dir> CPP C preprocessor CXX C++ compiler command CXXFLAGS C++ compiler flags CCAS assembler compiler command (defaults to CC) CCASFLAGS assembler compiler flags (defaults to CFLAGS) LT_SYS_LIBRARY_PATH User-defined run-time library search path. CXXCPP C++ preprocessor DOXYGEN_PAPER_SIZE a4wide (default), a4, letter, legal or executive MPICC MPI C compiler command MPIRUN MPI launch command
#!/bin/bash
export C_INCLUDE_PATH=-I/home/jrf/tools/anaconda3/x86_64-conda_cos6-linux- gnu/sysroot/usr/include/
export CPLUS_INCLUDE_PATH=-I/home/jrf/tools/anaconda3/x86_64-conda_cos6-linux- gnu/sysroot/usr/include/
export OBJC_INCLUDE_PATH=-I/home/jrf/tools/anaconda3/x86_64-conda_cos6-linux-gnu/sysroot/usr/include/
export LDFLAGS=-I/home/jrf/tools/anaconda3/x86_64-conda_cos6-linux-gnu/sysroot/usr/include/ -L/home/jrf/tools/anaconda3/x86_64-conda_cos6-linux-gnu/sysroot/usr/lib64/
export CFLAGS=-I/home/jrf/tools/anaconda3/x86_64-conda_cos6-linux-gnu/sysroot/usr/include/ -L/home/jrf/tools/anaconda3/x86_64-conda_cos6-linux-gnu/sysroot/usr/lib64/
export LDFLAGS=-L/home/jrf/tools/anaconda3/x86_64-conda_cos6-linux-gnu/sysroot/usr/lib64/
export LIBS=-L/home/jrf/tools/anaconda3/x86_64-conda_cos6-linux-gnu/sysroot/usr/lib64/
export CXXPFLA=
export CXXCPP
../configure --prefix=/home/jrf/tools/ucx
- 编译安装
$ make $ make install
2.编译OPENMPI
***************************老方法
- 使用git下载openmpi的最新版本
git clone https://github.com/open-mpi/ompi.git
- Autogen
$ cd ompi $ ./autogen.pl
- Configure with UCX:
这里再次遇到问题:$ mkdir build $ cd build $ ../configure --prefix=/home/jrf/tools/ompi --with-ucx=/home/jrf/tools/ucx
在configure: WARNING: *** Could not find Flex on your system. configure: WARNING: *** Flex is required for developer builds of Open MPI. configure: WARNING: *** Other versions of Lex are not supported. configure: WARNING: *** YOU DO NOT NEED FLEX WHEN BUILDING DISTRIBUTION TARBALLS!
anaconda.org
网站中寻找flex
包,找到如下命令
安装完后,再次configure。conda install -c conda-forge flex
- build
$ make $ make install
***********上面是老方法
new
- 网上搜索
openmpi4.1.0
稳定版本 链接 - 解压,并进入解压文件夹
mkdir build && cd build
- configure 设置安装路径以及对cuda的支持
../configure --prefix=/home/apps/jinrf/tools/ompi --enable-mpi-ext=cuda --with-cuda=/home/apps/jinrf/tools/cuda/cuda-11.0
3.nwchem的安装
官方教学文档点这里
3.1 cpu版本安装 (位置:/home/jrf/Quantum_Soft/nwchem-6.8.1)
- 根据官方教学文档写配置文档pccompile,设置环境变量,pccompile文件内容如下(最终版本):
运行命令#!/bin/bash export NWCHEM_TOP=/home/jrf/Quantum_Soft/nwchem-6.8.1 #这里文档一定要设为 "nwchem-6.8.1" export NWCHEM_TARGET=LINUX64 export ARMCI_NETWORK=MPI-PR export USE_MPI=yes export USE_MPIF=yes export USE_MPIF4=yes export NWCHEM_MODULES=all #BLAS AND LAPACK export BLASOPT="-L/home/jrf/tools/openblas/lib -lopenblas" export LAPACK_LIB="-L/I/DO/NOT/KNOW" export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/jrf/tools/ompi/lib/ export PATH=$PATH:/home/jrf/tools/openmpi/bin/ export MPI_LIB=/home/jrf/tools/ompi/lib export MPI_LOC=/home/jrf/tools/ompi export MPI_INCLUDE=/home/jrf/tools/ompi/include export LIBMPI="-I/home/jrf/tools/ompi/include -pthread -Wl,-rpath -Wl,/home/jrf/tools/ompi/lib -Wl,--enable-new-dtags -L/home/jrf/tools/ompi/lib -lmpi" #export LIBMPI="-lmpi_f77 -lmpi -ldl -Wl,--export-dynamic -lnsl -lutil" unset CC unset FC #export CC=mpicc #export FC=mpif90
注意,这里不能是./pccompile,因为./会重新生成一个shell来运行文件,这样当前shell的环境变量并没有被修改,而 ". pccompile"会在当前shell运行脚本,修改当前shell的环境变量. pccompile
- 运行nwchem_config配置文件
make nwchem_config
- 编译
以下是当时编译遇到的各种问题,1中写的pccompile文件写的就是在解决这些问题过程中一遍遍修改后的最终内容,按照该文件,应该可以避免很多问题。make
-
遇到部分文件没有执行权限,有很多,一个个加就行。
-
遇到部分.c文件中使用的mpi函数已经过时,就像如下所述的错误,按照提示修改对应函数就行。
../../ga-5.6.3/comex/src-armci/message.c: In function ‘armci_msg_sel_scope’: ../../ga-5.6.3/comex/src-armci/message.c:265:24: error: call to ‘MPI_Type_struct’ declared with attribute error: MPI_Type_struct was removed in MPI-3.0. Use MPI_Type_create_struct instead. MPI_Type_struct(2, block, disp, type, &MPI_LONGLONG_INT);
解决方法:按照提示修改对应文件的函数为新函数,新旧函数参数都是相同的,直接修改函数名就可以了,一共有两处,文件位置在
src/tools/ga-5.6.5/comex/src-armci/message.c
src/tools/ga-5.6.5/tcgmsg/tcgmsg-mpi/misc.c
-
遇到错误 gfortran 不识别 -i8标识符
-
make[2]: Leaving directory `/home/jrf/Quantum_Soft/nwchem-6.8.1/src/dimqm'
make[1]: Leaving directory `/home/jrf/Quantum_Soft/nwchem-6.8.1/src/include'
Making libraries in basis
make[1]: execvp: /home/jrf/Quantum_Soft/nwchem-6.8.1/src/tools/guess-mpidefs: Permission denied
make[1]: Entering directory `/home/jrf/Quantum_Soft/nwchem-6.8.1/src/basis'
mpif90 -c -i8 -g -I. -I/home/jrf/Quantum_Soft/nwchem-6.8.1/src/include
-I/home/jrf/Quantum_Soft/nwchem-6.8.1/src/tools/install/include
-DEXT_INT -DLINUX -DLINUX64 -DPARALLEL_DIAG basis.F
gfortran: error: unrecognized command line option ‘-i8’
make[1]: *** [/home/jrf/Quantum_Soft/nwchem-6.8.1/lib/LINUX64/libnwcutil.a(basis.o)] Error 1
make[1]: Leaving directory `/home/jrf/Quantum_Soft/nwchem-6.8.1/src/basis'
make: *** [libraries] Error 1
不设置CC
和FC
变量,使用unset
命令,因为会遇到
mpi_PR test failed
的问题,所以要加上MPI库文件、头文件路径以及设定MPILIB
环境变量,这个变量的内容由以下命令获得。
mpicc -show
mpif90 -show//两个命令得到的都要加上去
最终pccompile
文件修改为
#!/bin/bash
export NWCHEM_TOP=/home/jrf/Quantum_Soft/nwchem-6.8.1 #这里文档一定要设为 "nwchem-6.8.1"
export NWCHEM_TARGET=LINUX64
export ARMCI_NETWORK=MPI-PR
export USE_MPI=yes
export USE_MPIF=yes
export USE_MPIF4=yes
export NWCHEM_MODULES=all
export BLASOPT="-L/home/jrf/tools/openblas/lib -lnwclapack -lopenblas"
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/jrf/tools/ompi/lib/
export PATH=$PATH:/home/jrf/tools/openmpi/bin/
export MPI_LIB=/home/jrf/tools/ompi/lib
export MPI_LOC=/home/jrf/tools/ompi
export MPI_INCLUDE=/home/jrf/tools/ompi/include
export LIBMPI="-I/home/jrf/tools/ompi/include -pthread -Wl,-rpath -Wl,/home/jrf/tools/ompi/lib -Wl,--enable-new-dtags -L/home/jrf/tools/ompi/lib -lmpi"
#export LIBMPI="-lmpi_f77 -lmpi -ldl -Wl,--export-dynamic -lnsl -lutil"
unset CC
unset FC
#export CC=mpicc
#export FC=mpif90
再次遇到问题
gfortran -L/home/jrf/Quantum_Soft/nwchem-6.8.1/lib/LINUX64 -L/home/jrf/Quantum_Soft/nwchem-6.8.1/src/tools/install/lib -o /home/jrf/Quantum_Soft/nwchem-6.8.1/bin/LINUX64/nwchem nwchem.o stubs.o -lnwctask -lccsd -lmcscf -lselci -lmp2 -lmoints -lstepper -ldriver -loptim -lnwdft -lgradients -lcphf -lesp -lddscf -ldangchang -lguess -lhessian -lvib -lnwcutil -lrimp2 -lproperty -lsolvation -lnwints -lprepar -lnwmd -lnwpw -lofpw -lpaw -lpspw -lband -lnwpwlib -lcafe -lspace -lanalyze -lqhop -lpfft -ldplot -ldrdy -lvscf -lqmmm -lqmd -letrans -lpspw -ltce -lbq -lmm -lcons -lperfm -ldntmc -lccca -ldimqm -lnwcutil -lga -larmci -lpeigs -lperfm -lcons -lbq -lnwcutil -L/home/jrf/tools/openblas/lib -lnwclapack -lopenblas -lnwclapack -lnwcblas -L/home/jrf/tools/ompi/lib -I/home/jrf/tools/ompi/include -pthread -Wl,-rpath -Wl,/home/jrf/tools/ompi/lib -Wl,--enable-new-dtags -L/home/jrf/tools/ompi/lib -lmpi -lrt -lpthread -lm -lpthread
/home/jrf/Quantum_Soft/nwchem-6.8.1/lib/LINUX64/libnwcutil.a(util_wallsec.o):在函数‘util_wallsec_’中:
/home/jrf/Quantum_Soft/nwchem-6.8.1/src/util/util_wallsec.F:26:对‘mpi_wtime_’未定义的引用
/home/jrf/Quantum_Soft/nwchem-6.8.1/src/util/util_wallsec.F:32:对‘mpi_wtime_’未定义的引用
/home/jrf/Quantum_Soft/nwchem-6.8.1/src/util/util_wallsec.F:40:对‘mpi_wtime_’未定义的引用
/home/jrf/Quantum_Soft/nwchem-6.8.1/lib/LINUX64/libnwpwlib.a(Parallel-mpi.o):在函数‘parallel_mpiwaitall_’中:
Parallel-mpi.F:(.text+0x5ee):对‘mpi_waitall_’未定义的引用
/home/jrf/Quantum_Soft/nwchem-6.8.1/lib/LINUX64/libnwpwlib.a(Parallel-mpi.o):在函数‘parallel_init_’中:
Parallel-mpi.F:(.text+0x870):对‘mpi_comm_rank_’未定义的引用
Parallel-mpi.F:(.text+0x886):对‘mpi_comm_size_’未定义的引用
/home/jrf/Quantum_Soft/nwchem-6.8.1/lib/LINUX64/libnwpwlib.a(Parallel-mpi.o):在函数‘parallel2d_init_’中:
Parallel-mpi.F:(.text+0xee9):对‘mpi_comm_group_’未定义的引用
Parallel-mpi.F:(.text+0x1124):对‘mpi_group_incl_’未定义的引用
Parallel-mpi.F:(.text+0x113d):对‘mpi_comm_create_’未定义的引用
Parallel-mpi.F:(.text+0x12ec):对‘mpi_group_incl_’未定义的引用
Parallel-mpi.F:(.text+0x1305):对‘mpi_comm_create_’未定义的引用
/home/jrf/Quantum_Soft/nwchem-6.8.1/lib/LINUX64/libnwpwlib.a(Parallel-mpi.o):在函数‘parallel2d_finalize_’中:
Parallel-mpi.F:(.text+0x1629):对‘mpi_comm_free_’未定义的引用
应当是有部分的库路径没有加上,根据提示可以看出这是最后在src文件使用gfortran链接可执行程序,使用mpif90执行相同的命令
mpif90 -L/home/jrf/Quantum_Soft/nwchem-6.8.1/lib/LINUX64 -L/home/jrf/Quantum_Soft/nwchem-6.8.1/src/tools/install/lib -o /home/jrf/Quantum_Soft/nwchem-6.8.1/bin/LINUX64/nwchem nwchem.o stubs.o -lnwctask -lccsd -lmcscf -lselci -lmp2 -lmoints -lstepper -ldriver -loptim -lnwdft -lgradients -lcphf -lesp -lddscf -ldangchang -lguess -lhessian -lvib -lnwcutil -lrimp2 -lproperty -lsolvation -lnwints -lprepar -lnwmd -lnwpw -lofpw -lpaw -lpspw -lband -lnwpwlib -lcafe -lspace -lanalyze -lqhop -lpfft -ldplot -ldrdy -lvscf -lqmmm -lqmd -letrans -lpspw -ltce -lbq -lmm -lcons -lperfm -ldntmc -lccca -ldimqm -lnwcutil -lga -larmci -lpeigs -lperfm -lcons -lbq -lnwcutil -L/home/jrf/tools/openblas/lib -lnwclapack -lopenblas -lnwclapack -lnwcblas -L/home/jrf/tools/ompi/lib -I/home/jrf/tools/ompi/include -pthread -Wl,-rpath -Wl,/home/jrf/tools/ompi/lib -Wl,--enable-new-dtags -L/home/jrf/tools/ompi/lib -lmpi -lrt -lpthread -lm -lpthread
发现成功了,那么应当是因为之前在MPILIB
中没有加上如下命令显示的库,加上.
mpif90 -show
3.2 gpu+CUDA版本安装 (位置:/opt/soft/jinrf/nwchem-7.0.2)
-
在dgx A100上配置cuda环境,已完成.
-
编辑pccompile_nwchem文件
与3.1中纯CPU版本的编译文件略有不同,区别主要在:
1)吸取教训,添加了openmp的选项.之前因为没有添加openmp导致了速度略慢.openmp的环境不用单独配置,都是openmp的库都是跟着编译器一起发布的,GNU和INTEL的编译器都支持.直接在pccompile_nwchem中打开openmp的选项就行了.
2)添加CUDA的支持选项,其中SM表示显卡的计算能力,这里是A100,官方说明为8.0,乘以10即为SM的值.
3)修改NWCHEM_TOP的路径,因为安装路径变了
4)添加了LAPACK_LIB的路径设置(路径内容与blas路径一致,因为blas也提供lapack),这是因为从7.0.0版本开始,如果设置了blas路径,就必须再设置lapack路径.上面3.1的用的是老版本,不会出现这个问题.#!/bin/bash export NWCHEM_TOP=/home/apps/jinrf/nwchem export NWCHEM_TARGET=LINUX64 export ARMCI_NETWORK=MPI-PR export USE_MPI=yes export USE_MPIF=yes export USE_MPIF4=yes export NWCHEM_MODULES=all #blas and lapack library #openblas提供了完整的lapack函数库支持,因此两个函数库的路径,都指明并索引openblas的函数库就行了 export BLASOPT="-L/home/apps/jinrf/tools/openblas/lib -lopenblas" export LAPACK_LIB="-L/home/apps/jinrf/tools/openblas/lib -lopenblas" #调整nwchem的整数位32位整数 export USE_64TO32=y export BLAS_SIZE=4 #openmpi #这个路径是运行的时候才用的,现在不需要 #export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/jrf/tools/ompi/lib/ export PATH=$PATH:/home/apps/jinrf/tools/ompi/bin/ #MPI函数库的路径位置设置,已经不需要了.因为在7.0版本的nwchem,只要路径里面包含mpif90,就可以自动推导出这些位置 #export MPI_LIB=/home/jrf/tools/ompi/lib #export MPI_LOC=/home/jrf/tools/ompi #export MPI_INCLUDE=/home/jrf/tools/ompi/include #export LIBMPI="-I/home/jrf/tools/ompi/include -pthread -Wl,-rpath -Wl,/home/jrf/tools/ompi/lib -Wl,--enable-new-dtags -L/home/jrf/tools/ompi/lib -lmpi -I/home/jrf/tools/ompi/include -pthread -I/home/jrf/tools/ompi/lib -Wl,-rpath -Wl,/home/jrf/tools/ompi/lib -Wl,--enable-new-dtags -L/home/jrf/tools/ompi/lib -lmpi_usempi -lmpi_mpifh -lmpi" #cuda export CUDA_LIBS="-L/home/apps/jinrf/tools/cuda/cuda-11.0/lib64 -lcudart -lcublas" export CUDA_FLAGS="-arch sm_80" export CUDA_INCLUDE="-I/home/apps/jinrf/tools/cuda/cuda-11.0/include" export PATH=/home/apps/jinrf/tools/cuda/cuda-11.0/bin:$PATH export TCE_CUDA=yes export USE_NOIP=true #不需要另外安装openmp的函数库,都是随编译器一起发布的,gcc和icc都支持 export USE_OPENMP=1 #export LIBMPI="-lmpi_f77 -lmpi -ldl -Wl,--export-dynamic -lnsl -lutil" unset CC unset FC #export CC=mpicc #export FC=mpif90
-
编译安装(方法不同于3.1 cpu版本安装,可能是因为之前用的nwchem6.8.1版本,现在用的是7.0.2版本)
编译步骤. pccompile make nwchem_config make 64_to_32 #openblas使用的32位,因此要把nwchem也调整为32位 make -j #-j选项代表要并行编译,会快很多很多很多;但是有可能会出问题,编译不通过了去掉-j试一试
遇到的错误
1)未解决configure: searching for MPI_PR... checking mpi.h usability... yes checking mpi.h presence... yes checking for mpi.h... yes checking for library containing MPI_Init... no configure: error: test for COMEX_NETWORK=MPI_PR failed configure: error: ../../ga-5.7.2/comex/configure failed for comex make[1]: *** [build/config.status] 错误 1
可能的解决办法 链接.
因为装错机子(cu07)了,而另外一台机子(dgx a100)上面安装时候没有这个问题,故未去解决. -
运行测试
测试脚本同这里.
运行命令./run.sh number_of_mpi_process name_of_output_file
其中,run.sh文件的内容是
nohup mpirun -np $1 nwchem simple_cuda.nw |tee $2 &
命令解释
nohup 英文全称 no hang up(不挂起),用于在系统后台不挂断地运行命令,退出终端不会影响程序的运行。
& 在后台运行
tee 将输出同时输入到输出文件和屏幕上
$1运行脚本的第一个输入参数
$2运行脚本的第二个输入参数错误
1 geom_binvr: dsyev failed
Turning off AUTOSYM since SYMMETRY directive was detected! ------------------------------------------------------------------------ geom_binvr: dsyev failed 51539607552 ------------------------------------------------------------------------ ------------------------------------------------------------------------ current input line : 46: end ------------------------------------------------------------------------ ------------------------------------------------------------------------ ------------------------------------------------------------------------ For more information see the NWChem manual at https://github.com/nwchemgit/nwchem/wiki For further details see manual section: [0] Received an Error in Communication: (0) 0:geom_binvr: dsyev failed: MPI_ABORT was invoked on rank 0 in communicator MPI COMMUNICATOR 3 DUP FROM 0 with errorcode 0. 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.
解决
找到了参考3这一相同错误,解答中提供的官方文档参考4解释了错误的原因.这是因为即使在64位的电脑上,OPENBLAS函数库使用的整数默认是32位的(文中还说大部分blas函数库默认都是32位),但是在64位电脑上nwchem使用的整数是32位的.因此有两种解决办法:(1)将nwchem调整为32位整数 (2)将openblas调整为64位整数.这里选择的是方法(1), 如下所示.
- 将nwchem调整为32位整数
在pccompile中添加export USE_64TO32=y export BLAS_SIZE=4
- 编译步骤修改为
. pccompile make nwchem_config make 64_to_32 make -j #-j选项代表要并行编译,会快很多
2 出现大量的函数显示“未定义的引用”
这是在另外一次编译中出现的问题,许多不同库函数调用的函数是未定义的引用。查询得知,可能是因为pccompile 没有写好,忘记加上
错误1
中所提到的export USE_64TO32=y export BLAS_SIZE=4
加上后,重新编译
- 将nwchem调整为32位整数
[1]NVIDIA 不同显卡对应的GPU计算能力 链接
[2]显卡计算能力官方说明 链接
[3]h2o.nw testcase fails: geom_binvr: dsyev failed 链接
[4]nwchem: Compiling NWChem from source