In my C code I am allocating memory for 2d array double E[2000][2000]; but when I run it gets a runtime error Segmentation fault(core dumped) and when I reduce the array size to somewhere around 900 then the code runs fine.
Why it is showing runtime error since double take 64 bits memory (IEEE standard) so the code should take approximately 32MB which is not much compared to the ram size.And if it is not supported in C then how should I proceed if my maximum number of data that I have to store is 4000000 each are floating point numbers.
Are you declaring E as a local variable ? If so, you’re running out of stack memory.
Use dynamic allocation:
Or if you need the 2D array, use a zig-zag:
Then the deallocation is a little more complicated:
P.S. If you want to keep all of you data in a continuous way, there’s a trick (code from Takuya Ooura’s FFT Package)
The you just call
and