Using Chapel to teach parallel concepts David Bunde - - PowerPoint PPT Presentation

using chapel to teach parallel concepts
SMART_READER_LITE
LIVE PREVIEW

Using Chapel to teach parallel concepts David Bunde - - PowerPoint PPT Presentation

Using Chapel to teach parallel concepts David Bunde Knox College dbunde@knox.edu Acknowledgements Silent partner: Kyle Burke Material drawn from


slide-1
SLIDE 1

Using ¡Chapel ¡to ¡teach ¡parallel ¡ concepts ¡

David ¡Bunde ¡ Knox ¡College ¡ dbunde@knox.edu ¡

slide-2
SLIDE 2

Acknowledgements ¡

  • Silent ¡partner: ¡Kyle ¡Burke ¡
  • Material ¡drawn ¡from ¡tutorials ¡created ¡with ¡contribuDons ¡

from ¡Johnathan ¡Ebbers, ¡Maxwell ¡Galloway-­‑Carson, ¡Michael ¡ Graf, ¡Ernest ¡Heyder, ¡Sung ¡Joo ¡Lee, ¡Andrei ¡Papancea, ¡and ¡ Casey ¡Samoore ¡

  • Work ¡parDally ¡supported ¡by ¡NSF ¡awards ¡DUE-­‑1044299 ¡and ¡

CCF-­‑0915805. ¡Any ¡opinions, ¡findings, ¡and ¡conclusions ¡or ¡ recommendaDons ¡expressed ¡in ¡this ¡material ¡are ¡those ¡of ¡ the ¡author(s) ¡and ¡do ¡not ¡necessarily ¡reflect ¡the ¡views ¡of ¡the ¡ NaDonal ¡Science ¡FoundaDon ¡

slide-3
SLIDE 3

Outline ¡

  • IntroducDon ¡to ¡Chapel ¡

– Why ¡Chapel? ¡ – Basic ¡syntax ¡ – Parallel ¡keywords ¡ – ReducDons ¡ – Features ¡for ¡distributed ¡memory ¡

  • Using ¡Chapel ¡in ¡your ¡courses ¡
  • Hands-­‑on ¡Dme ¡
slide-4
SLIDE 4

Your ¡presenter ¡is... ¡

  • Interested ¡in ¡high-­‑level ¡parallel ¡programming ¡
  • EnthusiasDc ¡about ¡Chapel ¡and ¡its ¡use ¡in ¡

educaDon ¡

  • NOT ¡connected ¡to ¡Chapel ¡development ¡team ¡
slide-5
SLIDE 5

Basic ¡Facts ¡about ¡Chapel ¡

  • Parallel ¡programming ¡language ¡developed ¡

with ¡programmer ¡producDvity ¡in ¡mind ¡

  • Originally ¡Cray’s ¡project ¡under ¡DARPA’s ¡High ¡

ProducDvity ¡CompuDng ¡Systems ¡program ¡

  • Suitable ¡for ¡shared-­‑ ¡or ¡distributed ¡memory ¡

systems ¡

  • Installs ¡easily ¡on ¡Linux ¡and ¡Mac ¡OS; ¡use ¡

Cygwin ¡to ¡install ¡on ¡Windows ¡

slide-6
SLIDE 6

Why ¡Chapel? ¡

  • Flexible ¡syntax; ¡only ¡need ¡to ¡teach ¡features ¡

that ¡you ¡need ¡

  • Provides ¡high-­‑level ¡operaDons ¡
  • Designed ¡with ¡parallelism ¡in ¡mind ¡
slide-7
SLIDE 7

Flexible ¡Syntax ¡

  • Supports ¡scripDng-­‑like ¡programs: ¡

writeln(“Hello ¡World!”); ¡

  • Also ¡provides ¡objects ¡and ¡modules ¡
slide-8
SLIDE 8

Provides ¡High-­‑level ¡OperaDons ¡

  • ReducDons ¡

Ex: ¡x ¡= ¡+ ¡reduce ¡A ¡ ¡ ¡//sets ¡x ¡to ¡sum ¡of ¡elements ¡of ¡A ¡ Also ¡valid ¡for ¡other ¡operators ¡(min, ¡max, ¡*, ¡...) ¡

  • Scans ¡

