The MPI Message-passing Standard Lab Time Hands-on. SPD Course Massimo Coppola

Similar documents
The MPI Message-passing Standard Lab Time Hands-on. SPD Course 11/03/2014 Massimo Coppola

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

Virtualization (II) SPD Course 17/03/2010 Massimo Coppola

Holland Computing Center Kickstart MPI Intro

CSE. Parallel Algorithms on a cluster of PCs. Ian Bush. Daresbury Laboratory (With thanks to Lorna Smith and Mark Bull at EPCC)

MPI introduction - exercises -

Parallel Programming

High Performance Computing Lecture 41. Matthew Jacob Indian Institute of Science

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

Elementary Parallel Programming with Examples. Reinhold Bader (LRZ) Georg Hager (RRZE)

A few words about MPI (Message Passing Interface) T. Edwald 10 June 2008

Distributed Memory Programming with Message-Passing

Introduction to the Message Passing Interface (MPI)

L14 Supercomputing - Part 2

OpenMP - exercises - Paride Dagna. May 2016

MPI and OpenMP (Lecture 25, cs262a) Ion Stoica, UC Berkeley November 19, 2016

Chapter 3. Distributed Memory Programming with MPI

A Message Passing Standard for MPP and Workstations

PPCES 2016: MPI Lab March 2016 Hristo Iliev, Portions thanks to: Christian Iwainsky, Sandra Wienke

Introduction to Parallel and Distributed Systems - INZ0277Wcl 5 ECTS. Teacher: Jan Kwiatkowski, Office 201/15, D-2

Peter Pacheco. Chapter 3. Distributed Memory Programming with MPI. Copyright 2010, Elsevier Inc. All rights Reserved

MPI Message Passing Interface

Acknowledgments. Amdahl s Law. Contents. Programming with MPI Parallel programming. 1 speedup = (1 P )+ P N. Type to enter text

Distributed Memory Programming with MPI. Copyright 2010, Elsevier Inc. All rights Reserved

CS4961 Parallel Programming. Lecture 18: Introduction to Message Passing 11/3/10. Final Project Purpose: Mary Hall November 2, 2010.

Practical Scientific Computing: Performanceoptimized

Optimization of MPI Applications Rolf Rabenseifner

Introduction to Lab Series DMS & MPI

Introduction to OpenMP. OpenMP basics OpenMP directives, clauses, and library routines

Introduction to parallel computing concepts and technics

15-440: Recitation 8

Programming with MPI

Advanced Message-Passing Interface (MPI)

CS 426. Building and Running a Parallel Application

Parallel Computing Paradigms

An introduction to MPI

Introduction to Parallel Programming Message Passing Interface Practical Session Part I

OpenMP - exercises -

Practical Introduction to Message-Passing Interface (MPI)

HPC Parallel Programing Multi-node Computation with MPI - I

Message Passing Interface

Message Passing Programming. Modes, Tags and Communicators

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

Programming with MPI Basic send and receive

The Message Passing Interface (MPI) TMA4280 Introduction to Supercomputing

Tutorial on MPI: part I

COSC 6374 Parallel Computation. Message Passing Interface (MPI ) I Introduction. Distributed memory machines

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

Introduction to MPI, the Message Passing Library

Introduction to the Message Passing Interface (MPI)

CSE 160 Lecture 18. Message Passing

lslogin3$ cd lslogin3$ tar -xvf ~train00/mpibasic_lab.tar cd mpibasic_lab/pi cd mpibasic_lab/decomp1d

Lecture 14: Mixed MPI-OpenMP programming. Lecture 14: Mixed MPI-OpenMP programming p. 1

mith College Computer Science CSC352 Week #7 Spring 2017 Introduction to MPI Dominique Thiébaut

Message Passing Programming. Modes, Tags and Communicators

MPI Lab. How to split a problem across multiple processors Broadcasting input to other nodes Using MPI_Reduce to accumulate partial sums

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

MPI: The Message-Passing Interface. Most of this discussion is from [1] and [2].

MPI Runtime Error Detection with MUST

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

MPI Programming Techniques

MPI. (message passing, MIMD)

High Performance Computing Course Notes Message Passing Programming I

SHARCNET Workshop on Parallel Computing. Hugh Merz Laurentian University May 2008

Message Passing Interface

CS4961 Parallel Programming. Lecture 16: Introduction to Message Passing 11/3/11. Administrative. Mary Hall November 3, 2011.

Parallel Programming Using Basic MPI. Presented by Timothy H. Kaiser, Ph.D. San Diego Supercomputer Center

Parallel Programming

Point-to-Point Communication. Reference:

Message Passing Interface. George Bosilca

Message-Passing Programming with MPI. Message-Passing Concepts

CSE 160 Lecture 15. Message Passing

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

Parallel Techniques. Embarrassingly Parallel Computations. Partitioning and Divide-and-Conquer Strategies

