C++ 打开 MPI “你好,世界!” 没有编译

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14028136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:54:41  来源:igfitidea点击:

Open MPI "Hello, World!" is not compiling

c++g++mpi

提问by efpies

Here is a simple MPI "Hello, World!" program.

这是一个简单的 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);
}

However, it doesn't seem to compile:

但是,它似乎没有编译:

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

I've googled a lot, viewed mailing lists, thousands of them. They say libmpi_cxxis not linking. But it's in the compiler flags.

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

Here is --showmedata:

这是--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

My compiler is g++.

我的编译器是 g++。

回答by DOOM

Just place the mpi.hheader file above all header files sometimes that causes problem to compile

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

I am not sure how u execute your code. Compiling

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

mpic++ your_code_file.c

Execution

执行

mpirun -np <no. of Processors> ./a.out

回答by user1436187

It is a also much easer and more flexible to compile openmpi and mpi programs in a "Eclipse for Parallel Application Developers" IDE.

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

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

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

回答by Jeff Squyres

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 endof the line. It should be to the leftof -lmpi, not to the rightof it. I'm not show how your installation got borked like that, but that is another possible cause.

  1. 请注意,Open MPI 1.5 是古老的。请升级到 Open MPI 1.6.x 系列的最新版本(目前是 1.6.3,但请注意 www.open-mpi.org 网站目前正在进行计划中的年终维护,不会再回来了直到今天晚些时候,星期四,2012 年 12 月 28 日)。

  2. 我很好奇:你为什么要用 mpic++ 编译一个 C 程序?您只需要使用 mpicc —— C MPI 包装器编译器。那肯定会避免你的问题。然而,如果您使用这个小的 C hello world 程序作为一个简单的例子,而您的实际目标是编译一个 C++ MPI 程序,那么 mpic++ 是正确的包装器来尝试(即使是一个简单的 C 程序)。如果是这种情况,那么您的 C++ 编译器与编译/安装 Open MPI 的 C++ 编译器之间存在某种不兼容/错误配置。

  3. 查看您的 mpic++ --showme 输出,看起来您有某种 Open MPI 的包分发 -- 例如,默认情况下未将 -R 放入标志中。你从哪里得到这个 Open MPI 安装?它很可能与您的 g++ 安装不(完全)兼容(例如,如果它是用不同版本的 g++ 编译的)。

  4. 话虽如此,您的 mpic++ --showme 输出也很奇怪,因为它在行列出了 -lmpi_cxx 。它应该在-lmpi的左边,而不是它的右边。我没有展示您的安装是如何像那样无聊的,但这是另一个可能的原因。

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.
  1. 请尝试升级 Open MPI 并查看问题是否消失。
  2. 仔细检查您安装的 Open MPI 是否与您的系统兼容。