0
I’m getting segmentation fault error in the code below:
#include <stdio.h>
#include <stdlib.h>
#define linha 1000
#define coluna 1000
int main() {
long double M1[1000][1000];
long double M2[1000][1000];
long double matrizResultante[1000][1000];
/** multiplicando a matriz **/
for(int i = 0; i < linha; i++) {
for(int j = 0; j < coluna; j++) {
matrizResultante[i][j] = 0;
for(int k = 0; k < coluna; k++) {
matrizResultante[i][j] += M1[i][k] * M2[k][j];
}
}
}
return 0;
}
The purpose of this code is to analyze the access rates to cache memory, my suspicion is that the error is being generated by not initializing the matrix, but as the values are large the initialization is unviable. Is that really the problem?
I’m using gcc to compile the code.
There is no reason not to work, and it even worked (I reduced the size so as not to over-time the ideone): http://ideone.com/O2n3aE The code does not seem to help what you want.
– Maniero
moustache all right? very strange here when I try to compile it throws me a segmentation error, I’m using gcc. When you speak in the code does not seem to help in what I wish, this talking about the issue of accessing memory cache? my goal is to try to analyze the rate of miss and hit, by the size of the matrix I think should help me in this proposal.
– Emanoel
Happens seg fault when compiling, the problem is GCC :P I talk about it. You can even use this, but the experiment needs to be much more controlled than just running it. But that was more of an opinion, I can’t even talk without knowing everything you’re doing.
– Maniero
bigown because it is the problem this in gcc, I am running with codeblocks and apparently as you said this all right, about the experiment I am using the Valgrind, my goal is to try to improve the code, decrease the miss rates.
– Emanoel
The value that is going to this matrix may be getting higher than that supported by long double. I suggest you place a printf to identify at which point of iteration the segmentation failure occurs.
– Giuliana Bezerra