backed up working serial program and original program (that did not compile)
authorstephey <stephey>
Sat, 3 Apr 2010 08:42:56 +0000 (08:42 +0000)
committerstephey <stephey>
Sat, 3 Apr 2010 08:42:56 +0000 (08:42 +0000)
Robust/src/Tests/mlp/stephen/Test.java
Robust/src/Tests/mlp/stephen/Test.original [new file with mode: 0644]
Robust/src/Tests/mlp/stephen/Test.workingSerial [new file with mode: 0755]

index 421292f56c6002ef1ad01cb6f30a5115d14443ce..71a62d66f71aac65e7c20f7a75327c4a2815a625 100755 (executable)
@@ -1,6 +1,7 @@
 public class Test\r
 {\r
-    private final int MAX = 100000;\r
+    //Apparently global variables are not yet supported\r
+    //private int MAX = 100000;\r
 \r
     public Test(){}\r
 \r
@@ -14,6 +15,7 @@ public class Test
 \r
     public void doSomeWork()\r
     {\r
+        int MAX = 100000;\r
         long sum = 0;\r
         long time = System.currentTimeMillis();\r
         \r
@@ -21,19 +23,22 @@ public class Test
         //about the same time \r
         for(int i = 0; i < MAX/2 + 1; i++)\r
         {\r
-               int innerSum = 0;\r
-               \r
-               {\r
-                       int oppositeNum = MAX - i;\r
+               int innerSum = 0;\r
+               \r
+               rblock a {\r
+               \r
+               int oppositeNum = MAX - i;\r
                        \r
-                       if(isPrime(i))\r
-                               innerSum += i;\r
+               if(isPrime(i))\r
+                       innerSum += i;\r
                        \r
-                       if(i != oppositeNum && isPrime(oppositeNum))\r
-                               innerSum += MAX - i;\r
-               }\r
-               \r
+               if(i != oppositeNum && isPrime(oppositeNum))\r
+                       innerSum += oppositeNum;\r
+           }\r
+            \r
+           rblock b {\r
                sum += innerSum;\r
+           }\r
         }\r
 \r
         System.out.println("The sum of primes from 1 to " + MAX + " is " + sum + ".");\r
diff --git a/Robust/src/Tests/mlp/stephen/Test.original b/Robust/src/Tests/mlp/stephen/Test.original
new file mode 100644 (file)
index 0000000..d71d4b4
--- /dev/null
@@ -0,0 +1,65 @@
+public class Test\r
+{\r
+    private final int MAX = 100000;\r
+\r
+    public Test(){}\r
+\r
+    public static void main(String args[]) {\r
+\r
+        System.out.println("# it starts");\r
+        Test t = new Test();\r
+        t.doSomeWork();\r
+\r
+    }\r
+\r
+    public void doSomeWork()\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
+        {\r
+               int innerSum = 0;\r
+               \r
+               {\r
+                       int oppositeNum = MAX - i;\r
+                       \r
+                       if(isPrime(i))\r
+                               innerSum += i;\r
+                       \r
+                       if(i != oppositeNum && isPrime(oppositeNum))\r
+                               innerSum += oppositeNum;\r
+               }\r
+               \r
+               sum += innerSum;\r
+        }\r
+\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
+\r
+    }\r
+    \r
+\r
+    private boolean isPrime(int number)\r
+    {\r
+       //handles special cases\r
+        if(number < 1)\r
+            return false;\r
+\r
+        if (number < 3)\r
+               return true;\r
+\r
+        //Tests the rest of the numbers\r
+        for(int i = 2; i < number; i++)\r
+        {\r
+            if(number%i == 0)\r
+                return false;\r
+        }\r
+        \r
+        return true;\r
+    }\r
+\r
+}\r
diff --git a/Robust/src/Tests/mlp/stephen/Test.workingSerial b/Robust/src/Tests/mlp/stephen/Test.workingSerial
new file mode 100755 (executable)
index 0000000..9802b4e
--- /dev/null
@@ -0,0 +1,67 @@
+public class Test\r
+{\r
+    //Apparently global variables are not yet supported\r
+    //private int MAX = 100000;\r
+\r
+    public Test(){}\r
+\r
+    public static void main(String args[]) {\r
+\r
+        System.out.println("# it starts");\r
+        Test t = new Test();\r
+        t.doSomeWork();\r
+\r
+    }\r
+\r
+    public void doSomeWork()\r
+    {\r
+        int MAX = 100000;\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
+        {\r
+               int innerSum = 0;\r
+               \r
+               {\r
+                       int oppositeNum = MAX - i;\r
+                       \r
+                       if(isPrime(i))\r
+                               innerSum += i;\r
+                       \r
+                       if(i != oppositeNum && isPrime(oppositeNum))\r
+                               innerSum += oppositeNum;\r
+               }\r
+               \r
+               sum += innerSum;\r
+        }\r
+\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
+\r
+    }\r
+    \r
+\r
+    private boolean isPrime(int number)\r
+    {\r
+       //handles special cases\r
+        if(number < 1)\r
+            return false;\r
+\r
+        if (number < 3)\r
+               return true;\r
+\r
+        //Tests the rest of the numbers\r
+        for(int i = 2; i < number; i++)\r
+        {\r
+            if(number%i == 0)\r
+                return false;\r
+        }\r
+        \r
+        return true;\r
+    }\r
+\r
+}\r