I am using dynamical allocation because I need some memory space to define 3 matrices. When I use 2 matrices (please see the minimal working environment below), i.e. I put the third matrix as a comment, the program work very well and gives the desired results. However, when I include the third matrix, I get a segmentation fault, core dumped! I don't know if there are limits in the dynamical allocation using malloc. Any help would be highly appreciated. Thank you!
#include<stdio.h>
#include<malloc.h>
int main(int argc, char **argv)
{
int rows=160, cols=1999000;
float *mat1 = (float *)malloc(rows * cols * sizeof(float));
float *mat2 = (float *)malloc(rows * cols * sizeof(float));
//float *mat3 = (float *)malloc(rows * cols * sizeof(float));
int i, j;
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
mat1[i * cols + j]=i+j;
mat2[i * cols + j]=i-j;
//mat3[i * cols + j]=i*j;
}
}
for(i=0;i<2;i++)
{
for(j=0;j<6;j++)
{
printf("R[%d][%d] = %f\n", i, j, mat2[i * cols + j]);
}
}
}