Allocatable, heap arrays, segmentation...

Allocatable, heap arrays, segmentation...

Hello everybody,

I have written a fortran code that involves several calculations with 2D arrays. The program works fine below certain threshold... namely, 360x360. Above this, the program crash and a segmentation fault message appears. As I am working on a Mac OX 10.8.4 I can't increase the stack size... So, I have compiled with the -heap-arrays option, and the program runs without "problems" except for it takes around 2GB of the RAM memory, causing a poor performance on the machine. Below the thershold the program just takes 20MB in the RAM. All the arrays have been defined dinamically.

I've used the gdb debugger and I know exactly from where (which subroutine) the segmentation is coming, but, the code seems to be ok there.

Somebody can figure out how I could handling this issue?

Thanks in advanced,

Crist.

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Well, the change in behavior when you use -heap-arrays is a big clue. Without it, you have some large array being allocated on the stack. Maybe it's a local array, maybe it's a temporary copy made to satisfy a contihguity requirement. Have you also tried -check arg_temp_created to see if you get any useful diagnostics at run-time?

Retired 12/31/2016

Hi Steve, 

Thank you for your reply. Effectively, the problem was in local arrays... Althought all "my" arrays were defined dynamically, I was using a subroutine from the Fortran 90 numerical recipes, which possesses some internal arrays locally defined. I think that my problem was originated from the old precept about do not modify the subroutines...  

Thanks a lot!

Crist.

Glad to hear it. You could modify those routines to make the local arrays allocatable, allocating them to the desired size. For example, if you had this:

subroutine sub (a,b,n)
integer n
real localarray(n)

you could change it to:

subroutine sub (a,b,n)
integer n
real, allocatable :: localarray(:)
...
allocate (localarray(n))

This would have the behavior you want. Or use -heap-arrays.

Retired 12/31/2016

Quite so!

Now, it is running with a grid 1028x1028, and just takes around 100MB in the RAM memory. Great!

Leave a Comment

Please sign in to add a comment. Not a member? Join today