Parallel Programming, MPI Lecture 2

Similar documents
MPI Program Structure

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

Reusing this material

Parallel Programming with MPI: Day 1

Parallel Programming using MPI. Supercomputing group CINECA

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

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

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

Practical Introduction to Message-Passing Interface (MPI)

Introduction to MPI. HY555 Parallel Systems and Grids Fall 2003

Introduction to MPI. Ricardo Fonseca.

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

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

Introduction in Parallel Programming - MPI Part I

CS 426. Building and Running a Parallel Application

Introduction to parallel computing concepts and technics

MPI point-to-point communication

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

MPI. (message passing, MIMD)

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

MPI Message Passing Interface

Message Passing Interface

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

int sum;... sum = sum + c?

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

Lecture 3 Message-Passing Programming Using MPI (Part 1)

Introduction to the Message Passing Interface (MPI)

ME964 High Performance Computing for Engineering Applications

Introduction to MPI Programming Part 2

High Performance Computing Course Notes Message Passing Programming I

The Message Passing Model

Holland Computing Center Kickstart MPI Intro

MPI MESSAGE PASSING INTERFACE

Introduction to the Message Passing Interface (MPI)

MPI MPI. Linux. Linux. Message Passing Interface. Message Passing Interface. August 14, August 14, 2007 MPICH. MPI MPI Send Recv MPI

Message Passing Interface

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

CSE 160 Lecture 18. Message Passing

AMath 483/583 Lecture 21

Distributed Memory Programming with Message-Passing

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

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

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

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

Parallel hardware. Distributed Memory. Parallel software. COMP528 MPI Programming, I. Flynn s taxonomy:

Programming Using the Message Passing Paradigm

Lecture 7: Distributed memory

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

Working with IITJ HPC Environment

Parallel Programming in C with MPI and OpenMP

Parallel Programming. Using MPI (Message Passing Interface)

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

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

Recap of Parallelism & MPI

Practical Scientific Computing: Performanceoptimized

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

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

5/5/2012. Message Passing Programming Model Blocking communication. Non-Blocking communication Introducing MPI. Non-Buffered Buffered

An Introduction to Parallel Programming

Parallel Short Course. Distributed memory machines

Message Passing with MPI Christian Iwainsky HiPerCH

Writing Message Passing Parallel Programs with MPI

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

Programming with MPI. Pedro Velho

L14 Supercomputing - Part 2

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

Slides prepared by : Farzana Rahman 1

MPI Tutorial. Shao-Ching Huang. IDRE High Performance Computing Workshop

Introduction to MPI. Martin Čuma Center for High Performance Computing University of Utah

Parallel Computing Paradigms

Parallel Programming in C with MPI and OpenMP

Programming with MPI on GridRS. Dr. Márcio Castro e Dr. Pedro Velho

MPI introduction - exercises -

An Introduction to MPI

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

The Message Passing Interface (MPI) TMA4280 Introduction to Supercomputing

Experiencing Cluster Computing Message Passing Interface

CSE 160 Lecture 15. Message Passing

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

DISTRIBUTED MEMORY PROGRAMMING WITH MPI. Carlos Jaime Barrios Hernández, PhD.

HPC Parallel Programing Multi-node Computation with MPI - I

High performance computing. Message Passing Interface

Introduction to the Message Passing Interface (MPI)

Distributed Simulation in CUBINlab

Introduction to MPI HPC Workshop: Parallel Programming. Alexander B. Pacheco

Introduction to MPI. Shaohao Chen Research Computing Services Information Services and Technology Boston University

MPI Programming. Henrik R. Nagel Scientific Computing IT Division

Overview. Parallel Distributed Memory Programming - Message Passing. Section Contents. Section I: Background

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

Introduction to Parallel Programming

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

Point-to-Point Communication. Reference:

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

Parallel Computing Programming Distributed Memory Architectures

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

High Performance Computing Course Notes Message Passing Programming III

High Performance Computing Course Notes Message Passing Programming III

Distributed Systems + Middleware Advanced Message Passing with MPI

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

Message Passing Programming. Introduction to MPI

Transcription:

Parallel Programming, MPI Lecture 2 Ehsan Nedaaee Oskoee 1 1 Department of Physics IASBS IPM Grid and HPC workshop IV, 2011

Outline 1 Introduction and Review The Von Neumann Computer Kinds of Parallel Machine Distributed memory parallel machines Shared memory parallel machine 2 Methodical Design Partitioning Domain Decomposition Functional Decomposition 3 An Introduction to MPI 4 Point-to-Point Communication Blocking PTP Communication

