Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
754 views
in Technique[技术] by (71.8m points)

mpi - MPI_Rank return same process number for all process

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
", nProcId, szMachineName);

   if (nProcId == 0)
      printf ("Number of Processes: %d
", 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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...