working version ....
authoradash <adash>
Mon, 3 Nov 2008 03:34:50 +0000 (03:34 +0000)
committeradash <adash>
Mon, 3 Nov 2008 03:34:50 +0000 (03:34 +0000)
global array allocation in fft needs to address scaling problems

Robust/src/Benchmarks/Prefetch/2DFFT/dsm/Makefile
Robust/src/Benchmarks/Prefetch/2DFFT/dsm/fft1d.java
Robust/src/Benchmarks/Prefetch/2DFFT/dsm/fft2d.java

index a2f85c7f182b9333716fe9ab8b8f940b6664cd96..09f5170c48b230a382fc9a396518afcb5c599c30 100644 (file)
@@ -2,10 +2,27 @@ MAINCLASS=fft2d
 SRC=${MAINCLASS}.java \
        fft1d.java \
        Matrix.java
-FLAGS = -dsm -optimize -mainclass ${MAINCLASS}
+FLAGS =-dsm -dsmcaching -prefetch -transstats -optimize -excprefetch fft2d.main -excprefetch fft2d.twiddle -excprefetch fft1d.factorize -excprefetch fft1d.printFactors -excprefetch Matrix.setValues -trueprob 0.90 -mainclass ${MAINCLASS}
+FLAGS1=-dsm -transstats -optimize -mainclass ${MAINCLASS}
 
 default:
-       ../../../../buildscript ${FLAGS} ${SRC} -o ${MAINCLASS}
+       ../../../../buildscript ${FLAGS1} ${SRC} -o ${MAINCLASS}NPNC
+       ../../../../buildscript ${FLAGS} ${SRC} -o ${MAINCLASS}N
+       cp ${MAINCLASS}NPNC.bin ${MAINCLASS}1NPNC.bin
+       cp ${MAINCLASS}NPNC.bin ${MAINCLASS}2NPNC.bin
+       cp ${MAINCLASS}N.bin ${MAINCLASS}2.bin
+       cp ${MAINCLASS}NPNC.bin ${MAINCLASS}3NPNC.bin
+       cp ${MAINCLASS}N.bin ${MAINCLASS}3.bin
+       cp ${MAINCLASS}NPNC.bin ${MAINCLASS}4NPNC.bin
+       cp ${MAINCLASS}N.bin ${MAINCLASS}4.bin
+       cp ${MAINCLASS}NPNC.bin ${MAINCLASS}5NPNC.bin
+       cp ${MAINCLASS}N.bin ${MAINCLASS}5.bin
+       cp ${MAINCLASS}NPNC.bin ${MAINCLASS}6NPNC.bin
+       cp ${MAINCLASS}N.bin ${MAINCLASS}6.bin
+       cp ${MAINCLASS}NPNC.bin ${MAINCLASS}7NPNC.bin
+       cp ${MAINCLASS}N.bin ${MAINCLASS}7.bin
+       cp ${MAINCLASS}NPNC.bin ${MAINCLASS}8NPNC.bin
+       cp ${MAINCLASS}N.bin ${MAINCLASS}8.bin
 
 clean:
        rm -rf tmpbuilddirectory
