- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
I get a stackoverflow when adding two allocated arrays, so it seems to make a temporary array on the stack:
program main integer :: n=160000 integer*8, dimension(:), pointer :: a,b,c allocate(a(n)) allocate(b(n)) allocate(c(n)) a(:)=1 b(:)=2 c = a+b ! forrtl: severe (170): Program Exception - stack overflow end program
It does not fail if I make a loop and add one element at the time.
Is there a better way to avoid this?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I realized that I can use the compiler flag /heap-arrays[:size]
Is there any drawbacks of using this flag and how big should size be?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The size should be zero (i.e. /heap-arrays:0).
Why are your arrays pointers? Do they need to be? The compiler often has to assume that things that can be aliased (pointers and targets) are aliased (i.e. perhaps `c` is the same things as `a` or `b`)- the creation of temporaries is one of the consequences of this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you @IanH for the reply.
Is there any overhead when using /heap-arrays:0
I think the reason for using pointers instead of allocatable was that the arrays are declared in a type, and previous compilers did not like that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/heap-arrays means that storage for temporaries will be on the heap. Setting aside that storage is typically slower than setting aside storage on the stack.
Allocatable components are commonly supported and are a much better solution if you don't need the reference semantics of pointers.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page