On Wednesday, May 1, 2002, at 11:09 AM, David Byrne wrote:
> List Members:
>
> I'm bumping up against the f90 limit on the number of
> dimensions in an array (7) and wonder if anyone has
> suggestions for avoiding this.
>
> I would like to be able to store the values of a function
> in an array where the coordinates of a point in the array
> correspond to the arguments of the function.
> Unfortunately, my function has more than seven arguments.
>
> My most recent attempt to deal with this involved storing
> the function values in a vector instead of an array. I wrote a
> little routine that converts the arguments of the function
> to a scalar corresponding to the right element of the
> array. However, I use this function so often that when running a
> profiler, I discovered the
> program spends 60% of the time in this little routine. So
> this approach won't work.
>
> I wonder whether it's possible to work around the seven dimension
> limit by writing a derived type.
>
> Any suggestions on the issue would be very much appreciated.
>
> David Byrne
> University of Virginia Economics
> [log in to unmask]
>
>
If I gather correctly that your function is actually a lookup table
stored in an array, and you have the good luck/wonderful design that
your function arguments are always integers from a contiguous set so
they can be used as array index references, then I suggest looking more
carefully at your function that calculates the linear index, because it
shouldn't be a massive computational problem. A former graduate student
here did this for a nine-dimensional case, and her arithmetic was
similar to what must be going on inside the compiled code for each
multi-dimensional array reference, something like
I = I1 + (I2 - L2) * S1 + (I3 - L3) * S2 * S1 + (I4 - L4) * S3 * S2 *
S1 + ...
where Ix is the index position in the indicated dimension, Lx is it's
lower bound (default 1), and Sx is its size. If, as should usually be
the case for a lookup table, the L's and the S's can be hardcoded or set
with a parameter attribute, your compiler should be able to optimize the
daylights out of this and it just shouldn't be a major part of your
calculation time. The trick may be that if you are using a function,
are you getting the L's and S's into the function in a such a way that
the compiler knows they're parameters and can optimize out the
subcalculations?
A derived type could work, I suspect, but I can't imagine it being
faster than an index calculation.
Brian Hanson
Center for Climatic Research
University of Delaware
|