Matrix multiplication error: Segmentation fault (core dumped)

后端 未结 1 1445
说谎
说谎 2021-01-07 09:32

I have the following code, and I want to calculate the running time of several matrix multiplications, with different sizes. I started with matrix size of 100, and moved til

相关标签:
1条回答
  • 2021-01-07 09:51

    This is a classic stack overflow - you have 3 local arrays each of approx 4 MB in size (assuming 32 bit ints) on your stack for a total of around 12 MB. On most modern operating systems the stack is typically 8 MB or less. Either make the variables static, e.g.

    static int A[SIZE][SIZE], B[SIZE][SIZE], C[SIZE][SIZE] = {0};
    

    so that they no longer reside on the stack, or allocate them dynamically.

    0 讨论(0)
提交回复
热议问题