I am writing a C program. In the first lines, I have
typedef float m_elem[NMAX][NMAX][3];
m_elem asa_m;
m_elem asa_mi[100];
then, some calculations. At the moment, and for each run and depending on the input, I change on the code the NMAX value, and then recompile it and run it. For NMAX values below 500, the program runs ok, but for higher NMAX values (which I need for some input files), all I get is segmentation fault.
What do you recommend me to do here? I read about learning valgrind, but in this case I wonder if just changing compilation options somehow for allowing the program to deal with bigger matrices would help
Thanks
You’re probably running out of stack space.
At NMAX=500, the
asa_mivariable will need 500 * 500 * 3 * 100 * 4 bytes, or about 300 MB. Most operating systems won’t allow a stack that large, so you might want to check into your system’s limits.Did you try allocating it from the heap, with
malloc()instead?