Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29278 Discussions

dummy arguments and memory footprint

Izaak_Beekman
New Contributor II
526 Views
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.)
0 Kudos
2 Replies
TimP
Honored Contributor III
526 Views
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.
0 Kudos
Izaak_Beekman
New Contributor II
526 Views
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.)
0 Kudos
Reply