Você está na página 1de 18

The Message Passing Interface (MPI)

What Is MPI?
Stand for Message Passing Interface. It is a library of functions that you insert into source code to perform data communication between processes. Each processor runs a process. Processes communicate by exchanging messages.

Goals Of MPI

Standardization Portability Functionality

MPI Programming Structure


include MPI header file variable declarations initialize the MPI environment do computation and MPI communication calls... close MPI communications

Message Passing
It is a type of communication between processes. It is a form of communication used in parallel programming. Communications are completed by sending of messages to recipients.

Point to Point Communication


It is the simplest form of message passing in which one process sends a message to another process. Message consists of an envelope and a body. Envelope has four parts: source, destination, communicator, tag Message body has three parts: buffer, datatype, count

Basic MPI Datatypes


MPI datatype MPI_CHAR MPI_SIGNED_CHAR MPI_UNSIGNED_CHAR MPI_SHORT MPI_UNSIGNED_SHORT MPI_INT MPI_UNSIGNED MPI_LONG MPI_UNSIGNED_LONG MPI_FLOAT MPI_DOUBLE MPI_LONG_DOUBLE C datatype signed char signed char unsigned char signed short unsigned short signed int unsigned int signed long unsigned long float double long double

Set Of MPI Routines


MPI_Init MPI_Finalize MPI_Comm_size MPI_Comm_rank MPI_Send MPI_Recv

Initializes MPI. Terminates MPI. Determines the number of processes. Determines the label of calling process. Sends a message. Receives a message.

Header File:

All Subprogram that contains calls to MPI subroutine must include the MPI header file.

In C: #include<mpi.h>

Initializing MPI
The initialization routine MPI_INIT is the first MPI routine called.
MPI_INIT is called once
int mpi_Init( int *argc, char **argv );

MPI Communicator: Default Communicator is MPI_COMM_WORLD Communicator Size: C: MPI_Comm_size(MPI_Comm comm, int *size)

Communicator Rank:

C: MPI_Comm_rank(MPI_Comm comm, int*rank)

MPI_Send
int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)

MPI_Recv
int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag,MPI_Comm comm, MPI_Status *status)

MPI Finalize

MPI_Finalize();

This function should be called once at the end of the MPI program.

Terminates the MPI execution environment.

A MPI program(c)
#include mpi.h #include <stdio.h> int main(int argc, char *argv[]) { MPI_Init(&argc, &argv); printf(Hello, world!\n); MPI_Finalize(); Return 0; }

A Basic Hello Program


#include <stdio.h> #include <mpi.h> void main (int argc, char *argv[]) { int myrank, size; MPI_Init(&argc, &argv); /* Initialize MPI */ MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* Get my rank */ MPI_Comm_size(MPI_COMM_WORLD, &size); /* Get the total number of processors */ printf("Processor %d of %d: Hello World!\n", myrank, size); MPI_Finalize(); /* Terminate MPI*/ }

Compilation And Execution


Compilation in C:mpicc -o prog prog.c Compilation in C++: mpiCC -o prpg prog.c mpicxx -o prog prog.cpp Executing program: mpirun n N prog (N- No.of processes)

THANK YOU

Você também pode gostar