Intermediate MPI (Message-Passing Interface) 1/11

Similar documents
Intermediate MPI (Message-Passing Interface) 1/11

MPI (Message Passing Interface)

Buffering in MPI communications

Point-to-Point Communication. Reference:

Topics. Lecture 6. Point-to-point Communication. Point-to-point Communication. Broadcast. Basic Point-to-point communication. MPI Programming (III)

Non-Blocking Communications

High Performance Computing

Non-Blocking Communications

COSC 6374 Parallel Computation

Lesson 1. MPI runs on distributed memory systems, shared memory systems, or hybrid systems.

Message Passing Interface. George Bosilca

CSE 613: Parallel Programming. Lecture 21 ( The Message Passing Interface )

Introduction to MPI: Part II

Introduction to MPI. SuperComputing Applications and Innovation Department 1 / 143

The MPI Message-passing Standard Practical use and implementation (III) SPD Course 03/10/2010 Massimo Coppola

Parallel Programming

CS 179: GPU Programming. Lecture 14: Inter-process Communication

Topics. Lecture 7. Review. Other MPI collective functions. Collective Communication (cont d) MPI Programming (III)

HPCSE - I. «MPI Programming Model - Part II» Panos Hadjidoukas

Message-Passing Computing

High performance computing. Message Passing Interface

Programming Scalable Systems with MPI. Clemens Grelck, University of Amsterdam

ME964 High Performance Computing for Engineering Applications

High Performance Computing Course Notes Message Passing Programming III

More MPI. Bryan Mills, PhD. Spring 2017

Outline. Introduction to HPC computing. OpenMP MPI. Introduction. Understanding communications. Collective communications. Communicators.

Programming SoHPC Course June-July 2015 Vladimir Subotic MPI - Message Passing Interface

Standard MPI - Message Passing Interface

Cluster Computing MPI. Industrial Standard Message Passing

CS4961 Parallel Programming. Lecture 19: Message Passing, cont. 11/5/10. Programming Assignment #3: Simple CUDA Due Thursday, November 18, 11:59 PM

CME 194 Introduc0on to MPI

Message Passing Interface

High Performance Computing Course Notes Message Passing Programming III

Parallel Short Course. Distributed memory machines

Discussion: MPI Basic Point to Point Communication I. Table of Contents. Cornell Theory Center

Programming Scalable Systems with MPI. UvA / SURFsara High Performance Computing and Big Data. Clemens Grelck, University of Amsterdam

Introduction to parallel computing concepts and technics

Message Passing Programming. Modes, Tags and Communicators

Parallel Programming

More about MPI programming. More about MPI programming p. 1

Recap of Parallelism & MPI

A message contains a number of elements of some particular datatype. MPI datatypes:

COMP 322: Fundamentals of Parallel Programming

Lecture 7: More about MPI programming. Lecture 7: More about MPI programming p. 1

Message Passing Interface. most of the slides taken from Hanjun Kim

ECE 587 Hardware/Software Co-Design Lecture 09 Concurrency in Practice Message Passing

MPI. What to Learn This Week? MPI Program Structure. What is MPI? This week, we will learn the basics of MPI programming.

Document Classification Problem

CS 470 Spring Mike Lam, Professor. Distributed Programming & MPI

Reusing this material

The MPI Message-passing Standard Practical use and implementation (III) SPD Course 01/03/2017 Massimo Coppola

Document Classification

Distributed Systems + Middleware Advanced Message Passing with MPI

CS 470 Spring Mike Lam, Professor. Distributed Programming & MPI

MPI Message Passing Interface

Acknowledgments. Programming with MPI Basic send and receive. A Minimal MPI Program (C) Contents. Type to enter text

Department of Informatics V. HPC-Lab. Session 4: MPI, CG M. Bader, A. Breuer. Alex Breuer

Programming with MPI Basic send and receive

Practical Scientific Computing: Performanceoptimized

MPI, Part 3. Scientific Computing Course, Part 3

IPM Workshop on High Performance Computing (HPC08) IPM School of Physics Workshop on High Perfomance Computing/HPC08

Message Passing with MPI Christian Iwainsky HiPerCH

Further MPI Programming. Paul Burton April 2015

Parallel Programming using MPI. Supercomputing group CINECA

Message Passing Programming. Modes, Tags and Communicators

