--- jsr166/src/test/loops/DynamicLeftSpineFib.java 2009/11/03 01:04:02 1.6 +++ jsr166/src/test/loops/DynamicLeftSpineFib.java 2010/07/07 20:32:04 1.9 @@ -4,7 +4,6 @@ * http://creativecommons.org/licenses/publicdomain */ -//import jsr166y.*; import java.util.*; import java.util.concurrent.*; @@ -23,14 +22,13 @@ public final class DynamicLeftSpineFib e num = Integer.parseInt(args[1]); } catch (Exception e) { - System.out.println("Usage: java DynamicLeftSpineFib []"); + System.out.println("Usage: java DynamicLeftSpineFib []"); return; } for (int reps = 0; reps < 2; ++reps) { - ForkJoinPool g = (procs == 0) ? - new ForkJoinPool() : + ForkJoinPool g = procs == 0? new ForkJoinPool() : new ForkJoinPool(procs); lastStealCount = g.getStealCount(); for (int i = 0; i < 10; ++i) { @@ -47,9 +45,9 @@ public final class DynamicLeftSpineFib e DynamicLeftSpineFib f = new DynamicLeftSpineFib(num, null); g.invoke(f); long time = System.currentTimeMillis() - start; - double secs = (double) time / 1000.0; + double secs = ((double)time) / 1000.0; long result = f.getAnswer(); - System.out.print("DynamicLeftSpineFib " + num + " = " + result); + System.out.print("DLSFib " + num + " = " + result); System.out.printf("\tTime: %7.3f", secs); long sc = g.getStealCount(); long ns = sc - lastStealCount; @@ -75,14 +73,24 @@ public final class DynamicLeftSpineFib e public final void compute() { int n = number; if (n > 1) { + int r = 0; DynamicLeftSpineFib rt = null; - while (n > 1 && getSurplusQueuedTaskCount() <= 3) { - (rt = new DynamicLeftSpineFib(n - 2, rt)).fork(); + while (getSurplusQueuedTaskCount() <= 3) { + int m = n - 2; n -= 1; + if (m <= 1) { + r += m; + if (n > 1) { + r += n - 2; + n -= 1; + } + break; + } + (rt = new DynamicLeftSpineFib(m, rt)).fork(); } - int r = seqFib(n); + r += seqFib(n); while (rt != null) { - if (rt.tryUnfork()) rt.compute(); else rt.helpJoin(); + if (rt.tryUnfork()) rt.compute(); else rt.join(); r += rt.number; rt = rt.next; } @@ -99,3 +107,4 @@ public final class DynamicLeftSpineFib e } } +