I am working on a project that tests different methods of matrix multiplication. The goal is to test 1000 sets of data, 20 times each, for n x n matrices up to n = 2^i, where in my case I am going up to n = 256.
My methods for matrix multiplication all work just fine, but I cannot get it to test the correct amount of times. Below is my main method, where I am attempted to test this feature for correctness in output.
public static void main(String[] args)
{
final int SETS = 1;
final int TIMES = 2;
final int POWER = 1;
long timeStart, timeEnd;
long totalTimeClassical = 0;
long totalTimeDivideConquer = 0;
long totalTimeStrassen = 0;
long avgTimeClassical = 0;
long avgTimeDivideConquer = 0;
long avgTimeStrassen = 0;
int[][] a, b;
int n;
for (int i=1; i<=POWER; i++)
{
n = (int) Math.pow(2, i);
for (int j=1; j<=TIMES; j++)
{
for (int k=1; k<=SETS; k++)
{
a = buildMatrix(n);
b = buildMatrix(n);
timeStart = System.nanoTime();
classicalMatrixMult(a, b, n);
timeEnd = System.nanoTime();
totalTimeClassical += timeEnd - timeStart;
timeStart = System.nanoTime();
divideConquerMatrixMult(a, b, n);
timeEnd = System.nanoTime();
totalTimeDivideConquer += timeEnd - timeStart;
timeStart = System.nanoTime();
strassenMatrixMult(a, b);
timeEnd = System.nanoTime();
totalTimeStrassen += timeEnd - timeStart;
outputMatrix(a,n);
outputMatrix(b,n);
System.out.println(" -----------");
}
totalTimeClassical = totalTimeClassical / TIMES;
totalTimeDivideConquer = totalTimeDivideConquer / TIMES;
totalTimeStrassen = totalTimeStrassen / TIMES;
}
avgTimeClassical = totalTimeClassical / SETS;
avgTimeDivideConquer = totalTimeDivideConquer / SETS;
avgTimeStrassen = totalTimeStrassen / SETS;
System.out.print("For " + n + "x" + n + ":");
System.out.println("\nClassical Matrix multiplication took "
+ avgTimeClassical + " nanoseconds to run."
+"\nDivide and Conquer Matrix multiplcation took "
+ avgTimeDivideConquer + " nanoseconds to run."
+"\nStrassen's Matrix Multiplication took "
+ avgTimeStrassen + " nanoseconds to run."
+ "\n");
}
}
Above is my main method, where I currently have it set to print out the input matrices so I can see if it is running the correct amount of times with the correct number of data sets. With the current values I have plugged in, I want it to test 1 SET of 2 x 2 matrices, 2 TIMES. Instead, it tests 2 SETS of 2 x 2 matrices, as the printed out values are different.
9 -9
-4 4
-2 0
3 8
-----------
-5 10
-1 1
-2 -8
-5 -5
-----------
For 2x2:
Classical Matrix multiplication took 2514 nanoseconds to run.
Divide and Conquer Matrix multiplcation took 10575 nanoseconds to run.
Strassen's Matrix Multiplication took 1356 nanoseconds to run.
I have tried to rearrange the loops but end up breaking the code. How do I format this so it tests a set of data a specified amount of times?