Like ¡a ¡reducDon, ¡but ¡computes ¡value ¡for ¡each ¡prefix ¡ A ¡= ¡[1, ¡3, ¡2, ¡5]; ¡ B ¡= ¡+ ¡scan ¡A; ¡ ¡ ¡ ¡ ¡//sets ¡B ¡to ¡[1, ¡1+3=4, ¡4+2=6, ¡6+5=11] ¡

slide-9
SLIDE 9

Provides ¡High-­‑level ¡OperaDons ¡(2) ¡

  • FuncDon ¡promoDon: ¡

¡B ¡= ¡f(A); ¡ ¡//applies ¡f ¡elementwise ¡for ¡any ¡funcDon ¡f ¡

  • Includes ¡built-­‑in ¡operators: ¡

¡C ¡= ¡A ¡+ ¡1; ¡ ¡D ¡= ¡A ¡+ ¡B; ¡ ¡E ¡= ¡A ¡* ¡B; ¡ ¡... ¡

slide-10
SLIDE 10

Designed ¡with ¡Parallelism ¡in ¡Mind ¡

  • OperaDons ¡on ¡previous ¡slides ¡parallelized ¡

automaDcally ¡

  • Create ¡asynchronous ¡task ¡w/ ¡single ¡keyword ¡
  • Built-­‑in ¡synchronizaDon ¡for ¡tasks ¡and ¡variables ¡
slide-11
SLIDE 11

Chapel ¡Resources ¡

  • Materials ¡for ¡this ¡workshop ¡

hop://faculty.knox.edu/dbunde/teaching/chapel/CCSC-­‑CP14/ ¡

  • Our ¡tutorials ¡

hop://faculty.knox.edu/dbunde/teaching/chapel/ ¡ hop://cs.colby.edu/kgburke/?resource=chapelTutorial ¡

  • Chapel ¡website ¡(tutorials, ¡papers, ¡language ¡specificaDon) ¡

hop://chapel.cray.com ¡

  • Mailing ¡lists ¡(on ¡SourceForge) ¡
slide-12
SLIDE 12

Basic ¡syntax ¡

slide-13
SLIDE 13

“Hello ¡World” ¡in ¡Chapel ¡

  • Create ¡file ¡hello.chpl ¡containing ¡

¡writeln(“Hello ¡World!”); ¡

  • Compile ¡with ¡

¡chpl ¡–o ¡hello ¡hello.chpl ¡

  • Run ¡with ¡

¡./hello ¡

slide-14
SLIDE 14

Variables ¡and ¡Constants ¡

  • Variable ¡declaraDon ¡format: ¡

[config] ¡var/const ¡idenDfier ¡: ¡type; ¡

var ¡x ¡: ¡int; ¡ const ¡pi ¡: ¡real ¡= ¡3.14; ¡ ¡ config ¡const ¡numSides ¡: ¡int ¡= ¡4; ¡ ¡

slide-15
SLIDE 15

Serial ¡Control ¡Structures ¡

  • if ¡statements, ¡while ¡loops, ¡and ¡do-­‑while ¡loops ¡

are ¡all ¡preoy ¡standard ¡

  • Difference: ¡Statement ¡bodies ¡must ¡either ¡use ¡

braces ¡or ¡an ¡extra ¡keyword: ¡

¡if(x ¡== ¡5) ¡then ¡y ¡= ¡3; ¡else ¡y ¡= ¡1; ¡ ¡while(x ¡< ¡5) ¡do ¡x++; ¡ ¡

slide-16
SLIDE 16

Example: ¡Reading ¡unDl ¡eof ¡

var ¡x ¡: ¡int; ¡ while ¡stdin.read(x) ¡{ ¡ ¡ ¡writeln(“Read ¡value ¡“, ¡x); ¡ } ¡ ¡

slide-17
SLIDE 17

Procedures/FuncDons ¡

  • mit for generic function

proc addOne(in val : int, inout val2 : int) : int { } return val + 1; val2 = val + 1;

arg_type argument return type (omit if none

  • r if can be inferred)
slide-18
SLIDE 18

Arrays ¡

  • Indices ¡determined ¡by ¡a ¡range: ¡

