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

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

Ritratto di Gustavo C.

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.

7 post / 0 new
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Steve Lionel (Intel)

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

Steve
Ritratto di Gustavo C.

Quote:

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.

Ritratto di John Campbell

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

Ritratto di Steve Lionel (Intel)

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.

Steve
Ritratto di John Campbell

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

Ritratto di Steve Lionel (Intel)

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.

Steve

Accedere per lasciare un commento.