我正在尝试在debian 7上使用openmpi和mpirun运行此示例hello world程序。
#include <stdio.h>
#include <mpi/mpi.h>
int main (int argc, char **argv) {
int nProcId, nProcNo;
int nNameLen;
char szMachineName[MPI_MAX_PROCESSOR_NAME];
MPI_Init (&argc, &argv); // Start up MPI
MPI_Comm_size (MPI_COMM_WORLD,&nProcNo); // Find out number of processes
MPI_Comm_rank (MPI_COMM_WORLD, &nProcId); // Find out process rank
MPI_Get_processor_name (szMachineName, &nNameLen); // Get machine name
printf ("Hello World from process %d on %s\r\n", nProcId, szMachineName);
if (nProcId == 0)
printf ("Number of Processes: %d\r\n", nProcNo);
MPI_Finalize (); // Shut down MPI
return 0;
}
我的问题是MPI_Comm_Rank该过程的所有副本都返回0。当我在外壳上运行此命令时:
mpirun -np 4 helloWorld
它产生以下输出:
Hello World from process 0 on debian
Number of Processes: 1
Hello World from process 0 on debian
Number of Processes: 1
Hello World from process 0 on debian
Number of Processes: 1
Hello World from process 0 on debian
Number of Processes: 1
为什么进程数仍为1?
侃侃尔雅