- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Consider the following array declaration inside a subroutine:
Subroutine my_sub
Use Global_Var
real(8) array(N)
....
end subroutine my_subs
N is a parameter defined inside module Global_var
Is array an automatic array and hence allocated to the stack?
If yes, the only way for it to go to the heap is by making it allocatable? Or is there another way?
Thank you,
Rafael
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What are your compiler options? The default is that local arrays are statically allocated, but this could change if you added /Qopenmp, /parallel or /recursive.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If N is a PARAMETER constant, then this is an ordinary local array that is statically allocated by default. If N is a variable, then it is an automatic array on the stack - it can be placed on the heap by using the /heap-arrays option, though I would recommend making it ALLOCATABLE instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
If N is a PARAMETER constant, then this is an ordinary local array that is statically allocated by default. If N is a variable, then it is an automatic array on the stack - it can be placed on the heap by using the /heap-arrays option, though I would recommend making it ALLOCATABLE instead.
N is declared as a parameter inside a module (Global_var):
integer, parameter :: N = 10
That's curious then: I was having a stack overflow message (I presented here a small generalization of my original problem) and after some investigation I decided to declare"array" as allocatable and the stack overflow message was gone - the code worked. The /heap-arrays option has always been activated. That is why I was wondering whether array would be allocated to the stack... But your answer confused me.
Does the fact that I have lower and upper bounds in array change anything? Also the kind of array is also defined as an integer parameter inside Global_Data... I would guess not, but just checking.
real(KIND=DOUBLE) array(N1:N2,N3:N4)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What are your compiler options? The default is that local arrays are statically allocated, but this could change if you added /Qopenmp, /parallel or /recursive.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
What are your compiler options? The default is that local arrays are statically allocated, but this could change if you added /Qopenmp, /parallel or /recursive.
Yes, you are right, I added /Qopenmp, that makes local arrays automatic by default. Thank you!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page