Distributed Processing with MPI International Summer School 2015 Tomsk Polytechnic University Assistant Professor Dr. Sergey Axyonov.

Slides:



Advertisements
Similar presentations
Its.unc.edu 1 Collective Communication University of North Carolina - Chapel Hill ITS - Research Computing Instructor: Mark Reed
Advertisements

Reference: / MPI Program Structure.
MPI_Gatherv CISC372 Fall 2006 Andrew Toy Tom Lynch Bill Meehan.
Introduction to MPI. What is Message Passing Interface (MPI)?  Portable standard for communication  Processes can communicate through messages.  Each.
SOME BASIC MPI ROUTINES With formal datatypes specified.
Message-Passing Programming and MPI CS 524 – High-Performance Computing.
Distributed Memory Programming with MPI. What is MPI? Message Passing Interface (MPI) is an industry standard message passing system designed to be both.
EECC756 - Shaaban #1 lec # 7 Spring Message Passing Interface (MPI) MPI, the Message Passing Interface, is a library, and a software standard.
Collective Communication.  Collective communication is defined as communication that involves a group of processes  More restrictive than point to point.
Message Passing Interface. Message Passing Interface (MPI) Message Passing Interface (MPI) is a specification designed for parallel applications. The.
Programming Using the Message Passing Paradigm Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar To accompany the text ``Introduction to Parallel.
1 Tuesday, October 10, 2006 To err is human, and to blame it on a computer is even more so. -Robert Orben.
Sahalu JunaiduICS 573: High Performance Computing6.1 Programming Using the Message Passing Paradigm Principles of Message-Passing Programming The Building.
Parallel Programming with Java
CS 179: GPU Programming Lecture 20: Cross-system communication.
Parallel Programming with MPI Matthew Pratola
ORNL is managed by UT-Battelle for the US Department of Energy Crash Course In Message Passing Interface Adam Simpson NCCS User Assistance.
Parallel Processing1 Parallel Processing (CS 676) Lecture 7: Message Passing using MPI * Jeremy R. Johnson *Parts of this lecture was derived from chapters.
2a.1 Message-Passing Computing More MPI routines: Collective routines Synchronous routines Non-blocking routines ITCS 4/5145 Parallel Computing, UNC-Charlotte,
1 Collective Communications. 2 Overview  All processes in a group participate in communication, by calling the same function with matching arguments.
1 MPI: Message-Passing Interface Chapter 2. 2 MPI - (Message Passing Interface) Message passing library standard (MPI) is developed by group of academics.
PP Lab MPI programming VI. Program 1 Break up a long vector into subvectors of equal length. Distribute subvectors to processes. Let them compute the.
Parallel Computing A task is broken down into tasks, performed by separate workers or processes Processes interact by exchanging information What do we.
1 Review –6 Basic MPI Calls –Data Types –Wildcards –Using Status Probing Asynchronous Communication Collective Communications Advanced Topics –"V" operations.
Parallel Programming with MPI Prof. Sivarama Dandamudi School of Computer Science Carleton University.
1 What is MPI?  MPI = Message Passing Interface  Specification of message passing libraries for developers and users  Not a library by itself, but specifies.
CS 838: Pervasive Parallelism Introduction to MPI Copyright 2005 Mark D. Hill University of Wisconsin-Madison Slides are derived from an online tutorial.
Message Passing Programming Model AMANO, Hideharu Textbook pp. 140-147.
Summary of MPI commands Luis Basurto. Large scale systems Shared Memory systems – Memory is shared among processors Distributed memory systems – Each.
MPI Introduction to MPI Commands. Basics – Send and Receive MPI is a message passing environment. The processors’ method of sharing information is NOT.
CS 420 – Design of Algorithms MPI Data Types Basic Message Passing - sends/receives.
Parallel Programming with MPI By, Santosh K Jena..
Lecture 6: Message Passing Interface (MPI). Parallel Programming Models Message Passing Model Used on Distributed memory MIMD architectures Multiple processes.
CSCI-455/522 Introduction to High Performance Computing Lecture 4.
Oct. 23, 2002Parallel Processing1 Parallel Processing (CS 730) Lecture 6: Message Passing using MPI * Jeremy R. Johnson *Parts of this lecture was derived.
MPI Jakub Yaghob. Literature and references Books Gropp W., Lusk E., Skjellum A.: Using MPI: Portable Parallel Programming with the Message-Passing Interface,
Message Passing Interface (MPI) 2 Amit Majumdar Scientific Computing Applications Group San Diego Supercomputer Center Tim Kaiser (now at Colorado School.
-1.1- MPI Lectured by: Nguyễn Đức Thái Prepared by: Thoại Nam.
Message Passing Programming Based on MPI Collective Communication I Bora AKAYDIN
Message Passing Interface Using resources from
COMP7330/7336 Advanced Parallel and Distributed Computing MPI Programming: 1. Collective Operations 2. Overlapping Communication with Computation Dr. Xiao.
ITCS 4/5145 Parallel Computing, UNC-Charlotte, B
1 MPI: Message Passing Interface Prabhaker Mateti Wright State University.
Computer Science Department
Introduction to MPI Programming Ganesh C.N.
Introduction to parallel computing concepts and technics
MPI Jakub Yaghob.
CS4402 – Parallel Computing
Introduction to MPI.
MPI Message Passing Interface
Computer Science Department
Send and Receive.
Collective Communication with MPI
CS 584.
An Introduction to Parallel Programming with MPI
Send and Receive.
Programming Using the Message Passing Model
ITCS 4/5145 Parallel Computing, UNC-Charlotte, B
CS 5334/4390 Spring 2017 Rogelio Long
Lecture 14: Inter-process Communication
MPI: Message Passing Interface
Message-Passing Computing More MPI routines: Collective routines Synchronous routines Non-blocking routines ITCS 4/5145 Parallel Computing, UNC-Charlotte,
Introduction to parallelism and the Message Passing Interface
Hardware Environment VIA cluster - 8 nodes Blade Server – 5 nodes
Message-Passing Computing Message Passing Interface (MPI)
Computer Science Department
5- Message-Passing Programming
Parallel Processing - MPI
MPI Message Passing Interface
CS 584 Lecture 8 Assignment?.
Presentation transcript:

Distributed Processing with MPI International Summer School 2015 Tomsk Polytechnic University Assistant Professor Dr. Sergey Axyonov

Overview  Introduction & Basic functions  Point-to-point communication  Blocking and non-blocking communication  Collective communication

MPI Intro I  MPI is a language-independent communications protocol used to program parallel computers.  De facto standard for communication among processes that model a parallel program running on a distributed memory system.  MPI implementations consist of a specific set of routines directly callable from C, C++, Fortran and any language able to interface with such libraries.

MPI Intro II: Basic functions  MPI_Init  MPI_Finalize  MPI_Comm_Rank  MPI_Send  MPI_Recv

MPI Intro II: Basic functions int MPI_Init(int *argc, char **argv) Input argc, argv: Variables from the command line Returns MPI_SUCСESS or code Error MPI_Init has to be called by each MPI process before any other MPI routine is executed.

MPI Intro II: Basic functions int MPI_Finalize() Each process must call MPI_FINALIZE before it exits. Precondition: All pending communication has to be finished. One MPI_FINALIZE returns, no further MPI routines can be executed. MPI_FINALIZE frees any resources.

MPI Intro II: Basic functions int MPI_Comm_size(MPI_Comm comm, int *size) Input comm: Communicator Output rank: Number of processes in communicator Communicator Identifies a process group and defines the communication context. All message tags are unique with respect to a communicator. MPI_COMM_WORLD This is a predefined standard communicator. Its process group includes all processes of a parallel application. MPI_Comm_size It returns the number of processes in the process group of the given communicator.

MPI Intro II: Basic functions int MPI_Comm_rank(MPI_Comm comm, int *rank) Input comm: Communicator Output rank: Process rank Process number The process number is a unique identifier within the process group of the communicator. It is the only way to distinguish processes and to implement an SPMD program. MPI_Comm_rank returns the process number of the executing process.

MPI Intro II: Basic functions int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) Inputbuf: Address of the send buffer Input count:Number of data to be sent Input datatype:Data type Input dest:Receiver Input tag:Message Tag Input comm:Communicator Sends the data to the receiver. It is a blocking operation, i.e. it terminates when the send buffer can be reused, either because the message was delivered or the data were copied to a system buffer.

