Re: Array puzzle



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:
(snip)

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.

As far as I know, for some (maybe most) compilers, the copy is done if
it can't be proven to be contiguous. Maybe others will know for
specific compilers.

Now, how is that contiguity tested is an issue for itself. I find a blanket statement of "inefficient" to be too vague and imprecise to
be useful.
(snip)

Also, the cache will often be more efficient on a contiguous array,
so if each element is being accessed many times it may be more efficient
with the copy, even including the overhead of doing the copy.

-- glen

.



Relevant Pages

  • Re: Directly Modify Vector Item
    ... I didn't say it was inefficient. ... With an array in C+ ... one can directly manipulate the memory pointed to by any indexed ... array's base memory location. ...
    (comp.lang.java.programmer)
  • Re: How to randomize foreach
    ... help of the Benchmark module, and code that created the array ... and then spliced it randomly using those inefficient methods, ... So, if you don't have a really big array, ... Output including module loading: ...
    (comp.lang.perl.misc)
  • Re: Newbie question > Hash workings
    ... Actually this is very inefficient. ... This gives you the benefit of creating a new array when necessary, but means that you only get permanent effects if you explicitly use assignment, so you don't get this ... Of course, it means you can't use the << operator to stick values into non-present keys, but I rarely use the << operator anyway. ... approach has no means to efficiently work with Arrays as Hash values. ...
    (comp.lang.ruby)
  • Re: setting values in associative array to 0
    ... Inefficient? ... efficient way of modifying elements in an array, ... likely to be so small that it barely registers. ...
    (comp.lang.php)
  • Writing to a particular position
    ... want to append a text into this file at a specific position; ... storing the text content in an array and manipulating and writing this ... array to the file, but this seems inefficient to me too. ...
    (microsoft.public.dotnet.languages.csharp)