From 15c155ab2dc67ab4ef74b369fa54a8d534a1f2bd Mon Sep 17 00:00:00 2001 From: adash Date: Sun, 4 May 2008 19:46:53 +0000 Subject: [PATCH] modified Matrix multiply to take number of matrices as a parameter --- .../MatrixMultiply/MatrixMultiplyNrun.java | 174 ++++++++++++++++++ .../Prefetch/MatrixMultiply/makefile | 3 + 2 files changed, 177 insertions(+) create mode 100644 Robust/src/Benchmarks/Prefetch/MatrixMultiply/MatrixMultiplyNrun.java diff --git a/Robust/src/Benchmarks/Prefetch/MatrixMultiply/MatrixMultiplyNrun.java b/Robust/src/Benchmarks/Prefetch/MatrixMultiply/MatrixMultiplyNrun.java new file mode 100644 index 00000000..ba784797 --- /dev/null +++ b/Robust/src/Benchmarks/Prefetch/MatrixMultiply/MatrixMultiplyNrun.java @@ -0,0 +1,174 @@ +public class MatrixMultiply extends Thread{ + MMul mmul; + public int x0, y0, x1, y1; + public int nummatrix; + + public MatrixMultiply(MMul mmul, int x0, int x1, int y0, int y1, int nummatrix) { + this.mmul = mmul; + this.x0 = x0; + this.y0 = y0; + this.x1 = x1; + this.y1 = y1; + this.nummatrix = nummatrix; + } + + public void run() { + atomic { + double la[][]=mmul.a; + double lc[][]=mmul.c; + double lb[][]=mmul.btranspose; + int M=mmul.M; + + //Use btranspose for cache performance + for (int l = 0; l < nummatrix; l++) { + for(int i = x0; i< x1; i++){ + double a[]=la[i]; + double c[]=lc[i]; + for (int j = y0; j < y1; j++) { + double innerProduct=0; + double b[] = lb[j]; + for(int k = 0; k < M; k++) { + innerProduct += a[k] *b[k]; + } + c[j]=innerProduct; + } + } + System.clearPrefetchCache(); + //System.clea + } + } + } + + 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[4]; + mid[0] = (128<<24)|(195<<16)|(175<<8)|79; + mid[1] = (128<<24)|(195<<16)|(175<<8)|80; + mid[2] = (128<<24)|(195<<16)|(175<<8)|78; + mid[3] = (128<<24)|(195<<16)|(175<<8)|73; + int p, q, r; + MatrixMultiply[] mm; + MatrixMultiply tmp; + MMul matrix; + + atomic { + matrix = global new MMul(SIZE, SIZE, SIZE); + matrix.setValues(); + matrix.transpose(); + mm = global new MatrixMultiply[NUM_THREADS]; + int increment=SIZE/NUM_THREADS; + int base=0; + for(int i=0;i