如何安装Openmpi for xcode?

时间:2012-09-26 01:55:46

标签: c++ xcode linker mpi

我正在尝试在xcode 4中运行一些MPI程序。我通过键入sudo port install openmpi从MacPort安装了openmpi,安装正常完成。然后我将opt / local / include / openmpi添加到我的用户头搜索路径,将“libmpi.dylib”和“libmpi_cxx.dylib”拖到我的项目中。

但是当我尝试运行该程序时,我收到以下错误消息:

Undefined symbols for architecture x86_64:
  "_MPI_Comm_accept", referenced from:
      MPI::Intracomm::Accept(char const*, MPI::Info const&, int) const in main.o
  "_MPI_Comm_connect", referenced from:
      MPI::Intracomm::Connect(char const*, MPI::Info const&, int) const in main.o
  "_MPI_Comm_disconnect", referenced from:
      MPI::Comm::Disconnect() in main.o
  "_MPI_Comm_get_errhandler", referenced from:
      MPI::Comm::Get_errhandler() const in main.o
  "_MPI_Comm_set_errhandler", referenced from:
      MPI::Comm::Set_errhandler(MPI::Errhandler const&) const in main.o
  "_MPI_Comm_spawn", referenced from:
      MPI::Intracomm::Spawn(char const*, char const**, int, MPI::Info const&, int) const in main.o
      MPI::Intracomm::Spawn(char const*, char const**, int, MPI::Info const&, int, int*) const in main.o
  "_MPI_Comm_spawn_multiple", referenced from:
      MPI::Intracomm::Spawn_multiple(int, char const**, char const***, int const*, MPI::Info const*, int) in main.o
      MPI::Intracomm::Spawn_multiple(int, char const**, char const***, int const*, MPI::Info const*, int, int*) in main.o
  "_MPI_Grequest_complete", referenced from:
      MPI::Grequest::Complete() in main.o
  "_MPI_Op_commutative", referenced from:
      MPI::Op::Is_commutative() const in main.o
  "_MPI_Reduce_local", referenced from:
      MPI::Op::Reduce_local(void const*, void*, int, MPI::Datatype const&) const in main.o
  "_MPI_Win_call_errhandler", referenced from:
      MPI::Win::Call_errhandler(int) const in main.o
  "_MPI_Win_get_errhandler", referenced from:
      MPI::Win::Get_errhandler() const in main.o
  "_MPI_Win_set_errhandler", referenced from:
      MPI::Win::Set_errhandler(MPI::Errhandler const&) const in main.o
  "_ompi_mpi_comm_null", referenced from:
      MPI::Intracomm::Intracomm(ompi_communicator_t*) in main.o
      MPI::Graphcomm::Graphcomm(ompi_communicator_t* const&) in main.o
      MPI::Cartcomm::Cartcomm(ompi_communicator_t* const&) in main.o
  "_ompi_mpi_comm_world", referenced from:
      _main in main.o
  "_ompi_mpi_double", referenced from:
      _main in main.o
  "_ompi_mpi_op_sum", referenced from:
      _main in main.o
  "_ompi_op_set_cxx_callback", referenced from:
      MPI::Op::Init(void (*)(void const*, void*, int, MPI::Datatype const&), bool) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我在上述安装过程中遗漏了什么吗?

3 个答案:

答案 0 :(得分:15)

首先确保安装了MPI。 我个人使用brew来执行此操作。

brew update
brew install open-mpi

然后检查c ++的要求:

mpic++ -showme

mpicc -showme for c

我使用mpic ++的输出是:

clang++ -I/usr/local/Cellar/open-mpi/1.8.6/include -L/usr/local/opt/libevent/lib -L/usr/local/Cellar/open-mpi/1.8.6/lib -lmpi_cxx -lmpi

然后我们得到了包含路径,库路径和其他一些标志。从上一个命令的输出中我们得到了我们需要添加的内容:

  1. " /usr/local/Cellar/open-mpi/1.8.6/include"在“搜索路径 - 页眉搜索路径”
  2. "在/ usr /本地的/ opt / libevent的/ lib中"和" /usr/local/Cellar/open-mpi/1.8.6/lib"在“搜索路径 - 图书馆搜索路径”
  3. " -lmpi_cxx -lmpi"在“链接 - 其他链接标志”
  4. 这些可以通过Xcode项目中的构建设置选项完成。

    因为 mpi 需要使用它自己的运行我们的程序,我们需要更改可执行文件

    1. 选择"修改计划" enter image description here
    2. 可执行文件信息下的对话框中,从组合框中选择其他... enter image description here
    3. 将其更改为 mpiexec ,这是" orterun"的别名。对我而言,它位于 /usr/local/Cellar/open-mpi/1.8.6/bin 中。请注意,这通常是隐藏文件夹。您可以按cmd + shift + g
    4. 打开它
    5. 要运行 mpiexec ,需要知道参数处理器数量可执行文件。因此,在参数

      下的同一对话框中
      • 添加&#34; -n X&#34; 其中X是您要使用的处理器数量&#34;对于此示例,我将使用2&#34; < / em>的
      • 添加&#34; $ BUILT_PRODUCTS_DIR / $ EXECUTABLE_PATH&#34; 这是指定可执行文件的环境变量的组合。
    6. enter image description here

      • 然后在您的源代码中添加<mpi.h>标题。
      • 运行它,您将看到2 &#34; Hello,World!&#34; (因为我使用 -n 2 作为示例)。

      来源:open-mpi xcode FAQDebugging & running MPI programs in Xcode

答案 1 :(得分:5)

我遇到了同样的问题,当我从源代码编译openmpi时,添加了头和库搜索路径,但忘了将库添加为构建设置的链接器标志。添加它们就解决了这个您可以键入mpicc –showme以查看mpi运行所需的库。

答案 2 :(得分:0)

或者只输入mpic ++而不是mpicc。这对我有用;)