1 MPI Datatypes l The data in a message to sent or received is described by a triple (address, count, datatype), where l An MPI datatype is recursively.

Slides:



Advertisements
Similar presentations
E LEMENTARY D ATA STRUCTURES. A RRAYS Sequence of elements of similar type. Elements are selected by integer subscripts. For example, signs: array[37:239]
Advertisements

MPI 2.2 William Gropp. 2 Scope of MPI 2.2 Small changes to the standard. A small change is defined as one that does not break existing correct MPI 2.0.
MPI Message Passing Interface
1 Computer Science, University of Warwick Accessing Irregularly Distributed Arrays Process 0’s data arrayProcess 1’s data arrayProcess 2’s data array Process.
1 Introduction to Collective Operations in MPI l Collective operations are called by all processes in a communicator. MPI_BCAST distributes data from one.
Programming and Data Structure
MPI Collective Communications
1 Buffers l When you send data, where does it go? One possibility is: Process 0Process 1 User data Local buffer the network User data Local buffer.
Chapter 7:: Data Types Programming Language Pragmatics
Chapter 9 Imperative and object-oriented languages 1.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
Arrays. Memory organization Table at right shows 16 bytes, each consisting of 8 bits Each byte has an address, shown in the column to the left
1 Performance Modeling l Basic Model »Needed to evaluate approaches »Must be simple l Synchronization delays l Main components »Latency and Bandwidth »Load.
Derived Datatypes and Related Features. Introduction In previous sections, you learned how to send and receive messages in which all the data was of a.
Reference: Getting Started with MPI.
Introduction MPI Mengxia Zhu Fall An Introduction to MPI Parallel Programming with the Message Passing Interface.
A Message Passing Standard for MPP and Workstations Communications of the ACM, July 1996 J.J. Dongarra, S.W. Otto, M. Snir, and D.W. Walker.
ISBN Chapter 6 Data Types: Structured types.
Distributed Memory Programming with MPI. What is MPI? Message Passing Interface (MPI) is an industry standard message passing system designed to be both.
MPI Collective Communication CS 524 – High-Performance Computing.
1 Message protocols l Message consists of “envelope” and data »Envelope contains tag, communicator, length, source information, plus impl. private data.
S an D IEGO S UPERCOMPUTER C ENTER N ATIONAL P ARTNERSHIP FOR A DVANCED C OMPUTATIONAL I NFRASTRUCTURE Message Passing Interface (MPI) Part I NPACI Parallel.
Comp 422: Parallel Programming Lecture 8: Message Passing (MPI)
MPI Point-to-Point Communication CS 524 – High-Performance Computing.
Its.unc.edu 1 Derived Datatypes Research Computing UNC - Chapel Hill Instructor: Mark Reed
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
1 Tuesday, October 10, 2006 To err is human, and to blame it on a computer is even more so. -Robert Orben.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
A Brief Look At MPI’s Point To Point Communication Brian T. Smith Professor, Department of Computer Science Director, Albuquerque High Performance Computing.
Today Objectives Chapter 6 of Quinn Creating 2-D arrays Thinking about “grain size” Introducing point-to-point communications Reading and printing 2-D.
1 What is message passing? l Data transfer plus synchronization l Requires cooperation of sender and receiver l Cooperation not always apparent in code.
Part II: Addressing Modes
Parallel Programming Using Basic MPI Presented by Timothy H. Kaiser, Ph.D. San Diego Supercomputer Center Presented by Timothy H. Kaiser, Ph.D. San Diego.
HDF5 collective chunk IO A Working Report. Motivation for this project ► Found extremely bad performance of parallel HDF5 when implementing WRF- Parallel.
Edgar Gabriel MPI derived datatypes Edgar Gabriel.
1 An Introduction to MPI Parallel Programming with the Message Passing Interface Originally by William Gropp and Ewing Lusk Adapted by Anda Iamnitchi.
Copyright © 2012 Pearson Education, Inc. Chapter 8 Two Dimensional Arrays.
Part I MPI from scratch. Part I By: Camilo A. SilvaBIOinformatics Summer 2008 PIRE :: REU :: Cyberbridges.
1 Why Derived Data Types  Message data contains different data types  Can use several separate messages  performance may not be good  Message data.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Parallel Computing A task is broken down into tasks, performed by separate workers or processes Processes interact by exchanging information What do we.
Message Passing Programming with MPI Introduction to MPI Basic MPI functions Most of the MPI materials are obtained from William Gropp and Rusty Lusk’s.
MPI Communications Point to Point Collective Communication Data Packaging.
Message Passing Programming Model AMANO, Hideharu Textbook pp. 140-147.
Performance Oriented MPI Jeffrey M. Squyres Andrew Lumsdaine NERSC/LBNL and U. Notre Dame.
Summary of MPI commands Luis Basurto. Large scale systems Shared Memory systems – Memory is shared among processors Distributed memory systems – Each.
Message Passing Interface (MPI) 1 Amit Majumdar Scientific Computing Applications Group San Diego Supercomputer Center Tim Kaiser (now at Colorado School.
1 The Message-Passing Model l A process is (traditionally) a program counter and address space. l Processes may have multiple threads (program counters.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
MPI: the last episode By: Camilo A. Silva. Topics Modularity Data Types Buffer issues + Performance issues Compilation using MPICH2 Other topics: MPI.
Programming distributed memory systems: Message Passing Interface (MPI) Distributed memory systems: multiple processing units working on one task (e.g.
Sending large message counts (The MPI_Count issue)
CSE 160 – Lecture 16 MPI Concepts, Topology and Synchronization.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
REEM ALMOTIRI Information Technology Department Majmaah University.
Grouping Data and Derived Types in MPI. Grouping Data Messages are expensive in terms of performance Grouping data can improve the performance of your.
Two dimensional arrays A two dimensional m x n array A is a collection of m. n elements such that each element is specified by a pair of integers (such.
MPI Adriano Cruz ©2003 NCE/UFRJ e Adriano Cruz NCE e IM - UFRJ Summary n References n Introduction n Point-to-point communication n Collective.
Message Passing Programming Based on MPI Collective Communication I Bora AKAYDIN
1 ParallelAlgorithms Parallel Algorithms Dr. Stephen Tse Lesson 9.
Lecture 3 Point-to-Point Communications Dr. Muhammad Hanif Durad Department of Computer and Information Sciences Pakistan Institute Engineering and Applied.
Introduction to MPI Programming Ganesh C.N.
File System Implementation
MPI Message Passing Interface
Parallel Programming with MPI and OpenMP
MPI-Message Passing Interface
Introduction to parallelism and the Message Passing Interface
Message Passing Programming Based on MPI
5- Message-Passing Programming
MPI Message Passing Interface
Presentation transcript:

1 MPI Datatypes l The data in a message to sent or received is described by a triple (address, count, datatype), where l An MPI datatype is recursively defined as: »predefined, corresponding to a data type from the language (e.g., MPI_INT, MPI_DOUBLE_PRECISION) »a contiguous array of MPI datatypes »a strided block of datatypes »an indexed array of blocks of datatypes »an arbitrary structure of datatypes l There are MPI functions to construct custom datatypes, such an array of (int, float) pairs, or a row of a matrix stored columnwise.

2 Why Datatypes? l Since all data is labeled by type, an MPI implementation can support communication between processes on machines with very different memory representations and lengths of elementary datatypes (heterogeneous communication). l Specifying application-oriented layout of data in memory »can reduce memory-to-memory copies in the implementation »allows the use of special hardware (scatter/gather) when available

3 Non-contiguous Datatypes l Provided to allow MPI implementations to avoid copy »Not widely implemented yet l Handling of important special cases »Constant stride »Contiguous structures Network Extra copy

4 Potential Performance Advantage in MPI Datatypes l Handling non-contiguous data l Assume must pack/unpack on each end »cn + (s + r n) + cn = s + (2c + r)n l Can move directly »s + r’ n »r’ probably > r but < (2c+r) l MPI implementation must copy data anyway (into network buffer or shared memory); having the datatype permits removing 2 copies

5 Performance of MPI Datatypes l Test of 1000 element vector of doubles with stride of 24 doubles (MB/sec). »MPI_Type_vector »MPI_Type_struct (MPI_UB for stride) »User packs and unpacks by hand l Performance very dependent on implementation; should improve with time

6 Performance of MPI Datatypes II l Performance of MPI_Type_Vector »1000 doubles with stride 24 »Performance in MB/sec PlatformVendor MPIMPICH IBM SP Blue Pacific SGI O2000 Blue Mountain Intel Tflops Red User Equivalent Type_Struct MPICH is Vendor MPI

7 Datatype Abstractions l Standard Unix abstraction is “block of contiguous bytes” (e.g., readv, writev) l MPI specifies datatypes recursively as »count of (type,offset) where offset may be relative or absolute »MPICH uses a simplified form of this for MPI_Type_vector (and so outperforms vendor MPIs) l More general form would provide superior performance for most user-defined datatypes »MPI implementations can improve

8 Working With MPI Datatypes l An MPI datatype defines a type signature: »sequence of pairs: (basic type,offset) »An integer at offset 0, followed by another integer at offset 8, followed by a double at offset 16 is –(integer,0), (integer,4), (double,16) »Offsets need not be increasing: –(integer,64),(double,0) l An MPI datatype has an extent and a size »size is the number of bytes of the datatype »extent controls how a datatype is used with the count field in a send and similar MPI operations »extent is a misleading name

9 What does extent do? l Consider MPI_Send( buf, count, datatype, …) l What actually gets sent? l MPI defines this as do i=0,count-1 MPI_Send(buf(1+i*extent(datatype)),1, datatype,…) l extent is used to decide where to send from (or where to receive to in MPI_Recv) for count > 1 l Normally, this is right after the last byte used for (i-1)

10 Changing the extent l MPI-1 provides two special types, MPI_LB and MPI_UB, for changing the extent of a datatype »This doesn’t change the size, just how MPI decides what addresses in memory to use in offseting one datatype from another. l Use MPI_Type_struct to create a new datatype from an old one with a different extent »Use MPI_Type_create_resized in MPI-2

11 Sending Rows of a Matrix l From Fortran, assume you want to send a row of the matrix A(n,m), that is, A(row,j), for j=1,…, m l A(row,j) is not adjacent in memory to A(row,j+1) l One solution: send each element separately: Do j=1,m Call MPI_Send( A(row,j), 1, MPI_DOUBLE_PRECSION, …) l Why not?

12 MPI Type vector l Create a single datatype representing elements separated by a constant distance (stride) in memory »m items, separated by a stride of n: »MPI_Type_vector( m, 1, n, MPI_DOUBLE_PRECISION, newtype, ierr ) MPI_Type_commit( newtype, ierr ) »Type_commit required before using a type in an MPI communication operation. l Then send one instance of this type MPI_Send( a(row,1), 1, newtype, ….)

13 Test your understanding of Extent l How do you send 2 rows of the matrix? Can you do this: MPI_Send(a(row,j),2,newtype,…) l Hint: Extent(newtype) is distance from the first to last byte of the type »Last byte is a(row,m) l Hint: What is the first location of A that is sent after the first row?

14 Sending with MPI_Vector l Extent(newtype) is ((m-1)*n+1)*sizeof(double) »Last element sent is A(row,m) l do i=0,1 MPI_Send(buf(1+i*extent(datatype)),1, datatype,…) becomes l MPI_Send(A(row,1:m),…) (i=0) MPI_Send(A(row+1,m),…) (i=1) l ! The second step is not MPI_Send(A(row+1,1),…)

15 Solutions for Vectors l MPI_Type_vector is for very specific uses »rarely makes sense to use count other than 1 l Two send two rows, simply change the blockcount: MPI_Type_vector( m, 2, n, MPI_DOUBLE_PRECISION, newtype, ierr ) l Stride is still relative to basic type

16 Sending Vectors of Different Sizes l How would you send A(i,2:m) and A(i+1,3:m) with a single MPI datatype? »Use “count” to select the number, as in MPI_Send(A(i,2),m-1,type,…) MPI_Send(A(i+1,3),m-2,type,…) l Hint: Use an extent of n elements

17 Striding Type l Create a type with an extent of a column of the array: »types(1) = MPI_DOUBLE_PRECISION types(2) = MPI_UB displs(1) = 0 displs(2) = n * 8 ! Bytes! blkcnt(1) = 1 blkcnt(2) = 1 call MPI_Type_struct( 2, blkcnt, displs, types, newtype, ierr ) l MPI_Send(A(i,2),m-1,newtype,…) sends the elements A(i,2:m)

18 Exercises l Write a program that sends rows of a matrix from one processor to another. Use both MPI_Type_vector and MPI_Type_struct methods »Which is most efficient? »Which is easier to use? l Write a program that sends a matrix from one processor to another. Arrange the datatypes so that the matrix is received in transposed order »A(i,j) on sender arrives in A(j,i) on receiver