Parallel Programming. Using MPI (Message Passing Interface)

Similar documents
MPI. (message passing, MIMD)

Working with IITJ HPC Environment

CDP. MPI Derived Data Types and Collective Communication

Introduction to MPI. HY555 Parallel Systems and Grids Fall 2003

Parallel Programming in C with MPI and OpenMP

Programming Using the Message Passing Paradigm

Capstone Project. Project: Middleware for Cluster Computing

Collective Communications

Message Passing Interface

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

Distributed Systems + Middleware Advanced Message Passing with MPI

Parallel Computing Paradigms

Cluster Computing MPI. Industrial Standard Message Passing

Message Passing Interface

MPI: Parallel Programming for Extreme Machines. Si Hammond, High Performance Systems Group

Practical Scientific Computing: Performanceoptimized

Parallel Programming in C with MPI and OpenMP

Recap of Parallelism & MPI

Distributed Memory Systems: Part IV

4. Parallel Programming with MPI

Outline. Communication modes MPI Message Passing Interface Standard

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

Review of MPI Part 2

Parallel programming MPI

Introduction to Parallel Programming

Last Time. Intro to Parallel Algorithms. Parallel Search Parallel Sorting. Merge sort Sample sort

Scientific Computing

MPI - The Message Passing Interface

Outline. Communication modes MPI Message Passing Interface Standard. Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa Tp.HCM

Programming Using the Message Passing Interface

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

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

Agenda. MPI Application Example. Praktikum: Verteiltes Rechnen und Parallelprogrammierung Introduction to MPI. 1) Recap: MPI. 2) 2.

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

Distributed Memory Parallel Programming

Chapter 4. Message-passing Model

Programming with MPI Collectives

Introduction to the Message Passing Interface (MPI)

Collective Communications I

Slides prepared by : Farzana Rahman 1

Praktikum: Verteiltes Rechnen und Parallelprogrammierung Introduction to MPI

MPI MESSAGE PASSING INTERFACE

HPC Parallel Programing Multi-node Computation with MPI - I

Parallel Processing WS 2017/18. Universität Siegen Tel.: 0271/ , Büro: H-B Stand: January 15, 2018

COMP 322: Fundamentals of Parallel Programming. Lecture 34: Introduction to the Message Passing Interface (MPI), contd

15-440: Recitation 8

MPI Programming. Henrik R. Nagel Scientific Computing IT Division

Part - II. Message Passing Interface. Dheeraj Bhardwaj

MPI Tutorial Part 1 Design of Parallel and High-Performance Computing Recitation Session

Message Passing Interface

MPI Tutorial Part 1 Design of Parallel and High-Performance Computing Recitation Session

Cornell Theory Center. Discussion: MPI Collective Communication I. Table of Contents. 1. Introduction

Experiencing Cluster Computing Message Passing Interface

COMP 322: Fundamentals of Parallel Programming

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

1 Overview. KH Computational Physics QMC. Parallel programming.

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

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

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

First day. Basics of parallel programming. RIKEN CCS HPC Summer School Hiroya Matsuba, RIKEN CCS

MPI Message Passing Interface

Parallel Programming with MPI: Day 1

MPI Program Structure

Introduction to MPI. Ricardo Fonseca.

Programming Using the Message-Passing Paradigm (Chapter 6) Alexandre David

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

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

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

NUMERICAL PARALLEL COMPUTING

The Message Passing Model

Introduction to the Message Passing Interface (MPI)

Programming Distributed Memory Machines with Message Passing (MPI)

Parallel Programming with MPI MARCH 14, 2018

MPI point-to-point communication

MPI Collective communication

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

Message Passing Interface - MPI

Message Passing Programming with MPI. Message Passing Programming with MPI 1

Basic MPI Communications. Basic MPI Communications (cont d)

CPS 303 High Performance Computing

Today's agenda. Parallel Programming for Multicore Machines Using OpenMP and MPI

Lecture Topic: Multi-Core Processors: MPI 1.0 Overview (Part-II)

Parallel Computing. Distributed memory model MPI. Leopold Grinberg T. J. Watson IBM Research Center, USA. Instructor: Leopold Grinberg

Intermediate MPI. M. D. Jones, Ph.D. Center for Computational Research University at Buffalo State University of New York

Data parallelism. [ any app performing the *same* operation across a data stream ]

Parallel Programming, MPI Lecture 2

CS 426. Building and Running a Parallel Application

Message Passing with MPI

MPI 程式撰寫與實作 鄭守成 周朝宜 2006/11/04

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

Parallel Applications Design with MPI

Reusing this material

Collective Communication in MPI and Advanced Features

The Message Passing Interface (MPI): Parallelism on Multiple (Possibly Heterogeneous) CPUs

Parallel Computing. PD Dr. rer. nat. habil. Ralf-Peter Mundani. Computation in Engineering / BGU Scientific Computing in Computer Science / INF

Message-Passing and MPI Programming

Introduction to MPI: Part II

High-Performance Computing: MPI (ctd)

MPI Course Overview. Home MPI Programming MPI 2.2 Index Using MPI at NF

An Introduction to Parallel Programming

Transcription:

Parallel Programming Using MPI (Message Passing Interface)

Message Passing Model Simple implementation of the task/channel model Task Process Channel Message Suitable for a multicomputer Number of processes specified at startup Remains constant All execute from the same code Each has a unique ID (rank) allows different paths inside the code Alternately perform computations and communications 2010@FEUP Using MPI 2

