When you define an array statically:
complex double arr[512][512];
The compiler knows how large it will be, so it reserves memory appropriately. However, When you declare an array variably,
complex double arr[x][y];
which you can only do this within a function, the compiler can't know how big it will be, so it can't reserve an appropriate space for it. The space will be allocated on the stack, and your stack evidently doesn't have the 4MB required for that array.
Ex:
double arr1[10240][10240];
int main() {
double arr2[10240][10240];
int i = 10240;
int j = 10240;
double arr3[i][j];
}
arr3 causes a segfault when run, comment it out and it will work. arr1 is put in the data section, arr2 is put on the stack, but the stack is made large enough to hold it (which the compiler can do since it is of known size). arr3, however, is not of a fixed size, so the compiler can't reserve space for it. The program tries to allocate it on the stack, but its too big, so the allocation causes a segfault.
x=y=512the actual dimensions with which you get a segfault?