Good, I'm testing the execution time for different algorithms that solve the problem of matrix multiplication, but when I try to order arrays 417 up, the .exe stops working.
The program compiles without problems, but I would like to know why for high values of N
the program no longer runs since I will also try other algorithms that possibly cause this problem.
I am using C in codeblocks, I leave the code I use:
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define N 416
void llenarMat(long mat[][N]);
void multMat(long A[][N] , long B[][N] , long C[][N]);
void mostrarMat(long A[][N]);
int main()
{
long A[N][N];
long B[N][N];
long C[N][N];
clock_t start_t , end_t;
double total_t;
srand(time(NULL));
llenarMat(A);
llenarMat(B);
start_t = clock();
printf("El metodo empieza, start_t = %ld\n", start_t);
multMat(A , B , C);
end_t = clock();
printf("El metodo termina, end_t = %ld\n", end_t);
total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
printf("Tiempo total tomado por el CPU: %f\n", total_t);
/*mostrarMat(A);
mostrarMat(B);
mostrarMat(C);*/
return 0;
}
void llenarMat(long mat[][N])
{
long i, j;
for (i = 0 ; i < N ; i++)
{
for (j = 0 ; j < N ; j++)
mat[i][j] = (rand() % 10 )+ 1;
}
}
void multMat(long A[][N] , long B[][N] , long C[][N])
{
long i , j , k;
long sum;
for(i = 0 ; i < N ; i++)
{
for (j = 0 ; j < N ; j++)
{
sum = 0;
for(k = 0 ; k < N ; k++)
{
sum = sum + A[i][k] * B[k][j];
}
C[i][j] = sum;
}
}
}
void mostrarMat(long A[][N])
{
long i, j;
for (i = 0 ; i < N ; i++)
{
for (j = 0 ; j < N ; j++)
printf(" %d", A[i][j]);
printf("\n");
}
printf("\n");
}