Updated Test.java; it now achieves a speed-up of 8x on dc-11
authorstephey <stephey>
Mon, 5 Apr 2010 18:18:48 +0000 (18:18 +0000)
committerstephey <stephey>
Mon, 5 Apr 2010 18:18:48 +0000 (18:18 +0000)
Robust/src/Tests/mlp/stephen/Test.java

index 055aa96369a014894d654a8c7873d4cbacf4b14d..409319ef2e2c7542a73d77c8dd1c139569124bdf 100755 (executable)
@@ -16,25 +16,30 @@ public class Test
     public void doSomeWork()\r
     {\r
         int MAX = 100000;\r
+       int ittr = 100;\r
+\r
         long sum = 0;\r
         long time = System.currentTimeMillis();\r
         \r
         //I did the for loop this way so that each parallel thread would take\r
         //about the same time \r
-        for(int i = 0; i < MAX/2 + 1; i++)\r
+        for(int i = 0; i < MAX/2 + 1; i += ittr)\r
         {\r
                int innerSum = 0;\r
                \r
                sese a \r
                {\r
+                   for(int j = i; (j < i + ittr) && j < MAX/2 + 1; j++)\r
+                       {\r
                \r
-                       int oppositeNum = MAX - i;\r
+                           int oppositeNum = MAX - j;\r
                        \r
-                       if(isPrime(i))\r
-                               innerSum += i;\r
+                           if(isPrime(j))\r
+                               innerSum += j;\r
                        \r
-                       if(i != oppositeNum && isPrime(oppositeNum))\r
+                           if(i != oppositeNum && isPrime(oppositeNum))\r
                                innerSum += oppositeNum;\r
+                       }\r
                }\r
             \r
                sese b \r
@@ -45,7 +50,7 @@ public class Test
 \r
         System.out.println("The sum of primes from 1 to " + MAX + " is " + sum + ".");\r
         System.out.println("Note: 1 is counted as a prime.");\r
-        System.out.println("Time Consumed (Not Parallelized): " + (System.currentTimeMillis() - time) + " ms");\r
+        System.out.println("Time Consumed: " + (System.currentTimeMillis() - time) + " ms");\r
 \r
     }\r
     \r