15-440: Recitation 8

Introduction to MPI. HY555 Parallel Systems and Grids Fall 2003

CSE 160 Lecture 18. Message Passing

Outline. Communication modes MPI Message Passing Interface Standard

Parallel Computing Paradigms

Part - II. Message Passing Interface. Dheeraj Bhardwaj

Introduction to the Message Passing Interface (MPI)

Introduction to TDDC78 Lab Series. Lu Li Linköping University Parts of Slides developed by Usman Dastgeer

Parallel Programming with MPI: Day 1

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 9

Message Passing Interface

High-Performance Computing: MPI (ctd)

Writing Message Passing Parallel Programs with MPI

Basic MPI Communications. Basic MPI Communications (cont d)

Parallel programming MPI

Parallel Programming. Functional Decomposition (Document Classification)

Framework of an MPI Program

University of Notre Dame

Parallel Programming in C with MPI and OpenMP

More advanced MPI and mixed programming topics

Practical Scientific Computing: Performanceoptimized

Programming Using the Message Passing Paradigm

Collective Communication in MPI and Advanced Features

MPI Message Passing Interface. Source:

PCAP Assignment I. 1. A. Why is there a large performance gap between many-core GPUs and generalpurpose multicore CPUs. Discuss in detail.

MPI. (message passing, MIMD)

Slides prepared by : Farzana Rahman 1

Introduction to Parallel. Programming

MPI point-to-point communication

CSE 160 Lecture 15. Message Passing

What s in this talk? Quick Introduction. Programming in Parallel

4. Parallel Programming with MPI

Parallel programming with MPI Part I -Introduction and Point-to-Point Communications

The Message Passing Interface (MPI) TMA4280 Introduction to Supercomputing

The MPI Message-passing Standard Practical use and implementation (II) SPD Course 27/02/2017 Massimo Coppola

Transcription:

Intermediate MPI (Message-Passing Interface) 1/11

What happens when a process sends a message? Suppose process 0 wants to send a message to process 1. Three possibilities: Process 0 can stop and wait until Process 1 is ready to receive the message. 2/11

What happens when a process sends a message? Suppose process 0 wants to send a message to process 1. Three possibilities: Process 0 can stop and wait until Process 1 is ready to receive the message. Process 0 can copy the message into a buffer (internal to the library or user-specified) and return from the MPI_Send call. 2/11

What happens when a process sends a message? Suppose process 0 wants to send a message to process 1. Three possibilities: Process 0 can stop and wait until Process 1 is ready to receive the message. Process 0 can copy the message into a buffer (internal to the library or user-specified) and return from the MPI_Send call. It can report failure. An MPI implementation is allowed to use the first or second interpretation but is not required to use the second one. 2/11

Dealing with buffering in MPI How do we ensure that the parallel program works correctly without depending upon the amount of buffering, if any, provided by the message passing system? 3/11

Dealing with buffering in MPI How do we ensure that the parallel program works correctly without depending upon the amount of buffering, if any, provided by the message passing system? Ordered send and receive. For example even processes send first while odd processes receive first. 3/11

Dealing with buffering in MPI How do we ensure that the parallel program works correctly without depending upon the amount of buffering, if any, provided by the message passing system? Ordered send and receive. For example even processes send first while odd processes receive first. Combined send and receive. MPI provides a combined function MPI_Sendrecv that allows us to send and receive data without worrying about deadlock from a lack of buffering. 3/11

Dealing with buffering in MPI How do we ensure that the parallel program works correctly without depending upon the amount of buffering, if any, provided by the message passing system? Ordered send and receive. For example even processes send first while odd processes receive first. Combined send and receive. MPI provides a combined function MPI_Sendrecv that allows us to send and receive data without worrying about deadlock from a lack of buffering. Use buffered sends. We provide the buffering. 3/11

Dealing with buffering in MPI How do we ensure that the parallel program works correctly without depending upon the amount of buffering, if any, provided by the message passing system? Ordered send and receive. For example even processes send first while odd processes receive first. Combined send and receive. MPI provides a combined function MPI_Sendrecv that allows us to send and receive data without worrying about deadlock from a lack of buffering. Use buffered sends. We provide the buffering. Use nonblocking communication. This can often give the best performance, especially if we use it to overlap communication and computation. 3/11

