galois system tutorial
DESCRIPTION
Galois System Tutorial. Donald Nguyen Mario Méndez-Lojo. Writing Galois programs. Galois data structures choosing right implementation API basic flags (advanced) Galois iterators Scheduling assigning work to threads. Motivating example – spanning tree. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/1.jpg)
Galois System Tutorial
Donald NguyenMario Méndez-Lojo
![Page 2: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/2.jpg)
Writing Galois programs
• Galois data structures– choosing right implementation– API• basic• flags (advanced)
• Galois iterators• Scheduling– assigning work to threads
![Page 3: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/3.jpg)
Motivating example – spanning tree
• Compute the spanning tree of an undirected graph
• Parallelism comes from independent edges
• Release contains minimal spanning tree examples• Borůvka, Prim, Kruskal
![Page 4: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/4.jpg)
Spanning tree - pseudo codeGraph graph = read graph from fileNode startNode = pick random node from graphstartNode.inSpanningTree = trueWorklist worklist = create worklist containing startNodeList result = create empty list
foreach src : worklist foreach Node dst : src.neighbors
if not dst.inSpanningTree dst.inSpanningTree = true
Edge edge= new Edge(src,dst) result.add(edge)
worklist.add(dst)
create graph, initialize worklist and spanning tree
worklist elements can be processed in any order
neighbor not processed?•add edge to solution•add to worklist
![Page 5: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/5.jpg)
Outline
1. Serial algorithm– Galois data structures
• choosing right implementation• basic API
2. Galois (parallel) version– Galois iterators– scheduling
• assigning work to threads
3. Optimizations– Galois data structures
• advanced API (flags)
![Page 6: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/6.jpg)
Outline
1. Serial algorithm– Galois data structures
• choosing right implementation• basic API
2. Galois (parallel) version– Galois iterators– scheduling
• assigning work to threads
3. Optimizations– Galois data structures
• advanced API (flags)
![Page 7: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/7.jpg)
Galois data structures
• “Galoized” implementations– concurrent– transactional semantics
• Also, serial implementations• galois.object package– Graph– GMap, GSet– ...
![Page 8: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/8.jpg)
Graph API<<interface>>Graph<N>
createNode(data: N)add(node: GNode)remove(node: GNode)addNeighbor(s: GNode, d: GNode)removeNeighbor(s: GNode, d: GNode)…
GNode<N>
setData(data: N)getData()
ObjectMorphGraph
<<interface>>ObjectGraph<N,E>
addEdge(s: GNode, d: Gnode, data:E)setEdgeData(s:GNode, d:Gnode, data:E)…
ObjectLocalComputationGraph
<<interface>>
Mappable<T>
map (closure: LambdaVoid<T>)map(closure: Lambda2Void<T,E>)…
![Page 9: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/9.jpg)
Mappable<T> interface
• Implicit iteration over collections of type Tvoid map(LambdaVoid<T> body);
• LambdaVoid = closurevoid call(T arg);
• Graph is Mappable– “apply closure once per node in graph”
• GNode is Mappable– “apply closure once per neighbor of this node”
![Page 10: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/10.jpg)
Spanning tree - serial codeGraph<NodeData> graph=new MorphGraph.GraphBuilder().create()GNode startNode = Graphs.getRandom(graph)startNode.inSpanningTree = trueStack<GNode> worklist = new Stack(startNode);List<Edge> result = new ArrayList()
while !worklist.isEmpty() src = worklist.pop()
map(src, new LambdaVoid(){ void call(GNode<NodeData> dst) { NodeData dstData = dst.getData(); if !dstData.inSpanningTree dstData.inSpanningTree = true
result.add(new Edge(src, dst)) worklist.add(dst)
}})
graph utilities
LIFO scheduling
for every neighbor of the active node
has the node been processed? graphs created using builder pattern
![Page 11: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/11.jpg)
Outline
1. Serial algorithm– Galois data structures
• choosing right implementation• basic API
2. Galois (parallel) version– Galois iterators– scheduling
• assigning work to threads
3. Optimizations– Galois data structures
• advanced API (flags)
![Page 12: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/12.jpg)
initial worklist
apply closure to each active element
scheduling policy
Galois iteratorsstatic <T> void GaloisRuntime.foreach(Iterable<T> initial,
Lambda2Void<T, ForeachContext<T>> body, Rule schedule)
• GaloisRuntime– ordered iterators, runtime statistics, etc
• Upon foreach invocation– threads are spawned– transactional semantics guarantee• conflicts, rollbacks• transparent to the user
unordered iterator
![Page 13: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/13.jpg)
Scheduling
• Good scheduling → better performance• Available schedules
– FIFO, LIFO, Random– ChunkedFIFO/LIFO/Random– many others (see Javadoc)
• UsageGaloisRuntime.foreach(initialWorklist , new ForeeachBody() { void call(GNode src, ForeachContext context) { src.map(src, new LambdaVoid(){ void call(GNode<NodeData> dst) { …
context.add(dst) }}}}, Priority.defaultOrder())
default scheduling = ChunkedFIFO
set of initial active elements
new active elements are added through context
![Page 14: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/14.jpg)
Spanning tree - Galois codeGraph<NodeData> graph = builder.create()GNode startNode = Graphs.getRandom(graph)startNode.inSpanningTree = trueBag<Edge> result = Bag.create()Iterable<GNode> initialWorklist = Arrays.asList(startNode)
GaloisRuntime.foreach(initialWorklist , new ForeeachBody() { void call(GNode src, ForeachContext context) { src.map(src, new LambdaVoid(){ void call(GNode<NodeData> dst) { dstData = dst.getData()
if !dstData.inSpanningTree dstData.inSpanningTree = true
result.add(new Pair(src, dst)) context.add(dst)
}}}}, Priority.defaultOrder())
worklist facade
ArrayList replaced by Galois multiset
gets element from worklist + applies closure (operator)
![Page 15: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/15.jpg)
Outline
1. Serial algorithm– Galois data structures
• choosing right implementation• basic API
2. Galois (parallel) version– Galois iterators– scheduling
• assigning work to threads
3. Optimizations– Galois data structures
• advanced API (flags)
![Page 16: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/16.jpg)
Optimizations - “flagged” methods• Speculation overheads associated with invocations on
Galois objects– conflict detection– undo actions
• Flagged version of Galois methods→ extra parameter N getNodeData(GNode src)N getNodeData(GNode src, byte flags)
• Change runtime default behavior– deactivate conflict detection, undo actions, or both– better performance– might violate transactional semantics
![Page 17: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/17.jpg)
Spanning tree - Galois codeGaloisRuntime.foreach(initialWorklist , new ForeeachBody() { void call(GNode src, ForeachContext context) { src.map(src, new LambdaVoid(){ void call(GNode<NodeData> dst) { dstData = dst.getData(MethodFlag.ALL)
if !dstData.inSpanningTree dstData.inSpanningTree = true
result.add(new Pair(src, dst), MethodFlag.ALL) context.add(dst, MethodFlag.ALL)
} }, MethodFlag.ALL) }}, Priority.defaultOrder())
acquire abstract locks + store undo actions
![Page 18: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/18.jpg)
Spanning tree - Galois code (final version)
GaloisRuntime.foreach(initialWorklist , new ForeeachBody() { void call(GNode src, ForeachContext context) { src.map(src, new LambdaVoid(){ void call(GNode<NodeData> dst) { dstData = dst.getData(MethodFlag.NONE)
if !dstData.inSpanningTree dstData.inSpanningTree = true
result.add(new Pair(src, dst), MethodFlag.NONE) context.add(dst, MethodFlag.NONE)
} }, MethodFlag.CHECK_CONFLICT) }}, Priority.defaultOrder())
acquire lock on src and neighbors
we already have lock on dst
nothing to lock + cannot be aborted
nothing to lock + cannot be aborted
![Page 19: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/19.jpg)
Galois roadmap
efficient parallel execution?
correct parallel execution?
write serial irregular app, use Galois objects
foreach instead of loop, flags
change scheduling
adjust flags
NO
YES
YES
NO
consider alternative data
structures
![Page 20: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/20.jpg)
Irregular applications included• Lonestar suite
• N-body simulation– Barnes Hut
• Minimal spanning tree– Borůvka, Prim, Kruskal
• Maximum flow– Preflow push
• Mesh generation and refinement– Delaunay
• Graph partitioning– Metis
• SAT solver– Survey propagation
• Check the apps directory for more examples!
![Page 21: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/21.jpg)
Questions?
![Page 22: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/22.jpg)
Create a 2x2 grid, print contentsGraph<Integer> graph= builder.create()GNode<Integer> n0 = graph.createNode(0);//create other three nodes…graph.addNeighbor(n0, n1);graph.addNeighbor(n0, n2);// add the other two edges…graph.map(new LambdaVoid<GNode<Integer>>(){ void call(GNode<Integer> node) { int label = node.getData(); System.out.println(label); } });
![Page 23: Galois System Tutorial](https://reader035.vdocuments.mx/reader035/viewer/2022062316/56816726550346895ddbb9fe/html5/thumbnails/23.jpg)
Scheduling (II)
• Order hierarchy– apply 1st rule, in case of tie use 2nd and so on
Priority.first(ChunkedFIFO.class).then(LIFO.class).then(…)
• Local order– apply….
Priority.first(ChunkedFIFO.class).thenLocally(LIFO.class));
• Strict order– ordered + comparator
Priority.first(Ordered.class, new Comparator(){ int compare(Object o1, Object o2) {…} });