¡var ¡A ¡: ¡[1..5] ¡int; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡//declares ¡A ¡as ¡array ¡of ¡5 ¡ints ¡ ¡var ¡B ¡: ¡[-­‑3..3] ¡int; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡//has ¡indices ¡-­‑3 ¡thru ¡3 ¡ ¡var ¡C ¡: ¡[1..10, ¡1..10] ¡int; ¡ ¡//mulD-­‑dimensional ¡array ¡

  • Accessing ¡individual ¡cells: ¡

¡A[1] ¡= ¡A[2] ¡+ ¡23; ¡

  • Arrays ¡have ¡runDme ¡bounds ¡checking ¡
slide-19
SLIDE 19

For ¡Loops ¡

  • Ranges ¡also ¡used ¡in ¡for ¡loops: ¡

¡for ¡i ¡in ¡1..10 ¡do ¡statement; ¡ ¡for ¡i ¡in ¡1..10 ¡{ ¡ ¡ ¡ ¡ ¡ ¡loop ¡body ¡ ¡} ¡

  • Can ¡also ¡use ¡array ¡or ¡anything ¡iterable ¡
slide-20
SLIDE 20

Parallel ¡keywords ¡

slide-21
SLIDE 21

Parallel ¡Loops ¡

  • Two ¡kinds ¡of ¡parallel ¡loops: ¡

¡forall ¡i ¡in ¡1..10 ¡do ¡statement; ¡ ¡//omit ¡do ¡w/ ¡braces ¡ ¡coforall ¡i ¡in ¡1..10 ¡do ¡statement; ¡

  • forall ¡creates ¡1 ¡task ¡per ¡processing ¡unit ¡
  • coforall ¡creates ¡1 ¡per ¡loop ¡iteraDon ¡
  • Used ¡when ¡each ¡iteraDon ¡requires ¡lots ¡of ¡work ¡and/or ¡

they ¡must ¡be ¡done ¡concurrently ¡

slide-22
SLIDE 22

Asynchronous ¡Tasks ¡

  • Easy ¡asynchronous ¡task ¡creaDon: ¡

¡begin ¡statement; ¡

  • Easy ¡fork-­‑join ¡parallelism: ¡

¡cobegin ¡{ ¡ ¡ ¡statement1; ¡ ¡ ¡statement2; ¡ ¡ ¡... ¡ ¡} ¡ ¡//creates ¡task ¡per ¡statement ¡and ¡waits ¡here ¡ ¡

slide-23
SLIDE 23

Sync ¡blocks ¡

  • sync ¡blocks ¡wait ¡for ¡tasks ¡created ¡inside ¡it ¡
  • These ¡are ¡equivalent: ¡

¡ ¡sync ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡cobegin ¡{ ¡

¡begin ¡statement1; ¡ ¡ ¡ ¡ ¡ ¡ ¡statement1; ¡ ¡begin ¡statement2; ¡ ¡ ¡ ¡ ¡ ¡ ¡statement2; ¡ ¡... ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡... ¡ } ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡

slide-24
SLIDE 24

Sync ¡variables ¡

  • sync ¡variables ¡have ¡value ¡and ¡empty/full ¡state ¡

– store ¡≤ ¡1 ¡value ¡and ¡block ¡operaDons ¡can’t ¡proceed ¡

  • Can ¡be ¡used ¡as ¡lock: ¡

¡var ¡lock ¡: ¡sync ¡int; ¡ ¡lock ¡= ¡1; ¡ ¡ ¡ ¡//acquires ¡lock ¡ ¡... ¡ ¡var ¡temp ¡= ¡lock; ¡ ¡//releases ¡the ¡lock ¡

slide-25
SLIDE 25

Example ¡for ¡teaching ¡parallelism ¡

var ¡total ¡: ¡int ¡= ¡0; ¡ for ¡i ¡in ¡1..100 ¡do ¡total ¡+= ¡i; ¡

slide-26
SLIDE 26

Task ¡creaDon ¡with ¡begin ¡

var ¡lowTotal ¡: ¡int ¡= ¡0; ¡ var ¡highTotal ¡: ¡int ¡= ¡0; ¡ begin ¡ref(lowTotal) ¡{ ¡ ¡for ¡i ¡in ¡1..50 ¡do ¡lowTotal ¡+= ¡i; ¡ } ¡ begin ¡ref(highTotal) ¡{ ¡ ¡for ¡i ¡in ¡51..100 ¡do ¡highTotal ¡+= ¡i; ¡ } ¡ var ¡total ¡= ¡lowTotal ¡+ ¡highTotal; ¡ ¡

