Docsity

MPI - Parallel Computing - Lecture Slides, Slides of Parallel Computing and Programming

Partial preview of the text

Download MPI - Parallel Computing - Lecture Slides and more Slides Parallel Computing and Programming in PDF only on Docsity!

Message Passing and MPI

2

Topics for Today

- Principles of message passing - Building blocks (send,^ receive) - MPI: Message Passing Interface - Overlapping communication with computation - Topologies - Collective communication and computation - Groups and communicators - MPI derived data types - Threading - Remote Memory Access (RMA) - Using MPI - MPI Resources

4

Send and Receive

  • Prototype operations *send(void sendbuf, int nelems, int dest_rank) *receive(void recvbuf, int nelems, int source_rank)
  • Consider the following code fragments: Processor 0 Processor 1 a = 100; receive(&a, 1, 0) send(&a, 1, 1); printf("%d\n", a); a = 0;
  • The semantics of send — value received by process P1 must be 100, not 0 — motivates the design of send and receive protocols

5

Blocking Message Passing

  • Non-buffered, blocking sends —send does not return until the matching receive executes —issues - idling - deadlock
  • Buffered, blocking sends —sender copies the data into the designated buffer —returns after the copy completes —data is copied into buffer at the receiver as well —avoids idling at the expense of copying

7

Buffered, Blocking Message Passing

  • Buffering at the sending and receiving ends avoids idling
  • Sender copies the data into the buffer and returns
  • Data is buffered at the receiver as well
  • Tradeoff —buffering trades idling overhead for data copying overhead

8

Buffered, Blocking Message Passing

NIC moves the data behind the scenes

T

i

m

e

(illustrations show case when sender comes first)

10

Buffered, Blocking Message Passing

Deadlocks are possible with buffering

since receive operations block

Processor 0 Processor 1 receive(&a, 1, 1); receive(&a, 1, 0); send(&b, 1, 1); send(&b, 1, 0);

11

Non-Blocking Message Passing

  • Non-blocking protocols — send and receive return before it is safe - sender: data can be overwritten before it is sent - receiver: can read data out of buffer before it is received —ensuring proper usage is the programmer’s responsibility — status check operation to ascertain completion
  • Benefit — capable of overlapping communication with useful computation
  • Typical implementations —provide both blocking and non-blocking primitives

13

Send and Receive Protocols

Space of possible protocols for send and receive

14

MPI: the Message Passing Interface

  • Standard library for message-passing —portable —almost ubiquitously available —high performance —C and Fortran APIs
  • MPI standard defines —syntax of library routines —semantics of library routines
  • Details —MPI routines, data-types, and constants are prefixed by “MPI_”
  • Simple to get started —fully-functional programs using only six library routines

MPI Primitives at a Glance

16 http://www.mcs.anl.gov/research/projects/mpi/www/www

17

MPI: the Message Passing Interface

Minimal set of MPI routines MPI_Init initialize MPI MPI_Finalize (^) terminate MPI MPI_Comm_size (^) determine number of processes in group MPI_Comm_rank (^) determine id of calling process in group MPI_Send (^) send message MPI_Recv (^) receive message

19

Communicators

  • MPI_Comm : communicator = communication domain —group of processes that can communicate with one another
  • Supplied as an argument to all MPI message transfer routines
  • Process can belong to many different communication domains —domains may overlap
  • MPI_COMM_WORLD : root communicator — includes all the processes

20

Communicator Inquiry Functions

  • int^ MPI_Comm_size(MPI_Comm^ comm,^ int^ *size) —determine the number of processes
  • int^ MPI_Comm_rank(MPI_Comm^ comm,^ int^ *rank) —index of the calling process — 0 ≤ rank < communicator size