From 3f4500b0e92d606c2c74e69f7eabe3dea153d62d Mon Sep 17 00:00:00 2001 From: tmduong Date: Tue, 6 Apr 2010 21:08:28 +0000 Subject: [PATCH] First test case --- Robust/src/Tests/mlp/Tu/Random.java | 102 ++++++++++++++++++++++++++++ Robust/src/Tests/mlp/Tu/makefile | 47 +++++++++++++ Robust/src/Tests/mlp/Tu/test.java | 65 ++++++++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 Robust/src/Tests/mlp/Tu/Random.java create mode 100644 Robust/src/Tests/mlp/Tu/makefile create mode 100644 Robust/src/Tests/mlp/Tu/test.java diff --git a/Robust/src/Tests/mlp/Tu/Random.java b/Robust/src/Tests/mlp/Tu/Random.java new file mode 100644 index 00000000..611592b2 --- /dev/null +++ b/Robust/src/Tests/mlp/Tu/Random.java @@ -0,0 +1,102 @@ +public class Random { + int[] mt; + int mti; + int RANDOM_DEFAULT_SEED; + /* period parameter */ + int N; + int M; + int MATRIX_A; + int UPPER_MASK; + int LOWER_MASK; + int[] mag01; + + public Random() { + RANDOM_DEFAULT_SEED = 0; + N = 624; + M = 397; + mt = new int[N]; + mti = N; + MATRIX_A = 0x9908b0df; /* constant vector a */ + UPPER_MASK = 0x80000000; /* most significant w-r bits */ + LOWER_MASK = 0x7fffffff; /* least significant r bits */ + mag01 = new int[2]; + mag01[0] = 0x0; + mag01[1] = MATRIX_A; + + } + + public void random_alloc() { + init_genrand(this.RANDOM_DEFAULT_SEED); + } + + /* initializes mt[N] with a seed */ + public void init_genrand(int s) { + mt[0]= s & 0xFFFFFFFF; + for (int mti=1; mti> 30)) + mti); + /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ + /* In the previous versions, MSBs of the seed affect */ + /* only MSBs of the array mt[]. */ + /* 2002/01/09 modified by Makoto Matsumoto */ + mt[mti] &= 0xFFFFFFFF; + /* for >32 bit machines */ + } + this.mti=mti; + } + + public void random_seed(int seed) { + init_genrand(seed); + } + + public int random_generate() { + return genrand_int32(); + } + + public int posrandom_generate() { + int r=genrand_int32(); + if (r>0) + return r; + else + return -r; + } + + public int genrand_int32() { + int y; + int mti = this.mti; + + /* mag01[x] = x * MATRIX_A for x=0,1 */ + + if (mti >= 624) { /* generate N words at one time */ + int kk; + int[] mt = this.mt; + + if (mti == 624+1) /* if init_genrand() has not been called, */ + init_genrand(5489); /* a default initial seed is used */ + + for (kk=0;kk<(624-397);kk++) { + y = (mt[kk]&0x80000000)|(mt[kk+1]&0x7fffffff); + mt[kk] = mt[kk+397] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0:0x9908b0df); + } + for (;kk<(624-1);kk++) { + y = (mt[kk]&0x80000000)|(mt[kk+1]&0x7fffffff); + mt[kk] = mt[kk+(397-624)] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0:0x9908b0df); + } + y = (mt[624-1]&0x80000000)|(mt[0]&0x7fffffff); + mt[624-1] = mt[397-1] ^ (y >> 1) ^ ((y & 0x1)==0 ? 0:0x9908b0df); + + mti = 0; + } + + y = mt[mti++]; + + /* Tempering */ + y ^= (y >> 11); + y ^= (y << 7) & 0x9d2c5680; + y ^= (y << 15) & 0xefc60000; + y ^= (y >> 18); + + this.mti = mti; + + return y; + } +} diff --git a/Robust/src/Tests/mlp/Tu/makefile b/Robust/src/Tests/mlp/Tu/makefile new file mode 100644 index 00000000..b1ae9e97 --- /dev/null +++ b/Robust/src/Tests/mlp/Tu/makefile @@ -0,0 +1,47 @@ +PROGRAM=test + +PROGRAM1=testSingle +PROGRAM2=testMulti + +SOURCE_FILES=test.java + +BUILDSCRIPT=../../../buildscript + +#USE64BIT= -64bit +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) $(USE64BIT) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM) $(SOURCE_FILES) + +single: + ../../../buildscript $(BSFLAGS) -o $(PROGRAM) $(SOURCE_FILES) + +java: + ../../../buildscript $(USEMLP) $(BSFLAGS) $(OWNERSHIP) -o $(PROGRAM) $(SOURCE_FILES) + +both32bit: $(PROGRAM1).bin $(PROGRAM2).bin + + +$(PROGRAM1).bin: $(SOURCE_FILES) + $(BUILDSCRIPT) $(BSFLAGS) -o $(PROGRAM1) $(SOURCE_FILES) + rm -fr tmpbuilddirectory + +$(PROGRAM2).bin: $(SOURCE_FILES) + $(BUILDSCRIPT) $(USEMLP) $(BSFLAGS) -o $(PROGRAM2) $(SOURCE_FILES) + + + +clean: + rm -f $(PROGRAM).bin + rm -f $(PROGRAM1).bin + rm -f $(PROGRAM2).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 diff --git a/Robust/src/Tests/mlp/Tu/test.java b/Robust/src/Tests/mlp/Tu/test.java new file mode 100644 index 00000000..6bd25783 --- /dev/null +++ b/Robust/src/Tests/mlp/Tu/test.java @@ -0,0 +1,65 @@ +public class test { + + public static void main(String args[]) { + System.out.println("# it starts"); + test t = new test(); + t.doSomeWork(); + } + + public void doSomeWork(){ + + int numpoints = 100000000; + int numberOfWorker = 10; + int numpointsEachWorker = numpoints/numberOfWorker; + int numOfPointsInCircle = 0; + + + + + double side = 10;//side of the square + double x_conner = 0; + double y_conner = 0; //lower left conner of the square + double midpoint = 5;//(midpoint, midpoint) = (5,5) + for (int i = 0; i < numberOfWorker; i++) + { + sese parallel{ + //each worker has its own random object + Random r = new Random(); + r.random_alloc(); + int countPointInCircle = 0;//keep track of points in circle + for (int j = 0; j < numpointsEachWorker; j++) + { + int x = (r.random_generate())%10; + int y = (r.random_generate())%10; + //if the random point is outside the square then pick again + while ((x > side) || (y > side)) + { + x = (r.random_generate())%10; + y = (r.random_generate())%10; + } + //calculate the distance between the random point and the center of circle + double distance = (double)Math.sqrt(((x-midpoint)*(x-midpoint)) + ((y-midpoint)*(y-midpoint))); + //note: each worker has one countPointInCircle variable + if (distance <= 5.0) // side/2 is the radius of the circle + { + countPointInCircle++; + } + } + + } + //add all the countPointInCircle together + sese serial{ + numOfPointsInCircle += countPointInCircle; + } + } + + //calculate PI + double PI = (double)(4*(double)numOfPointsInCircle)/(double)(numpoints); + + System.out.println("PI="+PI); + } + + public test(){} + +} + -- 2.34.1