Dealing with buffering in MPI How do we ensure that the parallel program works correctly without depending upon the amount of buffering, if any, provided by the message passing system? Ordered send and receive. For example even processes send first while odd processes receive first. Combined send and receive. MPI provides a combined function MPI_Sendrecv that allows us to send and receive data without worrying about deadlock from a lack of buffering. Use buffered sends. We provide the buffering. Use nonblocking communication. This can often give the best performance, especially if we use it to overlap communication and computation. Use synchronous sends. MPI provides MPI_Ssend. Send doesn t return until the destination process starts receiving the message. However, this can have performance and scalability issues. 3/11

Send communication modes Standard Mode - Not assumed that corresponding receive routine has started. Amount of buffering not defined by MPI. If buffering provided, send could complete before receive reached. 4/11

Send communication modes Standard Mode - Not assumed that corresponding receive routine has started. Amount of buffering not defined by MPI. If buffering provided, send could complete before receive reached. Buffered Mode - Send may start and return before a matching receive. Necessary to specify buffer space via routine MPI_Buffer_attach(). 4/11

Send communication modes Standard Mode - Not assumed that corresponding receive routine has started. Amount of buffering not defined by MPI. If buffering provided, send could complete before receive reached. Buffered Mode - Send may start and return before a matching receive. Necessary to specify buffer space via routine MPI_Buffer_attach(). Synchronous Mode - Send and receive can start before each other but can only complete together. 4/11

Send communication modes Standard Mode - Not assumed that corresponding receive routine has started. Amount of buffering not defined by MPI. If buffering provided, send could complete before receive reached. Buffered Mode - Send may start and return before a matching receive. Necessary to specify buffer space via routine MPI_Buffer_attach(). Synchronous Mode - Send and receive can start before each other but can only complete together. Ready Mode - Send can only start if matching receive already reached, otherwise error. Use with care. 4/11

More on Send communication modes Each of the four modes can be applied to both blocking and nonblocking send routines. Only the standard mode is available for the blocking and nonblocking receive routines. Any type of send routine can be used with any type of receive routine. 5/11

Buffered Send Prototypes. int MPI_BSend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) int MPI_Buffer_attach(void *buffer, int size) int MPI_Buffer_detach(void *buffer, int *size) 6/11

Buffered Send Prototypes. int MPI_BSend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) int MPI_Buffer_attach(void *buffer, int size) int MPI_Buffer_detach(void *buffer, int *size) MPI_Bsend allows the user to send messages without worrying about where they are buffered (because the user must have provided buffer space with MPI_Buffer_attach ). 6/11

Buffered Send Prototypes. int MPI_BSend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) int MPI_Buffer_attach(void *buffer, int size) int MPI_Buffer_detach(void *buffer, int *size) MPI_Bsend allows the user to send messages without worrying about where they are buffered (because the user must have provided buffer space with MPI_Buffer_attach ). The buffer size given should be the sum of the sizes of all outstanding Bsends that you intend to have, plus MPI_BSEND_OVERHEAD for each Bsend that will be done. 6/11

Buffered Send Prototypes. int MPI_BSend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) int MPI_Buffer_attach(void *buffer, int size) int MPI_Buffer_detach(void *buffer, int *size) MPI_Bsend allows the user to send messages without worrying about where they are buffered (because the user must have provided buffer space with MPI_Buffer_attach ). The buffer size given should be the sum of the sizes of all outstanding Bsends that you intend to have, plus MPI_BSEND_OVERHEAD for each Bsend that will be done. MPI_Buffer_detach returns the buffer address and size so that nested libraries can replace and restore the buffer. 6/11

MPI Nonblocking routines Nonblocking send - MPI_Isend(...) - will return immediately even before source location is safe to be altered. Nonblocking receive - MPI_Irecv(...) - will return even there is no message to accept. 7/11

Nonblocking routine formats MPI_Isend(buf,count,datatype,dest,tag,comm,request) MPI_Irecv(buf,count,datatype,source,tag,comm, request) 8/11

Nonblocking routine formats MPI_Isend(buf,count,datatype,dest,tag,comm,request) MPI_Irecv(buf,count,datatype,source,tag,comm, request) Completion detected by MPI_Wait() and MPI_Test(). 8/11

