Re: Efficient way to pass different shaped arrays?
- From: "Michael Metcalf" <michaelmetcalf@xxxxxxxxxxxxxx>
- Date: Wed, 28 Jun 2006 22:16:11 GMT
"Peter" <sherwood@xxxxxxxxxxxxxx> wrote in message
news:1151528445.773612.191520@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm attempting to use an array argument of a subroutine for two
different purposes. One, which works fine, has the caller declare an
identical explicit shape array. The other, shown below, has the caller
(A) passing a small number of reals in the same memory space.
Subroutine B knows, via other arguments not shown, which kind of array
argument is being received.
In subroutine A:
REAL, DIMENSION(3) :: array
CALL B(array)
SUBROUTINE B(array)
REAL, DIMENSION(28,0:10001), INTENT(INOUT) :: array
Under CVF6, this worked as expected, but using IVF9, the compiler flags
an error because the extent of 'array' as a dummy argument for B
exceeds the size of the real argument 'array' in A; presumably this is
an error because B could write memory beyond the size of 'array'
declared by the caller.
So, my question is, what is a simple and efficient way to pass in the
3-element array? I don't really want to create a huge 28x10002 array in
the caller, and for efficiency it would be better not to add another
argument (subroutine B gets called many times).
Well, you could use an assumed-shape array. This would require an explicit
interface and also the ranks to be identical. Thus, it might look like:
REAL, DIMENSION(3,1) :: array ! dummy second dimension
CALL B(array)
SUBROUTINE B(array) ! in a module or as an internal procedure
REAL, DIMENSION(:, 0:), INTENT(INOUT) :: array
You can use the lbound and ubound intrinsics to find out the actual bounds
at run time.
This looks like legacy code, so maybe a more extensive makeover would be
useful.
Does that help?
Mike Metcalf
.
- Follow-Ups:
- References:
- Efficient way to pass different shaped arrays?
- From: Peter
- Efficient way to pass different shaped arrays?
- Prev by Date: Re: Fortran refactoring
- Next by Date: Re: Efficient way to pass different shaped arrays?
- Previous by thread: Efficient way to pass different shaped arrays?
- Next by thread: Re: Efficient way to pass different shaped arrays?
- Index(es):
Relevant Pages
|
|