Updated to working non-parallelized version for Test.c
authorstephey <stephey>
Sat, 3 Apr 2010 01:04:04 +0000 (01:04 +0000)
committerstephey <stephey>
Sat, 3 Apr 2010 01:04:04 +0000 (01:04 +0000)
Robust/src/Tests/mlp/stephen/Test.java [new file with mode: 0755]
Robust/src/Tests/mlp/stephen/makefile

diff --git a/Robust/src/Tests/mlp/stephen/Test.java b/Robust/src/Tests/mlp/stephen/Test.java
new file mode 100755 (executable)
index 0000000..421292f
--- /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 += MAX - i;\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
index 338028366c817b5843f1cfbd5c6ef8e5fcf22972..ce9662a6229084ff25edc9d2f7381493411f9e6d 100644 (file)
@@ -1,6 +1,6 @@
 PROGRAM=test
 
-SOURCE_FILES=test.java
+SOURCE_FILES=Test.java
 
 BUILDSCRIPT=../../../buildscript
 
@@ -26,4 +26,4 @@ clean:
        rm -f  *.txt
        rm -f  aliases.txt
        rm -f  mlpReport*txt
-       rm -f  results*txt
\ No newline at end of file
+       rm -f  results*txt