Outline 1 Introduction and Review The Von Neumann Computer Kinds of Parallel Machine Distributed memory parallel machines Shared memory parallel machine 2 Methodical Design Partitioning Domain Decomposition Functional Decomposition 3 An Introduction to MPI 4 Point-to-Point Communication Blocking PTP Communication

The Von Neumann Computer Figure: The Von Neumann Computer

Outline 1 Introduction and Review The Von Neumann Computer Kinds of Parallel Machine Distributed memory parallel machines Shared memory parallel machine 2 Methodical Design Partitioning Domain Decomposition Functional Decomposition 3 An Introduction to MPI 4 Point-to-Point Communication Blocking PTP Communication

Different type of parallel platforms:shared Memory Figure: The typical representation of a Shared Memory Parallel machine

Different type of parallel platforms:distributed Memory Figure: A typical representation of Distributed Memory Parallel machine

Outline 1 Introduction and Review The Von Neumann Computer Kinds of Parallel Machine Distributed memory parallel machines Shared memory parallel machine 2 Methodical Design Partitioning Domain Decomposition Functional Decomposition 3 An Introduction to MPI 4 Point-to-Point Communication Blocking PTP Communication

Methodical Design Partitioning Domain Decomposition Figure: Domain Decomposition 1 1 Designing and Building Parallel Programs (On-line book ), by Ian Foster

Methodical Design Partitioning Functional Decomposition Figure: Functional Decomposition 2 2 Designing and Building Parallel Programs (On-line book ), by Ian Foster

3 Methodical Design 3 Communication Number of tasks 8 8 = 64, Number of Communications 4 64 = 256.

3 Methodical Design 3 Communication Number of tasks 8 8 = 64, Number of Communications 4 64 = 256. Number of tasks 1 4 = 4, Number of Communications 4 4 = 16.

Methodical Design 4 Mapping 4 Designing and Building Parallel Programs (On-line book ), by Ian Foster

An Introduction to MPI Applications: Scalable Parallel Computers (SPCs) with distributed memory, Network Of Workstations (NOWs)

An Introduction to MPI Applications: Scalable Parallel Computers (SPCs) with distributed memory, Network Of Workstations (NOWs) Some Goals of MPI: Design an application programming interface, Allow efficient communication, Allow for implementations that can be used in a heterogeneous environment, Allow convenient C and Fortran 77 binding for the interface, Provide a reliable communication interface, Define an interface not too different from current practice, such as PVM, NX, etc.

An Introduction to MPI What is Included in MPI Point-to-point communication, Collective operations, Process groups, Communication domains, Process topologies, Environmental Management and inquiry, Profiling interface, Binding for Fortran 77 and C (Also for C++ and F90 in MPI-2)â, I/O functions (in MPI-2).â

An Introduction to MPI What is Included in MPI Point-to-point communication, Collective operations, Process groups, Communication domains, Process topologies, Environmental Management and inquiry, Profiling interface, Binding for Fortran 77 and C (Also for C++ and F90 in MPI-2)â, I/O functions (in MPI-2).â Versions of MPI Version 1.0 (was made in June 1994)â, Version 1.1 (was made in June 1995)â, Version 2.

An Introduction to MPI Procedure Specification The call uses but does not update an argument marked IN, The call may update an argument marked OUT, The call both uses and updates an argument marked INOUT.

An Introduction to MPI Procedure Specification The call uses but does not update an argument marked IN, The call may update an argument marked OUT, The call both uses and updates an argument marked INOUT. Types of MPI Calls Local, Non-local, Blocking, Non-blocking, Opaque Objects, Language Binding.

Outline 1 Introduction and Review The Von Neumann Computer Kinds of Parallel Machine Distributed memory parallel machines Shared memory parallel machine 2 Methodical Design Partitioning Domain Decomposition Functional Decomposition 3 An Introduction to MPI 4 Point-to-Point Communication Blocking PTP Communication

Point-to-Point Communication The Simplest Example main.for Program main implicit none include mpif.h integer ierr,rc call MPI_INIT(ierr) print*, HI There call MPI_FINALIZE(rc) End main.cpp #include <iostream.h> #include <mpi.h> int main(int argc, char **argv){ MPI_Init(&argc, &argv); cout«"hi There"; MPI_Finalize(); return 0; }

