For Programmers: Free Programming Magazines  


Home > Archive > Fortran > February 2005 > reshape problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author reshape problem
Alfredo Buttari

2005-02-18, 3:59 pm

Hi,
does reshape() work with pointers?
This is my problem:

program tryreshape

integer,allocatable :: vect1(:),resh1(:,:)
integer,pointer :: vect(:),resh(:,:)
integer :: vect2(2*4), resh2(2,4)
integer :: r, s(2)

r=2; nb=4

s(:)=(/r,nb/)

allocate(vect(nb*r),vect1(nb*r))
allocate(resh(r,nb),resh1(r,nb))

vect =1
vect1=1
vect2=1

write(*,'("Reshaping to ",1(i1.1,"x"),i2.2)')s

! THIS WORKS
resh2 = reshape(vect2,s)
write(*,'("resh2: ",1(i3,2x))')resh2(1,1)

! THIS WORKS
resh1 = reshape(vect1,s)
write(*,'("resh1: ",1(i3,2x))')resh1(1,1)

! THIS DOESN'T
resh = reshape(vect,s)
write(*,'("resh : ",1(i3,2x))')resh(1,1)

end program tryreshape

With gfortran4.0 (7th november snapshot) I got a segfault on the
pointers' case.
With ifc8.1 everything works except when dimensions become high (in
wich case also the allocatables segfault).

Thank you very much

Alfredo

Richard E Maine

2005-02-18, 3:59 pm

In article <1108749275.625623.200750@f14g2000cwb.googlegroups.com>,
"Alfredo Buttari" <pitagoras@tin.it> wrote:

> does reshape() work with pointers?


Yes. There's nothing particularly special about them for reshape. Your
code looks fine to me to visual inspection.

> With gfortran4.0 (7th november snapshot) I got a segfault on the
> pointers' case.


Then you might want to send it to the gfortran folk.

> With ifc8.1 everything works except when dimensions become high (in
> wich case also the allocatables segfault).


That's almost bound to be something like a stack space limit, which has
nothing directly to do with the validity of the code. Stack space limit
issues are pretty much a faq; google should find plenty on it.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
Donald R. Fredkin

2005-02-18, 8:57 pm

"Alfredo Buttari" <pitagoras@tin.it> wrote in news:1108749275.625623.200750
@f14g2000cwb.googlegroups.com:

> does reshape() work with pointers?


Your example works fine with g95.
Thomas Koenig

2005-02-19, 8:56 am

Richard E Maine <nospam@see.signature> wrote:
>In article <1108749275.625623.200750@f14g2000cwb.googlegroups.com>,
> "Alfredo Buttari" <pitagoras@tin.it> wrote:


[color=darkred]
>Then you might want to send it to the gfortran folk.


I have submitted this as bug report http://gcc.gnu.org/PR20074 .
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com