From 89e41a9b01a0f9b7dd6063715fc02370c8547a2b Mon Sep 17 00:00:00 2001 From: stephey Date: Mon, 5 Apr 2010 18:24:48 +0000 Subject: [PATCH] Moved Primes into its own folder --- Robust/src/Tests/mlp/stephen/Primes/Test.bak | 65 ++++++++++++++++ Robust/src/Tests/mlp/stephen/Primes/Test.java | 77 +++++++++++++++++++ .../Tests/mlp/stephen/Primes/Test.original | 65 ++++++++++++++++ .../src/Tests/mlp/stephen/Primes/Test.serial | 67 ++++++++++++++++ Robust/src/Tests/mlp/stephen/Primes/makefile | 29 +++++++ 5 files changed, 303 insertions(+) create mode 100755 Robust/src/Tests/mlp/stephen/Primes/Test.bak create mode 100755 Robust/src/Tests/mlp/stephen/Primes/Test.java create mode 100644 Robust/src/Tests/mlp/stephen/Primes/Test.original create mode 100755 Robust/src/Tests/mlp/stephen/Primes/Test.serial create mode 100644 Robust/src/Tests/mlp/stephen/Primes/makefile diff --git a/Robust/src/Tests/mlp/stephen/Primes/Test.bak b/Robust/src/Tests/mlp/stephen/Primes/Test.bak new file mode 100755 index 00000000..421292f5 --- /dev/null +++ b/Robust/src/Tests/mlp/stephen/Primes/Test.bak @@ -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 += MAX - i; + } + + 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/Primes/Test.java b/Robust/src/Tests/mlp/stephen/Primes/Test.java new file mode 100755 index 00000000..409319ef --- /dev/null +++ b/Robust/src/Tests/mlp/stephen/Primes/Test.java @@ -0,0 +1,77 @@ +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; + 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 += ittr) + { + int innerSum = 0; + + sese a + { + for(int j = i; (j < i + ittr) && j < MAX/2 + 1; j++) + { + + int oppositeNum = MAX - j; + + if(isPrime(j)) + innerSum += j; + + if(i != oppositeNum && isPrime(oppositeNum)) + innerSum += oppositeNum; + } + } + + sese b + { + 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: " + (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/Primes/Test.original b/Robust/src/Tests/mlp/stephen/Primes/Test.original new file mode 100644 index 00000000..d71d4b40 --- /dev/null +++ b/Robust/src/Tests/mlp/stephen/Primes/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/Primes/Test.serial b/Robust/src/Tests/mlp/stephen/Primes/Test.serial new file mode 100755 index 00000000..9802b4ea --- /dev/null +++ b/Robust/src/Tests/mlp/stephen/Primes/Test.serial @@ -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; + } + +} diff --git a/Robust/src/Tests/mlp/stephen/Primes/makefile b/Robust/src/Tests/mlp/stephen/Primes/makefile new file mode 100644 index 00000000..ce9662a6 --- /dev/null +++ b/Robust/src/Tests/mlp/stephen/Primes/makefile @@ -0,0 +1,29 @@ +PROGRAM=test + +SOURCE_FILES=Test.java + +BUILDSCRIPT=../../../buildscript + +USEMLP= -mlp 8 2 -mlpdebug # use to turn mlp on and off and make sure rest of build not broken +BSFLAGS= -32bit -nooptimize -debug -garbagestats -mainclass Test +OWNERSHIP= -ownership -ownallocdepth 1 -enable-assertions -methodeffects -flatirusermethods -ownwritedots final -ownaliasfile aliases.txt + +default: + ../../../buildscript -nojava $(USEMLP) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM) $(SOURCE_FILES) + +single: + ../../../buildscript $(BSFLAGS) -o $(PROGRAM) $(SOURCE_FILES) + +java: + ../../../buildscript $(USEMLP) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM) $(SOURCE_FILES) + +clean: + rm -f $(PROGRAM).bin + rm -fr tmpbuilddirectory + rm -f *~ + rm -f *.dot + rm -f *.png + rm -f *.txt + rm -f aliases.txt + rm -f mlpReport*txt + rm -f results*txt -- 2.34.1