Point-to-Point Communication Compiling a Program > more hostfile 192.168.189.11 1 Naft 2 Oil 1 > more hostfile HPCLAB ws01 ws02 ws03 Lamboot -v hostfile mpicc code_name.c -o code_exe_name mpicc code_name.cpp -o code_exe_name mpif77 code_name.for -o code_exe_name mpif90 code_name.f90 -o code_exe_name mpirun -v -np 9 code_exe_name mpirun N code_exe_name

Point-to-Point Communication A More Complex Program #include <iostream.h> #include <mpi.h> int main(int argc, char **argv) { int npes, myrank; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &npes); MPI_Comm_rank(MPI_COMM_WORLD, &myrank); cout«"hi There, I am node "«myrank«" and the total worker which you are using now is:" «npes«endl; MPI_Finalize(); return 0; }

Point-to-Point Communication A More Complex Program Program size_rank implicit none include mpif.h integer ierr,npes,myrank call MPI_INIT(ierr) call MPI_COMM_SIZE( MPI_COMM_WORLD, npes, ierr ) call MPI_COMM_RANK( MPI_COMM_WORLD, myrank, ierr ) print*,"hi There, I am node ",myrank," and the total", *"number of workers which you are using now is: ",npes call MPI_FINALIZE(ierr) End

Point-to-Point Communication Blocking Send Operation MPI_SEND(buf, count, datatype, dest, tag, comm) IN buf initial address of send buffer IN count number of entries to send IN datatype datatype of each entry IN dest rank of destination IN tag message tag IN comm communicator C Version int MPI_Send(void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm, comm)

Point-to-Point Communication Blocking Send Operation MPI_SEND(buf, count, datatype, dest, tag, comm) IN buf initial address of send buffer IN count number of entries to send IN datatype datatype of each entry IN dest rank of destination IN tag message tag IN comm communicator Fortran version MPI_SEND(BUF, COUNT, DATATYPE, DEST, TAG, COMM, IERROR) <type> BUF(*) INTEGER COUNT, DATATYPE, DEST, TAG, COMM, IERROR

Point-to-Point Communication Blocking Receive Operation MPI_RECV(buf, count, datatype, source, tag, comm, status)â OUT buf initial address of received buffer IN count number of entries to receive IN datatype datatype of each entry IN source rank of source IN tag message tag IN comm communicator OUT status return status C Version int MPI_Recv(void* buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status);

Point-to-Point Communication Blocking Receive Operation MPI_RECV(buf, count, datatype, source, tag, comm, status)â OUT buf initial address of received buffer IN count number of entries to receive IN datatype datatype of each entry IN source rank of source IN tag message tag IN comm communicator OUT status return status Fortran Version MPI_RECV(BUF, COUNT, DATATYPE, SOURCE, TAG, COMM, STATUS, IERROR) <type> BUF(*) STATUS(MPI_STATUS_SIZE), IERROR INTEGER COUNT, DATATYPE, SOURCE, TAG, COMM,

Point-to-Point Communication Data Type MPI Data Type MPI_INTEGER MPI_REAL MPI_DOUBLE_PRECISION MPI_COMPLEX MPI_LOGICAL MPI_CHARACTER MPI_BYTE MPI_PACKED Fortran Data Type INTEGER REAL BOUBLE PRECISION COMPLEX LOGICAL CHARACTER(1)â

Point-to-Point Communication Data Type MPI Data Type MPI_CHAR MPI_SHORT MPI_INT MPI_LONG MPI_UNSIGNED_CHAR MPI_UNSIGNED_SHORT MPI_UNSIGNED MPI_UNSIGNED_LONG MPI_FLOAT MPI_DOUBLE MPI_LONG_DOUBLE MPI_BYTE MPI_PACKED C Data Type signed char signed short int signed int signed long int unsigned char unsigned short int unsigned int unsigned long int float double long double

Point-to-Point Communication A useful command MPI_GET_PROCESSOR_NAME(name, resultlen) OUT name A unique specifier for the current physical node OUT resultlen Length (in printable characters) of the result returned in name C Version int MPI_Get_processor_name(char* name, int* resultlen) Fortran Version MPI_GET_PROCESSOR_NAME(NAME, RESULTLEN, IERROR) CHARACTER*(*) NAME INTEGER RESULTLEN, IERROR

Point-to-Point Communication Blocking Send & Receive (Bsend_recd_1.cpp) int npes, myrank, namelen, i; char processor_name[mpi_max_processor_name]; char greeting[mpi_max_processor_name + 80]; MPI_Status status; MPI_Get_processor_name( processor_name, &namelen ); sprintf( greeting, "Hello, World, From process %d of %d on %s", myrank, npes, processor_name ); if (myrank == 0 ) { printf( "%s", greeting ); for (i = 1; i < npes; i++) { MPI_Recv( greeting, sizeof( greeting ), MPI_CHAR, i, 1, MPI_COMM_WORLD, &status); printf( "%s", greeting ); } } else { MPI_Send( greeting, strlen( greeting ) + 1, MPI_CHAR, 0, 1, MPI_COMM_WORLD); } } }

