I, personally, would go like this (please note I never compile MPI code in XCode - I do it via Makefile, CMake).
I would have got MPI installed in certain location (from sources) - take a look here how to do it: Running Open MPI on macOS
Then, I'd have created supper simple MPI code (e.g. like this)
#include <stdio.h>
#include "mpi.h"
int main(int argc, char * argv[]){
int my_rank, p, n;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
printf("size: %d rank: %d\n", p, my_rank);
MPI_Finalize();
}
Then, I'd have it compiled using mpicc (as mentioned by @Gilles).
> mpicc -v -o mpi ./mpi.c
> mpirun -np 4 ./mpi
size: 4 rank: 1
size: 4 rank: 2
size: 4 rank: 0
size: 4 rank: 3
Option -v
will give you all the locations you need. Then, I'd have taken all these options into XCode.
You can also use mpicc -show
to get flags required to build MPI based code.
In fact, it should work out of the box. Take a look here:
You need to set includes (as at the picture)

and MPI lib (as in the picture)

and, you should be able to run it as well

To get it running using mpirun
, make sure to set: Product->Scheme->Edit Scheme
. And, make sure to change Arguments
to

and Executable
to mpirun
- it should be inside bin
directory where you have your MPI installed.

Update
It looks like XCode 11.0
requires passing library location as well. In the past it was inferred from the file. Now, you have to pass it explicitly inside build settings

Once you update this location. It will work as expected.
