Re: MODULEand USE versus Argument Passing



Herman D. Knoble wrote:

Given a Subprogram that gets called millions of times,
we know that there is (CPU) overhead for subprogram linkage.

My question is, independent of compilers,
which is more efficient in practice:

passing a list of (say 3 to 10) arguments
to a subprogram's corresponding parameters,
OR using a Module and companion USE statement,
OR use named COMMON?

Global variables are *always* a bad idea. Never pass function arguments through modules or common storage.

There is almost nothing
that modern computers do faster than [subprogram] calls.
You won't be able to measure the time that your function
spends on subprogram calls unless the subprogram does nothing.
A good optimizing compiler can "inline" lightweight
subprograms if the definition is visible at compile time --
if the subprogram is defined in the same source file
or in a module used by your program.

If your subprogram has more than a few arguments,
you probably have a design problem.
If some of the arguments can be grouped into larger objects,
create a derived type which contains them
and pass an object of that type to the function
instead of the separate arguments.
.



Relevant Pages

  • Re: call by reference
    ... It specifies the semantics of subprogram calls, ... > of pass by reference, but that can also be implemented with value-result ... Fortran compilers exist, I believe, ... Is the behavior of similar code in FORTRAN really undefined? ...
    (comp.lang.java.programmer)
  • Re: Help needed for a sorting code in the literature
    ... John E. Hadstate wrote: ... >>and yet have a subprogram such that one could simply call ... >>I would regard it as an inconvenience for the programmers. ... current compilers of certain PLs emit intermediate codes ...
    (sci.crypt)
  • Re: More odd code that seems to work
    ... > Why aren't arguments specified in the EXTERNAL statement? ... I think a better way to look at it is that the f77 language standard ... If the dummy subprogram is never called, then I do not know if the ... information to diagnose argument mismatches at compile time. ...
    (comp.lang.fortran)
  • Re: fortran question
    ... The array contains many different unrelated variables, ... Within the subprogram, a lengthy Equivalence ... variable of the derived type around: ... subroutine my_subroutine ...
    (comp.lang.fortran)