MPI_Rank return same process number for all process

走远了吗. 提交于 2019-11-26 04:28:15

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/20287564/mpi-rank-return-same-process-number-for-all-process

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!