![Page 1: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/1.jpg)
ROBERT BOCCHINO, ET AL.
U N I V ER SA L PA R A L L E L C O M P U T I N G R E S EA R C H C E N T ER
U N I V ER SI T Y O F I L L I N O I S
A Type and Effect System forDeterministic Parallel Java
*Based on OOPSLA-2009 conference presentation by Robert Bocchino
Presented by Thawan Kooburat
Computer Science DepartmentUniversity of Wisconsin - Madison
![Page 2: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/2.jpg)
2
Outline
PrologueIntroductionDeterministic Parallel Java (DPJ)Usage PatternsImplementationEvaluation
![Page 3: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/3.jpg)
3
Prologue
ParallelArray (Java 7 – java.util.concurrent) Slice up data into blocks Perform operation on all data concurrently
![Page 4: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/4.jpg)
4
Prologue
ParallelArray of distinct objects
Framework cannot prevent programmer from writing code will
break the semantic
Access global variables
Time
![Page 5: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/5.jpg)
5
Introduction
Deterministic Execution Same input always produce same output Many computational algorithms are deterministic
Many programs use parallel execution in order to gain performance , but it is not part of the specification.
![Page 6: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/6.jpg)
6
Deterministic-by-default
Guaranteed deterministic execution by default
Nondeterministic behavior must be explicitly requested. foreach
Iterating over independent objects foreach_nd
Iterating over overlapping objects
R. Bocchino, V. Adve, S. Adve, and M. Snir, “Parallel Programming Must Be Deterministic by Default”
![Page 7: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/7.jpg)
7
Benefits
Can reason sequentiallyNo hidden parallel bugs Testing based on input
No need to test all interleaving combinationsParallelize incrementally Easier to compose
![Page 8: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/8.jpg)
8
Deterministic Parallel Java (DPJ)
Based on Java languageFork/Join parallelism
Cobegin Foreach
Type and effect system Expose noninterference (Soundness) Field-level granularity Differentiate between readers and writers
Guarantee deterministic execution at compile time
![Page 9: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/9.jpg)
9
Regions and Effects
Regions Divide memory location into regions Can be formed into a tree
class TreeNode<region P> { region L, R, V; int value in V; TreeNode<L> left = new TreeNode<L>(); TreeNode<R> right = new TreeNode<R>();}
Parameterized by region
![Page 10: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/10.jpg)
10
Regions
Root
Root:L Root:R
Root:L:L
Root:L:R
Root:R:L
Root:R:R
![Page 11: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/11.jpg)
11
Effects
Effects Read or write operations on data Programmer specify effect summary for each method
class TreeNode<region P> { ... TreeNode<L> left = new TreeNode<L>(); TreeNode<R> right = new TreeNode<R>(); void updateChildren() writes L, R { cobegin { left.data = 0; /* writes L */ right.data = 1; /* writes R */ } }
Method effect summary
Compiler inferred from type
Non interferenc
e
![Page 12: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/12.jpg)
12
Usage Patterns
Region path lists (RPLs) Updating nested data structure with field-granularity
Index-parameterized array Updating an array of objects
Subarray Partition array for divide and conquer pattern.
Commutativity Declare effect summary based on operation’s
semantic
![Page 13: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/13.jpg)
13
Region Path Lists (RPLs)
class Tree<region P> { region L, R; int value in P; Tree<P:L> left = new Tree<P:L>(); Tree<P:R> right = new Tree<P:R>();}
P= Rootvalu
e Rootleft Root:L
right Root:R
P=Root:Lvalu
e Root:Lleft Root:L:L
right Root:L:R
P=Root:Rvalu
e Root:Rleft Root:R:L
right Root:R:R
![Page 14: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/14.jpg)
14
Region Path Lists (RPLs)
class Tree<region P> { ... int increment() writes P:* { value++; /* writes P */ cobegin { /* writes P:L:* */ if (left != null) left.increment(); /* writes P:R:* */ if (right != null) right.increment(); }}
P:L:* ⊆ P:* P:R:* ⊆ P:*
Inclusion(Method effect)
Disjointness(Cobegin
body)P:L:* ∩ P:R:* = ∅
Method effect summary
Effect inferred from type and summary
![Page 15: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/15.jpg)
15
Index-parameterized Array
Enforce disjointness of array’s element (reference)
Syntax: C<[i]>[]#i
1 2 3 4 1 2 3 4
a[i] b[i]
C<[1]> C<[2]> C<[3]> C<[4]>
1 2 3 4c[i]
![Page 16: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/16.jpg)
16
Index-parameterized Array
final Body<[_]>[]<[_] > bodies = new Body<[_]>[N]<[_]>;foreach (int i in 0, N) { /* writes [i] */ bodies[i] = new Body<[i]> ();}foreach (int i in 0, N) { /* reads [i], Link, *:M writes [i]:F */ bodies[i].computeForce();
class Body<region P> { double mass in P:M; double force in P:F; Body <*> link in Link; void computeForce() reads Link, *:M writes P:F {..}}
Write to each element is distinct
Read does not interfere write
Objects are parameterlized by index region
Operations in foreach block is noninterference
![Page 17: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/17.jpg)
17
Subarray
Mechanisms: DPJ Libraries DPJArray: Wrapper class for Java array DPJPartition: Collections of disjoint DPJArray
Divide and Conquer usage pattern Initialize an array using DPJArray Recursively partition original array using DPJPartition
Each partition is a disjoint subset of original array Create a tree of partition based on flat array
![Page 18: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/18.jpg)
18
Subarray
static <region R> void quicksort(DPJArray<R> A) writes R:* { int p = quicksortPartition(A); /* Chop array into two disjoint pieces */ final DPJPartition<R> segs = new DPJPartition<R>(A, p, OPEN); cobegin { /* write segs:[0]:* */ quicksort(segs.get(0)); /* write segs:[1]:* */ quicksort(segs.get(1)); }}
Use local variable to represent regions
RDPJArray
segs[0] segs[1]pDPJPartition
![Page 19: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/19.jpg)
19
Commutativity
Method annotation
Allow programmers to override effect system Compiler will not check inside the method
This allows cobegin { add(e1); add(e2); } Any order of operations is equivalent Operation is atomic
interface Set<type T, region R> { commutative void add(T e) writes R;}
![Page 20: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/20.jpg)
20
Commutativity
Method invocation
foreach (int i in 0, n) { /* invokes Set.add with writes R */ set.add(A[i]);}
cobegin { /* invokes Set.add with writes R */ set.add(A); /* invokes Set.size with read R */ set.size();}
![Page 21: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/21.jpg)
21
Implementation
Extend Sun’s javac compiler Covert DPJ into normal Java source
Compile to ForkJoinTask Framework (Java7) Similar to Cilk DPJ translates foreach and cobegin to tasks
![Page 22: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/22.jpg)
22
Evaluation
Benchmarks
![Page 23: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/23.jpg)
23
Performance
4
8
12
16
20
24
4 8 12 16 20 24
Spee
dup
Number of cores
Barnes-HutMergesortIDEAK-MeansCollision TreeMonte Carlo
![Page 24: A Type and Effect System for Deterministic Parallel Java](https://reader036.vdocuments.mx/reader036/viewer/2022062323/56816762550346895ddc3c73/html5/thumbnails/24.jpg)
24
Q/A