Implementation daemon messages daemon Send() Send() process computer node process computer node Recv() Recv() Recv() Send() 2010@FEUP Using MPI 3

Launching > mpiexec n <np> <executable> <args> Other options: -wdir <working directory> -host <hostname> Several hosts -hosts <n host1 host2 host3 hostn> -hosts <n host1 m1 host2 m2 host3 m3 hostn mn> -machinefile <filename> - one host per line, # commented Several executables example: mpiexec -n 1 foo master : -n 8 worker 2010@FEUP Using MPI 4

Building a program Usually there are bindings and libraries for C C++ Fortran Function declarations for C and C++ are in an include file: mpih When compiling it is necessary to link to the library containing the implementation: The name and the type (static or dynamic) is implementation dependent (usually libmpia or mpilib) Some installations provide a compilation script named mpicc: > mpicc myprogc -o myprog 2010@FEUP Using MPI 5

Initializing and finalizing First call to the MPI library must be to MPI_Init() Last call must be to MPI_Finalize() #include <mpih> int main(int argc, char *argv[ ]) { MPI_Init(&argc, &argv); // other MPI calls MPI_Finalize(); return 0; } 2010@FEUP Using MPI 6

Communicators Communicator: set of processes that can exchange messages between them MPI_COMM_WORLD Default communicator already built Includes all processes Possible to create new communicators Communicator Processes Ranks MPI_COMM_WORLD 0 5 2 1 4 3 Communicator Name 2010@FEUP Using MPI 7

Number and rank of the MPI processes Each process can determine the total number of processes in a communicator: int MPI_Comm_size(MPI_Comm comm, int *size); Each process can obtain its own identifier or rank in a communicator: int MPI_Comm_rank(MPI_Comm comm, int *rank); the ranks begin with 0 Time from a common point in the past can be obtained with: double MPI_Wtime(void); the returned time is in seconds double elapsedtime; elapsedtime = -MPI_Wtime(); elapsedtime += MPI_Wtime(); 2010@FEUP Using MPI 8

Send and receive a message To send a message to another process: int MPI_Send(void *buf, int count, MPI_Datatype dtype, int dest, int tag, MPI_Comm comm); Usual predefined datatype: MPI_CHAR, MPI_INT, MPI_SHORT, MPI_LONG, MPI_LONG_LONG, MPI_FLOAT, MPI_DOUBLE, MPI_LONG_DOUBLE, MPI_WCHAR, MPI_BYTE, MPI_PACKED To receive a message: int MPI_Recv(void *buf, int count, MPI_Datatype dtype, int source, int tag, MPI_Comm comm, MPI_Status *status); For receiving from any source use MPI_ANY_SOURCE For receiving from any tag use MPI_ANY_TAG 2010@FEUP Using MPI 9

Collective operations Can involve more than 2 processes Barrier synchronization Broadcast data from one to all processes Gather collect data from all and joins it Scatter sends a different piece of data from one to all Allgather the same as gather but everyone receives the all data Alltoall a combination of gather and scatter involving all processes also known as complete exchange Reduce a global operation from all to one Allreduce everyone receives the result ReduceScatter Combine reduction with a scatter Scan Process i receives the reduction of processes 0i 2010@FEUP Using MPI 10

Barrier int MPI_Barrier(MPI_Comm comm); 2010@FEUP Using MPI 11

Broadcast int MPI_Bcast(void *buf, int count, MPI_Datatype dtype, int root, MPI_Comm comm); 2010@FEUP Using MPI 12

Gather int MPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sdtype, void *recvbuf, int recvcount, MPI_Datatype rctype, int root, MPI_Comm comm); 2010@FEUP Using MPI 13

Allgather int MPI_Allgather(void* sbuf, int scount, MPI_Datatype sdtype, void* rbuf, int rcount, MPI_Datatype rctype, MPI_Comm comm); 2010@FEUP Using MPI 14

Scatter int MPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sdtype, void *recvbuf, int recvcount, MPI_Datatype rctype, int root, MPI_Comm comm); 2010@FEUP Using MPI 15

AlltoAll int MPI_Alltoall(void *sbuf, int scount, MPI_Datatype sdtype, void *rbuf, int rcount, MPI_Datatype rctype, MPI_Comm comm); 2010@FEUP Using MPI 16

Reduce int MPI_Reduce(void *sbuf, void* rbuf, int count, MPI_Datatype dtype, MPI_Op op, int root, MPI_Comm comm); Operations: MPI_MAX, MPI_MIN, MPI_SUM, MPI_PROD, MPI_LAND, MPI_BAND, MPI_LOR, MPI_BOR, MPI_LXOR, MPI_BXOR, MPI_MAXLOC, MPI_MINLOC 2010@FEUP Using MPI 17

AllReduce int MPI_Allreduce(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); All processes receive the reduce result 2010@FEUP Using MPI 18

ReduceScatter int MPI_Reduce_scatter(void* sendbuf, void* recvbuf, int *recvcounts, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm); recvcounts must be an array of size n (= nr of processes in the communicator) sendbuf in every process has recvcounts[i] elements After a reduction of size recvcounts[i] there is a scatter distributing the results to each process i according to recvcounts[i] 2010@FEUP Using MPI 19

Scan and Exscan int MPI_Scan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm ); int MPI_Exscan(void* sendbuf, void* recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm ); Scan does a reduction and puts in process i the reduction from processes 0i (0i-1 if an Exscan exclusive scan) 2010@FEUP Using MPI 20