Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Subroutine local and saved derived type with allocatable
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
legu  
View profile  
 More options Jun 5 2008, 12:54 pm
Newsgroups: comp.lang.fortran
From: legu <boole...@gmail.com>
Date: Thu, 5 Jun 2008 09:54:54 -0700 (PDT)
Local: Thurs, Jun 5 2008 12:54 pm
Subject: Subroutine local and saved derived type with allocatable
Hi,

in a subroutine, I have a local variable which is a derived type t_1
that contains an allocatable array f1, this local variable is SAVEd,
like this:    type(t_1), save :: d
After a conditional test on allocated(d%f1), the variable's member is
allocated or not, in such a way it is allocated once, when the
subroutine is first called.

With ifort (10.1,linux), it works as expected, but gfortran (4.2.1,
4.2.3, X 10.5.3) doesn't keep d%f1 allocated and it is allocated each
time the subroutine is called.

Is it a bug of gfortran ?
How can I check for memory leaking ?

Thx,
Legu.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Maine  
View profile  
 More options Jun 5 2008, 1:18 pm
Newsgroups: comp.lang.fortran
From: nos...@see.signature (Richard Maine)
Date: Thu, 5 Jun 2008 10:18:46 -0700
Local: Thurs, Jun 5 2008 1:18 pm
Subject: Re: Subroutine local and saved derived type with allocatable

legu <boole...@gmail.com> wrote:
> in a subroutine, I have a local variable which is a derived type t_1
> that contains an allocatable array f1, this local variable is SAVEd,
> like this:    type(t_1), save :: d
> After a conditional test on allocated(d%f1), the variable's member is
> allocated or not, in such a way it is allocated once, when the
> subroutine is first called.

Standard response number 1 to questions asking for help with code: show
the code instead of describing it. This is *VERY* common, not specific
to you. I just use "you" below because it is easier to write that way,
rather than to say anything personal.

If you need help with the code, that pretty much implies that you don't
have a thorough understanding of all the possible factors that could be
relevant. Thus, your description could easily fail to mention what turn
out to be the most important parts. People can spend an awful lot of
time trying to debug something based on a description that turns out not
to have the data critically needed to answer the questions.

In your particular case, the description actually sounds pretty coherent
and does mention those things that occur to me as the most obvious. So
perhaps you have described it adequately. The description does make it
sound like a compiler bug. Nonetheless, I, at least, am not willing to
draw conclusions about it illustrating a compiler bug based solely on
such a description, without seeing code, preferably a complete, testable
example. Shouldn't be hard to do an example of that unless there are
subtle interactions with other things such that the problem goes away in
small examples.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
legu  
View profile  
 More options Jun 5 2008, 3:52 pm
Newsgroups: comp.lang.fortran
From: legu <boole...@gmail.com>
Date: Thu, 5 Jun 2008 12:52:37 -0700 (PDT)
Local: Thurs, Jun 5 2008 3:52 pm
Subject: Re: Subroutine local and saved derived type with allocatable
You're right Richard, I'm working on a minimalist working example (the
code is pretty big).

Meanwhile, is there a sound reason (fortran standard ?) which could
explain the allocatable member of a subroutine local and saved derived
type is always reported as not allocated ?

Legu


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
legu  
View profile  
 More options Jun 5 2008, 4:08 pm
Newsgroups: comp.lang.fortran
From: legu <boole...@gmail.com>
Date: Thu, 5 Jun 2008 13:08:05 -0700 (PDT)
Local: Thurs, Jun 5 2008 4:08 pm
Subject: Re: Subroutine local and saved derived type with allocatable
Program main

type derived_type
  real, allocatable :: array(:)
end type derived_type

call test()
call test()

contains

subroutine test()
type(derived_type), save :: local

if ( allocated(local%array) ) then
  print*,'already allocated'
else
  allocate( local%array(1) )
  print*,'allocated'
end if

end subroutine test
end program main

With gfortran 4.2.1, 4.2.3 on os X 10.5.3, this gives:
 allocated
 allocated

whereas, with ifort 10.1 on linux, it gives the expected:
 allocated
 already allocated


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Van Buskirk  
View profile  
 More options Jun 5 2008, 5:32 pm
Newsgroups: comp.lang.fortran
From: "James Van Buskirk" <not_va...@comcast.net>
Date: Thu, 5 Jun 2008 15:32:36 -0600
Local: Thurs, Jun 5 2008 5:32 pm
Subject: Re: Subroutine local and saved derived type with allocatable
"legu" <boole...@gmail.com> wrote in message

news:53952ff2-5878-4ca4-96aa-da5c4ef1ff21@h1g2000prh.googlegroups.com...

> With gfortran 4.2.1, 4.2.3 on os X 10.5.3, this gives:
> allocated
> allocated

