ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/TorusSpanningTree.java
(Generate patch)

Comparing jsr166/src/test/loops/TorusSpanningTree.java (file contents):
Revision 1.2 by jsr166, Mon Nov 2 20:23:53 2009 UTC vs.
Revision 1.7 by jsr166, Mon Sep 20 20:44:17 2010 UTC

# Line 46 | Line 46 | public class TorusSpanningTree {
46                            MIN_SIDE, MAX_SIDE, SIDE_STEP);
47          ForkJoinPool pool = new ForkJoinPool(procs);
48  
49 +        boolean checked = false;
50          for (int side = MIN_SIDE; side <= MAX_SIDE; side += SIDE_STEP) {
51              int n = side * side;
52              Node[] graph = makeGraph(side);
# Line 55 | Line 56 | public class TorusSpanningTree {
56                  long start = System.nanoTime();
57                  pool.invoke(new Driver(root));
58                  long elapsed = System.nanoTime() - start;
59 <                double nanosPerEdge = (double)elapsed / (4 * n);
60 <                System.out.printf(" %7.2f", nanosPerEdge);
61 <                if (j == 0)
59 >                double nanosPerEdge = (double) elapsed / (4 * n);
60 >                System.out.printf(" %7.2f", nanosPerEdge);
61 >                if (!checked) {
62 >                    checked = true;
63                      checkSpanningTree(graph, root);
64 <                resetAll(graph);
64 >                }
65 >                pool.invoke(new Resetter(graph, 0, graph.length));
66              }
67              System.out.println();
68          }
69 +        System.out.println(pool);
70          pool.shutdown();
71      }
72  
# Line 119 | Line 123 | public class TorusSpanningTree {
123                          newList = e;
124                          if (batchSize == 0) {
125                              int s = getQueuedTaskCount();
126 <                            batchSize = ((s >= LOG_MAX_BATCH_SIZE)?
126 >                            batchSize = ((s >= LOG_MAX_BATCH_SIZE) ?
127                                           (1 << LOG_MAX_BATCH_SIZE) :
128                                           (1 << s));
129                          }
# Line 177 | Line 181 | public class TorusSpanningTree {
181          // connect each node to left, right, up, down neighbors
182          int maxcol = n - sideLength;
183          int col = 0;
184 <        for(int i = 0; i < sideLength; ++i) {
185 <            for(int j = 0; j < sideLength; ++j) {
184 >        for (int i = 0; i < sideLength; ++i) {
185 >            for (int j = 0; j < sideLength; ++j) {
186                  Node[] a = vs[col + j].neighbors;
187 <                a[0] = vs[col + ((j < sideLength-1)? (j+1) : 0)];
188 <                a[1] = vs[col + ((j != 0)? (j-1) : (sideLength-1))];
189 <                a[2] = vs[j + ((i < sideLength-1)? (col + sideLength) : 0)];
190 <                a[3] = vs[j + ((i != 0)? (col - sideLength) : maxcol)];
187 >                a[0] = vs[col + ((j < sideLength-1) ? (j+1) : 0)];
188 >                a[1] = vs[col + ((j != 0) ? (j-1) : (sideLength-1))];
189 >                a[2] = vs[j + ((i < sideLength-1) ? (col + sideLength) : 0)];
190 >                a[3] = vs[j + ((i != 0) ? (col - sideLength) : maxcol)];
191              }
192              col += sideLength;
193          }
# Line 213 | Line 217 | public class TorusSpanningTree {
217          }
218      }
219  
220 +    static final class Resetter extends RecursiveAction {
221 +        final Node[] g;
222 +        final int lo, hi;
223 +        Resetter(Node[] g, int lo, int hi) {
224 +            this.g = g; this.lo = lo; this.hi = hi;
225 +        }
226 +        public void compute() {
227 +            int mid = (lo + hi) >>> 1;
228 +            if (mid == lo || getSurplusQueuedTaskCount() > 3) {
229 +                for (int i = lo; i < hi; ++i)
230 +                    g[i].reset();
231 +            }
232 +            else
233 +                invokeAll(new Resetter(g, lo, mid), new Resetter(g, mid, hi));
234 +        }
235 +    }
236   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines