Re: Array puzzle
- From: Roy Lewallen <w7el@xxxxxxxxx>
- Date: Thu, 31 Aug 2006 15:23:49 -0700
Jugoslav Dujic wrote:
Roy Lewallen wrote:
| I'm a relatively inexperienced Fortran programmer, so please go gently.
| | While looking through the IVF documentation, I learned that it's
| inefficient to pass an assumed shape or allocatable array to a
| procedure, inside of which it's referenced as a non-deferred shape
| array. Further reading discourages using assumed size arrays. So I
| looked through the very old code I'd been using for some time, and found
| this:
Um, could you please point to that particular piece of documentation?
It doesn't seem quite true, especially regarding allocatable arrays (which, once allocated, behave quite like "normal" explicit-shape
arrays).
Virtually the same wording can be found at the bottom of the page at http://www.nersc.gov/vendor_docs/intel/f_ug2/prg_arrs.htm. A web search found it several other places, including Compaq documentation.
The basic issue at stake is *contiguity* of the array [section] passed
as the real argument for an assumed-size or explicit-shape dummy. If the
section (can be proven to be) discontiguous, a "copy-in/copy-out" to/from
a stack temporary must be generated, causing a performance penalty in most
cases. For assumed-shape dummies, that is [almost] never an issue.
My understanding of the explanation in the documentation is that this is indeed the case. Maybe I'm just not paraphrasing it properly -- a lot of the array terminology is new to me.
> . . .
The example you provide is standard-conforming, and uses "sequence association" between elements of arrays of different rank. The>
following works for me on IVF 0.0.029 for Windows:
Program Old
REAL A
INTEGER N
DIMENSION A(30)
> INTERFACE
> SUBROUTINE P2(B,N)
> REAL B
> INTEGER N
> DIMENSION B(N,*)
> END SUBROUTINE
> END INTERFACE
> . . .
As I mentioned, I modified the program some time ago to make A allocatable. So it seemed to me that when I pass it to the subroutines in my example, it violates the guideline in the Intel (and other) documentation. Your routine seems to be doing exactly what I have now, which I thought was the case to be discouraged. I tried in the P1 INTERFACE block to declare:
SUBROUTINE P1(B)
REAL :: B(:)
which works fine, but I can't find any similar thing I can do in P2's INTERFACE block. I get one error if I declare it B(:) and a different one if I declare it (:,:).
. . .
Roy Lewallen
.
- Follow-Ups:
- Re: Array puzzle
- From: Richard E Maine
- Re: Array puzzle
- Prev by Date: Re: Fortran code styles
- Next by Date: Re: Array puzzle
- Previous by thread: Re: Fortran code styles
- Next by thread: Re: Array puzzle
- Index(es):
Relevant Pages
|