17

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?

2
  • 1
    What command did you use to compile helloWorld? Nov 29, 2013 at 14:25
  • 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.
    – chuck
    Aug 27, 2014 at 13:25

1 Answer 1

17

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.

5
  • which mpicc and which mpirun both returns /usr/bin/mpicc and /usr/bin/mpirun
    – hamedkh
    Nov 29, 2013 at 17:39
  • Which MPI implementation are you using? Nov 30, 2013 at 12:13
  • I'm using libopenmpi-dev
    – hamedkh
    Dec 1, 2013 at 7:08
  • I had the same problem. Removing openmpi and using only mpich solved my problem.
    – Shibli
    Jan 25, 2015 at 3:25
  • 2
    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.
    – flatline
    Oct 26, 2015 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.