2 Lonestar Benchmark Suite for irregular applications that exhibit
3 amorphous data-parallelism.
5 Center for Grid and Distributed Computing
6 The University of Texas at Austin
8 Copyright (C) 2007, 2008, 2009 The University of Texas at Austin
10 Licensed under the Eclipse Public License, Version 1.0 (the "License");
11 you may not use this file except in compliance with the License.
12 You may obtain a copy of the License at
14 http://www.eclipse.org/legal/epl-v10.html
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
22 File: UndirectedEdgeGraph.java
26 public class SerialDelaunayRefinement {
27 public boolean isFirstRun;
28 public SerialDelaunayRefinement() {
32 public static void main(String args[]) {
33 SerialDelaunayRefinement sdr = new SerialDelaunayRefinement();
37 public void runMain(String args[]) {
39 //Numbers below are Long.Max_Value
40 long lasttime = 0x7fffffffffffffffL;
41 long mintime = 0x7fffffffffffffffL;
43 for (long run = 0; ((run < 3) || Math.abs(lasttime - runtime) * 64 > Math.min(lasttime, runtime)) && run < 7; run++) {
45 if (runtime < mintime) {
48 System.out.println( "Post-run garbage collection started..." );
50 System.out.println( "done gc" );
53 System.out.println("minimum runtime: " + mintime + " ms");
54 System.out.println("");
58 public long run(String args[]) {
61 System.out.println("Lonestar Benchmark Suite v2.1");
62 System.out.println("Copyright (C) 2007, 2008, 2009 The University of Texas at Austin");
63 System.out.println("http://iss.ices.utexas.edu/lonestar/");
65 System.out.println("application: Delaunay Mesh Refinement (serial version)");
66 System.out.println("Refines a Delaunay triangulation mesh such that no angle");
67 System.out.println("in the mesh is less than 30 degrees");
68 System.out.println("http://iss.ices.utexas.edu/lonestar/delaunayrefinement.html");
71 if (args.length < 2) {
72 System.out.println("Arguments: <input file> <num workers> [verify]");
76 EdgeGraph mesh = new UndirectedEdgeGraph();
79 m.read(mesh, args[0]);
81 int numWorkers = Integer.parseInt( args[1] );
83 Stack worklist = new Stack();
85 // REPLACE worklist.addAll(Mesh.getBad(mesh)); WITH...
86 HashMapIterator it = m.getBad(mesh).iterator();
87 while (it.hasNext()) {
88 worklist.push(it.next());
92 System.out.println("configuration: " +
93 mesh.getNumNodes() + " total triangles, " +
94 worklist.size() + " bad triangles");
98 System.out.println( "Post-config garbage collection started..." );
100 System.out.println( "done gc" );
103 Node [] nodesForBadTris = new Node [numWorkers];
104 Cavity[] cavities = new Cavity[numWorkers];
105 Cavity lastAppliedCavity = null;
111 long startTime = System.currentTimeMillis();
112 while (!worklist.isEmpty()) {
114 // Phase 1, grab enough work from list for
115 // each worker in the parent
116 for(int i=0;i<numWorkers;i++) {
117 if(worklist.isEmpty()) {
118 nodesForBadTris[i] = null;
120 nodesForBadTris[i] = (Node) worklist.pop();
124 // Phase 2, read mesh and compute cavities in parallel
125 for(int i=0;i<numWorkers;i++) {
127 Node nodeForBadTri = nodesForBadTris[i];
129 if (nodeForBadTri != null &&
130 nodeForBadTri.inGraph
133 //System.out.println( "computing a cavity for tri "+
134 // mesh.getNodeData( nodeForBadTri )+"..." );
138 Cavity cavity = new Cavity(mesh);
140 //Appears to only call getters (only possible conflict is inherent in Hashmap)
141 cavity.initialize(nodeForBadTri);
143 //Takes up 15% of computation
144 //Problem:: Build is recursive upon building neighbor upon neighbor upon neighbor
145 //This is could be a problem....
146 //TODO check dimensions problem
149 //Takes up a whooping 50% of computation time and changes NOTHING but cavity :D
154 LinkedList nodes = cavity.getPre().getNodes();
155 LinkedList border = cavity.getPre().getBorder();
156 LinkedList edges = cavity.getPre().getEdges();
158 String s = "nodes: \n";
160 for( Iterator iter = nodes.iterator(); iter.hasNext(); ) {
161 Node node = (Node) iter.next();
162 Element element = (Element) mesh.getNodeData(node);
163 s += " "+element+"\n";
168 for( Iterator iter = border.iterator(); iter.hasNext(); ) {
169 Node node = (Node) iter.next();
170 Element element = (Element) mesh.getNodeData(node);
171 s += " "+element+"\n";
176 for( Iterator iter = edges.iterator(); iter.hasNext(); ) {
177 Edge_d edge = (Edge_d) iter.next();
178 Element element = (Element) mesh.getEdgeData(edge);
179 s += " "+element+"\n";
182 System.out.println( "Pre:\n"+s );
188 cavities[i] = cavity;
198 // Phase 3, apply cavities to mesh, if still applicable
199 // this phase can proceed in parallel when a cavity's
200 // start nodes are still present
201 for(int i=0;i<numWorkers;i++) {
203 Cavity cavity = cavities[i];
204 boolean appliedCavity = false;
205 Node nodeForBadTri = nodesForBadTris[i];
209 // go ahead with applying cavity when all of its
210 // pre-nodes are still in
211 if( cavity != null &&
212 cavity.getPre().allNodesAndBorderStillInCompleteGraph() ) {
214 appliedCavity = true;
215 lastAppliedCavity = cavity;
218 //boolean printChange = true; //(zzz % 10 == 0);
223 //if( printChange ) {
224 // System.out.println( "\n\n\nbad tri: "+mesh.getNodeData( nodeForBadTri ) );
225 // System.out.println( "\npre nodes: " );
227 //Takes up 8.9% of runtime
228 for (Iterator iterator = cavity.getPre().getNodes().iterator();
229 iterator.hasNext();) {
231 node = (Node) iterator.next();
232 //if( printChange ) {
233 // System.out.println( " "+mesh.getNodeData( node ) );
235 mesh.removeNode(node);
239 //if( printChange ) {
240 // System.out.println( "post nodes: " );
242 //Takes up 1.7% of runtime
243 for (Iterator iterator1 = cavity.getPost().getNodes().iterator();
244 iterator1.hasNext();) {
246 node = (Node) iterator1.next();
247 //if( printChange ) {
248 // System.out.println( " "+mesh.getNodeData( node ) );
253 //if( printChange ) {
254 // System.out.println( "post edges: " );
256 //Takes up 7.8% of runtime
258 for (Iterator iterator2 = cavity.getPost().getEdges().iterator();
259 iterator2.hasNext();) {
261 edge = (Edge_d) iterator2.next();
262 //if( printChange ) {
263 // System.out.println( " "+mesh.getEdgeData( edge ) );
270 for (Iterator iterator1 = cavity.getPost().getNodes().iterator();
271 iterator1.hasNext();) {
272 node = (Node) iterator1.next();
274 Element e = (Element)mesh.getNodeData( node );
276 int cntOutNeighbors = 0;
277 for (Iterator iterator = mesh.getOutNeighbors(node); iterator.hasNext();) {
279 Node neighbor = (Node) iterator.next();
282 int dim = e.getDim();
283 int out = cntOutNeighbors;
285 if( dim == 3 && out < 3 ) {
286 System.out.println( e+" has dim="+dim+" and num out-neighbors in graph="+out );
294 sese scheduleMoreBad {
296 if( appliedCavity ) {
297 // we did apply the cavity, and we may
298 // have introduced new bad triangles
299 HashMapIterator it2 = cavity.getPost().newBad(mesh).iterator();
300 while (it2.hasNext()) {
301 worklist.push((Node)it2.next());
305 // the logic of having this out here seems wacky, and overconservative,
306 // but it matches the original algorithm and it works...
307 if( nodeForBadTri != null && mesh.containsNode( nodeForBadTri ) ) {
308 worklist.push( nodeForBadTri );
312 if( !appliedCavity ) {
314 // if we couldn't even apply this cavity, just
315 // throw it back on the worklist
316 if( nodeForBadTri != null && nodeForBadTri.inGraph ) {
317 worklist.push( nodeForBadTri );
319 System.out.println( "\n\n\nthis tri no longer a concern: "+
320 mesh.getNodeData( nodeForBadTri ) );
324 // otherwise we did apply the cavity,
325 // and we may have introduced new bad triangles
326 HashMapIterator it2 = cavity.getPost().newBad(mesh).iterator();
327 while (it2.hasNext()) {
328 worklist.push((Node)it2.next());
333 } // end scheduleMoreBad
337 //Node aNode = (Node)lastAppliedCavity.getPost().getNodes().iterator().next();
338 //mesh.discoverAllNodes( aNode );
339 //System.out.println( "\n\ntris="+mesh.getNumNodes()+
340 // " [wl="+worklist.size()+"]");
341 //if( zzz == 10 ) { System.exit( 0 ); }
343 } // end while( !worklist.isEmpty() )
345 long time = System.currentTimeMillis() - startTime;
346 System.out.println("runtime: " + time + " ms");
347 //TODO note how we only verify on first run...
348 //TODO verify is outside timing, do it each time
349 // since we MIGHT compute something different when
354 Node aNode = (Node)lastAppliedCavity.getPost().getNodes().iterator().next();
355 mesh.discoverAllNodes( aNode );
364 public void verify(EdgeGraph result) {
365 //Put in cuz of static issues.
367 if (!m.verify(result)) {
368 // throw new IllegalStateException("refinement failed.");
369 System.out.println("Refinement Failed.");
373 int size = m.getBad(result).size();
375 System.out.println("refinement failed\nstill have "+size+" bad triangles left.\n");
378 System.out.println("OK");