Hi C Wizards ...
Although I posted a similar question before, this is slightly different. It looks like the C compiler is self-limiting itself to small matrices... I need to perform matrix operations that should be 10000x10000 (I perform quite a bit of matrices operation, but multiplication is a good example). However, depending in how I run the matrix multiplication code I get different maximum matrix sizes ....
For example if I run this code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <stdlib.h>
#define MaxMatrix 20000
// Protos ...
float *MatrixMultiply (int r1, int c1, float Array1[][c1], int c2, float Array2[][c2], float Result[r1][c2]);
float *RandomMatrix (int Size, float Matrix[][Size]);
int main (void)
{
int Num;
for (Num = 1; Num < MaxMatrix; Num ++)
{
printf ("\n Matrix %ix%i \n", Num, Num);
float Random_M[Num][Num];
float Random_M2[Num][Num];
RandomMatrix (Num, Random_M);
MatrixMultiply (Num, Num, Random_M, Num, Random_M, Random_M2);
}
return 0;
}
float *MatrixMultiply (int r1, int c1, float Array1[][c1], int c2, float Array2[][c2], float Result[r1][c2])
{
int i, j, k;
for (i = 0; i < r1; i++)
{
for (j = 0; j < c2; j++)
{
Result[i][j] = 0.0;
for (k = 0; k < c1; k++)
{
Result[i][j] += Array1[i][k] * Array2[k][j];
}
}
}
return Result[0];
}
float *RandomMatrix (int Size, float Matrix[][Size])
{
int i, j;
srand((unsigned)time(NULL) );
if (Size > 1)
{
for (i = 0; i < Size; i++)
{
for (j = 0; j < Size; j++)
{
Matrix [i][j] = ((float) (rand() / ((float)RAND_MAX + 1.0)))*3;
}
}
}
return Matrix[0];
}
With this I can multiply matrices up to 73x73 and then afterwards I get an error message saying that:
====================
Program Error:
Program.exe has generated errors and will be closed by Windows. You will need to restart the program.
An error log is being generated.
====================
However, if I set up the matrix size to a specific size then I can multiply matrices that are 359x359. For example:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <stdlib.h>
#define MaxMatrix 20000
// Protos ...
float *MatrixMultiply (int r1, int c1, float Array1[][c1], int c2, float Array2[][c2], float Result[r1][c2]);
float *RandomMatrix (int Size, float Matrix[][Size]);
int main (void)
{
int Num = 359;
float Random_M[Num][Num];
float Random_M2[Num][Num];
RandomMatrix (Num, Random_M);
MatrixMultiply (Num, Num, Random_M, Num, Random_M, Random_M2);
return 0;
}
float *MatrixMultiply (int r1, int c1, float Array1[][c1], int c2, float Array2[][c2], float Result[r1][c2])
{
int i, j, k;
for (i = 0; i < r1; i++)
{
for (j = 0; j < c2; j++)
{
Result[i][j] = 0.0;
for (k = 0; k < c1; k++)
{
Result[i][j] += Array1[i][k] * Array2[k][j];
}
}
}
return Result[0];
}
float *RandomMatrix (int Size, float Matrix[][Size])
{
int i, j;
srand((unsigned)time(NULL) );
if (Size > 1)
{
for (i = 0; i < Size; i++)
{
for (j = 0; j < Size; j++)
{
Matrix [i][j] = ((float) (rand() / ((float)RAND_MAX + 1.0)))*3;
}
}
}
return Matrix[0];
}
If I attempt to multiply matrices that are bigger than 359 then I get the same error than before, but as you can see this time the matrix was bigger (however not enough for my case).
Does anyone of you know why I get this limitation in matrix handling?
Is there any way to increase the matrix handling capacity in my code?
Is this limitation due to hardware (RAM limitation)?
Any help in this matter is greatly appreciated.
NOTE: I compiled the application as a Win32 Console application (if this have to be compiled in a different way, please let me know).
Regards,
Delper