Point-to-Point Communication Blocking Send & Receive (Bsend_Recd_1.for) INTEGER ierr,npes,myrank,namelen,i INTEGER stat(mpi_status_size) CHARACTER*(MPI_MAX_PROCESSOR_NAME) processor_name CHARACTER (MPI_MAX_PROCESSOR_NAME + 80) greeting CHARACTER(1) numb(0:9) numb(0)="0" ; numb(1)="1"; numb(2)="2" ; numb(3)="3" numb(4)="4" ; numb(5)="5" ; numb(6)="6" ; numb(7)="7" numb(8)="8" ; numb(9)="9" call MPI_GET_PROCESSOR_NAME(processor_name,namelen,ierr) greeting = Hello Wold, From process //numb(myrank)// * of //numb(npes)// on //processor_name IF(myrank.EQ.0) THEN print*, greeting DO i = 1, npes -1 call MPI_RECV(greeting, len(greeting)+1,mpi_character,i,1, * MPI_COMM_WORLD,stat,ierr) print*,greeting END DO ELSE call MPI_SEND(greeting,len(greeting)+1,MPI_CHARACTER,0,1, * MPI_COMM_WORLD,ierr) ENDIF

Point-to-Point Communication Safety

Point-to-Point Communication Safety

Point-to-Point Communication Safety

Point-to-Point Communication Safety src = * :: MPI_ANY_SOURCE, tag = * :: MPI_ANY_TAG

Point-to-Point Communication Blocking Send Received example 2 Domain Decomposition

Point-to-Point Communication Blocking Send & Receive (Bsend_recd_2.cpp) for(j =0; j<= np+1; j++){ for(i=0; i<= np+1; i++)â a[i][j] = myrank*100+10*j+i;} left = myrank - 1; right= myrank + 1; if(myrank == 1 ) left = npes -1 ; if(myrank == (npes-1)) right = 1; if (myrank!= 0 ) { if(myrank%2==0){ MPI_Send(&a[1][0],np+2,MPI_INT,left,1,MPI_COMM_WORLD); MPI_Send(&a[np][0],np+2,MPI_INT,right,1,MPI_COMM_WORLD); MPI_Recv(&a[0][0],np+2,MPI_INT,left,1,MPI_COMM_WORLD,&stat); MPI_Recv(&a[np+1][0],np+2,MPI_INT,right,1,MPI_COMM_WORLD,&stat); } else { MPI_Recv(&a[np+1][0],np+2,MPI_INT,right,1,MPI_COMM_WORLD,&stat); MPI_Recv(&a[0][0],np+2,MPI_INT,left,1,MPI_COMM_WORLD,&stat); MPI_Send(&a[np][0],np+2,MPI_INT,right,1,MPI_COMM_WORLD); MPI_Send(&a[1][0],np+2,MPI_INT,left,1,MPI_COMM_WORLD); } }

Point-to-Point Communication Blocking Send & Receive (Bsend_Recd_2.for) IF(myrank.NE.0) THEN IF(MOD(myrank,2).EQ.0)THEN call MPI_SEND(a(0,1),np+2,MPI_INTEGER,left,1, * MPI_COMM_WORLD,ierr) call MPI_SEND(a(0,np),np+2,MPI_INTEGER,right,1, * MPI_COMM_WORLD,ierr) call MPI_RECV(a(0,0),np+2,MPI_INTEGER,left,1, * MPI_COMM_WORLD,stat,ierr) call MPI_RECV(a(0,np+1),np+2,MPI_INTEGER,right,1, * MPI_COMM_WORLD,stat,ierr) ELSE call MPI_RECV(a(0,np+1),np+2,MPI_INTEGER,right,1, * MPI_COMM_WORLD,stat,ierr) call MPI_RECV(a(0,0),np+2,MPI_INTEGER,left,1, * MPI_COMM_WORLD,stat,ierr) call MPI_SEND(a(0,np),np+2,MPI_INTEGER,right,1, * MPI_COMM_WORLD,ierr) call MPI_SEND(a(0,1),np+2,MPI_INTEGER,left,1, * MPI_COMM_WORLD,ierr) ENDIF ENDIF

The End That s All Folks