简体   繁体   中英

Matrix Multiplication C language

So, I have problem with matrix multiplication. I have to store the values of a matrix in a file and after that multiply them. The problem occurs when I try to multiply 900x900 matrix: Segmentation fault (core dumped), but 800x800 works perfectly). there is part of my code: create file for storing:

FILE *A, *B;
int num = atoi(argv[1]);
float a[num][num];
float b[num][num];
A = fopen(argv[2],"r");
B = fopen(argv[3],"r");
for (int i = 0; i < num; ++i)
{
    for (int j = 0; j < num; ++j)
    {
        fscanf(A,"%f",&a[i][j]);
    }
}
for (int i = 0; i < num; ++i)
{
    for (int j = 0; j < num; ++j)
    {
        fscanf(B,"%f",&b[i][j]);
    }
}

So i didn't write function for matrix multiplication because it works

Your two float variable-length arrays occupy 2*900 2 *4 bytes - that is a little over 6Mb. VLAs are typically created on the stack, the size of which will vary between systems and processes, but on a modern desktop system is typically perhaps 2 to 8 Mb.

Creating an array that large on the stack is somewhat unreasonable, and failure unsurprising.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM