Re: ALLOCATE and contiguous memory

From: James Giles (jamesgiles_at_worldnet.att.net)
Date: 10/12/04


Date: Tue, 12 Oct 2004 18:36:03 GMT

Richard E Maine wrote:
...
> But for the kind of architecture where one can ask simply about
> contiguity without needing to first write a thesis explaining
> what the term implies, then yes, regular arrays are stored in
> contiguous memory, and allocatables just the same.

All true (including the parts I elided), but beware! If the array
is a dummy argument, especially if declared as an assumed shape
array, and the corresponding actual argument is an array slice,
then the array will possibly (even probably) not be contiguous,
even though it doesn't have the pointer attribute.

I didn't see it mentioned whether the array in question actually
has the ALLOCATABLE attribute in the context where the call
to the C routine is made, or whether it was merely allocated
elsewhere and passed into the context where the C routine is
called. Hence the possible relevance of this issue.

Note also that if your compiler "thinks" the C routine is a Fortran
routine and your call uses array slice syntax, the compiler may be
passing a descriptor that C won't understand. Probably more details
about the OP's code and what symptoms are observed would be
useful.

-- 
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies."   --  C. A. R. Hoare


Relevant Pages

  • Re: [OT] Funny
    ... Every array in f77 occupied a contiguous sequence of ... > array that wasn't contiguous because the standard had no such ... > for all the compiler knows) written in f77. ... > you know that the benefits of contiguity will outweigh the ...
    (comp.lang.fortran)
  • Re: forrtl warning (402)
    ... | You are calling a routine that has an f77-style array argument (* as the ... | the outer, calling routine. ... but if inner is external the same assumption must be made ... but still has a chance to insert a run-time contiguity test before ...
    (comp.lang.fortran)
  • Re: cannot pass variable size array to subroutine
    ... TARGET attribute be treated by the compiler as if they might be ... For SSE code, not knowing whether an array is contiguous is quite ... contiguity which is really needed for the fastest SSE code. ...
    (comp.lang.fortran)
  • Re: auto_array<> [Was: The finally debate]
    ... > objects were contiguous - hence inside an array. ... I don't know what loopholes ... > or changes have emerged since the Standard came out. ... > requires contiguity, ...
    (comp.lang.cpp)
  • Speed versus memory
    ... My initial impulse was to use vector processes everywhere. ... an absurd amount of memory. ... Such a routine only has two input arrays ... and one output array but goes through ten intermediate arrays all of ...
    (comp.lang.fortran)