有的时候MPI需要使用多节点,那么测试哪些进程在哪些机器上就比较重要,如下可以简单测试一下。
#include <unistd.h>
#include <stdio.h>
#include <mpi.h>
int main (int argc, char* argv[]) {
char hostname[100];
int rank, size;
MPI_Init (&argc, &argv); /* starts MPI */
MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */
MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */
gethostname(hostname,sizeof(hostname));
printf( "Hello world from process %d of %d: host: %s\n", rank, size, hostname);
MPI_Finalize();
return 0;
}
另外使用
mpirun -np X hostname 可以输出X个当前机器hostname
可以方便将这些输出聚合在一起,写成一个machinelist
使用
mpirun -np 6 -machinefile ./machinelist ./a.out 即可多节点执行。