From: adash Date: Fri, 22 Aug 2008 02:32:09 +0000 (+0000) Subject: Add microbenchmarks with script for analyzing our Prefetch and other results X-Git-Tag: buildscript^6~84 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a38d2d90e22825b08a0c3da24d9370f2bb3eec1e;p=IRC.git Add microbenchmarks with script for analyzing our Prefetch and other results --- diff --git a/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/Banking.java b/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/Banking.java new file mode 100644 index 00000000..1b0c7918 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/Banking.java @@ -0,0 +1,66 @@ +public class Banking extends Thread { + Account myacc; + public Banking(Account myacc) { + this.myacc = myacc; + } + + public void run() { + for(int i = 0; i < 10000; i++) { + myacc + + + + + } + + public static void main(String[] args) { + Banking[] b; + int[] mid = new int[2]; + mid[0] = (128<<24)|(195<<16)|(175<<8)|79; //dw-8 + mid[1] = (128<<24)|(195<<16)|(175<<8)|73; //dw-5 + atomic { + b = global new Banking[2]; + for(int i = 0; i < 2; i++) { + b[i] = global new Banking(); + b[i].myacc = global new Account(i); + } + } + + Banking tmp; + for(int i = 0; i < 2; i++) { + atomic { + tmp = b[i]; + } + tmp.start(mid[i]); + } + + for(int i = 0; i < 2; i++) { + atomic { + tmp = b[i]; + } + tmp.join(); + } + } +} + +class Account { + int custid; + int balance; + + public Account(int custid) { + this.custid = custid; + this.balance = 0; + } + + public void deposit(int amt) { + balance += amt; + } + + public void withdraw(int amt) { + if(amt > balance) { + System.printString("Amount is greater than balance\n"); + } else { + balance -= amt; + } + } +} diff --git a/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/Cell.java b/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/Cell.java new file mode 100644 index 00000000..a5c19f02 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/Cell.java @@ -0,0 +1,48 @@ +/************************************************************************* +* Compilation: javac Cell.java +* Execution: java Cell +* +* +*************************************************************************/ + +public class Cell { + private boolean spin; // up (true) or down (false) + + public Cell(boolean spin) { + this.spin = spin; + } + + // random spin - up with probability p + public Cell(double p) { + spin = (Math.random() < p); + } + + // flip the spin + public void flip() { spin = !spin; } + + // +1 if up, -1 if down + public double magnetization() { + if (spin) return +1.0; + else return -1.0; + } + + // draw cell according to value of spin + public void draw(double x, double y) { + /* + if (spin) StdDraw.setPenColor(StdDraw.WHITE); + else StdDraw.setPenColor(StdDraw.BLUE); + StdDraw.filledSquare(x, y, 1); + */ + } + + // string representation + public String toString() { + if (spin) return "+"; + else return "-"; + } + + + + public static void main(String[] args) { + } +} diff --git a/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/Metropolis.java b/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/Metropolis.java new file mode 100644 index 00000000..4651c542 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/Metropolis.java @@ -0,0 +1,14 @@ +public class Metropolis { + public static void main(String[] args) { + int N = Integer.parseInt(args[0]); + double kT = Double.parseDouble(args[1]); + StdDraw.setXscale(0, N); + StdDraw.setYscale(0, N); + State state = new State(N, 0.5); + while (true) { + state.phase(kT); + state.draw(); + StdDraw.show(50); + } + } +} diff --git a/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/MultiMCReadcommit.java b/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/MultiMCReadcommit.java new file mode 100644 index 00000000..5954126d --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/MicroBenchmarks/MultiMCReadcommit.java @@ -0,0 +1,87 @@ +public class ReadArrayObj extends Thread { + int id, nthreads; + ReadArrayObj[] myra; + int val; + + public ReadArrayObj() { + } + + public ReadArrayObj(int id, int nthreads, ReadArrayObj[] ra) { + this.id = id; + this.nthreads = nthreads; + myra = ra; + } + + public void run() { + int tmpid; + Barrier barr; + barr = new Barrier("128.195.175.84"); + //Create array objects locally + atomic { + tmpid = id; + myra[tmpid] = global new ReadArrayObj(); + myra[tmpid].val = tmpid*10+1; + } + + Barrier.enterBarrier(barr); + + /* + //All machines reading data from array + int val; + for(int i=0; i<10000; i++) { + atomic { + for(int j=0; j0) { + nthreads = Integer.parseInt(args[0]); + } + + int[] mid = new int[5]; + mid[0] = (128<<24)|(195<<16)|(175<<8)|84;//dw-10 + mid[1] = (128<<24)|(195<<16)|(175<<8)|85;//dw-11 + mid[2] = (128<<24)|(195<<16)|(175<<8)|86;//dw-12 + mid[3] = (128<<24)|(195<<16)|(175<<8)|87;//dw-13 + mid[4] = (128<<24)|(195<<16)|(175<<8)|88;//dw-14 + + ReadArrayObj[] a; + atomic { + a=global new ReadArrayObj[nthreads]; //create object a + mybarr = global new BarrierServer(nthreads); + } + + mybarr.start(mid[0]); + + ReadArrayObjWrap[] ra = new ReadArrayObjWrap[nthreads]; + + atomic { + for(int i=0;i0) { + nthreads = Integer.parseInt(args[0]); + } + + int[] mid = new int[5]; + mid[0] = (128<<24)|(195<<16)|(175<<8)|84;//dw-10 + mid[1] = (128<<24)|(195<<16)|(175<<8)|85;//dw-11 + mid[2] = (128<<24)|(195<<16)|(175<<8)|86;//dw-12 + mid[3] = (128<<24)|(195<<16)|(175<<8)|87;//dw-13 + mid[4] = (128<<24)|(195<<16)|(175<<8)|88;//dw-14 + + WriteArrayObj[] wao; + atomic { + wao=global new WriteArrayObj[nthreads*nthreads]; //create array of objects + mybarr = global new BarrierServer(nthreads); + } + mybarr.start(mid[0]); + + WriteArrayObjWrap[] wawrap = new WriteArrayObjWrap[nthreads]; + + atomic { + for(int i=0;i0) { + nthreads = Integer.parseInt(args[0]); + } + int[] mid = new int[5]; + mid[0] = (128<<24)|(195<<16)|(175<<8)|84;//dw-10 + mid[1] = (128<<24)|(195<<16)|(175<<8)|85;//dw-11 + mid[2] = (128<<24)|(195<<16)|(175<<8)|86;//dw-12 + mid[3] = (128<<24)|(195<<16)|(175<<8)|87;//dw-13 + mid[4] = (128<<24)|(195<<16)|(175<<8)|88;//dw-14 + + ReadArray[] a; + atomic { + a=global new ReadArray[nthreads]; //create object a + } + + ReadArrayWrap[] ra = new ReadArrayWrap[nthreads]; + + atomic { + for(int i=0;i0) { + nthreads = Integer.parseInt(args[0]); + } + + int[] mid = new int[5]; + mid[0] = (128<<24)|(195<<16)|(175<<8)|84;//dw-10 + mid[1] = (128<<24)|(195<<16)|(175<<8)|85;//dw-11 + mid[2] = (128<<24)|(195<<16)|(175<<8)|86;//dw-12 + mid[3] = (128<<24)|(195<<16)|(175<<8)|87;//dw-13 + mid[4] = (128<<24)|(195<<16)|(175<<8)|88;//dw-14 + + WriteArray[] wa; + atomic { + wa=global new WriteArray[nthreads]; //create nthreads objects + } + + WriteArrayWrap[] wawrap = new WriteArrayWrap[nthreads]; + atomic { + for(int i=0;i ~/.tmpdir + echo "bin=$3" > ~/.tmpvars + if [ $2 -eq 2 ]; then + arg=$ARGS2 + MACHINES=$MACHINES2 + fi + if [ $2 -eq 3 ]; then + arg=$ARGS3 + MACHINES=$MACHINES3 + fi + if [ $2 -eq 4 ]; then + arg=$ARGS4 + MACHINES=$MACHINES4 + fi + if [ $2 -eq 5 ]; then + arg=$ARGS5 + MACHINES=$MACHINES5 + fi + chmod +x ~/.tmpvars + for machine in `echo $MACHINES` + do + ssh ${machine} 'cd `cat ~/.tmpdir`; source ~/.tmpvars; ./$bin' & + echo "" + done + sleep 2 + /usr/bin/time -f "%e" ./$3 master $arg 2>> ${LOGDIR}/${3}.txt + echo "Terminating ... " + for machine in `echo $MACHINES` + do + ssh ${machine} 'source ~/.tmpvars; killall $bin' + done + sleep 2 + i=`expr $i + 1` + done +} + +function localrun { + i=0; + while [ $i -lt $1 ]; do + /usr/bin/time -f "%e" ./${NONPREFETCH} master $ARGS1 2>> ${LOGDIR}/${NONPREFETCH}_local.txt + sleep 4 + i=`expr $i + 1` + done +} + +function callrun { + NONPREFETCH=${BENCHMARK}1NP.bin + NONPREFETCH2=${BENCHMARK}2NP.bin + NONPREFETCH3=${BENCHMARK}3NP.bin + NONPREFETCH4=${BENCHMARK}4NP.bin + NONPREFETCH5=${BENCHMARK}5NP.bin + + echo "---------- Running ${BENCHMARK} local non-prefetch on 1 machine ---------- " + localrun 1 + + echo "---------- Running ${BENCHMARK} two threads non-prefetch on 2 machines ---------- " + run 1 2 $NONPREFETCH2 + echo "---------- Running ${BENCHMARK} three threads non-prefetch on 3 machines ---------- " + run 1 3 $NONPREFETCH3 + echo "---------- Running ${BENCHMARK} four threads non-prefetch on 4 machines ---------- " + run 1 4 $NONPREFETCH4 + echo "---------- Running ${BENCHMARK} five threads non-prefetch on 5 machines ---------- " + run 1 5 $NONPREFETCH5 + + cd $TOPDIR +} + +benchmarks='rarray rao warray wao' + +echo "---------- Clean old files ---------- " +rm ../runlog/* +for b in `echo $benchmarks` +do + bm=`grep $b bm.txt` + BENCHMARK=`echo $bm | cut -f1 -d":"` + ARGS1=`echo $bm | cut -f2 -d":"` + ARGS2=`echo $bm | cut -f3 -d":"` + ARGS3=`echo $bm | cut -f4 -d":"` + ARGS4=`echo $bm | cut -f5 -d":"` + ARGS5=`echo $bm | cut -f6 -d":"` + EXTENSION=`echo $bm | cut -f7 -d":"` + callrun +done + +#----------Calulates the averages ----------- +for file in `ls ../runlog/*.txt` +do + echo -n $file >> average.txt + cat $file | awk '{sum += $1} END {print " "sum/NR}' >> average.txt +done +echo "===========" >> average.txt +echo "" >> average.txt + +echo "done"