slide-27
SLIDE 27

Task ¡creaDon ¡with ¡begin ¡

var ¡lowTotal ¡: ¡int ¡= ¡0; ¡ var ¡highTotal ¡: ¡int ¡= ¡0; ¡ begin ¡ref(lowTotal) ¡{ ¡ ¡for ¡i ¡in ¡1..50 ¡do ¡lowTotal ¡+= ¡i; ¡ } ¡ begin ¡ref(highTotal) ¡{ ¡ ¡for ¡i ¡in ¡51..100 ¡do ¡highTotal ¡+= ¡i; ¡ } ¡ var ¡total ¡= ¡lowTotal ¡+ ¡highTotal; ¡ ¡

Incorrect: ¡race ¡condiDon ¡

slide-28
SLIDE 28

Correct ¡implementaDon ¡w/ ¡begin ¡

var ¡lowTotal ¡: ¡int ¡= ¡0; ¡ var ¡highTotal ¡: ¡int ¡= ¡0; ¡ sync ¡{ ¡ ¡begin ¡ref(lowTotal) ¡{ ¡ ¡ ¡ ¡for ¡i ¡in ¡1..50 ¡do ¡lowTotal ¡+= ¡i; ¡ ¡} ¡ ¡begin ¡ref(highTotal) ¡{ ¡ ¡ ¡ ¡for ¡i ¡in ¡51..100 ¡do ¡highTotal ¡+= ¡i; ¡ ¡} ¡ } ¡ var ¡total ¡= ¡lowTotal ¡+ ¡highTotal; ¡ ¡

slide-29
SLIDE 29

A ¡common ¡paoern ¡

sync ¡{ ¡ ¡ ¡begin ¡task1(); ¡ ¡ ¡begin ¡task2(); ¡ ¡ ¡begin ¡task3(); ¡ } ¡

slide-30
SLIDE 30

cobegin: ¡SyntacDc ¡sugar ¡

cobegin ¡{ ¡ ¡ ¡task1(); ¡ ¡ ¡task2(); ¡ ¡ ¡task3(); ¡ } ¡

slide-31
SLIDE 31

Forall ¡loops ¡

var ¡total ¡: ¡int ¡= ¡0; ¡ forall ¡i ¡in ¡1..100 ¡{ ¡ ¡ ¡total ¡+= ¡i; ¡ } ¡

slide-32
SLIDE 32

Forall ¡loops ¡

var ¡total ¡: ¡int ¡= ¡0; ¡ forall ¡i ¡in ¡1..100 ¡{ ¡ ¡ ¡total ¡+= ¡i; ¡ } ¡

Why ¡doesn’t ¡this ¡work? ¡

slide-33
SLIDE 33

Fixing ¡the ¡race ¡

var ¡total ¡: ¡sync ¡int ¡= ¡0; ¡ forall ¡i ¡in ¡1..100 ¡{ ¡ ¡ ¡total ¡+= ¡i; ¡ } ¡

slide-34
SLIDE 34

More ¡sugar: ¡forall ¡shortened ¡

var ¡total ¡: ¡sync ¡int ¡= ¡0; ¡ forall ¡i ¡in ¡1..100 ¡{ ¡ ¡ ¡total ¡+= ¡i; ¡ } ¡ [i ¡in ¡1..100] ¡total ¡+= ¡i; ¡

slide-35
SLIDE 35

ReducDons ¡

slide-36
SLIDE 36

Summing ¡values ¡in ¡an ¡array ¡

2 2 1 4 3 2 1 3 16 10 6 3 7 4

slide-37
SLIDE 37

Summing ¡values ¡in ¡an ¡array ¡

16 2 1 4 3 2 1 3 3 7 4 2 6 10

slide-38
SLIDE 38

Finding ¡max ¡of ¡an ¡array ¡

3 2 1 4 3 2 1 3 2 2 4 4 4 3

slide-39
SLIDE 39

Finding ¡the ¡maximum ¡index ¡

4,2

2 1 4 3 2 1 3

1,1 4,2 3,3 1,4 0,6 3,5 3,5 2,7 2,7 2,0 2,0 4,2 4,2 3,5

slide-40
SLIDE 40

Finding ¡the ¡maximum ¡index ¡

