Prácticas recomendadas
MPI
30/07/202652914 vistas
Note: Testing has shown that the system runs normally on Ubuntu 20.04, but may hang on Ubuntu 22.04. Please select the Ubuntu 20.04 image. The cause is unknown; if you know the reason, please let us know. Thank you very much!
Installation
# 注意不要安装和使用openmpi包,该包存在问题
apt update && apt-get install mpich
Verification
Simple test:
# 使用mpi执行ls命令,看是否可以输出目录和文件
mpirun -n 2 ls
Compilation and testing:
# 编写test.c文件,内容为:
#include <stdio.h>
#include <mpi.h>
int main (int argc, char** argv) {
int size, rank;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("size = %d rank = %d\n", size, rank);
MPI_Finalize();
}
# 编译,将输出a.out可执行文件
mpicc test.c
# 执行,注意使用绝对路径,因为a.out不在PATH环境变量中,这里测试目录是/root
mpirun -n 1 /root/a.out
