- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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.
コピーされたリンク
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
The stack overflow error should have a traceback that points to either the subroutine/function statement or the array declaration. What is "large"?
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
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.
