Re: Array puzzle
- From: Tim Prince <timothyprince@xxxxxxxxxxxxx>
- Date: Thu, 31 Aug 2006 13:55:44 GMT
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:
The original code had basically explicit shape arrays, passed into procedures as automatic or assumed-size arrays. Example:
Program Old
REAL A
INTEGER N
DIMENSION A(30)
N=6
. . .
CALL P1(A)
CALL P2(A,N)
END
SUBROUTINE P1(B)
REAL B
DIMENSION B(*)
B(23) = . . .
END
SUBROUTINE P2(B,N)
REAL B
INTEGER N
DIMENSION B(N,*)
B(3,4) = . . .
END
I don't see any point in worrying about this until performance problems are demonstrated. The only such problem I have run across could not occur except with arrays of rank > 1. If such a procedure is called too often, it would be possible to spend significant time on integer multiplication when figuring out the data layout.
The caution would apply more to platforms which have relatively slow integer multiplication, such as original 32-bit only P4 CPUs.
.
- References:
- Array puzzle
- From: Roy Lewallen
- Array puzzle
- Prev by Date: Re: Array puzzle
- Next by Date: Re: Array subsetting
- Previous by thread: Re: Array puzzle
- Next by thread: Maple to Fortran?
- Index(es):