Richard Maine writes:
>
> I *REALLY* think that the best solution is to annoy the vendor enough
> so that they fix the abysmal performance of the compiler in this area.
[...]
In general, I agree with Richard. My experience is that even with a
_good_ compiler, there are still many ways a programer can scew it up.
Aleksandar Donev writes:
>
> When passing an array pointer as an actual for an assumed-size (i.e.
> contiguous) array, temporaries may be created even if not needed (i.e.
> even if the storage space with which the pointer is associated is
> continuous). I need to find a way to get around this and am having
> trouble coming up with one.
>
> The trick I want to use is to pass only the first element of the array,
> but this doesn't work:
[...]
Well, in case of compiler creating temporary (copy-in/copy-out), I
don't think you solution works. For x(1), a compiler has more reason to
create temporary.
In cases similar to your example, I normally add one intemediate
interface:
module m_test
contains
subroutine test_n(a,n)
integer,intent(in) :: n
real ,intent(??) :: a(n)
call test(a(1)) ! shouldn't it be "test(a(1),n)"?
end subroutine test_n
end module m_test
program main
use m_test,only : test_n
real,dimension(:),pointer :: pa
pa => [...] ! are you sure it is contiguous?
call test_n(pa) ! if it copies, it would be here.
end program main
In main(), a compiler may have a better chance _not_ to create temporary
as in your example, because of the presence of the explicit interface.
On the other hand, module procedure test_n() is implemented in a
standard conforming manner.
Jing
[the rest of the message is kept for reference]
>
> interface
> subroutine test(array)
> real, dimension(*) :: array
> end subroutine test
> end interface
>
> real, dimension(:), pointer :: x
> call test(x) ! May cause a temporary
>
> call test(x(1)) ! This trick DOES NOT WORK--it is forbidden by the
> standard
> ! (why does the standard have to be soo precise :)
> ! call test(x(1:1)) is also not an option since it is very likely to
> fail
>
> The only alternative I can think of is to lie in the interface
> declaration and hope things work (when interfacing to C one needs to go
> "beyond" the standard anyway, so this is OK):
>
> interface
> subroutine test(array)
> real :: array ! Lie about rank
> end subroutine test
> end interface
> call test(x(1)) ! It should work
>
> Does anyone know a different solution that is "safer" then this one?
>
> Many thanks,
> Aleksandar
>
--
________________________________ _-__-_-_ _-___---
Jing Guo, [log in to unmask], (301)614-6172(o), (301)614-6297(fx)
Data Assimilation Office, Code 910.3, NASA/GSFC, Greenbelt, MD 20771
|