Re: Derived type argument to subroutine
- From: *** Hendrickson <***.hendrickson@xxxxxxx>
- Date: Thu, 17 Apr 2008 12:43:58 GMT
Gib Bogle wrote:
Richard Maine wrote:If you're interested in fine scale performance, then big data types canGib Bogle <g.bogle@xxxxxxxxxxxxxxxxxxxxxx> wrote:
My question is motivated by concern about performance. I assume that
when I pass a variable that is a derived type as an argument to a subroutine, is it passed by reference, just as fundamental types are.
1. The standard does not specify that *ANYTHING* is passed by reference.
In practice, they often, but not always are. It is just plain incorrect
to say that "fundamental types are passed by reference". While they
sometimes are, they sometimes aren't. There are even some cases where
they pretty much cannot be.
2. However, that being said, it is just as likely that a derived type
object will be passed by reference. For the most part, the issues simply
don't have much to do with type. It is things orthogonal to type that
are much more important to the question of how arguments are passed. If
anything, to the extent that type matters, I would say that it is the
fundamental types that have greater odds of being passed by something
other than reference.
3. But as you say that your question is motivated by performance issues,
I'd say that you have expressed it in terms that don't really capture
that. Presumably, you don't really care so much about whether it is
passed by reference as whether it has performance comparable to that
expected of pass-by-reference. The answer to that is basically yes.
4. But to reiterate a point made above - a really, really important
point worthy of reiteration - type is *NOT* the most important factor
here. You can get copy-in/copy-out argument passing that can (in some
cases) cause really horrid performance. But the things that typically
trigger that have nothing to do with type. They have much more to do
with array issues and apply to all types.
Thanks. Some code timing with a range of sizes of my derived type convinced me that there is no significant performance penalty for large types on my system, and as you point out that's all I'm really concerned about.
sometimes help. Something like
real, dimension(100000) :: x,y,z
is likely to require 3 cache lines. Whereas, if you put scalar
x, y, and z in a type and declare an array of 100000 of that type,
then references to %x, %y, and %z are likely to only use one cache
line.
*** Hendrickson
.
- References:
- Derived type argument to subroutine
- From: Gib Bogle
- Re: Derived type argument to subroutine
- From: Richard Maine
- Re: Derived type argument to subroutine
- From: Gib Bogle
- Derived type argument to subroutine
- Prev by Date: Re: Derived type argument to subroutine
- Next by Date: Re: Is this standard-conforming code?
- Previous by thread: Re: Derived type argument to subroutine
- Next by thread: Re: Derived type argument to subroutine
- Index(es):