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

Is it possible to issue compiler warnings about large automatic arrays?

Gustavo_C_1
Beginner
632 Views

Hi there,

By a mistake of mine, an automatic array was failing to be created due to the large required size. It took me some time to understand that this was the reason for the stack overflow. Is there a compiler option to warn about this? I mean, possibly large automatic arrays in general.

Thanks in advance.

0 Kudos
6 Replies
Steven_L_Intel1
Employee
632 Views

The stack overflow error should have a traceback that points to either the subroutine/function statement or the array declaration. What is "large"?

0 Kudos
Gustavo_C_1
Beginner
632 Views

Steve Lionel (Intel) wrote:

The stack overflow error should have a traceback that points to either the subroutine/function statement or the array declaration. What is "large"?

Yes, it dit. Nevertheless it took me some time to realize what was exactly wrong. Since I'm using recursion, I thought maybe something was wrong with this. I didn't notice that 10^6 was being passed as the size to an automatic array of doubles. I think using the flag /heap-arrays would have avoided this.

0 Kudos
John_Campbell
New Contributor II
632 Views

Could there be a compiler option to allocate large automatic arrays ( as small as 10 to 20k) via malloc, rather than on the stack ?
Couldn't this be a preferred default response ?
This would certainly mitigate a lot of these stack overflow errors.

John

0 Kudos
Steven_L_Intel1
Employee
632 Views

One might expect the optional value for the /heap-arrays switch to do this, but it does not test the size at run-time. It greatly complicates the code to dynamically decide where to allocate a temporary, so we'd rather not do this.

My advice is to use /heap-arrays and/or make local "automatic" arrays allocatable instead. The headaches it will save you more than make up for the few microseconds of run time.

0 Kudos
John_Campbell
New Contributor II
632 Views

Steve,

I can't see the complication, as there are far more complex run time tests than to decide if an array is > 20k.
Stack overflow errors are annoying problems and a significant proportion could be avoided by this approach.

I certainly agree with the approach of not using automatic arrays, as at present, allocatable are more robust. Automatic are typically a "lazy" approach and can be a symptom of omitting an array from the argument list.

John

0 Kudos
Steven_L_Intel1
Employee
632 Views

It isn't the test that is the problem, it's having to always use a pointer to identify where the array is allocated. I agree it doesn't seem like a big deal, but it can hurt optimization.

0 Kudos
Reply