2

2 1 4 3 2 1 3

1,1 4,2 3,3 1,4 0,6 3,5 3,5 2,7 2,7 2,0 2,0 4,2 4,2 3,5 4,2

slide-41
SLIDE 41

Parts ¡of ¡a ¡reducDon ¡

  • Tally: ¡Intermediate ¡state ¡of ¡computaDon ¡
  • Combine: ¡Combine ¡2 ¡tallies ¡
  • Reduce-­‑gen: ¡Generate ¡result ¡from ¡tally ¡
  • Init: ¡Create ¡“empty” ¡tally ¡
  • Accumulate: ¡Add ¡single ¡value ¡to ¡tally ¡
slide-42
SLIDE 42

Parts ¡of ¡a ¡reducDon ¡

  • Tally: ¡Intermediate ¡state ¡of ¡computaDon ¡
  • Combine: ¡Combine ¡2 ¡tallies ¡
  • Reduce-­‑gen: ¡Generate ¡result ¡from ¡tally ¡
  • Init: ¡Create ¡“empty” ¡tally ¡
  • Accumulate: ¡Add ¡single ¡value ¡to ¡tally ¡

¡ ¡ ¡ ¡(value, ¡index) ¡ ¡ ¡ ¡ ¡take ¡whichever ¡pair ¡has ¡larger ¡value ¡ ¡ ¡ ¡ ¡return ¡index ¡

slide-43
SLIDE 43

Parts ¡of ¡a ¡reducDon ¡

  • Tally: ¡Intermediate ¡state ¡of ¡computaDon ¡
  • Combine: ¡Combine ¡2 ¡tallies ¡
  • Reduce-­‑gen: ¡Generate ¡result ¡from ¡tally ¡
  • Init: ¡Create ¡“empty” ¡tally ¡
  • Accumulate: ¡Add ¡single ¡value ¡to ¡tally ¡

¡ ¡ ¡ ¡(value, ¡index) ¡ ¡ ¡ ¡ ¡take ¡whichever ¡pair ¡has ¡larger ¡value ¡ ¡ ¡ ¡ ¡return ¡index ¡

slide-44
SLIDE 44

Parts ¡of ¡a ¡reducDon ¡

  • Tally: ¡Intermediate ¡state ¡of ¡computaDon ¡
  • Combine: ¡Combine ¡2 ¡tallies ¡
  • Reduce-­‑gen: ¡Generate ¡result ¡from ¡tally ¡
  • Init: ¡Create ¡“empty” ¡tally ¡
  • Accumulate: ¡Add ¡single ¡value ¡to ¡tally ¡

¡ ¡ ¡ ¡(value, ¡index) ¡ ¡ ¡ ¡ ¡take ¡whichever ¡pair ¡has ¡larger ¡value ¡ ¡ ¡ ¡ ¡return ¡index ¡ ¡ ¡ ¡ ¡return ¡(MIN_INT, ¡-­‑1) ¡ ¡ ¡ ¡ ¡(larger ¡value, ¡its ¡index) ¡

slide-45
SLIDE 45

Defining ¡reducDons ¡

  • Tally: ¡Intermediate ¡state ¡of ¡computaDon ¡
  • Combine: ¡Combine ¡2 ¡tallies ¡
  • Reduce-­‑gen: ¡Generate ¡result ¡from ¡tally ¡
  • Init: ¡Create ¡“empty” ¡tally ¡
  • Accumulate: ¡Add ¡single ¡value ¡to ¡tally ¡

Sample ¡problems: ¡+ ¡

slide-46
SLIDE 46

Defining ¡reducDons ¡

  • Tally: ¡Intermediate ¡state ¡of ¡computaDon ¡
  • Combine: ¡Combine ¡2 ¡tallies ¡
  • Reduce-­‑gen: ¡Generate ¡result ¡from ¡tally ¡
  • Init: ¡Create ¡“empty” ¡tally ¡
  • Accumulate: ¡Add ¡single ¡value ¡to ¡tally ¡

Sample ¡problems: ¡+, ¡histogram ¡

slide-47
SLIDE 47

Defining ¡reducDons ¡

  • Tally: ¡Intermediate ¡state ¡of ¡computaDon ¡
  • Combine: ¡Combine ¡2 ¡tallies ¡
  • Reduce-­‑gen: ¡Generate ¡result ¡from ¡tally ¡
  • Init: ¡Create ¡“empty” ¡tally ¡
  • Accumulate: ¡Add ¡single ¡value ¡to ¡tally ¡