index 9a5759a2e28d6510a8e8ac8c9ba30c1c1147b674..b2fd03de90f7a23432cb38fb07f7cae1bec72aac 100644 (file)
@@ -98,7 +98,7 @@ public class fft1d{
     outputIm = global new double[N];
 
     factorize();
-    printFactors();
+    //printFactors();
 
     // Allocate memory for intermediate result of FFT.
     temRe = global new double[maxFactor]; //Check usage of this
@@ -136,19 +136,20 @@ public class fft1d{
   public void printFactors() {
     if (factorsWerePrinted) return;
     factorsWerePrinted = true;
+    System.printString("factors.length = " + factors.length + "\n");
     for (int i = 0; i < factors.length; i++)
-      System.printString("factors[i] = " + factors[i]);
+      System.printString("factors[i] = " + factors[i] + "\n");
   }
 
   public void factorize() {
-    int radices[] = new int[6];
+    int radices[] = global new int[6];
     radices[0] = 2;
     radices[1] = 3;
     radices[2] = 4;
     radices[3] = 5;
     radices[4] = 8;
     radices[5] = 10;
-    int temFactors[] = new int[MaxFactorsNumber];
+    int temFactors[] = global new int[MaxFactorsNumber];
 
     // 1 - point FFT, no need to factorize N.
     if (N == 1) {
@@ -201,7 +202,7 @@ public class fft1d{
     //   maxFactor = 10;
 
     // Inverse temFactors and store factors into factors[].
-    factors = new int[NumofFactors];
+    factors = global new int[NumofFactors];
     for (i = 0; i < NumofFactors; i++) {
       factors[i] = temFactors[NumofFactors - i - 1];
     }
@@ -210,8 +211,8 @@ public class fft1d{
     // sofar[]  : finished factors before the current stage.
     // factors[]: factors of N processed in the current stage.
     // remain[] : finished factors after the current stage.
-    sofar = new int[NumofFactors];
-    remain = new int[NumofFactors];
+    sofar = global new int[NumofFactors];
+    remain = global new int[NumofFactors];
 
     remain[0] = N / factors[0];
     sofar[0] = 1;
index b8e76a2481f8da6956023f2b2a0860883bd16f14..d1ec64dd39d0af669acfd85c145405cc85b64b04 100644 (file)
@@ -12,9 +12,10 @@ public class fft2d extends Thread {
   public fft1d fft1, fft2;
   public Matrix data;
   public int x0, x1, y0, y1;
+  public double inputRe[], inputIm[];
 
   // Constructor: 2-d FFT of Complex data.
-  public fft2d(Matrix data, fft1d fft1, fft1d fft2, int x0, int x1, int y0, int y1) {
+  public fft2d(double[] inputRe, double[] inputIm, Matrix data, fft1d fft1, fft1d fft2, int x0, int x1, int y0, int y1) {
     this.data = data;
     this.x0 = x0;
     this.x1 = x1;
@@ -22,6 +23,8 @@ public class fft2d extends Thread {
     this.y1 = y1;
     this.fft1 = fft1;
     this.fft2 = fft2;
+    this.inputRe = inputRe;
+    this.inputIm = inputIm;
   }
 
   public void run() {
@@ -29,10 +32,9 @@ public class fft2d extends Thread {
     barr = new Barrier("128.195.175.84");
     double tempdataRe[][];
     double tempdataIm[][];
+    double mytemRe[][];
+    double mytemIm[][];
     int rowlength, columnlength;
-    double temRe[];// intermediate results
-    double temIm[]; 
-
 
     atomic {
       rowlength = data.M;  //height
@@ -41,8 +43,7 @@ public class fft2d extends Thread {
       tempdataIm = data.dataIm;
 
       // Calculate FFT for each row of the data.
-      // for (int i = 0; i < height; i++)
-      // fft1.fft(dataRe[i], dataIm[i]);
+      //System.printString("x0= " + x0 + " x1= " + x1 + " y0= "+ y0 + " y1= " + y1 + " width = " + columnlength + " height= " + rowlength+ "\n");
       for (int i = x0; i < x1; i++) {
         int N = fft1.N;
         if(columnlength != N) {
@@ -56,8 +57,8 @@ public class fft2d extends Thread {
           //output of FFT
           double outputRe[] = fft1.outputRe; //local array
           double outputIm[] = fft1.outputIm;
-          temRe = fft1.temRe;   // intermediate results
-          temIm = fft1.temIm;
+          double temRe[] = fft1.temRe;   // intermediate results
+          double temIm[] = fft1.temIm;
           int count[] = new int[fft1.MaxFactorsNumber];
           int j; 
           int k = 0;
@@ -86,7 +87,6 @@ public class fft2d extends Thread {
           for (int factorIndex = 0; factorIndex < fft1.NumofFactors; factorIndex++) {
             twiddle(factorIndex, fft1, temRe, temIm, outputRe, outputIm);
           }
-          //System.printString("ready to copy");
           // Copy the output[] data to input[], so the output can be
           // returned in the input array.
           for (int b = 0; b < N; b++) {
@@ -94,20 +94,20 @@ public class fft2d extends Thread {
             inputIm[b] = outputIm[b];
           }
         }
-      }
+      }//end of for
     }
+
     //Start Barrier
     Barrier.enterBarrier(barr);
 
     // Tranpose data.
-    double mytemRe[][], mytemIm[][];
     atomic {
-      tempdataRe = data.dataRe;
-      tempdataIm = data.dataIm;
+      mytemRe = new double[columnlength][rowlength];
+      mytemIm = new double[columnlength][rowlength];
       for(int i = x0; i<x1; i++) {
         double tRe[] = tempdataRe[i];
         double tIm[] = tempdataIm[i];
-        for(int j = 0; j<columnlength; j++) { //TODO Check this
+        for(int j = y0; j<y1; j++) { 
           mytemRe[j][i] = tRe[j];
           mytemIm[j][i] = tIm[j];
         }
@@ -116,13 +116,10 @@ public class fft2d extends Thread {
 
     //Start Barrier
     Barrier.enterBarrier(barr);
-   // double temRe[][] = transpose(data.dataRe);
-    //double temIm[][] = transpose(data.dataIm);
 
     // Calculate FFT for each column of the data.
     atomic {
       for (int j = y0; j < y1; j++) {
-        //fft2.fft(temRe[j], temIm[j]);
         int N = fft2.N;
         if(rowlength != N) {
           System.printString("Error: the length of real part & imaginary part " + "of the input to 1-d FFT are different");
@@ -135,8 +132,8 @@ public class fft2d extends Thread {
           //output of FFT
           double outputRe[] = fft2.outputRe; //local array
           double outputIm[] = fft2.outputIm;
-          temRe = fft2.temRe;   // intermediate results
-          temIm = fft2.temIm;
+          double temRe[] = fft2.temRe;   // intermediate results
+          double temIm[] = fft2.temIm;
           int count[] = new int[fft2.MaxFactorsNumber];
           int r; 
           int k = 0;
@@ -165,7 +162,6 @@ public class fft2d extends Thread {
           for (int factorIndex = 0; factorIndex < fft2.NumofFactors; factorIndex++) {
             twiddle(factorIndex, fft2, temRe, temIm, outputRe, outputIm);
           }
-          //System.printString("ready to copy");
           // Copy the output[] data to input[], so the output can be
           // returned in the input array.
           for (int b = 0; b < N; b++) {
@@ -182,17 +178,20 @@ public class fft2d extends Thread {
     // Tranpose data.
     // Copy the result to input[], so the output can be
     // returned in the input array.
-
-    for (int i = x0; i < x1; i++) {
+    atomic {
       for (int j = y0; j < y1; j++) {
-        tempdataRe[i][j] =  mytemRe[j][i];
-        tempdataIm[i][j] = mytemIm[j][i];
-        //inputRe[i * width + j] = temRe[j][i];
-        //inputIm[i * width + j] = temIm[j][i];
+        double tRe[] = mytemRe[j];
+        double tIm[] = mytemIm[j];
+        for (int i = x0; i < x1; i++) {
+          inputRe[i* data.N + j] = tRe[i];
+          inputIm[i* data.N + j] = tIm[i];
+        }
       }
     }
+
   }//end of run
 
+
   //("ready to twiddle");
   private void twiddle(int factorIndex, fft1d myfft, double[] temRe, double[] temIm, 
       double[] outputRe, double[] outputIm) {
@@ -564,6 +563,8 @@ public class fft2d extends Thread {
         SIZE = Integer.parseInt(args[1]);
     }
 
+    System.printString("Num threads = " + NUM_THREADS + " SIZE= " + SIZE + "\n");
+
     // Initialize Matrix 
     // Matrix inputRe, inputIm;
 
@@ -579,6 +580,13 @@ public class fft2d extends Thread {
       }
     }
 
+    /* For testing 
+    atomic {
+      System.printString("Element 231567 is " + (int)inputRe[231567]+ "\n");
+      System.printString("Element 10 is " + (int)inputIm[10]+ "\n");
+    }
+    */
+
     int[] mid = new int[8];
     mid[0] = (128<<24)|(195<<16)|(175<<8)|84; //dw-10
     mid[1] = (128<<24)|(195<<16)|(175<<8)|85; //dw-11
@@ -596,7 +604,6 @@ public class fft2d extends Thread {
     }
     mybarr.start(mid[0]);
 
-
     // Width and height of 2-d matrix inputRe or inputIm.
     int width, height;
     width = inputWidth;
@@ -607,6 +614,7 @@ public class fft2d extends Thread {
       Imlength = inputIm.length;
     }
 
+    //System.printString("Initialized width and height\n");
     Matrix data;
     fft1d fft1, fft2;
     // First make sure inputRe & inputIm are of the same length in terms of columns
@@ -627,13 +635,13 @@ public class fft2d extends Thread {
       fft2d[] myfft2d;
       atomic {
         myfft2d = global new fft2d[NUM_THREADS];
-        int increment = SIZE/NUM_THREADS;
+        int increment = height/NUM_THREADS;
         int base = 0;
         for(int i =0 ; i<NUM_THREADS; i++) {
           if((i+1)==NUM_THREADS)
-            myfft2d[i] = global new fft2d(data, fft1, fft2, base, SIZE, 0, SIZE);
+            myfft2d[i] = global new fft2d(inputRe, inputIm, data, fft1, fft2, base, increment, 0, width);
           else
-            myfft2d[i] = global new fft2d(data, fft1, fft2, base, base+increment, 0, SIZE);
+            myfft2d[i] = global new fft2d(inputRe, inputIm, data, fft1, fft2, base, base+increment, 0, width);
           base+=increment;
         }
       }
@@ -664,19 +672,27 @@ public class fft2d extends Thread {
       }
     }
 
+    System.printString("2DFFT done! \n");
+    /* For testing 
+    atomic {
+      System.printString("Element 231567 is " + (int)inputRe[231567]+ "\n");
+      System.printString("Element 10 is " + (int)inputIm[10]+ "\n");
+    }
+    */
+
     // Display results
     // Tranpose data.
     // Copy the result to input[], so the output can be
     // returned in the input array.
+    /* For testing
     atomic {
       for (int i = 0; i < height; i++) {
         for (int j = 0; j < width; j++) {
-          //inputRe[i * width + j] = temRe[j][i];
-          System.printInt((int)inputRe[i * width + j]);
-          //inputIm[i * width + j] = temIm[j][i];
-          System.printInt((int)inputIm[i * width + j]);
+          System.printString((int)inputRe[i * width + j]+ "\n");
+          System.printString((int)inputIm[i * width + j]+ "\n");
         }
       }
     }
+    */
   }
 }