Message Passing Interface: Basic Course

Similar documents
Open Multi-Processing: Basic Course

Introduction to MPI, the Message Passing Library

ECE 574 Cluster Computing Lecture 13

Practical Introduction to Message-Passing Interface (MPI)

Topic Notes: Message Passing Interface (MPI)

Masterpraktikum - Scientific Computing, High Performance Computing

HPC Parallel Programing Multi-node Computation with MPI - I

MPI Message Passing Interface

Advanced Message-Passing Interface (MPI)

Masterpraktikum - Scientific Computing, High Performance Computing

MPI Collective communication

Introduction to the Message Passing Interface (MPI)

Parallel programming MPI

Message-Passing and MPI Programming

Introduction to MPI. May 20, Daniel J. Bodony Department of Aerospace Engineering University of Illinois at Urbana-Champaign

Parallel Computing Paradigms

Welcome to the introductory workshop in MPI programming at UNICC

Parallel Programming. Using MPI (Message Passing Interface)

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

Distributed Memory Systems: Part IV

MPI. (message passing, MIMD)

Message Passing Interface - MPI

NUMERICAL PARALLEL COMPUTING

Introduction to Parallel Programming

Slides prepared by : Farzana Rahman 1

Parallel Programming

Programming with MPI Collectives

Standard MPI - Message Passing Interface

MPI - The Message Passing Interface

Introduction to Lab Series DMS & MPI

Review of MPI Part 2

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

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

Message Passing Interface

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

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

MPI MESSAGE PASSING INTERFACE

mpi4py HPC Python R. Todd Evans January 23, 2015

MPI 2. CSCI 4850/5850 High-Performance Computing Spring 2018

Tutorial: parallel coding MPI

Collective Communication in MPI and Advanced Features

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

The Message Passing Model

Working with IITJ HPC Environment

Our new HPC-Cluster An overview

Message Passing Interface

Parallel Computing MPI. Christoph Beetz. September 7, Parallel Computing. Introduction. Parallel Computing

MPI MESSAGE PASSING INTERFACE

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

The Message Passing Interface (MPI) TMA4280 Introduction to Supercomputing

Introduction to parallel computing concepts and technics

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

High Performance Computing

Holland Computing Center Kickstart MPI Intro

Outline. Communication modes MPI Message Passing Interface Standard

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

Praktikum: Verteiltes Rechnen und Parallelprogrammierung Introduction to MPI

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

MPI 5. CSCI 4850/5850 High-Performance Computing Spring 2018

MPI Tutorial. Shao-Ching Huang. High Performance Computing Group UCLA Institute for Digital Research and Education

Introduction to MPI. Ricardo Fonseca.

Message-Passing Interface Basics

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

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

Parallel Programming Basic MPI. Timothy H. Kaiser, Ph.D.

Programming with MPI

Distributed Systems + Middleware Advanced Message Passing with MPI

Introduction to MPI. HY555 Parallel Systems and Grids Fall 2003

Practical Introduction to Message-Passing Interface (MPI)

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

Collective Communications

Chapter 3. Distributed Memory Programming with MPI

Message Passing Interface - MPI

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

Recap of Parallelism & MPI

Introduction to MPI. Ekpe Okorafor. School of Parallel Programming & Parallel Architecture for HPC ICTP October, 2014

Distributed Memory Programming with Message-Passing

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

Introduction to MPI. Ritu Arora Texas Advanced Computing Center June 17,

Introduction to MPI Part II Collective Communications and communicators

MPI MESSAGE PASSING INTERFACE

Programming with Message Passing PART I: Basics. HPC Fall 2012 Prof. Robert van Engelen

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

Lecture 9: MPI continued

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

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

Practical Scientific Computing: Performanceoptimized

Part - II. Message Passing Interface. Dheeraj Bhardwaj

Non-Blocking Communications

An Introduction to MPI

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

Non-Blocking Communications

Introduction to MPI. Jerome Vienne Texas Advanced Computing Center January 10 th,

Collective Communication

MPI 1. CSCI 4850/5850 High-Performance Computing Spring 2018

