how to install Openmpi for xcode?

谁说胖子不能爱 提交于 2021-02-06 13:46:47

问题


I'm trying to run some MPI programs in xcode 4. I installed openmpi from MacPort by typing sudo port install openmpi and 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.

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?


回答1:


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 –showme to see the libraries that are necessary for mpi to run.




回答2:


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

brew update
brew install open-mpi

Then check the requirements for c++:

mpic++ -showme

or mpicc -showme for c

My output with mpic++ is :

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”

These can be done through the Build Settings option from the Xcode project.

Because mpi need to use it's own program to run ours we need to change the Executable.

  1. Select "Edit schemes" enter image description here
  2. In the dialog box under Info for the Executable choose Other... from the combobox.enter image description here
  3. Change it to mpiexec wich 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 mpiexec need to know as arguments the number of processors and 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.

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 2 for the example).

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




回答3:


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



来源:https://stackoverflow.com/questions/12593524/how-to-install-openmpi-for-xcode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!