I need to perform a Matrix multiplication of two matrices with dimension 10,000 x 10,000. I am using simple array multiplication, and it takes more than 2 hours to complete the calculation. I need to reduce the times to complete the multiplication.
Double[,] array1 = new double [10000, 10000];
Double[,] array2 = new double [10000, 10000];
Random randNum = new Random();
for (int i = 0; i < array1.GetLength(0); i++)
{
for (int j = 0; j < array1.GetLength(1); j++)
{
array1[i, j] = randNum.Next(1, 10);
}
}
for (int i = 0; i < array2.GetLength(0); i++)
{
for (int j = 0; j < array2.GetLength(1); j++)
{
array2[i, j] = randNum.Next(1, 10);
}
}
Double [,] mt = mMat(array1,array2);
public static double[,] mMat(double[,] A, double[,] B)
{
int aRows = A.GetLength(0);
int aColumns = A.GetLength(1);
int bRows = B.GetLength(0);
int bColumns = B.GetLength(1);
if (aColumns != bRows)
{
throw new ArgumentException("A:Rows: " + aColumns + " did not match B:Columns " + bRows + ".");
}
double[,] C = new double[aRows, bColumns];
for (int i = 0; i < aRows; i++)
{ // aRow
for (int j = 0; j < bColumns; j++)
{ // bColumn
for (int k = 0; k < aColumns; k++)
{ // aColumn
C[i, j] += A[i, k] * B[k, j];
}
}
}
return C;
}
I am newbie in programming world and need to do task to perform large matrix multiplication