11

这是一个简单的 MPI “Hello, World!” 程序。

#include <stdio.h>
#include <mpi.h>

int main(int argc, char **argv)
{
   int size, rank;
   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &size);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   printf("SIZE = %d RANK = %d\n",size,rank);
   MPI_Finalize();   
   return(0);
}

但是,它似乎没有编译:

Undefined                       first referenced
 symbol                             in file
MPI::Datatype::Free()               /var/tmp//ccE6aG2w.o
MPI::Win::Free()                    /var/tmp//ccE6aG2w.o
MPI::Comm::Comm()                   /var/tmp//ccE6aG2w.o
ld: fatal: symbol referencing errors. No output written to main
collect2: ld returned 1 exit status

我用谷歌搜索了很多,查看了数千个邮件列表。他们说libmpi_cxx没有链接。但它在编译器标志中。

这是--showme数据:

mpic++ --showme:compile
-I/usr/openmpi/ompi-1.5/include -I/usr/openmpi/ompi-1.5/include/openmpi

mpic++ --showme:link
-R/opt/mx/lib -R/usr/openmpi/ompi-1.5/lib -L/usr/openmpi/ompi-1.5/lib -lmpi -lopen-rte -lopen-pal -lnsl -lrt -lm -ldl -lsocket -lmpi_cxx

我的编译器是 g++。

4

3 回答 3

13

只需将mpi.h头文件放在所有头文件之上,有时会导致编译问题

我不确定你如何执行你的代码。编译

mpic++ your_code_file.c

执行

mpirun -np <no. of Processors> ./a.out
于 2012-12-25T09:19:22.577 回答
2

A few notes:

  1. Note that Open MPI 1.5 is ancient. Please upgrade to the latest version in the Open MPI 1.6.x series (which is currently 1.6.3, but note that the www.open-mpi.org web site is currently undergoing a planned year-end maintenance and won't be back up until later today, Thursday, December 28, 2012).

  2. I'm curious: why are you compiling a C program with mpic++? You only need to use mpicc -- the C MPI wrapper compiler. That would definitely avoid your issue. However, if you are using this small C hello world program as a simple example and your actual target is to compile a C++ MPI program, then mpic++ is the correct wrapper to try (even with a simple C program). If that's the case, then you have some kind of incompatibility / misconfiguration between your C++ compiler and the C++ compiler that Open MPI was compiled/installed with.

  3. Looking at your mpic++ --showme output, it looks like you have some kind of package distribution of Open MPI -- -R is not put in the flags by default, for example. Where did you get this Open MPI installation? It's quite possible that it is not (fully) compatible with your g++ installation (e.g., if it was compiled with a different version of g++).

  4. That being said, your mpic++ --showme output is also weird in that it lists -lmpi_cxx at the end of the line. It should be to the left of -lmpi, not to the right of it. I'm not show how your installation got borked like that, but that is another possible cause.

So to sum up, my answer is:

  1. Please try upgrading Open MPI and see if the problem goes away.
  2. Double check that your installation of Open MPI is compatible with your system.
于 2012-12-27T21:03:16.090 回答
1

在“Eclipse for Parallel Application Developers”IDE 中编译 openmpi 和 mpi 程序也更加容易和灵活。

http://www.eclipse.org/downloads/packages/eclipse-parallel-application-developers/junosr1

于 2012-12-25T09:41:05.307 回答