如何为 xcode 安装 Openmpi?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12593524/
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-09-15 01:38:22  来源:igfitidea点击:

how to install Openmpi for xcode?

c++xcodelinkermpi

提问by Vokram

I'm trying to run some MPI programs in xcode 4. I installed openmpi from MacPort by typing sudo port install openmpiand the installation finished normally. Then I added opt/local/include/openmpi to my user header search paths, dragged the "libmpi.dylib" and "libmpi_cxx.dylib" into my project.

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

But then when I tried to run the program, I got the following error message:

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

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)

Am I missing anything in the above installation processes?

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

回答by XOR

First be sure to have installed MPI. I personally use brewto do so.

首先确保已经安装了MPI。我个人使用brew来做到这一点。

brew update
brew install open-mpi

Then check the requirements for c++:

然后检查c++的要求:

mpic++ -showme

or mpicc -showme for c

或者 mpicc -showme for c

My output with mpic++ is :

我使用 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

Then we got the include path, library path and some other flags. From the output of the previous command we got that we need to add:

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

  1. "/usr/local/Cellar/open-mpi/1.8.6/include" in the “Search Paths – Header Search Paths”
  2. "/usr/local/opt/libevent/lib" and "/usr/local/Cellar/open-mpi/1.8.6/lib" in the “Search Paths – Library Search Paths”
  3. "-lmpi_cxx -lmpi" in the “Linking – Other Linker Flags”
  1. 搜索路径-标题搜索路径”中的“/usr/local/Cellar/open-mpi/1.8.6/include
  2. 搜索路径-库搜索路径”中的“/usr/local/opt/libevent/lib”和“/usr/local/Cellar/open-mpi/1.8.6/lib
  3. 链接 - 其他链接器标志”中的“-lmpi_cxx -lmpi

These can be done through the Build Settingsoption from the Xcode project.

这些可以通过Xcode 项目的Build Settings选项来完成。

Because mpineed to use it's own program to runours we need to change the Executable.

因为mpi需要使用它自己的程序来运行我们的程序,所以我们需要更改Executable

  1. Select "Edit schemes"enter image description here
  2. In the dialog box under Infofor the Executablechoose Other...from the combobox.enter image description here
  3. Change it to mpiexecwich is an alias of "orterun". For me it's in /usr/local/Cellar/open-mpi/1.8.6/bin. Note that this is usually an hidden folder. You can open it by pressing cmd + shift + g.
  4. For running mpiexecneed to know as arguments the number of processorsand the executable file. So, in the same dialog box under Arguments

    • add "-n X"where X is the number of processors you want to use "for this example i will use 2".
    • add "$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH"wich is the combination of environment variables that specify the executable file.
  1. 选择“编辑方案”在此处输入图片说明
  2. 在下面的对话框中信息可执行文件中选择其他...从ComboBox。在此处输入图片说明
  3. 将其更改为mpiexec,这是“orterun”的别名。对我来说,它在/usr/local/Cellar/open-mpi/1.8.6/bin 中。请注意,这通常是一个隐藏文件夹。您可以按 将其打开cmd + shift + g
  4. 为了运行mpiexec需要知道处理器的数量可执行文件作为参数。因此,在Arguments下的同一个对话框中

    • 添加“-n X”,其中 X 是您要使用的处理器数量“对于此示例,我将使用 2”
    • 添加“$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH”,这是指定可执行文件的环境变量的组合。

enter image description here

在此处输入图片说明

  • Then add <mpi.h>header to your source code.
  • Run it and you will see 2 "Hello, World!"(because I use -n 2for the example).
  • 然后将<mpi.h>标题添加到您的源代码中。
  • 运行它,你会看到 2 "Hello, World!" (因为我使用-n 2作为示例)。

sources : open-mpi xcode FAQ, Debugging & running MPI programs in Xcode

来源:open-mpi xcode FAQ在 Xcode 中调试和运行 MPI 程序

回答by Anton Yakushev

I had the same problem, when I compiled openmpi from the sources, added header and library search paths, but forgot to add libraries as the linker flags to the build settings. Adding them solved this. You can type mpicc –showmeto see the libraries that are necessary for mpi to run.

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

回答by Robin

Or just type mpic++ instead of mpicc. That worked for me ;)

或者直接输入 mpic++ 而不是 mpicc。那对我有用;)