OpenMP and MPI. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

Basic MPI Communications. Basic MPI Communications (cont d)

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

Introduction to MPI. SHARCNET MPI Lecture Series: Part I of II. Paul Preney, OCT, M.Sc., B.Ed., B.Sc.

Message-Passing Programming with MPI

Implementation of Parallelization

Introduction in Parallel Programming - MPI Part I

Parallel I/O. and split communicators. David Henty, Fiona Ried, Gavin J. Pringle

Collective Communication

Introduction to MPI. HY555 Parallel Systems and Grids Fall 2003

Exercises: Message-Passing Programming

AMath 483/583 Lecture 18 May 6, 2011

Chip Multiprocessors COMP Lecture 9 - OpenMP & MPI

Fractals exercise. Investigating task farms and load imbalance

OpenMP and MPI. Parallel and Distributed Computing. Department of Computer Science and Engineering (DEI) Instituto Superior Técnico.

AMath 483/583 Lecture 21

MPI: A Message-Passing Interface Standard

MMPI: Asynchronous Message Management for the. Message-Passing Interface. Harold Carter Edwards. The University of Texas at Austin

Review of MPI Part 2

An Introduction to MPI

Tutorial 2: MPI. CS486 - Principles of Distributed Computing Papageorgiou Spyros

Assignment 3 MPI Tutorial Compiling and Executing MPI programs

Exercises: April 11. Hermann Härtig, TU Dresden, Distributed OS, Load Balancing

Parallel and Distributed Computing Programming Assignment 1

Blocking SEND/RECEIVE

Introduction to MPI. Ricardo Fonseca.

Transcription:

The MPI Message-passing Standard Lab Time Hands-on SPD Course 2016-2017 Massimo Coppola

Remember! Simplest programs do not need much beyond Send and Recv, still... Each process lives in a separate memory space Need to initialize all your data structures Need to initialize your instance of the MPI library Use MPI_COMM_WORLD Need to define all your DataTypes Should you make assumptions on process number? How portable will your program be? Check your MPI man page about launching E.g. mpirun np 4 myprogram parameters SPD - MPI Lab hands-on 2

Initializing the runtime MPI_Init() Shall be called before using any MPI calls (very few exceptions) Initializes the MPI runtime for all processes in the running program, some kind of handshaking implied e.g. creates MPI_COMM_WORLD check its arguments! MPI_Finalize() Frees all MPI resources and cleans up the MPI runtime, taking care of any operation pending Any further call to MPI is forbidden some runtime errors can be detected at finalize e.g. calling finalize with communications still pending and unmatched SPD - MPI Lab hands-on 3

Note on mpich Mpich installation in the lab machine (centos 7) requires this in your.bash_profile ##### MPICH export PATH=/usr/local/bin:/usr/lib64/mpich/ bin:$path export LD_LIBRARY_PATH=/usr/local/lib:/usr/ lib64/mpich/lib:$ld_library_path export MANPATH=/usr/share/man/mpich/:`manpath` export PATH Mpirun becomes mpiexec, e.g. mpiexec np 2./pingpong Hello world(s) explicit relative path to the executable SPD - MPI Lab hands-on 4

Exercise 1 Define the classical ping-pong program with 2 processes they send back and fort a data buffer, the second process executes an operation on the data (e.g. sum 1). Verify after a given number N of iterations, that the expected result is achieved. Add printouts close to communications Does it work? Why? Generalize the ping-pong example to N processes Each process sends to the next one, with some processes being special, e.g. Token ring (a process has to start and stop the token) One-way pipeline (one process starts, one only receives) Can you devise the proper communicator structure? SPD - MPI Lab hands-on 5

Getting your identity MPI_Comm_rank After the MPI_Init Returns the rank of the current process within a specified communicator For now let s just use ranks related to MPI_COMM_WORLD Example: MPI_Comm_rank(MPI_COMM_WORLD, &myrank); SPD - MPI Lab hands-on 6

Writing structured MPI We ll never stress this enough Aim at separation of concern : avoid chaotically mixing up MPI primitives and sequential code When possible, write a separate function/class for each type of process in your program Parametric wrt to sequential program parameters and arguments, AND wrt parallel environment E.g. Operates in a give communicator with known assumptions Global initialization done by all processes, local initialization may be done locally (e.g. build a workerspecific communicator inside the farm implementation) Sometimes it may be possible to write MPI code which is generic and may be reused à try to decouple these parts into separate functions SPD - MPI Lab hands-on 7

Exercise 2 Build datatypes for a square matrix of arbitrary element types and constant size 120*120 a column of the matrix a row of the matrix a group of 3 columns of the matrix the upward and downward diagonals of the matrix Perform a test of the datatypes within the code of exercise 1 Initialize the matrix in a known way, perform computation on the part that you pass along (e.g. multiply or increment its elements) and check the result you receive back SPD - MPI Lab hands-on 8

Derived Datatypes don t forget MPI_TYPE_COMMIT(datatype) Mandatory to enables a newly defined datatype for use in all other MPI primitives Consolidates datatype definition, making it permanent May compile internal information needed to the MPI library runtime e.g. : optimized routines for data packing & unpacking MPI_TYPE_FREE(datatype) Free library memory used by a datatype that is no longer needed SPD - MPI Lab hands-on 9

Exercise 3 Define a datatype for a square matrix with parametric size Define a datatype for its lower triagular matrix Define one for its upper triangular. Test the them within the code of exercise 1 A i,j i,j in 1.. n A i,j i j A i,j i j SPD - MPI Lab hands-on 10

Exercise 3 (cont.) In the two-process program initialize randomly a square matrix send the lower triangular and receive it back as upper triangular in the same buffer. Is the result a symmetric matrix? How do you need to modify one of the two triangular datatypes in order to achieve that? In the end we want A i,j = B j,i a a b b SPD - MPI Lab hands-on 11

Exercise 4 How do you implement an asynchronous communication with given asynchrony? Implement a communication with asynchrony 1 Implement a communication with asynchrony K Assigned asynchrony of degree K: asynchronous communication (sender does not block) which becomes synchronous if more than K messages are still pending. Receiver can skip at most K receives before sender blocks Can you rely on MPI buffering? How would you implement a fixed size buffer? SPD - MPI Standard Use and Implementation 12

Exercise 5 Build a task farm skeleton program aiming at general reusability of MPI code Should allow to change the data structures, computing functions and possibly load distribution policies without changing the MPI implementation code Simplifying assumptions single emitter and collector stream generation and consumption are functions called within the emitter and collector processes explicitly manage End-of-stream conditions via messages/tags Separation of concerns Each kind of process is a C function Each computing task is a function called by the generic process Different communication and load balancing strategies Simple round-robin, explicit task request, degree of worker buffering explicit task request, implicit request via Ssend, What pros and cons in using separate communicators for the farm skeleton and its substructures? Think of how you could implement some common extensions of the basic farm semantics: initial/periodic worker initialization, workers with status and status collection, work stealing strategies SPD - MPI Lab hands-on 13

Exercise 5 example computation http://en.wikibooks.org/wiki/fractals/ Iterations_in_the_complex_plane/Mandelbrot_set Mandelbrot set Compute the escape time (number of iterations before diverging) of the Z=Z^2+c complex sequence for any starting point c c within the square (-2,-2) (2,2) Computation cannot be optimized, has rather high variance You can aggregate several points in a single task Passing a square or a row of points to compute can be quite effective in the emitter, only needing two coordinates and the number of samples to take int GiveEscapeTime(double C_x, double C_y, int imax, double _ER2) { int i; double Zx, Zy; double Zx2, Zy2; /* Zx2=Zx*Zx; Zy2=Zy*Zy */ Zx=0.0; /* initial value of orbit = critical point Z= 0 */ Zy=0.0; Zx2=Zx*Zx; Zy2=Zy*Zy; for (i=0;i<imax && ((Zx2+Zy2)<_ER2);i++) { Zy=2*Zx*Zy + C_y; Zx=Zx2-Zy2 +C_x; Zx2=Zx*Zx; Zy2=Zy*Zy; }; return i; } /* Example of the worker function computing the escape time for a single point on the complex plane. Here a sequence escapes if its squared modulo becomes greater than _ER2 _ER2 == 4 usually (modulo >= 2 implies divergence) */ SPD - MPI Lab hands-on 14

Exercise 5 (cont.) Pitfalls and suggestions Can you just change a communicator and plug the farm source code in a different program? Stream management should never depend on knowing the stream length in advance How do you add task grain management? Can you dynamically vary the grain? Aggregation of a square or row of points in a single task is problem-specific à nice feat but it is not a general form of farm grain control Can you model the execution time of the farm from a small execution and try to predict for a longer one? How do the grid resolution and iteration parameters, as well as choices about communication and load balancing affect the prototype? SPD - MPI Lab hands-on 15

Exercise 6 Add to the farm skeleton a mechanism to reinitialize the workers The stream computation depends on the status; each part of the stream (substream) is associated with a specific status Example: the status is the max number of iteration in Mandelbrot You cannot just assume to send the status within the job (status updates may be sporadic and quite larger than ordinary tasks) How do you send/receive status updates (ISSend, IBSend, Ssend versus non-determinism control in the worker receives) Should you serialize the communications and how? (adding a progressive identifier to the task, the status messages or both, and how to link them) Manage substream ordering in the emitter (chose semantics: no ordering, reordering the results by the tasks, reordering the result by substreams but not by the tasks SPD - MPI Lab hands-on 16