- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can someone please remind me if Fortran procedure arguments are passed by reference or by value, I think I have been confusing c and fortran in this regard. Also, does this change at all with attributes like INTENT(in), or with assumed shape arrays? I seem to recall someone saying that assumed shape arrays get added to the stack but I might be mistaken. I am working on re-engineering/rewriting a big scientific code and am trying to find a good balance between (generality/legibility/modularity) and performance (memory and speed constraints, but this question is in regards to memory usage/footprint). Obviously not all of this can be figured out a priori, but more knowledge about this behaviour will help.
Thanks in advance,
-z
(Basically I want to avoid global variable as much as possible and am wondering when there is a memory penalty for doing so.)
Thanks in advance,
-z
(Basically I want to avoid global variable as much as possible and am wondering when there is a memory penalty for doing so.)
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In the usual case (which I'm not prepared to count on when you don't show your code), ifort passes a pointer ("by reference") in a register, or, for longer argument lists, on stack. This isn't inherent in Fortran, but it is the way ifort (and, to my knowledge, all other linux Fortran implementations), do it. INTENT is extremely useful for checking your code, but doesn't affect the mechanism.
Fortran doesn't have anything called a global variable; the term might be applied loosely to either COMMON or MODULE variables, with the latter evidently intended to facilitate modularity.
Passing an array section to a procedure argument with INTENT(in) may involve a temporary array copy on the caller side, which the callee receives "by reference." This is probably the most likely situation which will consume stack or heap space and time unexpectedly.
Fortran doesn't have anything called a global variable; the term might be applied loosely to either COMMON or MODULE variables, with the latter evidently intended to facilitate modularity.
Passing an array section to a procedure argument with INTENT(in) may involve a temporary array copy on the caller side, which the callee receives "by reference." This is probably the most likely situation which will consume stack or heap space and time unexpectedly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so much for clearing this up for me Tim. I appreciate it. (As an aside when I said global variable I meant a common block variable or module variable USEd throughout the code.)

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