Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Re: Derived Typ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 17 Topic 8194 of 8775
Post > Topic >>

Re: Derived Type Pointer Allocation Issue

by nospam@[EMAIL PROTECTED] (Richard Maine) Apr 30, 2008 at 04:19 PM

Michael <mwpowellnm@[EMAIL PROTECTED]
> wrote:

>     type grid
>       real(kind = rkind), pointer :: x(:)
>       real(kind = rkind), pointer :: y(:)
>       real(kind = rkind), pointer :: sigmaz(:)
>       real(kind = rkind), allocatable :: zg(:,:)
>     end type grid
....
>      type (grid),     intent(out)    :: grid_dat
> 
> After a couple of these function calls, we end up two calls deep in a
> function with the following operation attempted,
> 
>      allocate(grid_dat%x(idim), grid_dat%y(jdim), grid_dat
> %sigmaz(kdim), grid_dat%zg(idim, jdim), stat = allocerr)
> 
> Now, the first time through, for m_grid, the call succeeds. We
> allocate memory properly. The second time through, for c_grid,
> however, the call fails. We consistently fail allocating memory for
> grid_dat%zg.

Hmm. As some others mentioned, lots of things could be going on here.
When messing with things like pointers, it is possible to get memory
badly enough corrupted that apparently unrelated things will fail in
apparently unrelated places. But then, you say it appears consistent, so
maybe things aren't that bad.

If it consistently failes on the second time through, that makes me
think about things like traying to allocate an allocatable that is
already allocated. That isn't allowed. I could well imagine the variable
getting allocated the first time through, and then failing on the second
time because the variable is already allocated.

Now the intent(out) ought to automatically deallocate grid_dat%sz on
entry. Actually, I haven't checked to find exactly where the standard
says that, but intuitively, that's the way it seems like it ought to be,
so I suspect the standard says it and I'm too lazy right now to check.
But...

That's a bit subtle. I wonder if the compiler might miss doing it. In
any case, I'd personally deallocate the thing when I was done with each
time anyway. Call it just a style preference on my part. You might try
it just to see if that happens to solve the problem. It "shouldn't" make
any difference, but I'd think it worth trying.

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




 17 Posts in Topic:
Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-04-30 14:05:06 
Re: Derived Type Pointer Allocation Issue
fj <francois.jacq@[EMA  2008-04-30 14:26:51 
Re: Derived Type Pointer Allocation Issue
Dick Hendrickson <dick  2008-04-30 21:40:38 
Re: Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-04-30 15:46:10 
Re: Derived Type Pointer Allocation Issue
nospam@[EMAIL PROTECTED]   2008-04-30 16:19:00 
Re: Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-04-30 16:25:12 
Re: Derived Type Pointer Allocation Issue
nospam@[EMAIL PROTECTED]   2008-04-30 16:38:24 
Re: Derived Type Pointer Allocation Issue
Steve Lionel <steve.li  2008-05-01 00:48:02 
Re: Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-04-30 16:27:59 
Re: Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-04-30 16:47:01 
Re: Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-05-01 08:15:12 
Re: Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-05-01 08:28:04 
Re: Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-05-01 09:03:30 
Re: Derived Type Pointer Allocation Issue
Steve Lionel <steve.li  2008-05-04 01:05:45 
Re: Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-05-01 12:48:23 
Re: Derived Type Pointer Allocation Issue
Dick Hendrickson <dick  2008-05-01 20:10:24 
Re: Derived Type Pointer Allocation Issue
Michael <mwpowellnm@[E  2008-05-01 14:08:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 8:46:48 CDT 2008.