parallel & concurrent programming: zpl - umass amherst · zpl parallel array language...

28
U U NIVERSITY OF NIVERSITY OF M M ASSACHUSETTS ASSACHUSETTS A A MHERST MHERST Department of Computer Science Department of Computer Science Parallel & Concurrent Programming: ZPL Emery Berger CMPSCI 691W Spring 2006

Upload: doanbao

Post on 05-Dec-2018

244 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science

Parallel & Concurrent Programming:

ZPLEmery BergerCMPSCI 691WSpring 2006

Page 2: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 2

Outline

Previously:MPI – point-to-point & collective

Complicated, far from problem abstraction

OpenMP - parallel directivesLanguage extensions to Fortran/C/C++Questionable semantics, error-prone

Today:Something way better: ZPL

lecture material from ZPL project, UW

Page 3: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 3

ZPL

Parallel array languageImplicitly parallel

No parallel constructs per se

Very high levelAssignments work at array level, as inA := B + C

Machine independentCompiles to ANSI C +communication library calls (e.g., MPI)

Efficient

Page 4: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 4

Comparison

Matrix-multiplication:C

triply-nested loop

ZPLdot-product of rows & columnsefficiently implemented on parallel machines

Page 5: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 5

ZPL Outline

Language overviewRegionsDirectionsParallel array operationsHandling boundary conditions

ZPL programs & performance

Page 6: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 6

Regions

Key abstraction in ZPL: regionsIndex sets (rows,cols) partition matricesOperate on regions, not indexed items!

rows

columns

Page 7: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 7

Region Examples

Interior of matrix

Left-most column

Page 8: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 8

Directions

Directions:Offset vectors used to manipulate regions & array data

Page 9: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 9

Creating New Regions

Prepositions create new regions:in

Applies direction to select part of region

ofCreates new region outside existing region

atShifts a region by a direction

byCreates new region strided by direction

Page 10: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 10

Applying Directions

Use “in” to apply direction to region

+ =

Page 11: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 11

Create Region Outside

Use “of” to create regionoutside existing region

Extends region

+ ==

Page 12: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 12

Shifting Regions

Use “at” to create new regionshifted by a direction

+ =

Page 13: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 13

Striding Regions

Use “by” to create new regionstrided by a direction

Page 14: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 14

Parallel Arrays

Parallel arrays declared over regions

Page 15: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 15

Computing Over Arrays

Can use regions as modifiers that define computations over arrays:

Page 16: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 16

Arrays & Communication

Most computations in ZPLdo not involve communication

Exceptions include:ShiftingReductionBroadcastAll-to-all

Page 17: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 17

Shifting Arrays

@ operator shifts data in directionThis translation induces point-to-pointcommunication

Page 18: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 18

Reduction

Op<< computes reductionsReduction (tree-style) communication

+<< (sum), *<< (times), min<<, max<<…

For prefix (scan), use op||

Page 19: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 19

Broadcast (Flooding)

>> (flood) replicates data across dimensions of array

Triggers broadcast operation

Page 20: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 20

Mapping

Remap (#) moves data between arraysSpecified by “map” arraysBuilt-in Index1, Index2

Index1 = row indices, Index2 = col indices

Page 21: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 21

Boundary Conditions

Boundary conditions (“corner cases”)Usually tedious, error-proneVery simple in ZPL

Page 22: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 22

Boundary Conditions

Periodic boundary conditions with wrap

Page 23: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 23

ZPL Example

Jacobi iteration – replace elements in array with average of four nearest neighbors, until largest change < δ

Consider difficulty of parallelizing with MPI/OpenMP

boundary conditions, etc.

3

1

2

4

2.5 3

1

2

4

Page 24: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 24

ZPL Example

Page 25: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 25

ZPL Performance

Page 26: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 26

ZPL Example: Life

Page 27: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 27

ZPL Example: Life

Page 28: Parallel & Concurrent Programming: ZPL - UMass Amherst · ZPL Parallel array language Implicitly parallel No parallel constructs per se Very high level Assignments work at array level,

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS AAMHERST MHERST •• Department of Computer ScienceDepartment of Computer Science 28

The End

Next time:Your turn!Occam & Multilisp