I'm trying to run this sample hello world program with openmpi and mpirun on debian 7.
#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;
}
My problem is MPI_Comm_Rank
returns 0 for all copies of the process. When I run this command on the shell:
mpirun -np 4 helloWorld
It produces this output:
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
Why is the number of processes still 1?