MPI Intro II: Basic functions MPIC MPI_CHARsigned char MPI_SHORTsigned short int MPI_INTsigned int MPI_LONGunsigned long int MPI_UNSIGNED_CHARunsigned char MPI_UNSIGNED_SHORTunsigned short int MPI_UNSIGNEDunsigned int MPI_UNSIGNED_LONGunsigned long int MPI_FLOATfloat MPI_DOUBLEdouble MPI_LONG_DOUBLElong double MPI_BYTE1 байт MPI_PACKEDУпакованные данные

MPI Intro II: Basic functions int MPI_Send(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status) Inputbuf: Address of the receive buffer Inputcount: Size of receive buffer Input datatype:Data type Input source:Sender Input tag:Message tag Input comm:Communicator Output status: Status information It is a blocking operation, i.e. it terminates after the message is available in the receive buffer. The message must not be larger than the receive buffer. The remaining part of the buffer not used for the received message will be unchanged.

MPI Intro II: Basic functions Message selection A message to be received by this function must match –the sender –the tag –the communicator Sender and tag can be specified as wild cards –MPI_ANY_SOURCE and MPI_ANY_TAG There is no wild card for the communicator. Status The data structure MPI_Status includes –status(MPI_SOURCE): sender of the message –status(MPI_TAG): message tag –status(MPI_ERROR): error code The actual length of the received message can be determined via MPI_Get_count.