Sample ¡problems: ¡+, ¡histogram, ¡max ¡

slide-48
SLIDE 48

Defining ¡reducDons ¡

  • Tally: ¡Intermediate ¡state ¡of ¡computaDon ¡
  • Combine: ¡Combine ¡2 ¡tallies ¡
  • Reduce-­‑gen: ¡Generate ¡result ¡from ¡tally ¡
  • Init: ¡Create ¡“empty” ¡tally ¡
  • Accumulate: ¡Add ¡single ¡value ¡to ¡tally ¡

Sample ¡problems: ¡+, ¡histogram, ¡max, ¡2nd ¡largest ¡ ¡

slide-49
SLIDE 49

RelaDonship ¡to ¡dynamic ¡programming ¡

  • Challenges ¡in ¡dynamic ¡programming: ¡

– What ¡are ¡the ¡table ¡entries? ¡ – How ¡to ¡compute ¡a ¡table ¡entry ¡from ¡previous ¡entries? ¡

  • Challenges ¡in ¡reducDon ¡framework: ¡

– What ¡is ¡the ¡tally? ¡ – How ¡to ¡compute ¡a ¡new ¡tallies ¡from ¡previous ¡ones? ¡

slide-50
SLIDE 50

ReducDons ¡in ¡Chapel ¡

  • Express ¡reducDon ¡operaDon ¡in ¡single ¡line: ¡

¡var ¡s ¡= ¡+ ¡reduce ¡A; ¡//A ¡is ¡array, ¡s ¡gets ¡sum ¡

  • Supports ¡+, ¡*, ¡^ ¡(xor), ¡&&, ¡||, ¡max, ¡min, ¡... ¡
  • minloc ¡and ¡maxloc ¡return ¡a ¡tuple ¡with ¡value ¡

and ¡its ¡index: ¡

¡var ¡(val, ¡loc) ¡= ¡minloc ¡reduce ¡A; ¡

slide-51
SLIDE 51

ReducDon ¡example ¡

  • Can ¡also ¡use ¡reduce ¡on ¡funcDon ¡plus ¡a ¡range ¡
  • Ex: ¡Approximate ¡π/2 ¡using ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡: ¡

¡config ¡const ¡numRect ¡= ¡10000000; ¡

¡const ¡width ¡= ¡2.0 ¡/ ¡numRect; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡//rectangle ¡width ¡ ¡const ¡baseX ¡= ¡-­‑1 ¡-­‑ ¡width/2; ¡ ¡const ¡halfPI ¡= ¡+ ¡reduce ¡[i ¡in ¡1..numRect] ¡ ¡ ¡ ¡(width ¡* ¡sqrt(1.0 ¡– ¡(baseX ¡+ ¡i*width)**2)); ¡

1− x

2 −1 1

dx

slide-52
SLIDE 52

Defining ¡a ¡custom ¡reducDon ¡

  • Create ¡object ¡to ¡represent ¡intermediate ¡state ¡
  • Must ¡support ¡

– accumulate: ¡adds ¡a ¡single ¡element ¡to ¡the ¡state ¡ – combine: ¡adds ¡another ¡intermediate ¡state ¡ – generate: ¡converts ¡state ¡object ¡into ¡final ¡output ¡

slide-53
SLIDE 53

Classes ¡in ¡Chapel ¡

class ¡Circle ¡{ ¡

var ¡radius ¡: ¡real; ¡ proc ¡area() ¡: ¡real ¡{ ¡

return ¡3.14 ¡* ¡radius ¡* ¡radius; ¡

} ¡

} ¡ var ¡c1, ¡c2 ¡: ¡Circle; ¡ ¡//creates ¡2 ¡Circle ¡references ¡ c1 ¡= ¡new ¡Circle(10); ¡ ¡/* ¡uses ¡system-­‑supplied ¡constructor ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡to ¡create ¡a ¡Circle ¡object ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡makes ¡c1 ¡refer ¡to ¡it ¡*/ ¡ c2 ¡= ¡c1; ¡ ¡ ¡ ¡ ¡//makes ¡c2 ¡refer ¡to ¡the ¡same ¡object ¡ delete ¡c1; ¡ ¡ ¡ ¡//memory ¡must ¡be ¡manually ¡freed ¡ ¡

