有的時候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 即可多節點執行。