Running Open MPI on macOS

I am, generally, against all these automation stuff (brew, etc.) at macOS. I prefer to install everything from sources (as long as it is possible).

So, here are few steps to get Open MPI up and running at macOS. Please make sure to download source package from:

# put this file somewhere inside your $HOME
# and untar it
> tar xf openmpi-2.0.2.tar
> cd openmpi-2.0.2/

# Make sure you have XCode and command line tools
# installed - all of these if free of charge
> ./configure --prefix=$HOME/opt/usr/local
> make all
> make install

# After installation is done, you can 
# verify it
> $HOME/usr/local/bin/mpirun --version
mpirun (Open MPI) 2.0.2

Report bugs to

Now, it’s time for Hello world! code.

/* Put this text inside hello.c file */

int main(int argc, char** argv) {
    int rank;
    int world;

    MPI_Init(NULL, NULL);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &world);
    printf("Hello: rank %d, world: %d\n",rank, world);

And, eventually, we can compile and run it

$HOME/opt/usr/local/bin/mpicc -o hello ./hello.c
$HOME/opt/usr/local/bin/mpirun -np 2 ./hello
Hello: rank 0, world: 2
Hello: rank 1, world: 2

That’s all.

Leave a comment

Your comment