MPI Message Passing Interface. Source:

Introduction to MPI part II. Fabio AFFINITO

High Performance Computing Course Notes Message Passing Programming I

Part One: The Files. C MPI Slurm Tutorial - Hello World. Introduction. Hello World! hello.tar. The files, summary. Output Files, summary

CS 6230: High-Performance Computing and Parallelization Introduction to MPI

Transcription:

Overview of DM- HPC2N, UmeåUniversity, 901 87, Sweden. April 23, 2015

Table of contents Overview of DM- 1 Overview of DM- Parallelism Importance Partitioning Data Distributed Memory Working on Abisko 2 Message Passing Interface 3 Point-to-point routines 4 Collective communication routines

Overview of DM- Application of Parallel algorithms Parallelism Importance Partitioning Data Distributed Memory Working on Abisko Molecular Dynamics Simulations of Galaxies properties Figure : AdK enzyme in water. Figure : Galaxies [Nat., 509, 177 (2014)].

Working with arrays Overview of DM- Parallelism Importance Partitioning Data Distributed Memory Working on Abisko F = U Newton s Law (1) solution of this equation requires the knowledge of an array of particles positions and velocities X = ( x 1 1, x 1 2, x 1 3, x 2 1, x 2 2, x 2 3... x N 1, x N 2, x N 3 ) (2) V = ( v 1 1, v 1 2, v 1 3, v 2 1, v 2 2, v 2 3... v N 1, v N 2, v N 3 ) (3)

Working with arrays Overview of DM- Parallelism Importance Partitioning Data Distributed Memory Working on Abisko F = U Newton s Law (1) solution of this equation requires the knowledge of an array of particles positions and velocities X = ( x 1 1, x 1 2, x 1 3, x 2 1, x 2 2, x 2 3... x N 1, x N 2, x N 3 ) (2) V = ( v 1 1, v 1 2, v 1 3, v 2 1, v 2 2, v 2 3... v N 1, v N 2, v N 3 ) (3)

Overview of DM- Parallelism Importance Partitioning Data Distributed Memory Working on Abisko Distributed Memory and Message-Passing Each process has a separate address space Processes communicate by explicitly sending and receiving messages Figure : Distributed memory. Figure : Abisko at HPC2N.

Overview of DM- Running jobs on Abisko Parallelism Importance Partitioning Data Distributed Memory Working on Abisko Load Modules Compiling and linking Testing programs Job submission

Modules Overview of DM- Parallelism Importance Partitioning Data Distributed Memory Working on Abisko # Open for the PathScale compiler module load openmpi/psc # Open for the GCC compiler module load openmpi/gcc # Open for the Portland compiler module load openmpi/pgi # Open for the Intel compiler module load openmpi/intel

Overview of DM- Compiling and linking Parallelism Importance Partitioning Data Distributed Memory Working on Abisko provides a compiler wrapper named mpicc/mpif90 Compile and link using the wrapper Example: # Compile mysrc.c mpicc -std=c99 -c mysrc.c # Compile main.c mpicc -std=c99 -c main.c # Link run.x mpicc/mpif90 -o run.x main.o mysrc.o

Overview of DM- Testing programs Parallelism Importance Partitioning Data Distributed Memory Working on Abisko You can test your programs on the login node Use the mpirun command to launch Example: Will give you some warnings but don t be alarmed Only for short-running jobs Cannot be used to test performance # Launch run.x with four processes on login node mpirun -np 4./run.x

Job submission Overview of DM- Parallelism Importance Partitioning Data Distributed Memory Working on Abisko Template for a job script (script.sbatch): #!/bin/bash #SBATCH -A SNIC2015-7-15 #SBATCH --reservation SNIC2015-7-15 #SBATCH -n 16 #SBATCH --time=00:30:00 #SBATCH --error=job-%j.err #SBATCH --output=job-%j.out echo "Starting at date " srun./run.x echo "Stopping at date " Job submission: sbatch script.sbatch

Overview of DM- Querying and cancelling jobs Parallelism Importance Partitioning Data Distributed Memory Working on Abisko # Get the status of all your jobs squeue -u <user> # Get the predicted start of your queued jobs squeue -u <user> --start # Cancel a job scancel <jobid>

