简体   繁体   English

矩阵乘法C语言

[英]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). 当我尝试乘以900x900矩阵时,会出现问题:分段错误(核心转储),但800x800可以正常工作)。 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. 您的两个float可变长度数组占用2 * 900 2 * 4字节-略超过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. VLA通常在堆栈上创建,其大小在系统和进程之间会有所不同,但在现代台式机系统上通常约为2至8 Mb。

Creating an array that large on the stack is somewhat unreasonable, and failure unsurprising. 创建一个在堆栈上很大的数组是不合理的,并且失败也就不足为奇了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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