From e9406bf4af188ab21c5eb3d75b62a5dd78ad5f42 Mon Sep 17 00:00:00 2001 From: stephey Date: Mon, 5 Apr 2010 18:18:48 +0000 Subject: [PATCH] Updated Test.java; it now achieves a speed-up of 8x on dc-11 --- Robust/src/Tests/mlp/stephen/Test.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Robust/src/Tests/mlp/stephen/Test.java b/Robust/src/Tests/mlp/stephen/Test.java index 055aa963..409319ef 100755 --- a/Robust/src/Tests/mlp/stephen/Test.java +++ b/Robust/src/Tests/mlp/stephen/Test.java @@ -16,25 +16,30 @@ public class Test public void doSomeWork() { int MAX = 100000; + int ittr = 100; + long sum = 0; long time = System.currentTimeMillis(); //I did the for loop this way so that each parallel thread would take //about the same time - for(int i = 0; i < MAX/2 + 1; i++) + for(int i = 0; i < MAX/2 + 1; i += ittr) { int innerSum = 0; sese a { + for(int j = i; (j < i + ittr) && j < MAX/2 + 1; j++) + { - int oppositeNum = MAX - i; + int oppositeNum = MAX - j; - if(isPrime(i)) - innerSum += i; + if(isPrime(j)) + innerSum += j; - if(i != oppositeNum && isPrime(oppositeNum)) + if(i != oppositeNum && isPrime(oppositeNum)) innerSum += oppositeNum; + } } sese b @@ -45,7 +50,7 @@ public class Test System.out.println("The sum of primes from 1 to " + MAX + " is " + sum + "."); System.out.println("Note: 1 is counted as a prime."); - System.out.println("Time Consumed (Not Parallelized): " + (System.currentTimeMillis() - time) + " ms"); + System.out.println("Time Consumed: " + (System.currentTimeMillis() - time) + " ms"); } -- 2.34.1