Overview of DM- : Message Passing Interface Message Passing Interface is the mostly used message passing-standard. There are many implementations, CH, MVAPICH, Open, etc. Figure : Distributed memory.

Overview of DM- : Message Passing Interface Message Passing Interface Figure : Distributed memory. is the mostly used message passing-standard. There are many implementations, CH, MVAPICH, Open, etc. Supports Fortran, C, C++, etc.

Overview of DM- : Message Passing Interface Message Passing Interface Figure : Distributed memory. is the mostly used message passing-standard. There are many implementations, CH, MVAPICH, Open, etc. Supports Fortran, C, C++, etc.

Resources Overview of DM- Message Passing Interface Official website: http://www.mpi-forum.org Specification ( version 2.2): http: //www.mpi-forum.org/docs/mpi-2.2/mpi22-report.pdf

Scope of Overview of DM- Message Passing Interface Collective communication One-sided communication Parallel I/O

The Big Six Overview of DM- Message Passing Interface The 6 core functions in : Init Initializes the runtime system. Finalize Cleans up the runtime system. Comm size Returns the number of processes. Comm rank Returns the rank (identifier) of the caller. Send Send a message. Recv Receive a message.

Overview of DM- Runtime system management Message Passing Interface Every program must begin by calling Init and end by calling Finalize. Init takes the command line as parameters in order to process command line arguments that are understood by and intended for the runtime system. Finalize takes no parameters and shuts down the runtime system.

Overview of DM- C program template Message Passing Interface // Include - related declarations # include <mpi.h> int main ( int argc, char * argv [] ) { // Initialize the runtime system _Init ( &argc, & argv ); //.. code that uses.. } // Finalize the runtime system _Finalize ( ); return 0;

Overview of DM- fortran program template Message Passing Interface program main use integer :: ierr, rank, size call _INIT ( ierr ) call _COMM_RANK ( _COMM_WORLD, rank, ierr ) call _COMM_SIZE ( _COMM_WORLD, size, ierr )... call _FINALIZE ( ierr ) end

Overview of DM- Message Passing Interface Number of processes and process ranks Processes are distinguished by their ranks. The rank of a process is a number between 0 and p 1, where p is the number of processes. The number of processes and the rank of the caller can be obtained through the functions Comm size and Comm rank, respectively. Example: int np; _Comm_size ( _COMM_WORLD, & np ); int me; _Comm_rank ( _COMM_WORLD, & me );

Overview of DM- COMM WORLD Message Passing Interface Communicators is the term for communication contexts. The constant COMM WORLD refers to a pre-defined communicator containing all processes. For now, we always use the world communicator.

Overview of DM- Point-to-point communication Point-to-point routines Only a sender and a receiver are involved in the communication. Figure : Point-to-point communication.

Sending a message Overview of DM- Point-to-point routines Point-to-point messages can be sent via the function Send An input buffer for the message data The number of elements in the message The element datatype The destination rank An identifying tag A communicator Example: char message [ 30 ] = " Hello!"; _ Send ( message, 30, _ CHAR, 0,23, _COMM_WORLD ); Sends 30 character elements to rank 0 with tag 23 in the world communicator.

Overview of DM- Receiving a message Point-to-point routines Point-to-point messages can be received via the function Recv It takes the following parameters: An output buffer for the message data The maximum number of elements to receive The element datatype The source rank An identifying tag A communicator An output status object Example: char message [ 30 ]; _ Recv ( message, 30, _ CHAR, 14, 0, _COMM_WORLD, _STATUS_IGNOR E );

