segmentation fault when array size exceed 1GB
My OS is RH9.0
When I order an array whose size exceed 1GB, then It fails with segmentation fault. How can I solve this problem? |
What in the world could require one gig of memory? Which programming language and is there any way to optimize your code so you don't need to use so much memory?
|
Quote:
|
Actualy I think this is a valid questions, maybe he do have a program that will use that amount of data? I myself been playing with terraforming rutins, and physics engiens for these worlds.. The worlds themself are much containted on harddrive and swapped up and such, but the "current state" data is huge to, and If I would ever continue my work, its not unreasonble to exspect to use 1Gig of memory for these calculations. Recursive calls kills the stack, yes it does, yes thats a wall you should avoid. But if you have 2Gig in your machine, or 512Mb and 4Gig swap... Why shouldnt you be able to do this: struct stateData[1000000000] currentState.. ?
|
I use Fortran for scientific computing. My PC has 2 giga bytes memory.
Quote:
|
Sorry, It is my fault. I should have told you I have 2 giga bytes memory fixed in my PC. And if I reduce the size of that array to 800MB, I can run the program with 2 threads at the same time, which cost 1.5GB memory.
And also I can change the stacksize to unlimited, but it still refuse to work. Quote:
|
Could you try doing the same in a short C program to see if that fails too?
Martin |
I don't think it will be easy to translate the code.
Quote:
|
I take it your allocation is more complicated than:
char *i = new char[1000000000]; I'm not familiar with fortran, is it possible to allocate memory both on the stack and on the heap? The above C example is stack allocation, this is heap allocation: char i[100000000]; Couldn't you try to do just the allocation part without the rest of the program logic? I'm sorry I can't do it myself. My bad excuse for a computer has only 192 MB ;) Regards Martin |
We don't know if your FORTRAN compiler allocates arrays on the stack on in heap memory. There is a BIG difference. Allocating to heap is the way to go for large arrays.
Are there compiler switches that change how memory allocates for variables? ie., make the array static (heap), not volatile. |
PS: some FORTRAN compilers used to have support for virtual arrays - ie., arrays kept mostly on disk and paged into/out of memory as needed. I don't know if your FORTRAN compiler does that, but it's worth investigating.
|
Quote:
|
Quote:
|
The new keyword is not a C keyword, it is C++
in C it would be: Code:
char *i; |
Quote:
I took the liberty to test this a little. This code snippet (which is C++) shows what happens on my machine: Code:
try One interesting thing to note is that I can easily allocate 300 MB 3 times, like this: Code:
char *i = new char[300000000]; // 300 MB Martin |
All times are GMT -5. The time now is 01:38 AM. |