From: stephey Date: Sat, 3 Apr 2010 08:42:56 +0000 (+0000) Subject: backed up working serial program and original program (that did not compile) X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6b49b4a447f4cd15d8a0f3da355153d475f1b7e6;p=IRC.git backed up working serial program and original program (that did not compile) --- diff --git a/Robust/src/Tests/mlp/stephen/Test.java b/Robust/src/Tests/mlp/stephen/Test.java index 421292f5..71a62d66 100755 --- a/Robust/src/Tests/mlp/stephen/Test.java +++ b/Robust/src/Tests/mlp/stephen/Test.java @@ -1,6 +1,7 @@ public class Test { - private final int MAX = 100000; + //Apparently global variables are not yet supported + //private int MAX = 100000; public Test(){} @@ -14,6 +15,7 @@ public class Test public void doSomeWork() { + int MAX = 100000; long sum = 0; long time = System.currentTimeMillis(); @@ -21,19 +23,22 @@ public class Test //about the same time for(int i = 0; i < MAX/2 + 1; i++) { - int innerSum = 0; - - { - int oppositeNum = MAX - i; + int innerSum = 0; + + rblock a { + + int oppositeNum = MAX - i; - if(isPrime(i)) - innerSum += i; + if(isPrime(i)) + innerSum += i; - if(i != oppositeNum && isPrime(oppositeNum)) - innerSum += MAX - i; - } - + if(i != oppositeNum && isPrime(oppositeNum)) + innerSum += oppositeNum; + } + + rblock b { sum += innerSum; + } } System.out.println("The sum of primes from 1 to " + MAX + " is " + sum + "."); diff --git a/Robust/src/Tests/mlp/stephen/Test.original b/Robust/src/Tests/mlp/stephen/Test.original new file mode 100644 index 00000000..d71d4b40 --- /dev/null +++ b/Robust/src/Tests/mlp/stephen/Test.original @@ -0,0 +1,65 @@ +public class Test +{ + private final int MAX = 100000; + + public Test(){} + + public static void main(String args[]) { + + System.out.println("# it starts"); + Test t = new Test(); + t.doSomeWork(); + + } + + public void doSomeWork() + { + 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++) + { + int innerSum = 0; + + { + int oppositeNum = MAX - i; + + if(isPrime(i)) + innerSum += i; + + if(i != oppositeNum && isPrime(oppositeNum)) + innerSum += oppositeNum; + } + + sum += innerSum; + } + + 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"); + + } + + + private boolean isPrime(int number) + { + //handles special cases + if(number < 1) + return false; + + if (number < 3) + return true; + + //Tests the rest of the numbers + for(int i = 2; i < number; i++) + { + if(number%i == 0) + return false; + } + + return true; + } + +} diff --git a/Robust/src/Tests/mlp/stephen/Test.workingSerial b/Robust/src/Tests/mlp/stephen/Test.workingSerial new file mode 100755 index 00000000..9802b4ea --- /dev/null +++ b/Robust/src/Tests/mlp/stephen/Test.workingSerial @@ -0,0 +1,67 @@ +public class Test +{ + //Apparently global variables are not yet supported + //private int MAX = 100000; + + public Test(){} + + public static void main(String args[]) { + + System.out.println("# it starts"); + Test t = new Test(); + t.doSomeWork(); + + } + + public void doSomeWork() + { + int MAX = 100000; + 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++) + { + int innerSum = 0; + + { + int oppositeNum = MAX - i; + + if(isPrime(i)) + innerSum += i; + + if(i != oppositeNum && isPrime(oppositeNum)) + innerSum += oppositeNum; + } + + sum += innerSum; + } + + 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"); + + } + + + private boolean isPrime(int number) + { + //handles special cases + if(number < 1) + return false; + + if (number < 3) + return true; + + //Tests the rest of the numbers + for(int i = 2; i < number; i++) + { + if(number%i == 0) + return false; + } + + return true; + } + +}