MPI_Rank return same process number for all process
Asked Answered
T

1

18

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?

Transformism answered 29/11, 2013 at 14:6 Comment(2)
What command did you use to compile helloWorld?Manard
I know this is a little late but mpicc helloWorld.c would normally create an executable called a.out. mpicc -o helloWorld helloWorld.c would create an executable called helloWorld.Reface
P
18

Make sure that both mpicc and mpirun come from the same MPI implementation. When mpirun fails to provide the necessary universe information to the launched processes, with the most common reason for that being that the executable was build against a different MPI implementation (or even a different version of the same implementation), MPI_Init() falls back to the so-called singleton MPI initialisation and creates an MPI_COMM_WORLD that only contains the calling process. Thus the result is many MPI processes within their own separate MPI_COMM_WORLD instances.

Usually commands like mpicc --showme, which mpicc and which mpirun could help you find out if that is the case indeed.

Plume answered 29/11, 2013 at 16:3 Comment(5)
which mpicc and which mpirun both returns /usr/bin/mpicc and /usr/bin/mpirunTransformism
Which MPI implementation are you using?Plume
I'm using libopenmpi-devTransformism
I had the same problem. Removing openmpi and using only mpich solved my problem.Genesisgenet
I have both openmpi and mpich installed on Mint 17 - and was switching between them using update-alternatives --configure mpi. This however does not switch out the mpiexec implementation, for which you must also do an update-alternatives --configure mpirun.Slobbery

© 2022 - 2024 — McMap. All rights reserved.