I realize that pointing to an allocatable may not normally be necessary. In the actual code that I am modifying I am getting rid of Cray pointers, and I'm trying to keep the structure of the code (variable names, etc.) as close to the original as possible, hence the use of pointers to allocatables.
I'm using a Portland Group compiler:
pgf90 8.0-6 64-bit target on x86-64 Linux -tp k8-64e
You may be right about a compiler bug. I tried using xlf90 and it works fine.
I simply used the forall as a short way to fill the array in the example; I don't normally use them in "real" codes. Just for the heck of it I changed it to a do loop, and it does the same thing.
The seg fault occurs where I fill the array, s(i)=i.
Doug Sondak
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf Of Dick Hendrickson
Sent: Monday, July 04, 2011 3:49 PM
To: [log in to unmask]
Subject: Re: Pointer Problem
I don't see anything obvious. Here's a few suggestions.
Pointing to an allocatable object is unusual (at least to me), you might have hit a compiler bug. I think most people allocate the pointer directly.
What compiler are you using? If it's reasonably old, you should get an update.
FORALL is rarely used and likely to be buggy. If you are using a FORALL, ask yourself why a DO isn't a better choice. It usually is.
Do you know where the seg fault comes from? Try putting in a few PRINT *, "we are here" statements.
Dick Hendrickson
On Mon, Jul 4, 2011 at 1:46 PM, Sondak, Douglas L <[log in to unmask]> wrote:
> I wrote a short code to test a construct involving a pointer to an
> allocatable array, and it results in a seg fault when I run. I'm not
> sure what I'm doing wrong; could someone please take a look at it? Thanks.
>
> Doug Sondak
>
> module alloc_mod
> implicit none
> contains
> subroutine alloc_1d(x,n)
> implicit none
> integer, intent(in) :: n
> real, allocatable, intent(inout), target :: x(:)
> allocate(x(n))
> end subroutine alloc_1d
> end module alloc_mod
> program alloc_test
> use alloc_mod
> implicit none
> integer :: i, nwords = 5
> real, allocatable, dimension(:), target :: x
> real, pointer, dimension(:) :: s => null()
> call alloc_1d(x,nwords)
> s => x
> forall(i=1:nwords) s(i) = i
> print*,'s = ', s
> end program alloc_test
|