Overview of DM- Hello World C Example Point-to-point routines 1 # include <mpi.h> 2 # include <stdio.h> 3 4 int main ( int argc, char * argv [] ) 5 { 6 int np, me; 7 _Init ( &argc, & argv ); 8 _Comm_size ( _COMM_WORLD, & np ); 9 _Comm_rank ( _COMM_WORLD, & me ); 10 if( me == 1 ) { 11 char message [ 30 ] = " Hello!"; 12 _Send ( message, 30, _CHAR, 13 0, 0, _COMM_WORLD ); 14 } else if( me == 0 ) { 15 char message [ 30 ]; 16 _Recv ( message, 30, _CHAR, 17 1, 0, _COMM_WORLD, 18 _STATUS_IGNORE ); 19 printf ( " Rank =0 received \"% s \"\ n", message ); 20 } 21 _Finalize ( ); 22 return Jerry Eriksson, 0; Mikael Rännar and Pedro Ojeda

Overview of DM- Point-to-point routines Blocking/Non-blocking Communication SEND and RECV block execution until message is received. ISEND and IRECV provide a non-blocking execution. using non-blocking communications requires sync with WAIT

Overview of DM- Blocking Communication Point-to-point routines if(rank == 0) then do i=1,nelem a(i)=i b(i)=2*i enddo write(6,10) rank 0 a,(a(i),i=1,10) write(6,10) rank 0 b,(b(i),i=1,10) call _SEND(a,nelem,_INT,1,1,_COMM_WORLD,ierr) call _SEND(b,nelem,_INT,1,2,_COMM_WORLD,ierr) elseif(rank ==1) then call _RECV(b,nelem,_INT,0,2,_COMM_WORLD,status,ierr) write(6,10) rank 1 b,(b(i),i=1,10) call _RECV(a,nelem,_INT,0,1,_COMM_WORLD,status,ierr) write(6,10) rank 1 a,(a(i),i=1,10) else print *, no other task endif

Overview of DM- Non-Blocking Communication Point-to-point routines if(rank == 0) then do i=1,ne a(i)=i b(i)=2*i enddo write(6,10) rank 0 a,(a(i),i=1,10) write(6,10) rank 0 b,(b(i),i=1,10) call _ISEND(a,ne,_INT,1,1,_COMM_WORLD,ierr) call _ISEND(b,ne,_INT,1,2,_COMM_WORLD,ierr) elseif(rank ==1) then call _IRECV(b,ne,_INT,0,2,_COMM_WORLD,req,ierr) call _WAIT(req, status, ierror) write(6,10) rank 1 b,(b(i),i=1,10) call _IRECV(a,ne,_INT,0,1,_COMM_WORLD,req,ierr) call _WAIT(req, status, ierror) write(6,10) rank 1 a,(a(i),i=1,10) else

Overview of DM- Blocking Ring Communication Point-to-point routines if(rank.ne. 0) then call _RECV(trans,1,_INT,rank-1,0,_COMM_WORLD, & status,ierr) write(6,*) Process,rank, received token,trans, & from process,rank-1 else trans=-1 endif call _SEND(trans,1,_INT,mod(rank+1,size),0, & _COMM_WORLD,ierr) if(rank.eq. 0) then call _RECV(trans,1,_INT,rank-1,0,_COMM_WORLD, & status,ierr) write(6,*) Process,rank, received token,trans,& from process,size-1 endif

Overview of DM- Routines Collective communication routines BCAST GATHER SCATTER REDUCE

Overview of DM- Collective communication Collective communication routines Many algorithms require communication of data between more than pairs of processes. In principle doable with Send and Recv But much more efficient implementations and convenient interfaces are often possible Special networks for special communication patterns Abstraction of complex communication patterns

Overview of DM- Collective communication routines Common features of collective operations Blocking (but non-blocking added in version 3.0) Involve all processes in the communicator Totally ordered within the communicator No tags (obviously) Designated root process (for many operations)

Overview of DM- Collective communication routines Collective communication operations in (2.2) Barrier Bcast Gather (+ variants) Scatter (+ variants) Allgather (+ variants) Alltoall (+ variants) Reduce Allreduce Reduce scatter (+ variants) Scan (+ variants) 17 functions in total (Version 3.0 doubles that with non-blocking variants)

BARRIER Overview of DM- Collective communication routines Figure : Barrier operation.

Barrier Overview of DM- Collective communication routines _Barrier ( _COMM_WORLD ); Synchronizes all processes. No-one returns until all have reached the barrier.

