Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29253 ディスカッション

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

Gustavo_C_1
ビギナー
657件の閲覧回数

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 件の賞賛
6 返答(返信)
Steven_L_Intel1
従業員
657件の閲覧回数

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

Gustavo_C_1
ビギナー
657件の閲覧回数

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.

John_Campbell
新規コントリビューター II
657件の閲覧回数

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

Steven_L_Intel1
従業員
657件の閲覧回数

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.

John_Campbell
新規コントリビューター II
657件の閲覧回数

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

Steven_L_Intel1
従業員
657件の閲覧回数

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.

返信