Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Allocatable, heap arrays, segmentation...

Cristian_M_
Beginner
424 Views

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.

0 Kudos
4 Replies
Steven_L_Intel1
Employee
424 Views

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?

0 Kudos
Cristian_M_
Beginner
424 Views

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.

0 Kudos
Steven_L_Intel1
Employee
424 Views

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.

0 Kudos
Cristian_M_
Beginner
424 Views

Quite so!

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

0 Kudos
Reply