BCAST Overview of DM- Collective communication routines Figure : Broadcast operation.

Broadcast Overview of DM- Collective communication routines _ Bcast ( array, 100, _ DOUBLE, root, _COMM_WORLD ); Broadcasts (duplicates) to all processes. array is input on the root array is output everywhere else

GATHER Overview of DM- Collective communication routines Figure : Gather operation.

Gather Overview of DM- Collective communication routines _Gather ( send, 100, _INT, recv, 100, _INT, root, _COMM_WORLD ); Collects on the root a message from each process (including itself) send is input everywhere recv is output on the root and everywhere else not referenced Related: Allgather returns the result on all processes

Gather: Details Overview of DM- Collective communication routines Q: How are the incoming messages packed in the recv array? A: In the order of the ranks. Q: How large must the recv buffer be? A: Large enough to acommodate p times the receive count number of elements

SCATTER Overview of DM- Collective communication routines Figure : Scatter operation.

Scatter Overview of DM- Collective communication routines _Scatter ( send, 100, _INT, recv, 100, _INT, root, _COMM_WORLD ); The dual of Gather Sends from the root one message to each process (including itself) send is input on the root and everywhere else not referenced recv is output everywhere

Scatter: Details Overview of DM- Collective communication routines The root can reuse the send buffer by specifying the constant IN PLACE instead of the recv argument (See also Gather)

Overview of DM- Example: Vector dot product Collective communication routines call _SCATTER (x,dim2, _REAL, xpart,dim2, _REAL, & root, _COMM_WORLD, ierr ) call _SCATTER (y,dim2, _REAL, ypart,dim2, _REAL, & root, _COMM_WORLD, ierr ) zpart = 0.0 do i = 1, dim2 zpart = zpart + xpart (i)* ypart (i) enddo

Reduce Overview of DM- Collective communication routines _Reduce ( send, recv, 100, _INT, _SUM, root, _COMM_WORLD ); Reduces one message from each process to a single message at the root send is input everywhere recv is output on the root Related: Allreduce returns the result of all processes

Overview of DM- Collective communication routines Reduce: Pre-defined reduction operators MAX MIN SUM PROD (product) LAND, LOR, LXOR (logical and, or, xor) BAND, BOR, BXOR (bitwise and, or, xor) MAXLOC (max value and location) MINLOC (min value and location)

Overview of DM- Collective communication routines Reduce: User-defined reduction operators Possible to define arbitrary reduction operators Must be associative Possibly also commutative Can operate on arbitrary datatypes (see below)

Overview of DM- Reduce/scatter dot product Collective communication routines call _SCATTER (x,dim2, _REAL, xpart,dim2, _REAL, & root, _COMM_WORLD, ierr ) call _SCATTER (y,dim2, _REAL, ypart,dim2, _REAL, & root, _COMM_WORLD, ierr ) zpart = 0.0 do i = 1, dim2 zpart = zpart + xpart (i)* ypart (i) enddo call _REDUCE ( zpart,z,1, _REAL, _SUM,root, & _COMM_WORLD, ierr ) print *, Finish processor, rank if( rank == root ) then print *, Vector product is:, z endif

Overview of DM- Scatter columns of a matrix Collective communication routines! Fortran stores this array in column major order, so th! scatter will actually scatter columns, not rows. data sendbuf /1.0, 2.0, 3.0, 4.0, & 5.0, 6.0, 7.0, 8.0, & 9.0, 10.0, 11.0, 12.0, & 13.0, 14.0, 15.0, 16.0 / call _INIT ( ierr ) call _ COMM_ RANK ( _COMM_WORLD, rank, ierr ) call _ COMM_ SIZE ( _COMM_WORLD, numtasks, ierr ) if ( numtasks. eq. SIZE ) then source = 1 sendcount = SIZE recvcount = SIZE call _ SCATTER ( sendbuf, sendcount, _REAL, recvbuf, & recvcount, _REAL, source, _COMM_WORLD, ierr ) print *, rank =,rank, Results :, recvbuf

Overview of DM- Collective communication routines The End!