Category Archives: mpi

Installing OpenMPI from Source for Slackware64

The Open MPI Project is an open source Message Passing Interface (MPI) implementation that is developed and maintained by a consortium of academic, research, and industry partners.

Message Passing Interface itself is a system designed by a group of researchers from academica and industry to function on a wide variety in parallel computers.The standard defines the syntax and semantics of a core routines useful to a wide range of users writing protable message-passing programs in Fortran77 or the C programming language.

This article will cover about compiling and installing latest OpenMPI for Linux Slackware64.

Obtain the Materials

The latest version (per May 23th, 2014) is 1.8.1. To build the program we need the source code. Download it from OpenMPI site or direct download from here.

Installation

Assuming we have downloaded the source code, we then extract and do compilation process:

tar -xvfj openmpi-1.8.1.tar.bz2
cd openmpi-1.8.1
./configure CFLAGS=-m64 CXXFLAGS=-m64 --with-wrapper-cflags=-m64 --with-wrapper-cxxflags=-m64
make

The flags we passed to configure script is used to ensure the -m64 flag to gcc and g++ during the build phase and also that mpicc wrapper knows to use -m64 when it compiles our code later.

Next we install it once the compilation process is successful.

make install

To check whether you have successfully install openmpi, invoke this command on terminal:

mpicc --version

Testing

Now let’s make a simple MPI application. Copy this source code and name it as mpi.c:

#include <mpi.h>
#include <stdio.h>

int main(int argc, char** argv) {
   int size, rank;
   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &size);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);

   printf("Hello world from %d of %d\n", rank, size);

   MPI_Finalize();
}

Compile it using:

mpicc -o my_mpi mpi.c

There is a special way to run MPI program. In general, we do like this:

mpirun <program name> <list of arguments>

Thus, to run our program we invoke:

mpirun my_mpi

Watch it and note the result ;)