3

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?

2
  • Check that Open MPI was compiled as 64-bit (x86_64) or as fat 64- and 32-bit and not as 32-bit (i386) only (e.g. run file /path/to/libmpi.dylib in Terminal.app). If it is 32-bit only, either recompile it or switch your project's target to i386. Commented Sep 27, 2012 at 9:07
  • macports is always a good option if your having trouble with Xcode Commented Sep 30, 2012 at 3:14

3 Answers 3

19

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

Sign up to request clarification or add additional context in comments.

3 Comments

Great tutorial! Should be top answer
The linker flag "-lmpi_cxx" failed for me on Mac OS 10.13, had to use "-lm" instead. Also note the hint on overlong temp file paths in open-mpi.org/faq/?category=osx on this OS.
yeah this answer is quite old, I invite you to update it.
5

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.

1 Comment

For me it returns the following: gcc -I/usr/local/include -L/usr/local/lib -lmpi -lm
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.