slide-54
SLIDE 54

Example ¡“custom” ¡reducDon ¡

class ¡MyMin ¡: ¡ReduceScanOp ¡{ ¡//finds ¡min ¡element ¡(equiv. ¡to ¡built-­‑in ¡“min”) ¡ ¡type ¡eltType; ¡ ¡ ¡ ¡ ¡ ¡//type ¡of ¡elements ¡ ¡var ¡soFar ¡: ¡eltType ¡= ¡max(eltType); ¡//minimum ¡so ¡far ¡ ¡proc ¡accumulate(val ¡: ¡eltType) ¡{ ¡ ¡ ¡ ¡if(val ¡< ¡soFar) ¡{ ¡soFar ¡= ¡val; ¡} ¡ ¡} ¡ ¡proc ¡combine(other ¡: ¡MyMin) ¡{ ¡ ¡ ¡ ¡if(other.soFar ¡< ¡soFar) ¡{ ¡soFar ¡= ¡other.soFar; ¡} ¡ ¡} ¡ ¡proc ¡generate() ¡{ ¡return ¡soFar; ¡} ¡ } ¡ ¡ var ¡theMin ¡= ¡MyMin ¡reduce ¡A; ¡

slide-55
SLIDE 55

Scans ¡

  • Instead ¡of ¡just ¡ge•ng ¡overall ¡value, ¡also ¡

compute ¡value ¡for ¡every ¡prefix ¡ var ¡sum ¡= ¡+ ¡scan ¡A; ¡

16 2 1 4 3 2 1 3 2 3 7 10 sum A 14 11 14

slide-56
SLIDE 56

CompuDng ¡the ¡scan ¡in ¡parallel ¡

14

2 1 4 3 3 2 1

3 7 10 16 6 2 4 Upward pass to compute reduction . Downward pass to also compute scan 10 3 10

slide-57
SLIDE 57

RepresenDng ¡locality ¡

  • Give ¡control ¡over ¡where ¡code ¡is ¡executed: ¡

¡ ¡ ¡on ¡Locales[0] ¡do ¡ ¡ ¡ ¡ ¡something(); ¡

  • and ¡where ¡data ¡is ¡placed: ¡

¡ ¡ ¡on ¡Locales[1] ¡ ¡{ ¡ ¡ ¡ ¡ ¡var ¡x ¡: ¡int; ¡ ¡ ¡ ¡} ¡

  • Can ¡move ¡computaDon ¡to ¡data: ¡

¡on ¡x ¡do ¡something(); ¡

slide-58
SLIDE 58

Features ¡for ¡distributed ¡memory ¡

slide-59
SLIDE 59

RepresenDng ¡locality ¡

  • Give ¡control ¡over ¡where ¡code ¡is ¡executed: ¡

¡ ¡ ¡on ¡Locales[0] ¡do ¡ ¡ ¡ ¡ ¡something(); ¡

  • and ¡where ¡data ¡is ¡placed: ¡

¡ ¡ ¡on ¡Locales[1] ¡ ¡{ ¡ ¡ ¡ ¡ ¡var ¡x ¡: ¡int; ¡ ¡ ¡ ¡} ¡

  • Can ¡move ¡computaDon ¡to ¡data: ¡

¡on ¡x ¡do ¡something(); ¡

slide-60
SLIDE 60

RepresenDng ¡locality ¡

  • Give ¡control ¡over ¡where ¡code ¡is ¡executed: ¡

¡ ¡ ¡on ¡Locales[0] ¡do ¡ ¡ ¡ ¡ ¡something(); ¡

  • and ¡where ¡data ¡is ¡placed: ¡

¡ ¡ ¡on ¡Locales[1] ¡ ¡{ ¡ ¡ ¡ ¡ ¡var ¡x ¡: ¡int; ¡ ¡ ¡ ¡} ¡

  • Can ¡move ¡computaDon ¡to ¡data: ¡

¡on ¡x ¡do ¡something(); ¡

slide-61
SLIDE 61

Separate ¡from ¡parallelism ¡

  • Serial ¡but ¡mulD-­‑locale: ¡

¡on ¡Locales[0] ¡do ¡funcDon1(); ¡ ¡on ¡Locales[1] ¡do ¡funcDon2(); ¡

