From b0d937743ae3db7b368f71f8abef1c1b1cdd9ae5 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 25 Sep 2009 01:45:51 +0000 Subject: [PATCH] new programs --- .../MatrixMultiply/dsm/MatrixMultiplyD2.java | 202 ++++++++++++++++++ .../MatrixMultiply/dsm/MatrixMultiplyD3.java | 174 +++++++++++++++ 2 files changed, 376 insertions(+) create mode 100644 Robust/src/Benchmarks/Prefetch/MatrixMultiply/dsm/MatrixMultiplyD2.java create mode 100644 Robust/src/Benchmarks/Prefetch/MatrixMultiply/dsm/MatrixMultiplyD3.java diff --git a/Robust/src/Benchmarks/Prefetch/MatrixMultiply/dsm/MatrixMultiplyD2.java b/Robust/src/Benchmarks/Prefetch/MatrixMultiply/dsm/MatrixMultiplyD2.java new file mode 100644 index 00000000..293f8120 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/MatrixMultiply/dsm/MatrixMultiplyD2.java @@ -0,0 +1,202 @@ +public class MatrixMultiply extends Thread{ + MMul mmul; + public int x0, y0, x1, y1; + public int tid, numthreads; + + public MatrixMultiply(MMul mmul, int x0, int x1, int y0, int y1, int tid, int numthreads) { + this.mmul = mmul; + this.x0 = x0; + this.y0 = y0; + this.x1 = x1; + this.y1 = y1; + this.tid=tid; + this.numthreads=numthreads; + } + + public void run() { + Barrier barr=new Barrier("128.195.136.162"); + atomic { + mmul.setValues(tid, numthreads); + } + + Barrier.enterBarrier(barr); + + atomic { + double la[][][]=mmul.a; + double lc[][][]=mmul.c; + double lb[][][]=mmul.btranspose; + int M=mmul.M; + int P=mmul.P; + //Use btranspose for cache performance + if ((tid%2)==0) { + for(int q=0;q=0;q--) { + double ra[][]=la[q]; + double rb[][]=lb[q]; + double rc[][]=lc[q]; + for(int i = x0; i< x1; i++){ + double a[]=ra[i]; + double c[]=rc[i]; + for (int j = y0; j < y1; j++) { + double innerProduct=0; + double b[] = rb[j]; + for(int k = 0; k < M; k++) { + innerProduct += a[k] * b[k]; + } + c[j]=innerProduct; + } + } + } + } + } + } + + public static void main(String[] args) { + int NUM_THREADS = 4; + int SIZE=150; + int NUM_MATRIX = 1; + if (args.length>0) { + NUM_THREADS=Integer.parseInt(args[0]); + if (args.length>1) { + SIZE=Integer.parseInt(args[1]); + if (args.length>2) + NUM_MATRIX=Integer.parseInt(args[2]); + } + } + + int[] mid = new int[8]; + mid[0] = (128<<24)|(195<<16)|(136<<8)|162; + mid[1] = (128<<24)|(195<<16)|(136<<8)|163; + mid[2] = (128<<24)|(195<<16)|(136<<8)|164; + mid[3] = (128<<24)|(195<<16)|(136<<8)|165; + mid[4] = (128<<24)|(195<<16)|(136<<8)|166; + mid[5] = (128<<24)|(195<<16)|(136<<8)|167; + mid[6] = (128<<24)|(195<<16)|(136<<8)|168; + mid[7] = (128<<24)|(195<<16)|(136<<8)|169; + + int p, q, r; + MatrixMultiply[] mm; + MatrixMultiply tmp; + MMul matrix; + BarrierServer mybarr; + + atomic { + mybarr = global new BarrierServer(NUM_THREADS); + } + mybarr.start(mid[0]); + + + atomic { + matrix = global new MMul(NUM_MATRIX, SIZE, SIZE, SIZE); + mm = global new MatrixMultiply[NUM_THREADS]; + int increment=SIZE/NUM_THREADS; + int base=0; + for(int i=0;i0||numthreads==1) { + int delta=numthreads>1?numthreads-1:1; + int start=numthreads>1?tid-1:0; + + for(int q = start; q < P; q+=delta) { + for(int i = 0; i < N; i++) { + double bi[] = global new double[M]; + for(int j = 0; j < M; j++) { + bi[j] = j+1; + } + btranspose[q][i]=bi; + } + } + } + } +} diff --git a/Robust/src/Benchmarks/Prefetch/MatrixMultiply/dsm/MatrixMultiplyD3.java b/Robust/src/Benchmarks/Prefetch/MatrixMultiply/dsm/MatrixMultiplyD3.java new file mode 100644 index 00000000..a655fe33 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/MatrixMultiply/dsm/MatrixMultiplyD3.java @@ -0,0 +1,174 @@ +public class MatrixMultiply extends Thread{ + MMul mmul; + public int x0, y0, x1, y1; + public int tid, numthreads; + + public MatrixMultiply(MMul mmul, int x0, int x1, int y0, int y1, int tid, int numthreads) { + this.mmul = mmul; + this.x0 = x0; + this.y0 = y0; + this.x1 = x1; + this.y1 = y1; + this.tid=tid; + this.numthreads=numthreads; + } + + public void run() { + Barrier barr=new Barrier("128.195.136.162"); + atomic { + mmul.setValues(tid, numthreads); + } + + Barrier.enterBarrier(barr); + + atomic { + double la[][][]=mmul.a; + double lc[][][]=mmul.c; + double lb[][][]=mmul.btranspose; + int M=mmul.M; + int P=mmul.P; + //Use btranspose for cache performance + for(int q=0;q0) { + NUM_THREADS=Integer.parseInt(args[0]); + if (args.length>1) { + SIZE=Integer.parseInt(args[1]); + if (args.length>2) + NUM_MATRIX=Integer.parseInt(args[2]); + } + } + + int[] mid = new int[8]; + mid[0] = (128<<24)|(195<<16)|(136<<8)|162; + mid[1] = (128<<24)|(195<<16)|(136<<8)|163; + mid[2] = (128<<24)|(195<<16)|(136<<8)|164; + mid[3] = (128<<24)|(195<<16)|(136<<8)|165; + mid[4] = (128<<24)|(195<<16)|(136<<8)|166; + mid[5] = (128<<24)|(195<<16)|(136<<8)|167; + mid[6] = (128<<24)|(195<<16)|(136<<8)|168; + mid[7] = (128<<24)|(195<<16)|(136<<8)|169; + + int p, q, r; + MatrixMultiply[] mm; + MatrixMultiply tmp; + MMul matrix; + BarrierServer mybarr; + + atomic { + mybarr = global new BarrierServer(NUM_THREADS); + } + mybarr.start(mid[0]); + + + atomic { + matrix = global new MMul(NUM_MATRIX, SIZE, SIZE, SIZE); + mm = global new MatrixMultiply[NUM_THREADS]; + int increment=SIZE/NUM_THREADS; + int base=0; + for(int i=0;i