From: jjenista Date: Sun, 3 Apr 2011 18:52:23 +0000 (+0000) Subject: reworking parallel implementation, both single and DFJ runs build a zero-node configu... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f002abd225d8eb09b7692233185e98eea055bbd3;p=IRC.git reworking parallel implementation, both single and DFJ runs build a zero-node configuration right now, whoops --- diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedEdgeGraph.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedEdgeGraph.java index 05c8057f..37a98c8b 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedEdgeGraph.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedEdgeGraph.java @@ -1,10 +1,67 @@ public class DirectedEdgeGraph implements EdgeGraph { - public DirectedEdgeGraph() { - // nodes = Collections.synchronizedSet(new HashSet()); - // nodes = new HashSet(); + // jjenista - we need this set to find all nodes in a graph + // (as hard a problem as keeping a reference to one node that + // is in the graph from which to do a traversal and find all + // nodes currently in the graph). + // + // Problem: when you add or remove one node, the obvious update + // is to add or remove it to this set as well. That is a conflict + // for concurrent add and remove ops that don't collide in terms of + // modifying the graph elements though. + // + // SOLUTION: let add and remove ops to the true graph happen in + // parallel, then use a special update method to keep the set of + // all nodes maintained. It is up the user to invoke a traversal + // of the set of all nodes only at points where the set is valid. + protected HashSet nodes; + + // only use when the nodes set is up-to-date + public DirectedEdgeGraph() { nodes = new HashSet(); } + public Iterator iterator() { return nodes.iterator(); } + public int getNumNodes() { return nodes.size(); } + public Node getRandom() { return (Node) nodes.iterator().next(); } + + // keep the nodes set up-to-date, but use AFTER... + public void addNodeToAllNodesSet( Node n ) { + if( !n.inGraph ) { + System.out.println( "Error: adding a node NOT IN the graph to the all-nodes set!" ); + System.exit( -1 ); + } + nodes.add( n ); + } + + public void removeNodeFromAllNodesSet( Node n ) { + if( n.inGraph ) { + System.out.println( "Error: removing a node IN the graph to the all-nodes set!" ); + System.exit( -1 ); + } + nodes.add( n ); + } + + // these are the normal methods for truly adding and removing nodes + // from the graph, nodes know locally if they are in and out but they + // haven't been added or removed from the nodes set until ABOVE methods + public boolean addNode(Node n) { + boolean notInAlready = !n.inGraph; + n.inGraph = true; + return notInAlready; + } + + public boolean removeNode(Node n) { + boolean wasIn = n.inGraph; + removeConnectingEdges((EdgeGraphNode) n); + return wasIn; } + public boolean containsNode(Node n) { + return n.inGraph; + } + + + + + public boolean addEdge(Edge_d e) { GraphEdge ge = (GraphEdge) e; EdgeGraphNode src = ge.getSrc(); @@ -90,46 +147,17 @@ public class DirectedEdgeGraph implements EdgeGraph { return retval; } - //public Iterator iterator() { - // return nodes.iterator(); - //} - - public boolean addNode(Node n) { - boolean notInAlready = !n.inGraph; - n.inGraph = true; - return notInAlready; - } - - public boolean containsNode(Node n) { - return n.inGraph; - } - public Object getNodeData(Node n) { EdgeGraphNode egn = (EdgeGraphNode) n; return egn.data; } - //public int getNumNodes() { - // return nodes.size(); - //} - - //public Node getRandom() { - // // return (Node)Sets.getAny(nodes); - // return (Node) nodes.iterator().next(); - //} - public boolean hasNeighbor(Node src, Node dest) { EdgeGraphNode esrc = (EdgeGraphNode) src; EdgeGraphNode edest = (EdgeGraphNode) dest; return esrc.hasOutNeighbor(edest); } - public boolean removeNode(Node n) { - boolean wasIn = n.inGraph; - removeConnectingEdges((EdgeGraphNode) n); - return wasIn; - } - protected void removeConnectingEdges(EdgeGraphNode n) { EdgeGraphNode g; for (Iterator iterator1 = n.getOutNeighborsCopy(); iterator1.hasNext();) { diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java index a37fba5a..89aece39 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java @@ -1,9 +1,9 @@ public class DirectedGraph implements Graph { - protected HashSet nodes; - + //protected HashSet nodes; + public DirectedGraph() { // nodes = Collections.synchronizedSet(new HashSet()); - nodes = new HashSet(); + //nodes = new HashSet(); } public boolean addNeighbor(Node src, Node dest) { @@ -13,11 +13,13 @@ public class DirectedGraph implements Graph { } public boolean addNode(Node n) { - return nodes.add((GraphNode) n); + boolean notInAlready = !n.inGraph; + n.inGraph = true; + return notInAlready; } public boolean containsNode(Node n) { - return nodes.contains(n); + n.inGraph; } public Node createNode(Object n) { @@ -36,9 +38,9 @@ public class DirectedGraph implements Graph { return ((GraphNode)node).inNeighbors.size(); } - public int getNumNodes() { - return nodes.size(); - } + //public int getNumNodes() { + // return nodes.size(); + //} public Iterator getOutNeighbors(Node src) { GraphNode src_c = (GraphNode) src; @@ -67,8 +69,9 @@ public class DirectedGraph implements Graph { } public boolean removeNode(Node n) { + boolean wasIn = n.inGraph; removeConnectingEdges((GraphNode) n); - return nodes.remove(n); + return wasIn; } protected void removeConnectingEdges(GraphNode n) { @@ -95,9 +98,9 @@ public class DirectedGraph implements Graph { return retval; } - public Iterator iterator() { - return nodes.iterator(); - } + //public Iterator iterator() { + // return nodes.iterator(); + //} public boolean isDirected() { return true; diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/EdgeGraph.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/EdgeGraph.java index 1a6d24c8..61981cc4 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/EdgeGraph.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/EdgeGraph.java @@ -21,4 +21,7 @@ public interface EdgeGraph extends Graph { public abstract Object getEdgeData(Edge_d edge); public abstract Object setEdgeData(Edge_d edge, Object obj); + + public abstract void addNodeToAllNodesSet( Node n ); + public abstract void removeNodeFromAllNodesSet( Node n ); } diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java index 67d2eee4..3ec6220b 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java @@ -203,8 +203,17 @@ public class SerialDelaunayRefinement { } } else { - // otherwise we did apply the cavity, but we - // may have introduced new bad triangles + // otherwise we did apply the cavity, so repair the all-nodes set of the mesh + Iterator itrPreNodes = cavity.getPre().getNodes().iterator(); + while( itrPreNodes.hasNext() ) { + mesh.removeNodeFromAllNodesSet( (Node)itrPreNodes.next() ); + } + Iterator itrPostNodes = cavity.getPost().getNodes().iterator(); + while( itrPostNodes.hasNext() ) { + mesh.addNodeToAllNodesSet( (Node)itrPostNodes.next() ); + } + + // and we may have introduced new bad triangles HashMapIterator it2 = cavity.getPost().newBad(mesh).iterator(); while (it2.hasNext()) { worklist.push((Node)it2.next());