gpt4 book ai didi

c++ - 如何为 xcode 安装 Openmpi?

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:26:41 26 4
gpt4 key购买 nike

我正在尝试在 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)

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

最佳答案

首先一定要安装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/local/opt/libevent/lib”和“/usr/local/Cellar/open-mpi/1.8.6/lib”
  3. “Linking – Other Linker Flags”中的“-lmpi_cxx -lmpi”

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

因为 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. 要运行 mpiexec,需要知道作为参数的处理器数量可执行文件。因此,在 Arguments

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

enter image description here

  • 然后添加<mpi.h> header 到您的源代码。
  • 运行它,您将看到 2 “Hello, World!”(因为我使用 -n 2 作为示例)。

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

关于c++ - 如何为 xcode 安装 Openmpi?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12593524/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com