C:\gfortran\clf\component_test>type component_test1.f90
Program main

type derived_type
  real, allocatable :: array(:)
end type derived_type

call test()
call test()

contains

subroutine test()
type(derived_type), save :: local

if ( allocated(local%array) ) then
  print*,'already allocated'
else
  allocate( local%array(1) )
  print*,'allocated'
end if

end subroutine test
end program main

C:\gfortran\clf\component_test>gfortran
component_test1.f90 -ocomponent_test1

C:\gfortran\clf\component_test>component_test1
 allocated
 already allocated

C:\gfortran\clf\component_test>gfortran -v
Using built-in specs.
Target: x86_64-pc-mingw32
Configured with:
../gcc/configure -q --prefix=/var/tmp/w64 --with-sysroot=/var/t
mp/w64 --host=x86_64-pc-mingw32 --target=x86_64-pc-mingw32 --silent
Thread model: win32
gcc version 4.4.0 20080528 (experimental) (GCC)

gfortran has been getting better lately.  Many errors I see posted
here are fixed in more recent versions.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Maine  
View profile  
 More options Jun 5 2008, 7:05 pm
Newsgroups: comp.lang.fortran
From: nos...@see.signature (Richard Maine)
Date: Thu, 5 Jun 2008 16:05:41 -0700
Local: Thurs, Jun 5 2008 7:05 pm
Subject: Re: Subroutine local and saved derived type with allocatable

legu <boole...@gmail.com> wrote:

[excellent code sample]

> With gfortran 4.2.1, 4.2.3 on os X 10.5.3, this gives:
>  allocated
>  allocated

> whereas, with ifort 10.1 on linux, it gives the expected:
>  allocated
>  already allocated

I'd say that was pretty clear and definitive. Sounds like a gfortran
bug. Though as James said, perhaps it might have been fixed in a later
version.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Franke  
View profile  
 More options Jun 6 2008, 5:15 am
Newsgroups: comp.lang.fortran
From: Daniel Franke <nos...@nowhere.com>
Date: Fri, 06 Jun 2008 11:15:50 +0200
Local: Fri, Jun 6 2008 5:15 am
Subject: Re: Subroutine local and saved derived type with allocatable

legu wrote:
> With ifort (10.1,linux), it works as expected, but gfortran (4.2.1,
> 4.2.3, X 10.5.3) doesn't keep d%f1 allocated and it is allocated each
> time the subroutine is called.

> Is it a bug of gfortran ?

In those versions, allocatable components have some rough edges left. This
is being worked on. However, from your description it is very likely that
it's a compiler bug. If it turns out to be (from the minimal example you
are working on), could you please also file a PR at gcc.gnu.org/bugzilla?

> How can I check for memory leaking ?

Try valgrind (www.valgrind.org).

Thanks

        Daniel


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tobias Burnus  
View profile  
 More options Jun 7 2008, 2:51 am
Newsgroups: comp.lang.fortran
From: Tobias Burnus <bur...@net-b.de>
Date: Fri, 6 Jun 2008 23:51:37 -0700 (PDT)
Local: Sat, Jun 7 2008 2:51 am
Subject: Re: Subroutine local and saved derived type with allocatable
On 6 Jun., 11:15, Daniel Franke <nos...@nowhere.com> wrote:

> > With ifort (10.1,linux), it works as expected, but gfortran (4.2.1,
> > 4.2.3, X 10.5.3) doesn't keep d%f1 allocated and it is allocated each
> > time the subroutine is called.
> However, from your description it is very likely that
> it's a compiler bug.

It is a compiler bug, but it is fixed in 4.3.x (and 4.4.0). As it is
no regression, it is extremely unlikely that the fix will be
backported to 4.2.x, especially as there is the general notion that
4.3 is a good version.

4.4.0 binaries (nightly developer builds)* are available from:
http://gcc.gnu.org/wiki/GFortranBinaries#MacOS

Tobias

* Highlights of 4.4 currently are OpenMP 3 support and some more
Fortran 200x features (http://gcc.gnu.org/wiki/GFortran#news) plus a
couple bugfixes [153 bugreport/feature request numbers for this year's
commits].


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
legu  
View profile  
 More options Jun 7 2008, 5:40 pm
Newsgroups: comp.lang.fortran
From: legu <boole...@gmail.com>
Date: Sat, 7 Jun 2008 14:40:58 -0700 (PDT)
Local: Sat, Jun 7 2008 5:40 pm
Subject: Re: Subroutine local and saved derived type with allocatable
On Jun 7, 12:51 am, Tobias Burnus <bur...@net-b.de> wrote:

I found this bug report submitted earlier this year as I was looking
for reporting it. With gfortran 4.4 it works fine, thanks.

Legu.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »