This tutorial discusses how to debug, compile, and run MPI programs in Xcode 4.
Install OpenMPI & Xcode
First of all, make sure you have already installed Xcode & MPI.(I’m using Xcode 4.5 and OpenMPI 1.6.1)
Xcode now available on the Mac App Store: http://itunes.apple.com/us/app/xcode/id497799835?mt=12
this version(4.5) of Xcode has a pretty annoying bug – it only shows the first letter of input, but the variable would take in the full string
*Xcode 4.5.1 fixes the issue where the debug console failed to display some text.
Open MPI is available here : http://www.open-mpi.org/software/ompi/
Open MPI Installation tutorial: https://sites.google.com/site/dwhipp/tutorials/installing-open-mpi-on-mac-os-x
Create a new Xcode Project
Let’s create a command line C project called mpi_hello. I will use the the example given at <http://www.cs.usfca.edu/~peter/cs220/code/mpi_hello/mpi_hello.c> to demonstrate. The author of this program is Prof.Pacheco.
Change Project Build Settings
As Prof.Pacheco said in class,
“The mpicc command is just a “wrapper” for gcc. It runs gcc and makes sure that gcc knows where the MPI header files are and how to link in the MPI libraries.”
Open a new terminal window and type $ mpicc -showme
gcc -I/usr/local/include -L/usr/local/lib -lmpi -lm
Then we got the include path, library path and some other flags.
So click on the project in Xcode and then click on Build Settings and change the following:
add “/usr/local/include” to “Search Paths – Header Search Paths”
add”/usr/local/lib” to “Search Paths – Library Search Paths”
add “-lmpi -lm” to “Linking – Other Linker Flags”
the “mpi.h file not found error” should be gone now.
In order to run the program with multi processors, we need to edit the “schemes” of the project.
when we run the MPI program via command line, we use “mpiexec -n <number of processes>”
so, we need to change the “Executable” to mpiexec
mpiexec is located at “/usr/local/bin”, it’a an alias of “orterun”
“/usr/local/bin” is by default hidden in the Finder. You can press “command + shift + G” then type in “/usr/local/bin” and press “Go”. Then choose “orterun”
For running with multi processors, we also the arguments “-n <number of processors> <executable file>”.
So, click on “Arguments”, add “-n 4” and “$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH” to “Arguments Passed On Launch”
($BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH is the combination of environment variables that specify the executable file.)
Now you can run your MPI programs~!