Re: Efficient way to pass different shaped arrays?



Peter wrote:

(snip)

Efficiency is paramount here, because B is called millions of times. So
I am reluctant to use any method which adds execution time. I guess
that for an assumed-shape array, the address computations are more
time-consuming, since the dimensions are not compile-time constants,
but run-time variables.

For an assumed shape array the rank must match, but (3,0:0) isn't
that much more work. For assumed size it is something like second
subscript times 28 plus first subscript plus some constant.

For assumed shape it has to do two multiplies, as the array could
be in non-contiguous storage, loading the multipliers from the
descriptor. As Richard indicates, that may or may not make a big
difference. If you make the first subscript constant and 32, it
might be able to use a shift instead of a multiply, but it will
also take somewhat more memory, and not as much of the array will
stay in the cache. Most likely that doesn't help.

The bounds of the array are being passed as separate arguments now.

If the bounds are being passed, use either the passed bounds or
a * (or 0:*) for the second subscript. With assumed size, even
without a constant first subscript you might still do a little
better than assumed shape.

Or keep it the first at 28 and pass a 28 element array.

I agree with Richard that the only way to be sure is to time it.

-- glen

.



Relevant Pages

  • Re: Ideal Fortran
    ... (snip on column major array order) ... If you use the first subscript for row and the second for ... array is stored in the wrong order for printing out as ... When actually writing processing code (as opposed to I/O), ...
    (comp.lang.fortran)
  • Re: internal procedure cant use array of derived type from main
    ... Richard Maine wrote: ... >host association. ... All the subroutine really needs to know is the array index, ... Richard E. Hawkins, Asst. ...
    (comp.lang.fortran)
  • Re: Seriously struggling with C
    ... from the high end to the low end of an array. ... const unsigned char *p2 = s2; ... It was a contrived example for my "exactly perfect" claim. ... I was responding to this false claim by Richard Harter: ...
    (comp.lang.c)
  • Re: Gaussian statics law
    ... Richard you are taking things out of context since the arrays ... "Terman was referring to close spaced of the parasitic form, ... and he also mentions the Yagi array. ... he wrote the comments on page 185 in "Antennas". ...
    (rec.radio.amateur.antenna)
  • Re: print variable inside function
    ... Richard it is great that you are at least throwing out code that you are trying, keep up the effort and continue to come back here for help. ... But to experiment blindly can be dangerous and at best frustrating, but I do love the challenge of solving a particular problem on my own. ... I hate package solutions, don't seem to learn much from them. ... Indexing an array with a variable is one of the fundamental things to do with an array, and is clearly demonstrated in the manual. ...
    (comp.lang.php)