MPI: P2P - Example #include "mpi.h" #include int main(int argc, char* argv[] ) { int i, rank, array[100]; MPI_Status status; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD,&rank); if (rank==0) { for(i =0; i<100; i++) array[i] = i; MPI_Send(array, 100, MPI_INT, 1, 5, MPI_COMM_WORLD); printf("The first process has sent the message..."); }

MPI: P2P - Example else if (rank ==1) { MPI_Recv(array, 100, MPI_INT,0, 5, MPI_COMM_WORLD, &status); printf("The second process has recieved the message"); } MPI_Finalize(); return 0; }

Non-blocking communication Properties Nonblocking send and receive operations terminate after a communication request was created. (Posting of send or receive operation) A separate test is required to ensure that the posted operation completed. Only after the test it is safe to access the send and receive buffer. This allows: Send: Overlap communication with local computation. Receive: Copy a message directly into the address space of an application without blocking on the message.

Non-blocking communication Non-blocking send int MPI_Isend (void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) Non-blocking recv int MPI_Irecv (void* buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request)

Collective communication Must be executed by all processes of the process group. MPI provides three classes of collective operations Synchronization –Barrier Communication –Broadcast –gather –scatter Reduction –Global value returned to one or all processes. –Combination with subsequent scatter. –Parallel prefix operations

Collective communication int MPI_Barrier(MPI_Comm comm) Input comm: Communicator This operation synchronizes all processes. #include "mpi.h" main (int argc,char *argv[]){... MPI_Comm_size(MPI_COMM_WORLD, &np); MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Barrier(MPI_COMM_WORLD)...

Collective communication: Bcast int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm comm) Input/Output buf: Address of send/receive buffer Input count: Number of elements Input datatype:Data type Input root: Sender Inputcomm:Communicator The contents of the send buffer is copied to all other processes. Collective vs P2P operations No tag Number of elements sent must be equal to number of elements received. The routines do not necessarily synchronize processes.

Collective communication: Scatter int MPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) Входsendbuf: Send buffer Вход sendcount: Number of elements sent to each process Вход sendtype:Data type Вход/Выходrecvbuf:Receive buffer Входrecvcount:Number of elements to be received by a process Входrecvtype:Data type Вход root: Sender Входcomm:Communicator The root sends a part of its send buffer to each process. Process kreceives sendcountelements starting with sendbuf+ k*sendcount.

Collective communication: Scatter

Collective communication: Gather int MPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) Inputsendbuf: Send buffer Input sendcount: Number of elements to be sent to the root Input sendtype:Data type Input/Outputrecvbuf:Receive buffer Inputrecvcount:Number of elements to be received from each process Inputrecvtype:Data type Input root: Receiver Inputcomm:Communicator The root receives from all processes the data in the send buffer. It stores the data in the receive buffer ordered by the process number of the senders.

Collective communication: Gather

Reduction The data of the processes are combined via a specified operation, e.g. ’+’. There are three different variants The result is only available at the root process. The result is available at all processes. The result is different for the processes according to a prefix operation. Input values at each process: Scalar variable: The operations combines all variables of the processes. Array: The elements of the arrays are combined in an elementwise fashion. The result is an array.

Collective communication: Reduce int MPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm) Inputsendbuf: Send buffer Output recvbuf: Receive buffer Input count:Number of elements Inputdatatype:Data type Inputop:Operation Inputroot:Root process Inputcomm:Communicator This operation combines the elements in the send buffer and delivers the result to root. Count, op, and root have to be equal in all processes

Collective communication: Reduce 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 Data types The operations are defined for appropriate data types The data type for MPI_MAXLOC and MPI_MINLOC is a structure with two components: –value –index The operations define

Collective communication: Reduce int main (int argc, char *argv[]) { int *sendbuf, *recvbuf, i, n=5, rank; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD,&rank); sendbuf = malloc(5*sizeof(int)); recvbuf = malloc(5*sizeof(int)); // Here we fill sendbufs MPI_Reduce(sendbuf,recvbuf,n,MPI_INT,MPI_MAX,0,MPI_COMM_WORLD); if (rank==0) for (i=0; i<5; i++) printf(“MAX Value at %d is %d \n“, i, recvbuf[i] ); MPI_Finalize(); return 0: }