MPI: Message Passing Interface An Introduction S. Lakshmivarahan School of Computer Science.

Slides:



Advertisements
Similar presentations
MPI Message Passing Interface Portable Parallel Programs.
Advertisements

CS 140: Models of parallel programming: Distributed memory and MPI.
Chapter 3. MPI MPI = Message Passing Interface Specification of message passing libraries for developers and users –Not a library by itself, but specifies.
Reference: / MPI Program Structure.
MPI Program Structure Self Test with solution. Self Test 1.How would you modify "Hello World" so that only even-numbered processors print the greeting.
A Message Passing Standard for MPP and Workstations Communications of the ACM, July 1996 J.J. Dongarra, S.W. Otto, M. Snir, and D.W. Walker.
Point-to-Point Communication Self Test with solution.
CS 240A: Models of parallel programming: Distributed memory and MPI.
Distributed Memory Programming with MPI. What is MPI? Message Passing Interface (MPI) is an industry standard message passing system designed to be both.
S an D IEGO S UPERCOMPUTER C ENTER N ATIONAL P ARTNERSHIP FOR A DVANCED C OMPUTATIONAL I NFRASTRUCTURE Message Passing Interface (MPI) Part I NPACI Parallel.
Comp 422: Parallel Programming Lecture 8: Message Passing (MPI)
1 Tuesday, October 10, 2006 To err is human, and to blame it on a computer is even more so. -Robert Orben.
A Brief Look At MPI’s Point To Point Communication Brian T. Smith Professor, Department of Computer Science Director, Albuquerque High Performance Computing.
Basics of Message-passing Mechanics of message-passing –A means of creating separate processes on different computers –A way to send and receive messages.
Parallel Programming Using Basic MPI Presented by Timothy H. Kaiser, Ph.D. San Diego Supercomputer Center Presented by Timothy H. Kaiser, Ph.D. San Diego.
A Message Passing Standard for MPP and Workstations Communications of the ACM, July 1996 J.J. Dongarra, S.W. Otto, M. Snir, and D.W. Walker.
Parallel & Cluster Computing MPI Basics Paul Gray, University of Northern Iowa David Joiner, Shodor Education Foundation Tom Murphy, Contra Costa College.
2.1 Message-Passing Computing ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, Jan 17, 2012.
ECE 1747H : Parallel Programming Message Passing (MPI)
1 MPI: Message-Passing Interface Chapter 2. 2 MPI - (Message Passing Interface) Message passing library standard (MPI) is developed by group of academics.
9-2.1 “Grid-enabling” applications Part 2 Using Multiple Grid Computers to Solve a Single Problem MPI © 2010 B. Wilkinson/Clayton Ferner. Spring 2010 Grid.
Part I MPI from scratch. Part I By: Camilo A. SilvaBIOinformatics Summer 2008 PIRE :: REU :: Cyberbridges.
CS 240A Models of parallel programming: Distributed memory and MPI.
Introduction to Parallel Programming with C and MPI at MCSR Part 1 The University of Southern Mississippi April 8, 2010.
Parallel Computing A task is broken down into tasks, performed by separate workers or processes Processes interact by exchanging information What do we.
Parallel Programming with MPI Prof. Sivarama Dandamudi School of Computer Science Carleton University.
Message Passing Programming with MPI Introduction to MPI Basic MPI functions Most of the MPI materials are obtained from William Gropp and Rusty Lusk’s.
Message Passing Programming Model AMANO, Hideharu Textbook pp. 140-147.
Summary of MPI commands Luis Basurto. Large scale systems Shared Memory systems – Memory is shared among processors Distributed memory systems – Each.
Message Passing Interface (MPI) 1 Amit Majumdar Scientific Computing Applications Group San Diego Supercomputer Center Tim Kaiser (now at Colorado School.
1 The Message-Passing Model l A process is (traditionally) a program counter and address space. l Processes may have multiple threads (program counters.
Computer Science and Engineering Parallel and Distributed Processing CSE 8380 February Session 11.
Distributed-Memory (Message-Passing) Paradigm FDI 2004 Track M Day 2 – Morning Session #1 C. J. Ribbens.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Principles of Parallel Programming First Edition by Calvin Lin Lawrence Snyder.
Parallel Programming with MPI By, Santosh K Jena..
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd Edition, by B. Wilkinson & M. Allen, ©
CSCI-455/522 Introduction to High Performance Computing Lecture 4.
1 Message Passing Models CEG 4131 Computer Architecture III Miodrag Bolic.
Chapter 4 Message-Passing Programming. The Message-Passing Model.
Message Passing and MPI Laxmikant Kale CS Message Passing Program consists of independent processes, –Each running in its own address space –Processors.
Message-Passing Computing Chapter 2. Programming Multicomputer Design special parallel programming language –Occam Extend existing language to handle.
Introduction to MPI Nischint Rajmohan 5 November 2007.
Programming distributed memory systems: Message Passing Interface (MPI) Distributed memory systems: multiple processing units working on one task (e.g.
An Introduction to MPI (message passing interface)
Introduction to Parallel Programming at MCSR Message Passing Computing –Processes coordinate and communicate results via calls to message passing library.
Message Passing Interface (MPI) 2 Amit Majumdar Scientific Computing Applications Group San Diego Supercomputer Center Tim Kaiser (now at Colorado School.
Project18 Communication Design + Parallelization Camilo A Silva BIOinformatics Summer 2008.
3/12/2013Computer Engg, IIT(BHU)1 MPI-1. MESSAGE PASSING INTERFACE A message passing library specification Extended message-passing model Not a language.
Implementing Processes and Threads CS550 Operating Systems.
1 Parallel and Distributed Processing Lecture 5: Message-Passing Computing Chapter 2, Wilkinson & Allen, “Parallel Programming”, 2 nd Ed.
MPI-Message Passing Interface. What is MPI?  MPI is a specification for the developers and users of message passing libraries. By itself, it is NOT a.
1 Programming distributed memory systems Clusters Distributed computers ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, Jan 6, 2015.
PVM and MPI.
3/12/2013Computer Engg, IIT(BHU)1 MPI-2. POINT-TO-POINT COMMUNICATION Communication between 2 and only 2 processes. One sending and one receiving. Types:
MPI Message Passing Interface
CS4961 Parallel Programming Lecture 18: Introduction to Message Passing Mary Hall November 2, /02/2010 CS4961.
Is System X for Me? Cal Ribbens Computer Science Department
CS 584.
An Introduction to Parallel Programming with MPI
MPI-Message Passing Interface
Message Passing Models
A Message Passing Standard for MPP and Workstations
Quiz Questions ITCS 4145/5145 Parallel Programming MPI
Introduction to parallelism and the Message Passing Interface
Hardware Environment VIA cluster - 8 nodes Blade Server – 5 nodes
Hello, world in MPI #include <stdio.h> #include "mpi.h"
Hello, world in MPI #include <stdio.h> #include "mpi.h"
MPI Message Passing Interface
CS 584 Lecture 8 Assignment?.
Programming Parallel Computers
Presentation transcript:

MPI: Message Passing Interface An Introduction S. Lakshmivarahan School of Computer Science

MPI: A specification for message passing libraries designed to be a standard for distributed memory message passing, parallel computing Released in the summer FORTRAN and C versions Not a language, a collection of subroutines Knowledge of MPI DOES NOT imply knowledge of parallel programming Precursor to MPI: PVM, EXPRESS, PARMACS, p4

Basic concepts: Processor vs. process Processor is the stand alone computer Process is a task represented by a piece of program One process per processor – else loss of parallelism In MPI need to allocate a fixed number of processors Cannot dynamically spawn processes

Programming Model SPMD Single Program Multiple Data MPMD Multiple Program Multiple Data Each processor does the same computation on different data sets DNA matching IRS agent Different processors doing different computations on different data set University- academic/administration

Parallel Programming requires knowledge of Processors – network topology Algorithms Data structures Possible patterns of communications

A functional view of the parallel processor is essential for successful parallel programming experience To drive a car a functional view would help - on average automobile has over 2000 parts Functional view is – engine, transmission, throttle, break, steering, gas tank, lights, wiper, heater/air conditioner, etc

Processors are connected in a network Physical network topology – Ring, Star, Hypercube, Toroid Ring popo p1p1 p2p2 p3p3 Each processor has two neighbors – two ports One processor is designated as the master – handles I/O Programs/data to all the other processors via master

A View of Processor In buffer Out buffer In buffer Out buffer Port/ Channel Port/ Channel Processor - OS Network OS Processor and NOS communicate by interrupt

Packets DataSourceDestination Packet size system specified – 4Kbytes Packets enter the networks via the in/out buffers

In all MPI has 129 functions - subroutines Many of these require a handful of parameters Classification Point to Point Collective communication within a group A few – about a dozen are sufficient to get started

include “mpif.h” Not an MPI command but every program needs this and is the first line in each program Makes the MPI subroutine library available to the given program

Structure of MPI commands: MPI_ command-name ( parameters) These are names of subroutines to be called using the FORTRAN Call statement MPI standard does not specify the implementation details

First command: MPI_INIT (error) - initiates an MPI session Last command: MPI_FINALIZE (error) - terminates an MPI session error – integer variable

MPI_INITIALIZED (flag, error) Checks initialization of an MPI session flag – logical variable error – integer variable MPI_COMM_SIZE (MPI_COMM_WORLD, nprocs, error) Communicator/ Handle. Integer Determines the total number of processes in a session nprocs, error - integer

MPI_COMM_RANK (MPI_COMM_WORLD, myrank,error) Determines the rank of each processor (assigned by the system) involved in a given MPI session After this command each processor can print their rank myrank, error - integer

A sample program: /* This program uses the five MPI commands*/ Program Sample_1 include “mpif.h” Integer myrank, nprocs, error call MPI_INIT (error) call MPI_COMM_SIZE ( MPI_COMM_WORLD, nprocs, error) call MPI_COMM_RANK (MPI_COMM_WORLD, myrank, error) Print *, “My rank is “, myrank” If ( myrank.eq. 0) “Total number of processes =“, nprocs call MPI_FINALIZE (error) stop end

How many processors to use in a given session? How to run an MPI program? Example: Let myprog be the name of the executable for our sample program myprog –n 4 /*Executes this program on 4 processors*/ Output: My rank is 2 /* output order is not defined*/ My rank is 1 My rank is 0 My rank is 3

Point to point communication: MPI_SEND – to send data – uses 7 parameters - variable name denoting the data items to be sent – real, array - count denoting the number of data items being sent- integer - MPI_INTEGER - destination – processor id - tag – integer to indicate the assigned type - MPI_COMM_WORLD - error

MPI_RECV – to receive data- uses 8 parameters - data item to be received –real array - count denoting the number of data items being sent- integer - MPI_INTEGER - source – processor id - tag – integer to indicate the assigned type - MPI_COMM_WORLD - status to indicate if the receive action is complete - error

There are two modes: block vs. non-block In block send/receive control is returned is returned to the calling program when it is safe to use the sending/receiving buffer In non-block mode control is returned even before it is safe to use the buffer

Problem statement: There are two processors labeled 0 and 1 – master is 0 Master sends a data item (say the value of the year 2002) to processor 1 This is done using the SPMD mode of programming where all the processors have the same copy of the program. p0p0 p1p1 A logical view of the algorithm

Program Sample_2 /* A sample of SPMD program – next 4 slides*/ include “mpif.h” integer myrank, nprocs, error, source, dest, count, tag, year integer status (MPI_STATUS_SIZE) call MPI_INT(error) call MPI_COMM_SIZE (MPI_COMM_WORLD, nprocs, error) call MPICOMM_RANK (MPI_COMM_WORLD, myrank, error) If(nprocs.ne. 2) then /* can use only two processors*/ If (myrank.eq.0) write(6,*) “Nprocs.ne. 2, stop” call MPI_FINALIZE(error) Stop End if

If ( myrank.eq.0) then Year = 2002 /* the data being sent*/ Dest = 1 /* Destination is processor 1*/ Count =1 /* Number of data items*/ Tag=99 /* This message is asigned a tag value of 99 */ Write (6,*) “My rank is, “ myrank, “year=“ year Call MPI_SEND(Year, count, MPI_INTEGER, dest, tag, 1 MPI_COMM_WORLD, error) Endif /* Note that identical copy of the program resides in each processor and what one does at what time depends on the rank of the processor. Tag values range from 0 to */

If ( myrank.eq. 1) then Source = 0 Count = 1 Tag = 99 call MPI_RECV (year, count, MPI_INTEGER, source, tag, 1 MPI_COMM_WORLD, Status, error) Write(6,*) “Myrank,”, myrank, “year = “, year Call MPI_GET_COUNT(status, MPI_Integer, count,error) Write(6,*) “No of Integers Received = “, count Endif

/* Need to complete the program Sample_2 */ Call MPI_FINALIZE (error) Stop End Program Sample_2

System decides which of the two processors you get for this session - may depend on other active jobs The actual communication time depends on if the assigned processors are physically neighbors in the network. If they are, then communication overhead is a minimum, else there is a penalty for mismatch. Notice that the program will still work and give results but may take a longer time - affecting the performance

In the previous example we have specified that processor 1 receive data from a specified source. We can instead use MPI_ANY_SOURCE to receive data from any source We can also use MPI_ANY_TAG can be used to receive data with the specific tag as was used in the above example

Global Communication primitives: MPI_Broadcast: master sends the same data items to all others MPI_Scatter: master sends different data items to all others (This is known as personalized communication) MPI_Gather: all the processors send their results to the master MPI_Send/Recv: all neighbors communicate – used in finite difference calculations MPI_BARRIER

a p0p0 p1p1 p2p2 p3p3 a a a a One to all broadcast: master broadcast its rank to all others MPI_BCAST(myrank, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, error)

Scatter: Personalized communication abcd p0p0 p2p2 p3p3 p1p1 a b c d MPI_SCATTER ( has 9 arguments)

a b c d p0p0 p2p2 p3p3 p1p1 abcd GATHER: all the processors send to master MPI_Gather ( has 9 arguments)

Writing a parallel is like writing music for an ensemble References: W.Gropp, E. Lusk, and A. Skjellum (1995) Using MPI: Portable Parallel Programming with the Message Passing Interface, MIT Press Ian Foster (1995) Design and Building Parallel Programs, Addison Wesley S.Lakshmivarahan and S. K. Dhall (2002) Programming in FORTRAN 90/95, Pearson Publishing