  • Parallel ¡and ¡mulD-­‑locale: ¡

¡cobegin ¡{ ¡ ¡ ¡ ¡on ¡Locales[0] ¡do ¡funcDon1(); ¡ ¡ ¡ ¡on ¡Locales[1] ¡do ¡funcDon2(); ¡ ¡} ¡

slide-62
SLIDE 62

Managing ¡data ¡distribuDon ¡

  • Domain ¡maps ¡say ¡how ¡arrays ¡are ¡mapped ¡

¡ ¡var ¡A ¡: ¡[D] ¡int ¡dmapped ¡Block(boundingBox=D) ¡ ¡ ¡var ¡A ¡: ¡[D] ¡int ¡dmapped ¡Cyclic(startIdx=1) ¡

slide-63
SLIDE 63

Using ¡Chapel ¡in ¡your ¡courses ¡

slide-64
SLIDE 64

Parallel ¡programming ¡

  • Can ¡demonstrate ¡standard ¡concepts ¡
  • “Global ¡view” ¡language ¡
  • ParDcularly ¡suited ¡to ¡demonstrate ¡

– reducDons ¡(and ¡scans) ¡ – data ¡layout ¡and ¡locality ¡management ¡

  • Topic ¡of ¡many ¡research ¡papers ¡for ¡a ¡seminar ¡
slide-65
SLIDE 65

Programming ¡languages ¡

  • “Parallel ¡paradigm” ¡
  • Can ¡illustrate ¡both ¡task ¡and ¡data ¡parallelism ¡
  • “Global ¡view” ¡
  • Expressively ¡represent ¡locality ¡
  • Data ¡layout ¡is ¡orthogonal ¡to ¡operaDons ¡on ¡it ¡
  • Language ¡evolving ¡and ¡design ¡is ¡acDvely ¡being ¡

discussed ¡

slide-66
SLIDE 66

Algorithms ¡

  • Introduce ¡only ¡basic ¡Chapel ¡

– Assign ¡tutorial ¡and ¡give ¡minimal ¡introducDon ¡

  • Parallel ¡divide ¡& ¡conquer ¡and/or ¡brute ¡force ¡
  • ReducDons ¡and ¡custom ¡reducDons ¡
slide-67
SLIDE 67

How ¡else ¡might ¡you ¡use ¡Chapel? ¡

  • OperaDng ¡Systems ¡

– Easy ¡thread ¡generaDon ¡for ¡scheduling ¡projects ¡

  • So€ware ¡Design ¡

– Some ¡parallel ¡design ¡paoerns ¡have ¡lightweight ¡ Chapel ¡ ¡implementaDons ¡

  • ArDficial ¡Intelligence ¡

(or ¡other ¡courses ¡with ¡computaDonally-­‑intense ¡ projects) ¡

  • Independent ¡Projects ¡
slide-68
SLIDE 68

Caveats ¡

  • SDll ¡in ¡development ¡

– Error ¡messages ¡thin ¡ – New ¡versions ¡every ¡6 ¡months ¡ – Not ¡many ¡libraries ¡

  • No ¡development ¡environment ¡

– Command-­‑line ¡compilaDon ¡in ¡Linux ¡

slide-69
SLIDE 69

Conclusions ¡

  • Chapel ¡is ¡easy ¡to ¡pick ¡up ¡
  • Flexible ¡depth ¡of ¡material ¡
  • Suitable ¡for ¡many ¡courses ¡
  • SDll ¡plenty ¡to ¡do ¡for ¡teaching ¡it ¡
slide-70
SLIDE 70

Conclusions ¡

  • Chapel ¡is ¡easy ¡to ¡pick ¡up ¡
  • Flexible ¡depth ¡of ¡material ¡
  • Suitable ¡for ¡many ¡courses ¡
  • SDll ¡plenty ¡to ¡do ¡for ¡teaching ¡it ¡

Let ¡me ¡know ¡how ¡you ¡use ¡it! ¡ dbunde@knox.edu ¡

slide-71
SLIDE 71

Hands ¡on ¡Dme ¡

(and/or ¡break) ¡

hop://faculty.knox.edu/dbunde/teaching/chapel/CCSC-­‑CP14/exercises.html ¡