Thursday, 20 June 2013

MPI

Posted by Mahesh Doijade
Message Passing Interface, MPI, What is MPI

         

MPI

(Message Passing Interface) is an open standardized message passing library specification to carry out portable message passing on a wide variety of parallel computers and is designed by a wide group of researchers from academia and industry. The first MPI standard draft was prepared in 1992 and after some community reviews MPI 1.0 standard was released in 1994 since then a lot of improvements have been done in the MPI standard, the latest MPI standard is MPI 3.0 released in September 2012.

What MPI is not ?

          MPI is not a programming language nor any compiler specification. Also MPI is not any specific implementation or any software product. MPI is just a message library specification which any MPI implementer can use to develop a message passing library or one can say message passing implementation.

          Various message passing implementations currently exists both in open source as well as commercial vendor provided implementations. Some popular open source MPI implementations are MPICH, OpenMPI, MVAPICH, MPICH is been maintained by Argonne National Laboratory, OpenMPI is been developed and maintained by the open source community whereas MVAPICH is been developed and maintained by Ohio State University and it is a highly optimized implementation for Infiniband, 10Gigabit Ethernet/iWARP and RoCE kind of networks.  All the mentioned open source implementations are available for C, C++ and Fortran. Also, the vendor specific implementations are Intel MPI, HP MPI, SGI MPI etc.
           Following is a minimal MPI program :

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

int main( int argc, char *argv[] )
{
    MPI_Init( &argc, &argv );
    printf( "Hello, world!\n" );
    MPI_Finalize();
    return 0;
}
          Only whatever happens between MPI_Init() and MPI_Finalize() is been defined by MPI standard.The program below is much better MPI program providing idea about which processes are actually in action by giving its rank through MPI_Comm_rank()  and how many MPI processes are there overall through MPI_Comm_size(). 
    
#include "mpi.h"
#include <stdio.h>

int main( int argc, char *argv[] )
{
     int rank, size;

    MPI_Init( &argc, &argv );
    MPI_Comm_rank( MPI_COMM_WORLD, &rank );
    MPI_Comm_size( MPI_COMM_WORLD, &size );

    printf( “Hello I am %d of %d\n", rank, size );

    MPI_Finalize();

    return 0;
 }           
         In order to run a MPI program, like ones written above, one need to install any of the previously mentioned MPI implementation and can compile it as follows in any linux machine "mpicc 'your_source_code.c'   " and can then run through "mpiexec -np 'no_of_processes_required' 'path_to_your_executable' " command. Suppose by compiled MPI executable is 'a.out' and in my working directory and I want to launch 4 processes then my launching command would be.
mpiexec -np 4 ./a.out  
         


 

0 comments:

Post a Comment