Nonblocking routine formats MPI_Isend(buf,count,datatype,dest,tag,comm,request) MPI_Irecv(buf,count,datatype,source,tag,comm, request) Completion detected by MPI_Wait() and MPI_Test(). MPI_Wait(MPI_Request *request, MPI_Status *status) int MPI_Waitall(int count, MPI_Request array_of_requests[], MPI_Status array_of_statuses[]) int MPI_Waitany(int count, MPI_Request array_of_requests[], int *index, MPI_Status *status) MPI_Test(MPI_Request *request, int *flag, MPI_Status *status) 8/11

MPI_Isend example MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /* find rank */ if (myrank == 0) { int x; MPI_Isend(&x,1,MPI_INT, 1, msgtag, MPI_COMM_WORLD, req1); compute(); MPI_Wait(req1, status); } else if (myrank == 1) { int x; MPI_Recv(&x,1,MPI_INT,0,msgtag, MPI_COMM_WORLD, status); } 9/11

Sending/Receiving structures (Part 1) We can send a structure by packing it as an array of bytes: struct test { int n; double x[3], y[3]; }; if (pid == source) { struct test test1; MPI_Send(&test1, sizeof(struct test), MPI_BYTE, destination, tag, MPI_COMM_WORLD); } else (pid == destination) { struct test test2; MPI_Recv(&test2, sizeof(struct test), MPI_BYTE, source, tag, MPI_COMM_WORLD, status); } 10/11

Sending/Receiving structures (Part 1) We can send a structure by packing it as an array of bytes: struct test { int n; double x[3], y[3]; }; if (pid == source) { struct test test1; MPI_Send(&test1, sizeof(struct test), MPI_BYTE, destination, tag, MPI_COMM_WORLD); } else (pid == destination) { struct test test2; MPI_Recv(&test2, sizeof(struct test), MPI_BYTE, source, tag, MPI_COMM_WORLD, status); } However, this relies on the layout of the structure being the same on all nodes. It also obfuscates the code and introduces platform dependency so it is not a recommended practice for MPI programs. 10/11

Sending/Receiving structures (Part 2) We can send a structure by creating a custom MPI data type for the structure struct test { int n; double x[3], y[3]; }; const int nitems = 3; int blocklengths[3] = {1, 3, 3}; //lengths of i, x and y as #items MPI_Datatype types[3] = {MPI_INT, MPI_DOUBLE, MPI_DOUBLE}; MPI_Aint offsets[3]; MPI_Datatype mpi_test_type; offsets[0] = offsetof(struct test, n); offsets[1] = offsetof(struct test, x); offsets[2] = offsetof(struct test, y); MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_test_type); MPI_Type_commit(&mpi_test_type); 11/11

Sending/Receiving structures (Part 2) We can send a structure by creating a custom MPI data type for the structure struct test { int n; double x[3], y[3]; }; const int nitems = 3; int blocklengths[3] = {1, 3, 3}; //lengths of i, x and y as #items MPI_Datatype types[3] = {MPI_INT, MPI_DOUBLE, MPI_DOUBLE}; MPI_Aint offsets[3]; MPI_Datatype mpi_test_type; offsets[0] = offsetof(struct test, n); offsets[1] = offsetof(struct test, x); offsets[2] = offsetof(struct test, y); MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_test_type); MPI_Type_commit(&mpi_test_type); See example lab/mpi/send-struct/ for a working example. This is the recommended way of sending a structure in MPI. 11/11

Sending/Receiving structures (Part 2) We can send a structure by creating a custom MPI data type for the structure struct test { int n; double x[3], y[3]; }; const int nitems = 3; int blocklengths[3] = {1, 3, 3}; //lengths of i, x and y as #items MPI_Datatype types[3] = {MPI_INT, MPI_DOUBLE, MPI_DOUBLE}; MPI_Aint offsets[3]; MPI_Datatype mpi_test_type; offsets[0] = offsetof(struct test, n); offsets[1] = offsetof(struct test, x); offsets[2] = offsetof(struct test, y); MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_test_type); MPI_Type_commit(&mpi_test_type); See example lab/mpi/send-struct/ for a working example. This is the recommended way of sending a structure in MPI. Note that there is no way to send a structure that has variable length (because of pointers stored in it) in one message. We have to use two messages. 11/11