Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPI_Rank return same process number for all process

Tags:

mpi

openmpi

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?

like image 571
hamedkh Avatar asked Nov 29 '13 14:11

hamedkh


1 Answers

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.

like image 99
Hristo Iliev Avatar answered Nov 21 '22 20:11

Hristo Iliev