Centos7下mpich编译
2024-03-06
1分钟阅读时长
编译mpich
解压源码包 最好在/tmp目录下进行,使用内存盘编译速度更快
tar xzf mpich-3.4.3.tar.gz
进入目录
cd mpich-3.4.3
配置安装目录,指定使用CH4通信子系统,并且通过OFI接口与网络硬件进行交互
./configure --prefix=/public/software/mpich-4.0.1 --with-device=ch4:ofi
编译 加入-j自动调用所有核心
make -j
安装
make install
配置它的modulefile
在/public/software/module/tools/modules/modulefiles新建目录mpich
创建文件/public/software/module/tools/modules/modulefile/mpich/3.4.3
#%Module1.0
module-whatis "MPICH is a high performance and widely portable implementation of the Message Passing Interface (MPI) standard."
proc ModulesHelp { } {
puts stderr "MPICH is a high performance and widely portable implementation of the"
puts stderr "Message Passing Interface (MPI) standard."
}
prepend-path LD_LIBRARY_PATH "/public/software/mpich-3.4.3/lib"
prepend-path PATH "/public/software/mpich-3.4.3/bin"
prepend-path MANPATH "/public/software/mpich-3.4.3/share/man"
prepend-path PKG_CONFIG_PATH "/public/software/mpich-3.4.3/lib/pkgconfig"
prepend-path CMAKE_PREFIX_PATH "/public/software/mpich-3.4.3/"
prepend-path CPATH "/public/software/mpich-3.4.3/include"
setenv MPICC "/public/software/mpich-3.4.3/bin/mpicc"
setenv MPICXX "/public/software/mpich-3.4.3/bin/mpic++"
setenv MPIF77 "/public/software/mpich-3.4.3/bin/mpif77"
setenv MPIF90 "/public/software/mpich-3.4.3/bin/mpif90"
测试
新建mpic的hello.c
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv){
//初始化MPI环境
MPI_Init(NULL, NULL);
//获取进程数
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
//获取进程的等级
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
//获取进程的名字
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
//打印helloworld
printf("Hello world from processor %s, rank %d out of %d processors\n",processor_name, world_rank, world_size);
//关闭MPI环境
MPI_Finalize();
}
编译hello.c
mpicc hello.c -o hello
验证mpirun
mpirun -n 4 ./hello
验证mpirun和slurm srun提交到集群都通过